randomizing things
#1

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
Reply
#2

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();
Reply
#3

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?!
Reply
#4

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.
Reply
#5

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.
Reply
#6

Yeah I checked and random(4) returns 0, 1, 2 and 3
Reply
#7

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)