randomizing things - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: randomizing things (
/showthread.php?tid=92659)
randomizing things -
dafel2 - 21.08.2009
Like when i enter a vehicle it displays:
you just found a medkit.
For example randomise this code:
Код:
PlayerInventoryAddItem(playerid,"MedKit");
Or sometimes i enter a vehicle and sends a message
you did not find any item.
And my question how can i randomize them.
Dunno if you understand my question
i am trying to create /search code
Re: randomizing things -
woot - 21.08.2009
https://sampwiki.blast.hk/wiki/Random
I'm unsure if it's 0, 1 and 2 in that case, I never really understood that "random" wiki page
pawn Код:
new r = random(3);
if(r == 0) return dosomethinghere();
if(r == 1) return dosomethinghere();
if(r == 2) return dosomethinghere();
Re: randomizing things -
dafel2 - 21.08.2009
Quote:
Originally Posted by //exora
https://sampwiki.blast.hk/wiki/Random
I'm unsure if it's 0, 1 and 2 in that case, I never really understood that "random" wiki page
pawn Код:
new r = random(3); if(r == 0) return dosomethinghere(); if(r == 1) return dosomethinghere(); if(r == 2) return dosomethinghere();
|
That
wiki code is only for spawns?!
Re: randomizing things -
Weirdosport - 21.08.2009
One piece of code can apply for many things..
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
switch(random(4))
{
case 0: // do something
case 1: // do something
case 2: // do something
case 3: // do something
}
}
return 1;
}
As previous poster says, I'm not sure if you need 0,1,2,3 or 1,2,3,4.
Re: randomizing things -
Burridge - 21.08.2009
Quote:
Originally Posted by Weirdosport
As previous poster says, I'm not sure if you need 0,1,2,3 or 1,2,3,4.
|
I do belive you need the 0 first, all code i've ever done has 0,1,2,3,4 ect ect.
Re: randomizing things -
Weirdosport - 21.08.2009
Yeah I checked and random(4) returns 0, 1, 2 and 3
Re: randomizing things -
dafel2 - 21.08.2009
Cool. I got it working
Код:
if(strcmp(cmd, "/search", true) == 0)
{
switch(random(1))
{
case 0:
{
SendClientMessage(playerid, COLOR_RED,"You just found detonator use /info detonator about info.");
}
}
return 1;
}
thanks for helping!