Easy and Flexible Random Script

Aerisetta

Active member
Hi, looking for some help, thanks :)

I currently have a text entity that plays a random follow animation (follow1, follow2, follow3, etc)

I am looking to create a more flexible random script so I can update and add new follow animations quicker without redoing the formula each time.

For example, I want it to be like

spawn
if frame 1
generate random number between 1 to 14

if 1, anim follow1
if 2, anim follow2
if 3, anim follow3
...
if 14, anim follow14

And then when I try to update and add 2 more follow animations, i can simply add like this

spawn
if frame 1
generate random number between 1 to 16

if 1, anim follow1
if 2, anim follow2
if 3, anim follow3
...
if 14, anim follow14
if 15, anim follow15
if 16, anim follow16
 
@Kratus taught me this one, thanks!

@script
if(frame==2){
void self = getlocalvar("self");
int result = 1; //RESULT START FROM 1 ONCE USUALLY THE ENGINE CONSIDER A RANGE FROM 0 TO THE VALUE-1 (EX: rand()%10 will be 0-9)
int maxFollows = 5; //FILL THE MAX FOLLOW POSSIBILITIES FOR THIS ENTITY
int rand = rand()%maxFollows;

if(rand < 0){rand = rand*(-1);} //AVOID NEGATIVE NUMBERS
if(rand != 0){result = result+rand;} //AVOID ZERO VALUE, ONCE THERE'S NO FOLLOW0
performattack(self, openborconstant("ANI_FOLLOW"+result)); //CHANGE THE FOLLOW ANIMATION
}
@end_script
 
Back
Top Bottom