Random Weapons?
#1

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

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

How could the player take the random weapons?

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

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

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

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

Thanks, works!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)