Need help with random - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with random (
/showthread.php?tid=606828)
Need help with random -
GoldenLion - 09.05.2016
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.
Re: Need help with random -
Konstantinos - 09.05.2016
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..
}
}
Re: Need help with random -
F1N4L - 09.05.2016
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
Re: Need help with random -
vannesenn - 09.05.2016
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?
Re: Need help with random -
GoldenLion - 09.05.2016
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.