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



Random Weapons? - JimmyNeonHD - 11.05.2013

Hello, how can i give the player random weapons every time he spawn?

Like every time a new weapons in Cases?

I can't find any tutorial


AW: Random Weapons? - HurtLocker - 11.05.2013

no need for cases, but you have to add exceptions after the selection has already taken place for weapons you don't want. https://sampwiki.blast.hk/wiki/Random


Re: Random Weapons? - JimmyNeonHD - 11.05.2013

How could the player take the random weapons?

I mean like he take 5 weapons, Every time he spawn he take new one


Re: Random Weapons? - Onfroi - 11.05.2013

pawn Код:
new RandomWeap[][4] =
{
    {WEAPON_MP5},
    {WEAPON_M4},
    {WEAPON_SHOTGUN}
    // you can keep adding more just have to change the "[4]" to the number you have defined +1
};

public OnPlayerSpawn(playerid)
{
    new rand = random(sizeof(RandomWeap));
 
    GivePlayerWeapon(playerid, RandomWeap[rand][0], ammo); //change "ammo" to the amount of ammo you want
    GivePlayerWeapon(playerid, RandomWeap[rand][1], ammo); //change "ammo" to the amount of ammo you want
    GivePlayerWeapon(playerid, RandomWeap[rand][2], ammo); //change "ammo" to the amount of ammo you want
 
    return 1;
}
Not sure if it'll work though, test it.


Re: Random Weapons? - JimmyNeonHD - 11.05.2013

pawn Код:
error 017: undefined symbol "RandomWeap"
error 029: invalid expression, assumed zero
warning 215: expression has no effect
error 017: undefined symbol "RandomWeap"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


6 Errors.



AW: Random Weapons? - HurtLocker - 11.05.2013

weapons[5] array contains the weapons' ids.

Under OnPlayerSpawn:
pawn Код:
new weapons[5]={24, 26, 28, 29, 31};
new rand=random(5);
GivePlayerWeapon(playerid,weapons[rand], 400);
EDIT: late


Re: Random Weapons? - JimmyNeonHD - 11.05.2013

Thanks, works!