このセクションでは、前に設定した仕掛けをランタイム時に検出する方法について説明します。
-
Verse Explorer を開き、team_elimination_game.verse をダブルクリックすると Visual Studio Code でスクリプトが開きます。
-
ファイルの先頭で、次を実行します。
-
using { /Fortnite.com/Game}を追加して、elimination_result構造体 を参照できるようにします。 -
using { /Fortnite.com/Characters}を追加して、GetFortCharacter[]API を使用できるようにします。
using { /Fortnite.com/Characters} using { /Fortnite.com/Devices} using { /Fortnite.com/Game} using { /Fortnite.com/Teams} using { /Verse.org/Simulation} -
-
team_elimination_gameのクラス定義内で、以下のフィールドを追加します。-
プレイヤーに武器を付与するために必要なすべてのアイテム グランターを格納するための、
WeaponGrantersという名前の 編集可能 なitem_granter_device配列 変数 。@editable var WeaponGranters : []item_granter_device = array{} -
チームが勝利するために必要なプレイヤー 1 人あたりの撃破の数を表す、
EliminationsToEndGameという名前の整数変数。所属するプレイヤーの 1 人がシーケンスの最終武器を使用して撃破すると、チームの勝利となります。var EliminationsToEndGame : int = 0 -
チームが
EliminationsToEndGameに到達したときにゲームを終了するための、EndGameDeviceという名前の編集可能なend_game_device。@editable EndGameDevice : end_game_device = end_game_device{} -
撃破をテストするためのセントリーを格納するための、
Sentriesという名前の編集可能なsentry_device配列変数。@editable var Sentries : []sentry_device = array{} -
両チームのプレイヤー スポーン パッドを格納するための、
PlayerSpawnersという名前の編集可能なplayer_spawner_device配列変数。@editable var PlayerSpawners : []player_spawner_device = array{} -
ゲーム内の各チームへの参照を格納するための、
Teamsという名前のチーム配列変数。var Teams:[]team = array{} -
team_elimination_gameのクラス定義のコードは次のようになっているはずです。team_elimination_game := class(creative_device): @editable EndGameDevice: end_game_device = end_game_device{} @editable var WeaponGranters : []item_granter_device = array{} @editable var PlayerSpawners : []player_spawner_device = array{} @editable var Sentries : []sentry_device = array{} var EliminationsToEndGame : int = 0 var Teams:[]team = array{}
-
-
OnBegin()内で、前に [Island Settings (島設定)] で設定した各チームのTeams配列を更新します。fort_team_collectionAPI のGetTeams()関数を使用して、プレイ空間内のすべてのチームの配列を取得することができます。OnBegin<override>()<suspends> : void = # すべてのプレイヤーを取得します。 set Teams = GetPlayspace().GetTeamCollection().GetTeams() -
EliminationsToEndGameをWeaponGrantersの長さに設定します。そうすることで、プレイヤーが最終武器を使用して撃破したときにのみゲームが終了するようになります。OnBegin()のコードは次のようになっているはずです。OnBegin<override>()<suspends> : void = # すべてのプレイヤーを取得します。 set Teams = GetPlayspace().GetTeamCollection().GetTeams() set EliminationsToEndGame = WeaponGranters.Length Print("Number of eliminations to end game is {EliminationsToEndGame}") -
Visual Studio Code でスクリプトを保存してから UEFN ツールバーの [Verse] をクリックし、[Build Verse Code (Verse コードをビルド)] をクリックして、レベルにある Verse で作成した仕掛けを更新します。
-
team_elimination_game の仕掛けを選択します。[Details] パネルで各 アイテム グランター を WeaponGranters 配列に、各 プレイヤー スポーン パッド を PlayerSpawners 配列に、各 セントリー を Sentries に、エンド ゲームの仕掛け を EndGameDevice に追加します。
アイテム グランターを追加する順番が重要です![Details] パネルの順序が、ゲーム内でプレイヤーに使用させる武器の順序と一致していることを確認してください。
-
UEFN ツールバーの [Launch Session (セッションを開始)] をクリックしてレベルをプレイテストします。レベルをプレイテストする場合、
EliminationsToEndGameとWeaponGranters配列の長さは同じである必要があります。この動作をログで確認してください。
次のステップ
このチュートリアルの 次のステップ では、ゲームの開始時にプレイヤーに武器を割り当て、スポーン イベントにサブスクライブする方法について学びます。