Random Array for all players = 0?

V87BF

I am trying to select random players, regardless of dead or living to spawn.
So, currently, I have
Set Global variable(A, Random Value in Array(All Players(All Teams)))

but when I inspect it never sets variable A (or B where applicable). It stays 0 even though it is reaching the step. I feel like I am missing something dumb. What am I doing wrong?

objective

I want to make a Western High Noon Draw scenario. The desired application is: Select 2 random ffa players to one-shot duel at specific coordinates and when one dies it resets and pulls 2 random players again.

This is correct. The first problem is that all your code gets executed instantly when the gamemode starts, before any player has joined the game yet. To prevent this you could add a condition count of(all living players(all teams)) >= 2 in the first rule. Then you disable the built-in respawn and kill everyone as initialisation.

The next problem is this action:
respawn(players in slot(global variable(A), all teams))
Since you set A to a player you dont need to input it into “players in slot”, because this action gets a number as input. So instead do this:
respawn(global variable(A))

This should fix your problem, however I have 2 more suggestions for your code:

  • Make sure that set global variable(B, random value in array(all players(all teams))) doesnt set B to the same player that is in A. You can do this by either use a custom array instead all players that contains all players first and then remove from array(custom array variable, global variable(A)), or by looping the set variable B action until its a different player than A.
  • You use teleport(closest player to(vector), vector) but this can teleport the same player twice. Instead you should use teleport(global variable(A), vector)
1 Like

Thanks so much for your help, I’m going to test that out right now!
Yes, I wasn’t sure how to make sure that B and A were different. Maybe I could put a rule in to check B versus A and keep playing respawn until it’s not? I’m not entirely sure how to set a custom array, this is my first script and I have trouble concentrating.

You can simply set a variable to the player array: set global variable(C, all players(all teams))
It now contains a copy of the all player array and you can manipulate it as much as you want.
So the first player for the duel would be picked by: set global variable(A, random value in array(global variable(C)))
Then for the second player: set global variable(B, random value in array(remove from array(global variable(C), global variable(A))))

I started completely over and now I ended up doing set z to randomized array living players then set A-H as value positions in that array. this way I can pull and teleport new pairings after deaths without changing each variable every time. you’ve kickstarted my brain, thanks! Now I just gotta figure out what I am doing with facing