Hello guys,
I’m trying to figure out a way of giving each player a unique ID when they join the game. It only needs to last until the game finishes or they leave.
I’ll explain what i’m trying to achieve:
at the start of each round(10 rounds in total) I need to randomly select one player on each team that will be put on a different random loot pool.
so everyone else will have random loot from the same loot pool but the randomly selected player will have a random loot pool that will always grant them port-a-bunkers. I need at least one player on each team to receive bunkers. I need a way of detecting if a player leaves so that player doesn’t receive the bunker loot on the next round.
if this explanation isn’t clear I’ll try and explain it better, Thanks in advance!
Hi.
I don’t know if this helps but…
The unique ID could simply be a reference to that player as an agent type. When the game starts, you would create a map with the key as the agent reference and the value to whatever variable you want, an integer, a string, whatever. You could also use an array instead of a map and then randomly reference the array to get a reference to that player. The key idea is that every player is an agent and has a unique reference value. The agent type for each player is then the player’s unique ID. That ID can then be paired with whatever else you want in a map or an array. For what you want to do, it actually seems like an array would work better because you could randomly access any array index value, and that would reference a random player. Once that player was id’d, then you would do whatever you want to them.
These tutorials might help:
You could also do something simple as this:
Players:=GetPlayspace().GetPlayers()
Index:= GetRandomInt(0, Players.Length-1)
if (RandomPlayer:=Players[Index]):
RandomPlayer.SendToLobby() # or whatever you want to do
Awesome thank you! I didn’t get a notification for your reply, otherwise I would’ve responded sooner.
I’m assuming I then update the array when a player leaves the match?
Also how would I create arrays that are team specific?
Thank you
Players are unique by default, if you store a player type you can compare it later
var BunkerPlayerMaybe : ?player = false
GiveBunker(Player: player):void=
# TODO: Grant item
set BunkerPlayerMaybe = option{Player}
OnNewRound():void=
EligiblePlayers := for(Player : GetPlayspace().GetPlayers(), not BunkerPlayerMaybe? or BunkerPlayerMaybe? <> Player) { Player }
if(NewBunkerPlayer := Shuffle(EligiblePlayers)[0]):
GiveBunker(NewBunkerPlayer)
More or less, it’s a dumb example coz it only stores one player but you get the gist
Awesome thank you, how would I create the array to be team specific?
You can use a [team]player
map or [int]player
map, but also maybe you can just store an array of players, doesn’t seem to hurt performance much here
Sorry, I’m new to verse. So I could create a map with the individual Players as the keys and their team as the value? and then randomly select two players with different values and make them the NewBunkerPlayer?
Sorry if these are stupid questions, this is a little beyond my limited capabilities
Well you’re also new to coding then I guess, map keys are on the left side, which could lead to this usage
if(RandomPlayer <> BunkerPlayers[RandomPlayerTeam]):
Print("RandomPlayer is not the previous bunker player or smth")
Not sure it’s the ideal solution, the array seem better imo, so that players can swap teams too