SA-MP Forums Archive
Random Gun!! - 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: Random Gun!! (/showthread.php?tid=66272)



Random Gun!! - Martin_Smith - 20.02.2009

Hey, i want to make a command, Where you say /randgun and you get a random gun, one of these id guns:

24,25,26,27,28,29,30,31,36,37,38

So, any idea on how to do this? i asumed it would have sumin to do with

GivePlayerWeapon(playerid,*sumin goes here to do with Random number* ,200);

Lol, well i duno, so any help?


Re: Random Gun!! - Lazarus - 20.02.2009

pawn Код:
GivePlayerWeapon(playerid, random(38 - 24) + 24, 500);
http://forum.sa-mp.com/index.php?top...5123#msg555123

EDIT:
Or,

pawn Код:
new weapon = random(11);
switch(weapon)
{
    case 0: GivePlayerWeapon(playerid, 24, 500);
    case 1: GivePlayerWeapon(playerid, 25, 500);
    case 2: GivePlayerWeapon(playerid, 26, 500);
    case 3: GivePlayerWeapon(playerid, 27, 500);
    case 4: GivePlayerWeapon(playerid, 28, 500);
    case 5: GivePlayerWeapon(playerid, 29, 500);
    case 6: GivePlayerWeapon(playerid, 30, 500);
    case 7: GivePlayerWeapon(playerid, 31, 500);
    case 8: GivePlayerWeapon(playerid, 36, 500);
    case 9: GivePlayerWeapon(playerid, 37, 500);
    case 10: GivePlayerWeapon(playerid, 38, 500);
}



Re: Random Gun!! - walrus - 20.02.2009

Ain't array would be faster and more compact in script?


Re: Random Gun!! - Lazarus - 20.02.2009

I'm just putting down random ideas.

pawn Код:
new weapons[] =
{
    24,
    25,
    26,
    27,
    28,
    29,
    30,
    31,
    36,
    37,
    38
};

GivePlayerWeapon(playerid, weapons[random(11)], 500);