• 🏆 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!

Random Integer not being random??

Status
Not open for further replies.
Level 3
Joined
Sep 21, 2005
Messages
33
OK, so i have a powerup buff like in dota, a rune that gives u an ability. The type of rune is meant to spawn randomly.
My trigger is:
Rune 1 Respawn
Events
Time - T_Rune1_Respawn expires
Conditions
Actions
Set I_RandRune = (Random integer number between 1 and 6)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
I_RandRune Equal to 1
Then - Actions
Item - Create Rune - Attack at (Center of Rune Spawn 1 <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
I_RandRune Equal to 2
Then - Actions
Item - Create Rune - Defence at (Center of Rune Spawn 1 <gen>)
Else - Actions

The problem is that every time it ALWAYS spawns the 5th rune, then the 4th rune twice, then the 1st rune, every game!

i added a second randomisation after the first to see what would happen and all that happens is the sequence is changed in which they spawn but it is always the same EVERY game!!! :( plz help, i hope its just code error i've made!
 
Level 2
Joined
Apr 21, 2006
Messages
21
You may have setup the trigger improperly, I'm not sure exactly without seeing it but I guess you use the if then else statement repeating the if then through the else. Ill have something for you in a bit
 
Level 2
Joined
Apr 21, 2006
Messages
21
Use this:
JASS:
function Trig_Rune_1_Respawn_Actions takes nothing returns nothing
local integer i=GetRandomInt(1, 6)
if i==1 then
 call CreateItemLoc( 'rde1', GetRectCenter(gg_rct_RectName) )
elseif i==2 then
 call CreateItemLoc( 'rwiz', GetRectCenter(gg_rct_RectName) )
elseif i==3 then
 call CreateItemLoc( 'rag1', GetRectCenter(gg_rct_RectName) )
elseif i==4 then
 call CreateItemLoc( 'hcun', GetRectCenter(gg_rct_RectName) )
elseif i==5 then
 call CreateItemLoc( 'mcou', GetRectCenter(gg_rct_RectName) )
else
call CreateItemLoc( 'befv', GetRectCenter(gg_rct_RectName) )
 endif 
endfunction

//===========================================================================
function InitTrig_Rune_1_Respawn takes nothing returns nothing
    set gg_trg_Rune_1_Respawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Rune_1_Respawn, udg_T_Rune1_Respawn )
    call TriggerAddAction( gg_trg_Rune_1_Respawn, function Trig_Rune_1_Respawn_Actions )
endfunction

Change the raw values to the values of the runes you wish to use, change the location of the rect you wish to use by renaming "RectName" to your rect, it must retain the "gg_rct_" and if you use a space replace it with an underscore (_).

And go to File > Preferences > Test Map. Make sure that box is NOT CHECKED[/code]
 
Level 22
Joined
Jan 10, 2005
Messages
3,426
no u rly wont need jass. i said u should use math random number in my last post

if: math random number => random number between 1 and 6 is equal to 6
then: .........
else: if: math random number ......... to 2
then: ........
else...... if: ........... etc etc
 
Level 3
Joined
Sep 21, 2005
Messages
33
And go to File > Preferences > Test Map. Make sure that box is NOT CHECKED

Haha! Thank You! That's all i apparantly needed, to untick the "use fixed random seed" button. Not really sure what it does but by unticking it made it random.

Ramza i tested your solution first and it worked as i expected, at least if i did it the way you meant. What it did was run a random number 6 times, once each time for each of the 6 possible runes in the if/then/else statements.

The problem is that each random number generated for each if/then/else statement is localised to that if/then/else. This means that if the 1st if/then/else which is checking for 1, comes up with a random number = 6, and the 2nd if/then/else which is checking for 2, comes up with 1, etc. etc. Then you will have the rune sometimes never spawn unless you put the whole thing in a loop.
 
Status
Not open for further replies.
Top