Having Issue with my gun game. Sometimes it will skip gun for no reason. But most of the time is ok.
I don’t if its a issue when players join or what.
Thanks
Here is the map 7298-1477-0485
Having Issue with my gun game. Sometimes it will skip gun for no reason. But most of the time is ok.
I don’t if its a issue when players join or what.
Thanks
Here is the map 7298-1477-0485
Can you show your script ?
I thought I pasted it oops will paste it again, still learning verse.
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{}
@editable
var Sentries : []sentry_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{}
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)
# 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)
# Subscribe to new players joining the game
for (Sentry : Sentries):
Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
# Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
Print("Player Eliminated")
EliminatingCharacter := Result.EliminatingCharacter
if (FortCharacter := EliminatingCharacter?):
if (EliminatingAgent := FortCharacter.GetAgent[]):
GrantNextWeapon(EliminatingAgent)
TestPlayerEliminated(Agent: ?agent) : void =
Print("Sentry Down!")
if(EliminatingAgent := Agent?):
GrantNextWeapon(EliminatingAgent)
# Check if there is a winner for the game, if not then grant the next weapon
GrantNextWeapon(Agent:agent):void=
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) {}
# 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
EndGame(Agent:agent):void=
EndGameDevice.Activate(Agent)
# Handles a new player joining the game
OnPlayerAdded(InPlayer : player) : void =
Print("A New Player Joined!")
if:
FortCharacter := InPlayer.GetFortCharacter[]
set AgentMap[InPlayer] = 1
FirstItemGranter:= WeaponItemGranters[0]
then:
FirstItemGranter.GrantItem(InPlayer)
Print("Set new player weapon tier to 0 in the TeamMap")
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event
Looks okay to me, but is this happening when players join twice ? I believe the InPlayer.FortCharacter[].EliminatedEvent().Subscribe
will stay subscribed if you don’t unsubscribe inside OnPlayerRemoved
Otherwise I’m not sure, maybe check if you don’t have any additional direct event binding on your granters?
Dont’ think so How would I do a player removed.
The same way you did OnPlayerAdded
Thanks will give it a try
Hmm can’t figure out how to unsubscribe, and there really is not much documentation on how to do that.
Do you have a example? OnplayerRemove Unsubscribe?
So basically, every subscribable.Subscribe()
function returns a cancelable
type which can be canceled by calling cancelable.Cancel()
(see cancelable interface)
Requires a bit of programing knowledge for sure
Thanks but still a noob at this verse script and I learn very well by example so if you can help write a section that would really apprciated
Ok I think I got it
I added these 2
GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
OnPlayerRemoved(InPlayer : player) : void =
Print(“A New Player Joined!”)
if:
FortCharacter := InPlayer.GetFortCharacter
set AgentMap[InPlayer] = 1
#FirstItemGranter:= WeaponItemGranters[0]
then:
#FirstItemGranter.GrantItem(InPlayer)
#Print(“Set new player weapon tier to 0 in the TeamMap”)
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this player’s elimination event
Seems to still not work as if I am player 0 and player 1 leaves the game, player 0 skips guns
Can you show your updated formatted code ?
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{}
@editable
var Sentries : []sentry_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{}
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)
# 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)
# Subscribe to new players joining the game
for (Sentry : Sentries):
Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
# Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
Print("Player Eliminated")
EliminatingCharacter := Result.EliminatingCharacter
if (FortCharacter := EliminatingCharacter?):
if (EliminatingAgent := FortCharacter.GetAgent[]):
GrantNextWeapon(EliminatingAgent)
TestPlayerEliminated(Agent: ?agent) : void =
Print("Sentry Down!")
if(EliminatingAgent := Agent?):
GrantNextWeapon(EliminatingAgent)
# Check if there is a winner for the game, if not then grant the next weapon
GrantNextWeapon(Agent:agent):void=
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) {}
# 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
EndGame(Agent:agent):void=
EndGameDevice.Activate(Agent)
# Handles a new player joining the game
OnPlayerAdded(InPlayer : player) : void =
Print("A New Player Joined!")
if:
FortCharacter := InPlayer.GetFortCharacter[]
set AgentMap[InPlayer] = 1
FirstItemGranter:= WeaponItemGranters[0]
then:
FirstItemGranter.GrantItem(InPlayer)
Print("Set new player weapon tier to 0 in the TeamMap")
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event
OnPlayerRemoved(InPlayer : player) : void =
Print("A New Player Joined!")
if:
FortCharacter := InPlayer.GetFortCharacter[]
then:
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this player's elimination event
Can you post the formatted code ?
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{}
@editable
var Sentries : []sentry_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{}
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)
# 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)
# Subscribe to new players joining the game
for (Sentry : Sentries):
Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
# Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
Print("Player Eliminated")
EliminatingCharacter := Result.EliminatingCharacter
if (FortCharacter := EliminatingCharacter?):
if (EliminatingAgent := FortCharacter.GetAgent[]):
GrantNextWeapon(EliminatingAgent)
TestPlayerEliminated(Agent: ?agent) : void =
Print("Sentry Down!")
if(EliminatingAgent := Agent?):
GrantNextWeapon(EliminatingAgent)
# Check if there is a winner for the game, if not then grant the next weapon
GrantNextWeapon(Agent:agent):void=
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) {}
# 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
EndGame(Agent:agent):void=
EndGameDevice.Activate(Agent)
# Handles a new player joining the game
OnPlayerAdded(InPlayer : player) : void =
Print("A New Player Joined!")
if:
FortCharacter := InPlayer.GetFortCharacter[]
set AgentMap[InPlayer] = 1
FirstItemGranter:= WeaponItemGranters[0]
then:
FirstItemGranter.GrantItem(InPlayer)
Print("Set new player weapon tier to 0 in the TeamMap")
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event
OnPlayerRemoved(InPlayer : player) : void =
Print("A New Player Joined!")
if:
FortCharacter := InPlayer.GetFortCharacter[]
then:
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this player's elimination event
Thanks, so here you’re only getting the reference to the Cancel
function, you’re not actually calling it, maybe doing .Cancel()
would work better.
But even with this, you’re only cancelling a new subscriber you just created (using .Subscribe()
)
The .Subscribe()
call you make in OnBegin returns an actual cancelable
, and it’s this one you need to call .Cancel()
on.
But it’s still strange imo that your player gets granted a weapon when the other player leaves, this is not what I understood in the first place…
Sorry Let me try and explain a bit better.
Player 0 is on Weapon 1
Player 1 gets a elimiation which moves him to Weapon 2.
Player 1 leaves the Game
Player 0 gets an elimination which moves him to weapon 3(should be weapon 2)
So it is skipping for the player 0 if that makes sense.
Does the issue happen if player doesn’t reconnect ? You didn’t try my solution yet, maybe it will fix it.
I thought that onplayerRemoved function does this.
I call GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
So this gets the playspace and the player removed then I call the function which
OnPlayerRemoved(InPlayer : player) : void =
Print("Player has left")
if:
FortCharacter := InPlayer.GetFortCharacter[]
then:
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this
So this function from what I can tell gets the player and then cancels it.
Or is this not where I am supposed to do this.
thanks for the help by the way, Verse is not my cup of tea compared to other languages