このステップでは、コンボを達成したときに新しい武器をプレイヤーに付与するためにアイテム グランターの仕掛けを使用する、ガン ゲーム風の武器レベルアップ システムを Verse で作成します。
島を編集する
ビューポートまたは [アウトライナー] パネルで [島設定] の仕掛けを選択します。
[詳細] パネルで、以下のパラメーターを設定します。
[無限予備弾薬] を [True] に設定します。
[無限マガジン弾薬] を [False] に設定します。 この変更により、プレイヤーはリロードが必要になります。これは多くのフォートナイトの武器における重要な要素です。
ビューポートまたは [アウトライナー] パネルで [アイテムグランター] の仕掛けを選択します。
[詳細] パネルで、以下のパラメーターを設定します。
[On Grant Action (付与時のアクション)] を [Clear Inventory (インベントリをクリア)] に設定します。
[Grant (付与)] を [Current Item (現在のアイテム)] に設定します。
[Index List (インデックスリスト)] の全ての要素を削除し、次の 5 つの要素を追加します。
Assault Rifle L1 (アサルト ライフル L1)
レバーアクションライフル L2
ヘビーショットガン L3
シックスシューター L4
ハンドキャノン L5
[受け取るプレイヤー] を [全て] に設定します。
[Grant on Cycle (切り替え時にアイテムを付与)] を [True] に設定します。
[Grant on Game Start (ゲーム開始時に付与)] を [True] に設定します。
[Enable and Grant Item (有効化してアイテムを付与)] 関数バインディングを削除します。
ビューポートまたは [アウトライナー] パネルで [スコアマネージャー] の仕掛けを選択します。
[詳細] パネルで [Display Score Update on HUD (スコアの更新を HUD に表示)] を [True] に設定します。
Verse コードを書く
このページでは、コード変更をステップごとに案内します。作業内容を確認したい場合は、最終結果として「完全なコード」セクションを参照してください。
shooting_range_manager_device.verseファイルを開きます。アイテムグランターの仕掛けへの参照と、アイテム レベルのプロパティを追跡するための以下の変数を追加します。
Verse@editable ItemGranter:item_granter_device = item_granter_device{} @editable MaxWeaponLevel:int = 5 var CurrentWeaponLevel:int = 1IncreaseWeaponLevelメソッドを追加し、武器レベル変数を増加させて次のアイテムに切り替えます。Verse# Increases the player's weapon level by one (up to the maximum value). IncreaseWeaponLevel():void= if: # If able to retrieve the first player and current weapon level isn't maxed, then... Player:player = GetPlayspace().GetPlayers()[0] CurrentWeaponLevel < MaxWeaponLevel then: # Increase weapon level and cycle to the next item. set CurrentWeaponLevel += 1 ItemGranter.CycleToNextItem(Player)OnComboTargetHitメソッドを修正し、IncreaseWeaponLevelを呼び出すようにします。Verse# A hit callback that scores the ComboTarget and resets the combo. OnComboTargetHit():void= AdjustScore(ComboTargetScore) <# --- New Code Start --- #> IncreaseWeaponLevel() <# --- New Code End --- #>AdjustScoreメソッドを修正し、付与されるスコアを武器レベルで乗算します。Verse# Adjusts the player's score by the provided value. AdjustScore(Value:int):void= # Start the timer if it hasn't started yet. if (not IsTimerStarted?): StartTimer() <# --- New Code Start --- #> # Sets the score award to the base value of the target multiplied by the current weapon level. ScoreManager.SetScoreAward(Value * CurrentWeaponLevel)Verse コードを保存してビルドします。
完全なコード
using { /Fortnite.com/Devices }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
# A device that manages shooting range gameplay.
shooting_range_manager_device := class(creative_device):
@editable
ScoreManager:score_manager_device = score_manager_device{}
まとめ
ビューポートまたは [アウトライナー] パネルで shooting_range_manager_device を選択します。
[詳細] パネルで、ItemGranter をアイテムグランターの仕掛けに設定します。
変更をプッシュして島をプレイテストします。
コンボ ターゲットに命中した後、最大 5 回まで武器が切り替わることを確認します。 5 レベル目では同じ武器のままであることを確認します。
加算されるスコアが武器レベルで乗算されることを確認します。