Random numbers
Random numbers
Hi people. Do anyone knows a way to generate random numbers in GTA2 scripts? I want to randomize the spawn position, weapons and objective of BOTS in my maps. I could use different counters that change over time to add some randomization, but it would overcomplicate the script. I want to know if theres an easier way. Also, is it possible to use counters as parameters? Or I have to make different cases with IFs?
Re: Random numbers
There's no random function but you can make your own by adding to a counter every frame or when keys are pushed or some other pseudo random method.
Most commands don't support counters. CHANGE_GANG_CHAR_RESPECT is a special command that can read/write memory and it supports counters. You can use that command to change the value of the bot coordinates. If there's a random value in GTA2 RAM then you could use it to read that too.
Most commands don't support counters. CHANGE_GANG_CHAR_RESPECT is a special command that can read/write memory and it supports counters. You can use that command to change the value of the bot coordinates. If there's a random value in GTA2 RAM then you could use it to read that too.
Re: Random numbers
Oh, guess I'll just use counters for some pseudo-randomization. I'm not familiar with direct memory access, but I probably don't need it for what I'm trying to do. Thanks anyway
Re: Random numbers
I'm just in a loop is added to the counter + 1, randomly of course will depend on the elapsed time and the start of the game will always be the same, but if the time has passed and you do not follow the steps very random.
Code: Select all
COUNTER random_3 = 0
COUNTER random_65535 = 0
WHILE_EXEC ( true = 1 )
++ random_3
IF ( random_3 >= 3 )
SET random_3 = 0
ENDIF
++ random_65535
IF ( random_65535 >= 65535 )
SET random_65535 = 0
ENDIF
ENDWHILE
Re: Random numbers
Random number between 1 and 6 using the frame count as the seed. It will update the score to the number each time you fire the pistol.
[mis]
PLAYER_PED p1 = (49.5, 46.5, 255.0) 25 0
COUNTER true = 1
COUNTER framepointer = 6193416
COUNTER frameaddress
COUNTER frame
COUNTER random
LEVELSTART
WHILE_EXEC (true=1)
GIVE_WEAPON (p1, pistol)
IF (IS_CHAR_FIRING_ONSCREEN(p1))
CHANGE_GANG_CHAR_RESPECT (framepointer, frameaddress, 104)
CHANGE_GANG_CHAR_RESPECT (frameaddress, frame, 102)
SET random = (frame MOD 6) //change 6 to maximum random value
++random //change this to SET random = random + minimum value you want for random
ADD_SCORE (p1,-999999999)
ADD_SCORE (p1,random)
ENDIF
ENDWHILE
LEVELEND
[/mis]
[mis]
PLAYER_PED p1 = (49.5, 46.5, 255.0) 25 0
COUNTER true = 1
COUNTER framepointer = 6193416
COUNTER frameaddress
COUNTER frame
COUNTER random
LEVELSTART
WHILE_EXEC (true=1)
GIVE_WEAPON (p1, pistol)
IF (IS_CHAR_FIRING_ONSCREEN(p1))
CHANGE_GANG_CHAR_RESPECT (framepointer, frameaddress, 104)
CHANGE_GANG_CHAR_RESPECT (frameaddress, frame, 102)
SET random = (frame MOD 6) //change 6 to maximum random value
++random //change this to SET random = random + minimum value you want for random
ADD_SCORE (p1,-999999999)
ADD_SCORE (p1,random)
ENDIF
ENDWHILE
LEVELEND
[/mis]