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



Random weapon - SymonClash - 24.01.2019

Can someone tell me why this code just gives 1 weapon at the player?

I want to give 1 weapon for every set. Like 1 deagle, 1 sawn, 1 uzi, 1 grenade etc.

pawn Code:
new RandomWeapon[][2] =
{
   // {Weapon ID, Amount of Ammo}
   {22, 320}, // 9mm
   {24, 320}, // Desert Eagle
   {26, 320}, // Sawnoff Shotgun
   {27, 320}, // Combat Shotgun
   {28, 320}, // Micro SMG/Uzi
   {29, 320}, // MP5
   {30, 320}, // AK-47
   {32, 320}, // Tec-9
   {16, 10}, // Grenade
   {18, 10} // Molotov Cocktail
};
new wep = random(sizeof(RandomWeapon));
GivePlayerWeapon(playerid, RandomWeapon[wep][0], RandomWeapon[wep][1]);



Re: Random weapon - Hazon - 24.01.2019

Not tested.

Code:
new RandomWeapons[][3] =
{
	//Weapons
	{},
	{},
	{},
	//etc..
};
new randw = random(sizeof(RandomWeap));
GivePlayerWeapon(playerid, RandomWeapons[randw][0], ammo);
GivePlayerWeapon(playerid, RandomWeapons[randw][1], ammo);
GivePlayerWeapon(playerid, RandomWeapons[randw][2], ammo);



Re: Random weapon - Calisthenics - 24.01.2019

https://sampwiki.blast.hk/wiki/Weapons

Each weapon belongs to a certain category. For instance, combat shotgun replaces sawn-off shotgun and vice-versa because they have the same slot.


Re: Random weapon - codExpert - 24.01.2019

PHP Code:
//weapon slot, weapon, ammo
new weapons[][3]={
    {
0,30,300},
    {
0,31,300},
    {
1,30,300},
    {
1,31,300},
    {
2,30,300},
    {
2,31,300}
};
getRandomWeaponFromSlot(slot){
    new 
slots[],cnt;
    for(new 
i,i2=sizeof(weapons); i2i++){
        if(
weapons[i][0]==slot){
            
slots[cnt++]=i;
        }
    }
    return 
slots[random(cnt)];
}
new 
slot=getRandomWeaponFromSlot(0);
GivePlayerWeapon(playeridweapons[slot][1], weapons[slot][2]);
slot=getRandomWeaponFromSlot(1);
GivePlayerWeapon(playeridweapons[slot][1], weapons[slot][2]);
slot=getRandomWeaponFromSlot(2);
GivePlayerWeapon(playeridweapons[slot][1], weapons[slot][2]);