Setting this random script

NED

Well-known member
Hi,
Can you help me setting this random script.
BB helped me with it few years ago for a rise anim random effect.
Now, I need to use it on pain anims.
I need to know how to evaluate the percentage of possibility to complete the cancel.

Code:
anim pain

      @script
    void self = getlocalvar("self");
    if( frame == 0){
      int r = rand()%30;
      if( r >= 20){
        changeentityproperty(self, "animation", openborconstant("ANI_PAIN32"));
      }
    }
   @end_script

Does this setting means it allows 33% chances of cancel?

Thanks
 
Code:
int dc_vars_get_random_int(int lower_bound, int upper_bound)
{
    int     result;
    int     mod;

    // OpenBOR's random generator is a bit odd,
    // so we'll need to do some math work to get
    // usable values.

    // Find difference between desired min and max,
    // then add 1 to create random seed.
    mod = (upper_bound - lower_bound) + 1;

    // Generate random number.
    result  = rand()%mod;

    // If resulting random number is negative, convert to positive.
    if (result < 0)
    {
        result = result * -1;
    }

    // Add minimum for final result.
    result = result + lower_bound;

    // Return final result.
    return result;
}

Here's a portable version of my random number generator. It will produce a random integer from {lower_bound} to {upper_bound}.

So if you want 33%, then do this (obviously you'll need to include, import or copy in the function first):

Code:
int rnd;
int probability;

// Set probability.
probability = 33;

// Set random.
rnd = dc_vars_get_random_int(0, 100);

// If random is less than probability, do some stuff...
if(rnd < probability)
{

}
 
Back
Top Bottom