• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] How to assign each Player 1-8 a different value from 1-8?

Status
Not open for further replies.
Level 6
Joined
Mar 27, 2019
Messages
51
Hey there,

I'm currently trying to work with the loop function and trying to assign every player a different value from each other.

  • Actions
    • Set VariableSet Temp_Integer = 0
    • Custom script: loop
    • Set VariableSet Temp_Integer = (Temp_Integer + 1)
    • Set VariableSet Player_ID[Temp_Integer] = (Random integer number between 1 and 8)
    • Custom script: exitwhen udg_Temp_Integer == 8
    • Custom script: endloop
Now my following problem is, how to check if the next set Player_ID isnt the same value as the already given IDs. Example:

Player_ID[1] = 7
Player_ID[2] = 5
Player_ID[3] = 8
Player_ID[4] = 7 --> 5 --> 2
Player_ID[5] = 4
etc.

Any help would be highly appreciated!
 
A simple solution for GUI could be to use a PlayerGroup as help.
  1. Add players 1-8 to the PlayerGroup as setup.
  2. To get a random integer from 1-8 don't use RandomInt(1, 8), but use GetRandomPlayer From PlayerGroup. Store the player into a variable, and use the player number as random number.
  3. Remove the random player from PlayerGroup.
A Loop in GUI does exist, too, btw. In case you aren't aware of ForEachIntegerLoop.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
Bo’s solution is simple and clever, but for completeness here are two more solutions to how it could be done:

  • Set PLAYCOUNT = 8
  • For each (Integer A) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set UsedNum[(Integer A)] = False
  • For each (Integer INT_VAR) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set pick = (Random integer between 1 and PLAYCOUNT)
      • If (All conditions) then (Actions) Else (Actions)
        • If - Conditions
          • UsedNum[pick] = False
        • Then - Actions
          • Set Player_ID[INT_VAR] = Pick
          • Set UsedNum[pick] = True
        • Else - Actions
          • Set INT_VAR= INT_VAR - 1
  • Set PLAYCOUNT = 8
  • For each (Integer A) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set PickNum[(Integer A)] = (Integer A)
  • For each (Integer A) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set pick = (Random integer between 1 and PLAYCOUNT)
      • Set Player_ID[(Integer A)] = PickNum[pick]
      • Set PickNum[pick] = PickNum[PLAYCOUNT]
      • Set PLAYCOUNT = PLAYCOUNT - 1
 
Level 6
Joined
Mar 27, 2019
Messages
51
A simple solution for GUI could be to use a PlayerGroup as help.
  1. Add players 1-8 to the PlayerGroup as setup.
  2. To get a random integer from 1-8 don't use RandomInt(1, 8), but use GetRandomPlayer From PlayerGroup. Store the player into a variable, and use the player number as random number.
  3. Remove the random player from PlayerGroup.
A Loop in GUI does exist, too, btw. In case you aren't aware of ForEachIntegerLoop.

That's absolutely brillant. Simple & effective. Here is the trigger for everyone that needs it

  • Actions
    • For each (Integer A) from 1 to 8, do (Actions)
      • Loop - Actions
        • Player Group - Add (Player((Integer A))) to Setup
    • Set VariableSet Temp_Integer = 0
    • For each (Integer A) from 1 to 8, do (Actions)
      • Loop - Actions
        • Set VariableSet Temp_Player = (Random player from Setup)
        • Set VariableSet Temp_Integer = (Temp_Integer + 1)
        • Set VariableSet Player_ID[Temp_Integer] = (Player number of Temp_Player)
        • Player Group - Remove Temp_Player from Setup.
 
Level 6
Joined
Mar 27, 2019
Messages
51
Bo’s solution is simple and clever, but for completeness here are two more solutions to how it could be done:

  • Set PLAYCOUNT = 8
  • For each (Integer A) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set UsedNum[(Integer A)] = False
  • For each (Integer INT_VAR) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set pick = (Random integer between 1 and PLAYCOUNT)
      • If (All conditions) then (Actions) Else (Actions)
        • If - Conditions
          • UsedNum[pick] = False
        • Then - Actions
          • Set Player_ID[INT_VAR] = Pick
          • Set UsedNum[pick] = True
        • Else - Actions
          • Set INT_VAR= INT_VAR - 1
  • Set PLAYCOUNT = 8
  • For each (Integer A) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set PickNum[(Integer A)] = (Integer A)
  • For each (Integer A) from 1 to PLAYCOUNT do (Actions)
    • Loop - Actions
      • Set pick = (Random integer between 1 and PLAYCOUNT)
      • Set Player_ID[(Integer A)] = PickNum[pick]
      • Set PickNum[pick] = PickNum[PLAYCOUNT]
      • Set PLAYCOUNT = PLAYCOUNT - 1

Thanks you for showing alternative ways to do it! Comes handy for other "ID Randomizer" that do not use Players / Player Group.
 
Status
Not open for further replies.
Top