このセクションでは、ゲームプレイをカスタマイズするために、Verse スクリプトを追加し、Verse の仕掛けを配置する方法について説明します。

[Verse] > [Verse Explorer] に移動して、Verse スクリプトを作成します。

次に、プロジェクト ファイル名を右クリックし、[Add new Verse file to project (新規 Verse ファイルをプロジェクトに追加する)] を選択します。

[Verse Device (Verse の仕掛け)] を選択して名前を付け、[Create (作成)] をクリックします。このチュートリアルでは、Verse の仕掛けに「Stronghold_Game_Manager」という名前を付けています。

仕掛けの Verse ファイルをダブルクリックすると、Verse スクリプトが表示されます。 以下のコードをコピーして貼り付けます。
using { /Fortnite.com/AI}
using { /Fortnite.com/Characters}
using { /Fortnite.com/Devices}
using { /Fortnite.com/Game}
using { /UnrealEngine.com/Temporary/Diagnostics}
using { /UnrealEngine.com/Temporary/SpatialMath}
using { /Verse.org/Simulation}
using { /Verse.org/Verse}
# Stronghold (要塞) は、厳重に守りを固めた要塞で、プレイヤーが敵兵をすべて撃破することを目的とするゲーム モードです。
# Stronghold Game Manager (要塞ゲーム マネージャー) Verse の仕掛けは、要塞の AI を管理、監視、制御するために使用されます。
stronghold_game_manager := class(creative_device):
# 撃破に関して記録するガード スポナーの仕掛けへの仕掛けの参照です。
@editable
GuardsInitialSpawners:[]guard_spawner_device := array{}
# マルチプレイヤー スケールで撃破に関して記録するガード スポナーの仕掛けへの仕掛けの参照です。
@editable
GuardsInitialSpawnersAdditional:[]guard_spawner_device := array{}
# 要塞のガードの 1 人が警戒状態にあるときにトリガーされる援軍ガード スポナーの仕掛けへの仕掛けの参照です。
@editable
GuardsReinforcementSpawners:[]guard_spawner_device := array{}
# マルチプレイヤー スケールで要塞のガードの 1 人が警戒状態にあるときにトリガーされる援軍ガード スポナーの仕掛けへの仕掛けの参照です。
@editable
GuardsReinforcementSpawnersAdditional:[]guard_spawner_device := array{}
# 目標を表示、追跡するための仕掛けの参照です。
@editable
ObjectiveTracker:tracker_device := tracker_device{}
# 援軍のインゲーム メッセージを表示するための仕掛けの参照です。
@editable
MessageDeviceReinforcement:hud_message_device := hud_message_device{}
# フォールバックのインゲーム メッセージを表示するための仕掛けの参照です。
@editable
MessageDeviceFallback:hud_message_device := hud_message_device{}
# プレイヤーが検知されることなく要塞を制覇した場合に、勝利でゲームを終了するための仕掛けの参照です。
@editable
EndGameVictoryDeviceUndetected:end_game_device := end_game_device{}
# プレイヤーが検知されながらも、要塞を制覇した場合に、勝利でゲームを終了するための仕掛けの参照です。
@editable
EndGameVictoryDeviceDetected:end_game_device := end_game_device{}
# プレイヤーがリトライを使い果たした場合、失敗でゲームを終了するための仕掛けの参照です。
@editable
EndGameFailDevice:end_game_device := end_game_device{}
# プレイヤーの調整可能なライフ数です。
@editable
var PlayerRetries:int = 2
# 要塞のリーシュの位置を参照する仕掛けです。
@editable
ReinforcementLeashReference:stronghold_leash_position := stronghold_leash_position{}
# フォールバックのリーシュの位置を参照する仕掛けです。
@editable
FallbackLeashReference:stronghold_leash_position := stronghold_leash_position{}
# フォールバック後に無効にする必要のあるリーシュです。
@editable
LeashesToDisableForFallback:[]stronghold_leash_position := array{}
# 爆発の仕掛けです。
@editable
ExplosiveDevice:explosive_device := explosive_device{}
# ガードの知覚はこのスクリプトによって監視されます。その他のスクリプトはそのイベントにサブスクライブすることができます。
# ガードが援軍を要請するときにブロードキャストされるイベントです。
ReinforcementsCalledEvent:event(agent) = event(agent){}
# ガードが要塞の中心を防御しているときにブロードキャストされるイベントです。
FallbackEvent:event() = event(){}
# ガードが不審に感じているときにブロードキャストされるイベントです。
GuardsSuspiciousEvent:event(agent) = event(agent){}
# どのガードにも検知されていないときにブロードキャストされるイベントです。
GuardsUnawareEvent:event(agent) = event(agent){}
# プレイヤーが検知されたときにブロードキャストされるイベントです。
PlayerDetectedEvent:event(agent) = event(agent){}
# すべてのガードがターゲット見失ったときにブロードキャストされるイベントです。
PlayerLostEvent:event(agent) = event(agent){}
# 知覚の変化を監視するために、特定の警戒状態にあるガードのリストです。
# 援軍ガードを格納する変数です。
var<private> NumGuardsSpawned:int := 0
# 要塞の全ガードを格納する変数です。
var<private> StrongholdGuards:[]agent := array{}
# 援軍ガードを格納する変数です。
var<private> ReinforcementGuards:[]agent := array{}
# 現在不審に感じているガードのリストです。
var<private> SuspiciousGuards : []agent = array{}
# 現在警戒状態にあるガードのリストです。
var<private> AlertedGuards : []agent = array{}
# 現在調査中のガードのリストです。
var<private> InvestigatingGuards : []agent = array{}
# 初期ガード スポナー。マルチプレイヤー セッションでは追加のスポナーが含まれます
var<private> GuardsInitialSpawnersInternal:[]guard_spawner_device = array{}
# 援軍ガード スポナー。マルチプレイヤー セッションでは追加のスポナーが含まれます。
var<private> GuardsReinforcementSpawnersInternal:[]guard_spawner_device = array{}
# ゲームプレイ ロジック変数です。
# 要塞のすべてのガード スポナーから撃破した数を追跡する変数です。
var<private> GuardsEliminated:int := 0
# 援軍が呼び出されたかどうかを追跡する変数です。
var<private> ReinforcementTriggered:logic := false
# フォールバックがトリガーされたかどうかを追跡する変数です。
var<private> FallbackTriggered:logic := false
# ガードによって検知された最初のプレイヤー エージェントを格納する変数です。
var<private> DetectedPlayer:?player := false
# 実行中のゲームで仕掛けが開始されたときに実行します。
OnBegin<override>()<suspends>:void=
# 難易度のスケーリングのためにアクティブなプレイヤーをチェックします。
AllPlayers := GetPlayspace().GetPlayers()
NumberOfActivePlayers := AllPlayers.Length
set GuardsInitialSpawnersInternal = GuardsInitialSpawners
set GuardsReinforcementSpawnersInternal = GuardsReinforcementSpawners
#プレイヤーが 3 人以上の場合、ガード スポナーを追加します。
if (NumberOfActivePlayers > 2):
set GuardsInitialSpawnersInternal += GuardsInitialSpawnersAdditional
set GuardsReinforcementSpawnersInternal += GuardsReinforcementSpawnersAdditional
var NumInitialGuards:int = 0
for (GuardSpawner : GuardsInitialSpawnersInternal):
GuardSpawner.Enable()
SubscribeToGuardSpawnerEvents(GuardSpawner);
set NumInitialGuards += GuardSpawner.GetSpawnLimit()
ObjectiveTracker.SetTarget(NumInitialGuards)
for (GuardReinforcementSpawner : GuardsReinforcementSpawnersInternal):
SubscribeToGuardSpawnerEvents(GuardReinforcementSpawner);
# 援軍がスポーンしたイベントをサブスクライブします。
GuardReinforcementSpawner.SpawnedEvent.Subscribe(OnReinforcementSpawned)
GuardReinforcementSpawner.AlertedEvent.Subscribe(OnReinforcementAlerted)
GuardReinforcementSpawner.UnawareEvent.Subscribe(OnReinforcementUnaware)
# プレイヤーによる撃破イベントをサブスクライブします。
for (StrongholdPlayer : AllPlayers, StrongholdPC := StrongholdPlayer.GetFortCharacter[]):
StrongholdPC.EliminatedEvent().Subscribe(OnPlayerEliminated)
StartGameplay()
SubscribeToGuardSpawnerEvents(SpawnerDevice:guard_spawner_device):void =
SpawnerDevice.SpawnedEvent.Subscribe(OnGuardSpawned)
SpawnerDevice.EliminatedEvent.Subscribe(OnGuardEliminated)
SpawnerDevice.SuspiciousEvent.Subscribe(OnGuardSuspicious)
SpawnerDevice.AlertedEvent.Subscribe(OnGuardAlerted)
SpawnerDevice.TargetLostEvent.Subscribe(OnGuardLostTarget)
SpawnerDevice.UnawareEvent.Subscribe(OnGuardUnaware)
# 撃破されたガードの追跡を開始し、爆発をトリガーします。
StartGameplay()<suspends>:void =
ObjectiveTracker.AssignToAll()
Sleep(3.0)
if (FirstPlayer:=GetPlayspace().GetPlayers()[0]):
ExplosiveDevice.Explode(FirstPlayer)
# ガード スポナーが警戒状態イベントを受信したときに実行されます。最初の警戒状態イベントのみが考慮されます。
OnGuardAlerted(InteractionResult:device_ai_interaction_result):void=
if:
not ReinforcementTriggered?
set DetectedPlayer = option{player[InteractionResult.Target?]}
Guard:=InteractionResult.Source?
then:
var NumGuards:int = ObjectiveTracker.GetTarget()
# 援軍ガード スポナーの仕掛けを有効にすることで、ガード スポナーの仕掛けで設定された数のガードを確実にスポーンします。
for (GuardReinforcementSpawner : GuardsReinforcementSpawnersInternal):
GuardReinforcementSpawner.Enable()
set NumGuards += GuardReinforcementSpawner.GetSpawnLimit()
ObjectiveTracker.SetTarget(NumGuards)
# 援軍の検出と到着に関するインゲーム メッセージを表示します。
MessageDeviceReinforcement.Show()
set ReinforcementTriggered = true
# 援軍イベントを通知します。
ReinforcementsCalledEvent.Signal(Guard)
# 追加されていない場合は、警戒状態にあるガードのリストにガードを追加します。
if(Guard:=InteractionResult.Source?):
if (not AlertedGuards.Find[Guard]):
set AlertedGuards += array{Guard}
option {set SuspiciousGuards = SuspiciousGuards.RemoveFirstElement[Guard]}
option {set InvestigatingGuards = InvestigatingGuards.RemoveFirstElement[Guard]}
# 1 名のガードが警戒状態にある場合は、プレイヤー検知イベントをブロードキャストします。
if (AlertedGuards.Length = 1):
PlayerDetectedEvent.Signal(Guard)
# 援軍ガード スポナーが警戒状態イベントを受信したときに実行されます。
OnReinforcementAlerted(InteractionResult:device_ai_interaction_result):void=
if:
not FallbackTriggered?
Guard:=InteractionResult.Source?
then:
# ターゲットを攻撃するように、警戒状態にある援軍ガードのリーシュをクリアします。
ReinforcementLeashReference.ClearLeashOnGuard(Guard)
# 援軍ガード スポナーが未検知イベントを受信したときに実行されます。
OnReinforcementUnaware(Guard:agent):void=
if (not FallbackTriggered?):
# リーシュを元に戻します。
ReinforcementLeashReference.ApplyLeashOnGuard(Guard)
# ガード スポナーが未検知イベントを受信したときに実行されます。
OnGuardSuspicious(Guard:agent):void=
if (not SuspiciousGuards.Find[Guard]):
set SuspiciousGuards += array{Guard}
# 1 名のガードが不審に感じている場合は、不審イベントをブロードキャストします。
if:
SuspiciousGuards.Length = 1
AlertedGuards.Length = 0
InvestigatingGuards.Length = 0
then:
GuardsSuspiciousEvent.Signal(Guard)
# ガード スポナーが未検知イベントを受信したときに実行されます。
OnGuardUnaware(Guard:agent):void=
option {set AlertedGuards = AlertedGuards.RemoveFirstElement[Guard]}
option {set SuspiciousGuards = SuspiciousGuards.RemoveFirstElement[Guard]}
option {set InvestigatingGuards = InvestigatingGuards.RemoveFirstElement[Guard]}
# 不審に感じているガード、警戒状態にあるガード、調査中のガードがいない場合は、未検知イベントをブロードキャストします。
if:
SuspiciousGuards.Length = 0
AlertedGuards.Length = 0
InvestigatingGuards.Length = 0
then:
GuardsUnawareEvent.Signal(Guard)
# 1 名のガードがプレイヤーを見失ったら、警戒状態にあるガードのリストからそのガードを削除し、ガード全員がプレイヤーを見失ったら、イベントを知らせます。
OnGuardLostTarget(InteractionResult:device_ai_interaction_result):void=
if (Guard := InteractionResult.Source?):
if (not InvestigatingGuards.Find[Guard]):
set InvestigatingGuards += array{Guard}
# どのガードも警戒状態にない場合、Player Lost (プレイヤーを見失った) イベントをブロードキャストします。
if (set AlertedGuards = AlertedGuards.RemoveFirstElement[Guard]):
if (AlertedGuards.Length = 0):
PlayerLostEvent.Signal(Guard)
# 援軍ガードがスポーンされたときに実行されます。各援軍ガードは要塞の警戒状態にあるプレイヤーを強制的に攻撃する
OnReinforcementSpawned(Guard:agent):void=
set ReinforcementGuards += array{Guard}
ReinforcementLeashReference.ApplyLeashOnGuard(Guard)
# 要塞のガードを警戒状態にしたプレイヤーをターゲットとして割り当てます。
if (Target := DetectedPlayer?):
for (GuardReinforcementSpawner : GuardsReinforcementSpawnersInternal):
GuardReinforcementSpawner.ForceAttackTarget(Target, ?ForgetTime:=30.0)
# 要塞のいずれかのガードがスポーンされたときに実行されます。
OnGuardSpawned(Guard:agent):void=
set StrongholdGuards += array{Guard}
set NumGuardsSpawned += 1
# 初期または援軍スポナーが撃退を受信したときに実行されます。
OnGuardEliminated(InteractionResult:device_ai_interaction_result):void=
set GuardsEliminated += 1
if (EliminatedAgent := InteractionResult.Target?):
# 撃退されたガードを警戒状態にあるガードのリストから削除します。
option {set AlertedGuards = AlertedGuards.RemoveFirstElement[EliminatedAgent]}
option {set SuspiciousGuards = SuspiciousGuards.RemoveFirstElement[EliminatedAgent]}
option {set InvestigatingGuards = InvestigatingGuards.RemoveFirstElement[EliminatedAgent]}
option {set StrongholdGuards = StrongholdGuards.RemoveFirstElement[EliminatedAgent]}
if (EliminationAgent := InteractionResult.Source?):
# 撃退ごとに Tracker の仕掛けの進捗値を進めます。
ObjectiveTracker.Increment(EliminationAgent)
if (ReinforcementTriggered?):
if (NumGuardsSpawned - GuardsEliminated = 3):
StartFallback()
# 援軍なしですべてのガードが撃退された場合、ゲーム モードを終了します。
if (GuardsEliminated >= NumGuardsSpawned):
EndGameVictoryDeviceDetected.Activate(EliminationAgent)
else:
# Ends the game mode if all guards were eliminated with the reinforcements
if (GuardsEliminated >= NumGuardsSpawned):
EndGameVictoryDeviceUndetected.Activate(EliminationAgent)
# 要塞の中央を防御するため、警戒状態にあるガードが数人残っている場合、新しいフォールバック リーシュを割り当てます。
StartFallback():void=
# ガードが要塞の建築物内に退却していることを示すインゲーム メッセージを表示します。
MessageDeviceFallback.Show()
set FallbackTriggered = true
for (LeashDevice : LeashesToDisableForFallback):
LeashDevice.DisableLeashAndPatrolPaths()
FallbackLeashPosition := FallbackLeashReference.GetTransform().Translation
FallbackEvent.Signal()
for (Guard : StrongholdGuards):
FallbackLeashReference.ApplyLeashOnGuard(Guard)
# プレイヤー撃退イベントを受信したときに実行されます。
OnPlayerEliminated(EliminationResult:elimination_result):void=
set PlayerRetries -= 1
if (PlayerRetries = 0, Agent := EliminationResult.EliminatedCharacter.GetAgent[]):
EndGameFailDevice.Activate(Agent)

