# I need you to decide if this verse code is right.

**URL:** <https://forums.unrealengine.com/t/i-need-you-to-decide-if-this-verse-code-is-right/2121500>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [November 14, 2024, 2:02am UTC](https://forums.unrealengine.com/t/i-need-you-to-decide-if-this-verse-code-is-right/2121500 "2024-11-14T02:02:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![studyingUEFN](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/studyinguefn/32/997250_2.png) [@studyingUEFN](https://forums.unrealengine.com/u/studyingUEFN)\
**Post date:** [November 14, 2024, 2:02am UTC](https://forums.unrealengine.com/t/i-need-you-to-decide-if-this-verse-code-is-right/2121500/1 "2024-11-14T02:02:42Z")

</div>

![Team B](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/2/7e2989d5280e8b1f82d05ed38f3b26b945329feb.png)

[Previous Question.](https://forums.unrealengine.com/t/i-want-to-be-able-to-choose-where-to-spawn-so-please-let-me-know/2110970)

If a screen appears after a player is killed and your team occupies an area, you want to select a spawnable location (including the initial spawn) and spawn there.

I have written the code and I would like you to judge whether it is correct or not.  
Please let me know if I’m missing something or if I’m doing something wrong.

```auto
using { /Fortnite.com/Devices }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /UnrealEngine.com/Temporary/UI }

spawn_selection_device := class(creative_device):
    # Spawner device
    @editable
    var InitialSpawners:[]player_spawner_device = array{}
    @editable
    var AreaASpawners:[]player_spawner_device = array{}
    @editable
    var AreaBSpawners:[]player_spawner_device = array{}
    @editable
    var AreaCSpawners:[]player_spawner_device = array{}

    # Capture area device
    @editable
    CapturePoints:[]capture_area_device = array{}

    # Button device
    @editable
    SelectAreaAButton:button_device = button_device{}
    @editable
    SelectAreaBButton:button_device = button_device{}
    @editable
    SelectAreaCButton:button_device = button_device{}

    OnBegin<override>()<suspends>:void=
        # Initial setup
        EnableInitialSpawners()
        SetupButtonEvents()

    # Setup button events
    SetupButtonEvents():void=
        SelectAreaAButton.InteractedWithEvent.Subscribe(OnSelectAreaA)
        SelectAreaBButton.InteractedWithEvent.Subscribe(OnSelectAreaB)
        SelectAreaCButton.InteractedWithEvent.Subscribe(OnSelectAreaC)

    # Processing when Area A is selected
    OnSelectAreaA(Agent:agent):void=
        EnableAreaSpawn(AreaASpawners)

    # Processing when Area B is selected
    OnSelectAreaB(Agent:agent):void=
        EnableAreaSpawn(AreaBSpawners)

    # Processing when Area C is selected
    OnSelectAreaC(Agent:agent):void=
        EnableAreaSpawn(AreaCSpawners)

    # Enable initial spawn points
    EnableInitialSpawners():void=
        for (Spawner : InitialSpawners):
            Spawner.Enable()

    # Enable area spawns
    EnableAreaSpawn(AreaSpawners:[]player_spawner_device):void=
        # Disable all current spawns
        DisableAllSpawners()
        # Enable spawns for the selected area
        for (Spawner : AreaSpawners):
            Spawner.Enable()

    # Disable all spawns
    DisableAllSpawners():void=
        for (Spawner : InitialSpawners):
            Spawner.Disable()
        for (Spawner : AreaASpawners):
            Spawner.Disable()
        for (Spawner : AreaBSpawners):
            Spawner.Disable()
        for (Spawner : AreaCSpawners):
            Spawner.Disable()

```

---

<div class="post-metadata">

**Author:** ![studyingUEFN](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/studyinguefn/32/997250_2.png) [@studyingUEFN](https://forums.unrealengine.com/u/studyingUEFN)\
**Post date:** [November 15, 2024, 12:48pm UTC](https://forums.unrealengine.com/t/i-need-you-to-decide-if-this-verse-code-is-right/2121500/2 "2024-11-15T12:48:11Z")

</div>

I’ve made some changes to the code.

```auto

using { /Fortnite.com/Devices }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
# リスポーンタグ定義
DominationSpawnTags<public> := module:
    Tag_SpawnGroup<public> := class(tag){}
    Tag_SpawnGroup_Initial<public> := class(Tag_SpawnGroup){}
    Tag_SpawnGroup_GroupA<public> := class(Tag_SpawnGroup){}
    Tag_SpawnGroup_GroupB<public> := class(Tag_SpawnGroup){}
    Tag_SpawnGroup_GroupC<public> := class(Tag_SpawnGroup){}
    Tag_TeamOwnership<public> := class(tag){}
    Tag_TeamOwnership_Team1<public> := class(Tag_TeamOwnership){}
    Tag_TeamOwnership_Team2<public> := class(Tag_TeamOwnership){}

# リスポーン管理クラス
respawn_manager := class(creative_device):
    var SpawnPointGroupInitial:[]player_spawner_device = array{}
    var SpawnPointGroupsCapPoint:[][]player_spawner_device = array{array{}, array{}, array{}}
    var SelectedSpawnIndex:int = 0 # プレイヤーが選択したリスポーン地点のインデックス
    @editable  
    CapturePoints:[]capture_area_device = {array{}}
    
    # 初期リスポーンの無効化時間（秒）
    InitialGroupDisableTime:float = 5.0
    
    # 初期化処理
    OnBegin<override>()<suspends>:void=
        FindAndCacheSpawnDevices()
        DisableInitialSpawnGroup()

    # スポーンデバイスを取得
    FindAndCacheSpawnDevices<private>():void=
        InitialSpawnPoints:[]creative_object_interface = GetCreativeObjectsWithTag(DominationSpawnTags.Tag_SpawnGroup_Initial{})
        for (FoundDevice : InitialSpawnPoints, DeviceAsSpawner := player_spawner_device[FoundDevice]):
            set SpawnPointGroupInitial = SpawnPointGroupInitial + array{DeviceAsSpawner}

        GroupTags:[]tag = array:
            DominationSpawnTags.Tag_SpawnGroup_GroupA{}
            DominationSpawnTags.Tag_SpawnGroup_GroupB{}
            DominationSpawnTags.Tag_SpawnGroup_GroupC{}

        for (I -> GroupTag:GroupTags): 
            FoundSpawnGroup:[]creative_object_interface := GetCreativeObjectsWithTag(GroupTag)
            for (FoundDevice : FoundSpawnGroup, DeviceAsSpawner := player_spawner_device[FoundDevice]):
                if:
                    set SpawnPointGroupsCapPoint[I] = SpawnPointGroupsCapPoint[I] + array{DeviceAsSpawner}

    # 初期リスポーン地点の無効化処理
    DisableInitialSpawnGroup<private>()<suspends>:void=
        Sleep(InitialGroupDisableTime)
        for (SpawnPoint : SpawnPointGroupInitial):
            SpawnPoint.Disable()
    
    # プレイヤーが倒された時のUI表示
    OnPlayerEliminated(EliminatedPlayer:agent):void=
        DisplaySpawnSelectionUI(EliminatedPlayer)

    # リスポーン選択UIを表示
    DisplaySpawnSelectionUI(TargetPlayer:agent):void= {}
        # UIコードをここに実装（取得済エリアA, B, Cの選択肢を表示）
        # プレイヤーの選択をトリガーするボタン設定なども含む

    # リスポーン地点に応じた処理
    RespawnPlayerAtSelectedPoint(TargetPlayer:agent):void=
        if (SelectedSpawnIndex >= 0 and SelectedSpawnIndex < SpawnPointGroupsCapPoint.Length):
            SelectedGroup := SpawnPointGroupsCapPoint[SelectedSpawnIndex]
            for (SpawnDevice : SelectedGroup):
                if (SpawnDevice.IsEnabled()):
                    SpawnDevice.SpawnPlayer(TargetPlayer)
                    return # スポーン完了後に終了

```
