Here is my code so far, I need it so my code does not count killing yourself as a kill for # gun game
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
elimination_game_device := class(creative_device):
@editable
EndGameDevice : end_game_device = end_game_device{}
# Array of item granters used to grant the weapons
@editable
var WeaponItemGranters : []item_granter_device = array{}
# This is set later, this will be equal to the the number of weapon item_granters in the island
var NumberOfEliminationsToWin : int = 0
# Map container to track players progress. This is how to determine which weapon to award to the player
var AgentMap : [agent]int = map{}
#Checking for new players
OnPlayerAdded(InPlayer : player) : void =
AllPlayers := GetPlayspace().GetPlayers()
# Check if the victory condition has been met and return the the result
IsVictoryConditionMet(EliminationNumber:int)<transacts>:logic=
if:
EliminationNumber = NumberOfEliminationsToWin
then:
return true
else:
return false
#Ending game once player reaches goal
EndGame(Agent:agent):void=
EndGameDevice.Activate(Agent)
# Check if there is a winner for the game, if not then grant the next weapon
GrantNextWeapon(Agent:agent):void=
if(PlayerObj := player[Agent]):
if (var CurrentItemNumber:int = AgentMap[Agent]):
if (IsVictoryConditionMet(CurrentItemNumber) = true):
EndGame(Agent) # Game has been won
else: # Game is not over yet
set CurrentItemNumber = CurrentItemNumber + 1
if (ItemGranter := WeaponItemGranters[CurrentItemNumber - 1]):
ItemGranter.GrantItem(Agent)
if (set AgentMap[Agent] = CurrentItemNumber) {}
# Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
Print("Player Eliminated")
# Character who was eliminated
Eliminated := Result.EliminatedCharacter
# Character who killed other
Eliminator := Result.EliminatingCharacter
if (FortCharacter := Eliminator? ,EliminatingAgent := FortCharacter.GetAgent[]):
Print("Elimation through if statement")
GrantNextWeapon(EliminatingAgent)
Print("Player Has Killed Themselves")
OnBegin<override>()<suspends>:void=
Sleep(0.0)
# Can use this variable to scale the number of eliminations needed based on how many item granters there are in the experience
set NumberOfEliminationsToWin = WeaponItemGranters.Length
Print("Number of Weapon Item Granters: {WeaponItemGranters.Length}")
# Randomize the order in which the weapons are granted
# set WeaponItemGranters = Shuffle(WeaponItemGranters)
Self.GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
# Get all the players in the experience
AllPlayers := GetPlayspace().GetPlayers()
for (EliminationGamePlayer : AllPlayers):
if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to eliminated event
# Add Players to a Map to track progress
if (set AgentMap[EliminationGamePlayer] = 1) {}
# Grant the first weapon to each player
if (FirstItemGranter:item_granter_device = WeaponItemGranters[0]):
FirstItemGranter.GrantItem(EliminationGamePlayer)