Need help with random
#1

Hi, this script is supposed to make player struggle when shot in any leg, but the chance is 1 in 2 as I understand, but I get these errors:
Код:
(21) : error 017: undefined symbol "Random"
(41) : error 017: undefined symbol "Random"
Code:
Код:
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
        SetPlayerHealth(playerid, 0.0);
    }
	if(bodypart == 7)
	{
		if(IsPlayerInAnyVehicle(playerid))
		{
		}
		else
		{
			new Struggle = Random(1);
			switch(Struggle)
			{
			case 1:
			{
				ApplyAnimation(playerid, "ped", "FALL_collapse", 4.1, 0, 1, 1, 0, 0, 1);
			}
			case 2:
			{
			}
			}
		}
    }
	if(bodypart == 8)
	{
		if(IsPlayerInAnyVehicle(playerid))
		{
		}
		else
		{
			new Struggle = Random(1);
			switch(Struggle)
			{
			case 1:
			{
				ApplyAnimation(playerid, "ped", "FALL_collapse", 4.1, 0, 1, 1, 0, 0, 1);
			}
			case 2:
			{
			}
			}
		}
    }
How to fix it? Or there's a better way to make it random?
I tried putting new Struggle = Random(1); at the top of the script, but when I compile it successfully compiles, but pawno crashes.
Reply
#2

It is random but that will not work.
Using random(1) will return 0 all the time. Use:
pawn Код:
switch (random(2))
{
    case 0:
    {
        // code..
    }
    default: // 1
    {
        // code..
    }
}
Reply
#3

As @Konstantinos said, the random function is random numbers from 0 (zero) to close the final value, ie:
random(2) = 0, 1 (two numbers)

random(1) = 0
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It is random but that will not work.
Using random(1) will return 0 all the time. Use:
pawn Код:
switch (random(2))
{
    case 0:
    {
        // code..
    }
    default: // 1
    {
        // code..
    }
}
Why he's using swtich instead normal if-statement?
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It is random but that will not work.
Using random(1) will return 0 all the time. Use:
pawn Код:
switch (random(2))
{
    case 0:
    {
        // code..
    }
    default: // 1
    {
        // code..
    }
}
Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)