次に、[Verse] > [Build Verse Code (Verse コードをビルド)] に移動して、Verse スクリプトをコンパイルします。

「All/"Project Name"/CreativeDevices/」に移動し、Verse の仕掛けを選択します。

次に、Verse の仕掛けをマップ上にドラッグします。 これは、Verse スクリプトをコンパイルした後にのみ表示されます。
Verse の仕掛けを選択した状態で、[Details (詳細)] パネルに移動し、[User Options (ユーザー オプション)] を以下のように更新します。

オプション | Value | 説明 |
---|---|---|
ゲーム中に表示 | オフ | この仕掛けは、ゲーム中に表示されません。 |
Guards_InitialSpawners | 3 Array elements (3 つの配列要素) | [+] をクリックして、この設定に 3 つの要素を追加します。 |
0 | ガードスポナー | 要塞の初期ガードをスポーンするために使用されるすべての仕掛けの配列です。 |
1 | Guard Spawner Sniper Tower 1 (ガード スポナー スナイパー タワー 1) | 要塞の初期ガードをスポーンするために使用されるすべての仕掛けの配列です。 |
2 | Guard Spawner Sniper Tower 2 (ガード スポナー スナイパー タワー 2) | 要塞の初期ガードをスポーンするために使用されるすべての仕掛けの配列です。 |
Guards_ReinforcementSpawner | Guard Spawner Reinforcement (ガード スポナー援軍) | 援軍ガードをスポーンします。 |
Objective Tracker (目標 Tracker) | Tracker | 要塞の目標と撃退数を表示します。 |
MessageDeviceReinforcement | HUD Message Device Reinforcement (HUD 援軍メッセージの仕掛け) | 援軍のオンスクリーン メッセージを表示します。 |
MessageDeliverFallback | HUD Message Device Fallback (HUD メッセージの仕掛けのフォールバック) | フォールバックのオンスクリーン メッセージを表示します。 |
EndGameVictoryDeviceUndetected | End Game Device Undetected (未検知でエンド ゲームの仕掛け) | 勝利および未検知での終了画面を表示します。 |
EndGameVictoryDeviceDetected | End Game Device Detected (検知でのエンド ゲームの仕掛け) | 勝利および検知での終了画面を表示します。 |
EndGameFailDevice | End Game Device Fail (失敗でエンドゲームの仕掛け) | プレイヤーがライフを使い果たしたために失敗した終了画面を表示します。 |
EliminationCount | 6 | 未検知で要塞をコンプリートするために必要なガード撃退数を決定します。 |
EliminationCountWithReinforcement | 10 | 援軍がトリガーされた状態で要塞をコンプリートするのに必要なガード撃退数を決定します。 |
PlayerRetries | 2 人 | プレイヤーが要塞のコンプリートを成功させるまでに必要なライフ数を決定します。プレイヤーがライフを使い果たした場合、その要塞は失敗します。 |
StrongholdLeashReferernce | Leash Position Stronghold (リーシュ位置要塞) | リーシュ位置仕掛けは、その位置を要塞のリーシュの原点として使用します。 |
FallbackLeashReference | Leash Position Fallback (リーシュ位置フォールバック) | リーシュ位置仕掛けは、その位置をフォールバック リーシュの原点として使用します。 |
StrongholdLeashInnerRadius | 2400.0 | 要塞リーシュの内径を cm 単位で決定します。内径は、外径より小さい必要があります。 |
StrongholdLeashOuterRadius | 2500.0 | 要塞リーシュの外径を決定します。 |
DefendFallbackLeashInnerRadius | 700.0 | 防御フォールバック リーシュの内径を cm 単位で決定します。内径は、外径より小さい必要があります。 |
DefendFallbackLeashOuterRadius | 750.0 | 防御フォールバック リーシュの外径を cm 単位で決定します。 |
次のセクション
%verse-stronghold-template-4-add-devices-in-unreal-editor-for-fortnite:topic%