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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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