Hello! I am currently having trouble fixing uefn gun game! I have been working out a lot of bugs.
I believe I am on the right track and that it is a simple fix, I just am not experienced with verse.
Right now I am stuck on players joining and it resets the entire gun game, I fixed it slightly but I do not have a solution. I want the player to be able to join, be added to AllPlayers, and start from the first weapon without changing anyother players.
Because I need someone else to test it, it has been difficult since I need to upload it every time.
Here is my code, thank you for any help you can give!
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Teams}
using { /Fortnite.com/Game}
using { /Fortnite.com/Characters}
using { /UnrealEngine.com/Temporary/Diagnostics }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.# A Verse-authored creative device that can be placed in a level
game_manager := class(creative_device):
var PlayerMap : [player]int = map{}
@editable
var WeaponGranters : []item_granter_device = array{}
@editable
var Sentries : []sentry_device = array{}
@editable
EndGameDevice : end_game_device = end_game_device{}
var ElimsToEndGame : int = 0
OnBegin<override>()<suspends>:void=
set ElimsToEndGame = WeaponGranters.Length;
InitPlayers()
InitTestMode()
InitPlayers() : void=
AllPlayers := GetPlayspace().GetPlayers()
#This is the line I added, not sure if this is in the right place.
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
for (Player : AllPlayers, FortCharacter := Player.GetFortCharacter[]):
if (set PlayerMap[Player] = 0, WeaponTier := PlayerMap[Player]):
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)
GrantWeapon(Player, WeaponTier)
GrantWeapon(Player : player, WeaponTier: int) : void=
if (ItemGranter := WeaponGranters[WeaponTier]):
ItemGranter.GrantItem(Player)
OnPlayerEliminated(Result : elimination_result) : void=
Eliminator := Result.EliminatingCharacter
if (FortCharacter := Eliminator?, EliminatingAgent := FortCharacter.GetAgent[]):
PromotePlayer(EliminatingAgent)
PromotePlayer (Agent : agent) : void=
var WeaponTier : int = 0
if (Player := player[Agent], PlayerWeaponTier := PlayerMap[Player]):
set WeaponTier = PlayerWeaponTier + 1
CheckEndGame(Agent, WeaponTier)
if (Player := player[Agent], set PlayerMap[Player] = WeaponTier):
GrantWeapon(Player, WeaponTier)
InitTestMode() : void=
for (Sentry : Sentries):
Sentry.EliminatedEvent.Subscribe(TestPlayerElimination)
TestPlayerElimination(Agent : ?agent) : void=
if (Player := Agent?):
PromotePlayer(Player)
CheckEndGame(Player : agent, WeaponTier: int) : void=
if (WeaponTier >= ElimsToEndGame):
EndGameDevice.Activate(Player)
OnPlayerAdded(InPlayer : player) : void =
Print("Trying to add the joining player!")
# Im not sure if this connects to AllPlayers in InitPlayers
AllPlayers := GetPlayspace().GetPlayers()
Print("Should be added now, or the whole game is broken!")