Random weapon
#1

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]);
Reply
#2

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

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

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]); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)