Hello everyone. I have very little experience programming and I’m having a hard time figuring out what’s going wrong.
I’m stuck at this step of the Team Elimination Game - to be more precise, I finished all the steps from ’ 4. Tracking Players Using Maps’ and stopped before starting ’ Mapping Teams of Players’.
The issue is that no weapon is being granted on respawn.
I already erased my code and started it over from scratch three times, but I can’t figure out what I’m doing wrong.
On the previous step/page (this one) everything worked pretty well.
The last message that shows up on the console is “A Player just spawned!” but that doesnt mean much since it can be pretty much anything besides the first lines.
Here’s the code:
using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }
team_elimination_game := class(creative_device):
var PlayerMap : [player]int = map{} # This stores a reference to each player and their weapon tier
@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{}
OnPlayerSpawn(InPlayer : agent) : void =
Print("A Player just spawned!")
if(WeaponTier := PlayerMap[InPlayer]):
GrantWeapon(option{InPlayer}, WeaponTier)
Print("Spawned Player was granted a gun of tier {WeaponTier}")
GrantWeapon(InPlayer : ?agent, WeaponTier : int) : void=
Print("Granting Player a weapon of Tier {WeaponTier}")
if(ItemGranter := WeaponGranters[WeaponTier], GrantedPlayer := InPlayer?):
ItemGranter.GrantItem(GrantedPlayer)
PopulateTeamsAndPlayers() : void=
Print("Beginning to populate players")
AllPlayers := GetPlayspace().GetPlayers()
for (Agent : AllPlayers, TeamPlayer := player[Agent], FortCharacter := TeamPlayer.GetFortCharacter[]):
if(set PlayerMap[TeamPlayer] = 0, WeaponTier := PlayerMap[TeamPlayer]):
Print("Assigned Player to PlayerMap with Tier {WeaponTier}")
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)
OnPlayerEliminated(Result : elimination_result) : void=
Print("A Player was eliminated!")
OnBegin<override>()<suspends> : void =
# Get all the players
set Teams = GetPlayspace().GetTeamCollection().GetTeams()
set EliminationsToEndGame = WeaponGranters.Length
Print("Number of eliminations to end game is {EliminationsToEndGame}")
for (Spawner : PlayerSpawners):
Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn) # Subscribe to each player spawn pad