a tricky problem with random numbers

LoveTD's

New Member
Reaction score
34
hi all, I'm having a problem...

This is what it is:

I want a random number between 1 and 5 but whenever a player leaves
I want that to be like this:
player 1 leaves: random number between 1 and 5 except 1
player 2 leaves: random number between 1 and 5 except 2
player 3 leaves: random number between 1 and 5 except 3
player 4 leaves: random number between 1 and 5 except 4
player 5 leaves: random number between 1 and 5 except 5

how can I make this?
I have been breaking my head over it for the last 5 hours already :banghead:
if you know how to do this I will +rep you :thup:
 

Faust

You can change this now in User CP.
Reaction score
123
Well you must get a random number between 1 and 5 again and again until you get the right one o_O

Or, presuming that you want to link those numbers to the players somehow, create a special unit at the beginning for each player, if one leaves, remove his special unit, and then get a random unit from unit group.
You can assign numbers to them easily.
 

wraithseeker

Tired.
Reaction score
122
Trigger:
  • set variable = Random Number between 1 and 5
    • if variable != 1 then
    • else
    • set variable = Random Number between 1 and 5
    • endif

I am sure you can understand.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
What is the number used for.
For all of them, u can just put random number between 1-4.
And thn do accordingly, dun have to be that way, u dun hav to use number for number, as long as u knw which belongs to which, thn u can do the stuff.
E.g. Player 3 leaves
Random number between 1-4
1 belongs to player 1
2 belongs to player 2
3 belongs to player 4
4 belongs to player 5

Omg im sorry... For some very strange reasons my post came out really late. sorry...
 

Faust

You can change this now in User CP.
Reaction score
123
Wraith, you have to loop that I think...
And I also think, my second solution is quite handy... Units are pretty useful for storing and solving things like that.
 

LoveTD's

New Member
Reaction score
34
I fixed it thanks to wraith....

Trigger:
  • check for attack
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Player[(Integer A)] slot status) Equal to Has left the game
            • Then - Actions
              • Set Number = (Random integer number between 1 and 5)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Number Not equal to (Integer A)
                • Then - Actions
                  • Unit - Order Last_created_unit to Attack-Move To *(Position of (Random unit from units_of_player[Number]))*
                • Else - Actions
                  • Trigger - Run (This trigger) (checking conditions)
            • Else - Actions


b.t.w. does this leak a position or not? **

EDIT: nevermind it seems that it is not working :S

EDIT: lol nevermind I forgot this part:
Trigger:
  • check for attack
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Player[(Integer A)] slot status) Equal to Has left the game
            • Then - Actions
              • Set Number = (Random integer number between 1 and 5)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Number Not equal to (Integer A)
                • Then - Actions
                  • Unit - Order Last_created_unit to Attack-Move To (Position of (Random unit from units_of_player[Number]))
                • Else - Actions
                  • Set Number = (Random integer number between 1 and 5)
                  • Trigger - Run (This trigger) (checking conditions)
            • Else - Actions
              • Unit - Order Last_created_unit to Attack-Move To (Position of (Random unit from units_of_player[(Random integer number between 1 and 5)]))
 

Strilanc

Veteran Scripter
Reaction score
42
There's no need for any of this looping stuff.

Code:
n = random from 1 to 4
if n = player# then n = 5
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
local integer n = random from 1 to 5
if n != player# then
set n = random from 1 to 5
if n != player# then
set n = random from 1 to 5 (Test)


JASS:

   local integer n = //(random number from 1 to 5 in JASS, sorry i forgot, just //started learning JASS)*
Loop
   exitwhen n == player#
if n != player# then
set n = //(Set random number from 1 to 5 in JASS again)*


I started learning JASS only so this might be really bad... But I tink it works. Keep randoming until they dun get a leaver's number.
 

LoveTD's

New Member
Reaction score
34
isn't this exactly the same but then in GUI?

Trigger:
  • check for attack
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Player[(Integer A)] controller) Not equal to User
                  • (Player[(Integer A)] slot status) Not equal to Is playing
            • Then - Actions
              • Set Number = (Random integer number between 1 and 5)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Number Not equal to (Integer A)
                • Then - Actions
                  • Unit - Order Last_created_unit to Attack-Move To (Position of (Random unit from units_of_player[Number]))
                • Else - Actions
                  • Trigger - Run (This trigger) (checking conditions)
            • Else - Actions


this checks if the number is not equal to integer a which referrs to the player number... but for some strange reasons it isn't working :S
 

Strilanc

Veteran Scripter
Reaction score
42
wtf? why set n = 5?
I don't get your point :S

have you read the first post?

Did you even work out what the code will do? It does exactly what you asked for.

Try tracing out all the possibilities and you'll see it works.
 

Somebody

New Member
Reaction score
0
If I understand the problem correctly, after a player(1 through 5) leaves the game, you would like to randomly pick one of the four remaining players, to execute some action?

If that's so, then I may have a solution

First, a player group is initialized and stores players one through five granted they are in the game, secondly, an integer variable to count the number of players in the group
Trigger:
  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Players = (All players matching (((Matching player) slot status) Equal to Is playing))
      • Set NumOfPlayers = (Number of players in Players)


Trigger:
  • RandomNumber
    • Events
      • Player - Player 1 (Red) leaves the game
      • Player - Player 2 (Blue) leaves the game
      • Player - Player 3 (Teal) leaves the game
      • Player - Player 4 (Purple) leaves the game
      • Player - Player 5 (Yellow) leaves the game
    • Conditions
    • Actions
      • Set PlayersRemaining = <Empty String>
      • Set NumOfPlayers = (NumOfPlayers - 1)
      • Player Group - Remove (Triggering player) from Players
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) is in Players) Equal to True
            • Then - Actions
              • Set PlayersRemaining = (PlayersRemaining + (String((Integer A))))
            • Else - Actions
      • Set RandomNumber = (Random integer number between 1 and (Number of players in Players))
      • Set RandomNumber = (Integer((Substring(PlayersRemaining, RandomNumber, RandomNumber))))


at the end of all this the variable RandomNumber corresponds to one of the remaining players in the game
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top