onplayerspawn random weapon
#1

how to give random gun onplayerspawn? with some prohibited weapons like. flame thrower,granede, minigun, rocket. rocket seaker. thanks!
Reply
#2

decide your weapon's.
pawn Code:
new x = random(5);
switch(x)
{
    case 0:
    {
        //Weapon1
        //Weapon2
        //Weapon3
        //Weapon4
    }
    case 1:
    {
        //Weapon1
        //Weapon2
        //Weapon3
        //Weapon4
    }
    case 2:
    {
        //Weapon1
        //Weapon2
        //Weapon3
        //Weapon4
    }
    case 3:
    {
        //Weapon1
        //Weapon2
        //Weapon3
        //Weapon4
    }
    case 4:
    {
        //Weapon1
        //Weapon2
        //Weapon3
        //Weapon4
    }
}
Reply
#3

As DanRT said you could use that code, to give a random weapon on spawn. You could do this by replacing "//weapon1//" with "GivePlayerWeapon(playerid, 26, 64)" Obviously replacing the "26" with your weapon(ID). You can view (a) list of weapon IDS by clicking here. You can then replace the "64" with the desired amount of ammo. Of-course you don't have to put a number if your script doesn't use ammo/has unlimited ammo.
Reply
#4

Or, you can use that, and fill in the weapon, and the ammo.

Check this to see the weapon IDs and more.


Good luck!
Reply
#5

pawn Code:
public OnPlayerSpawn(playerid)
{
    GivePlayerWeapon(playerid, (random(35 - 22) + 22), 500);
    return 1;
}
Reply
#6

You can use emmets method, alswell. But if you want them to be random might wanna use DanRT's method...

Heres an example...

Code:
new x = random(5);
switch(x)
{
    case 0:
    {
        
        GivePlayerWeapon(playerid, 26, 64); // Give the player a sawn-off shotgun, with 64 ammo.
    }
    case 1:
    {
        GivePlayerWeapon(playerid, 24, 64); // Give the player a deagle, with 64 ammo.
    }
    case 2:
    {
        GivePlayerWeapon(playerid, 27, 64); // Give the player a spas(combat shotgun), with 64 ammo.
    }
    case 3:
    {
    GivePlayerWeapon(playerid, 21, 64); // Give the player an M-4, with 64 ammo.
    }
    case 4:
    {
       GivePlayerWeapon(playerid, 30, 64); // Give the player an AK-47, with 64 ammo.
    }
}
This would go under ([Public OnPlayerSpawn]). You have a 1/4 chance of getting each of the above weapons, at a random. I believe thats what you want.
Reply
#7

Yeah follow what user said above
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)