Give ammo to a weapon slot
#1

Hello,

I want to give player ammo to a weapon slot. I check if player has got the right weapon. But it gives player the ammo if he hasn't got the right weapon slot. The script not checks for the weapon.

pawn Код:
if(GetPlayerWeapon(playerid) == 29) return SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
           {
             GivePlayerMoney(playerid, -500);
             new Ammo = GetPlayerAmmo(playerid);
             SetPlayerAmmo(playerid, 29, Ammo+20);
Reply
#2

pawn Код:
if(GetPlayerWeapon(playerid) == 29)
{
     GivePlayerMoney(playerid, -500);
     new Ammo = GetPlayerAmmo(playerid);
     SetPlayerAmmo(playerid, 29, Ammo+20);
}
else
{
     SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
}
Reply
#3

Quote:
Originally Posted by funky1234
Посмотреть сообщение
pawn Код:
if(GetPlayerWeapon(playerid) == 29)
{
     GivePlayerMoney(playerid, -500);
     new Ammo = GetPlayerAmmo(playerid);
     SetPlayerAmmo(playerid, 29, Ammo+20);
}
else
{
     SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
}
How to make it so it wont check if player is holding the right weapon? Just if he has got the weapon in his case.
Reply
#4

pawn Код:
new weap[2];
for(new i; i<12;i++)
{
   GetPlayerWeaponData(playerid,i,weap[0],weap[1]);
   if(weap[0] == MODEL HERE)
   {
    // ur code here.
   }

}
Reply
#5

Quote:
Originally Posted by wups
Посмотреть сообщение
pawn Код:
new weap[2];
for(new i; i<12;i++)
{
   GetPlayerWeaponData(playerid,i,weap[0],weap[1]);
   if(weap[0] == MODEL HERE)
   {
    // ur code here.
   }

}
How can i add this to this?

pawn Код:
if(GetPlayerWeapon(playerid) == 22 && GetPlayerWeapon(playerid) == 23 && GetPlayerWeapon(playerid) == 24)
           {
             GivePlayerMoney(playerid, -200);
             new Ammo = GetPlayerAmmo(playerid);
             SetPlayerAmmo(playerid, 22, Ammo+20);
             SetPlayerAmmo(playerid, 23, Ammo+20);
             SetPlayerAmmo(playerid, 24, Ammo+20);
         }
         else
           {
               SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
           }
Reply
#6

Quote:
Originally Posted by ZamaXor
Посмотреть сообщение
How can i add this to this?

pawn Код:
if(GetPlayerWeapon(playerid) == 22 && GetPlayerWeapon(playerid) == 23 && GetPlayerWeapon(playerid) == 24)
           {
             GivePlayerMoney(playerid, -200);
             new Ammo = GetPlayerAmmo(playerid);
             SetPlayerAmmo(playerid, 22, Ammo+20);
             SetPlayerAmmo(playerid, 23, Ammo+20);
             SetPlayerAmmo(playerid, 24, Ammo+20);
         }
         else
           {
               SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
           }
pawn Код:
new weap[2],bool:ammogiven;
for(new i; i<12;i++)
{
   GetPlayerWeaponData(playerid,i,weap[0],weap[1]);
   if(weap[0] == 22 || weap[0] == 23 || weap[0] == 24)
   {
             GivePlayerMoney(playerid, -200);
             new Ammo = GetPlayerAmmo(playerid);
             SetPlayerAmmo(playerid, 22, Ammo+20);
             SetPlayerAmmo(playerid, 23, Ammo+20);
             SetPlayerAmmo(playerid, 24, Ammo+20);
             ammogiven=true;
             break;
   }
}
if(!ammogiven) return  SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
Reply
#7

Ok a little mod, since pistols are always slot 2.
pawn Код:
new weap[2];
   GetPlayerWeaponData(playerid,2,weap[0],weap[1]); // weap[0] is the weapon, and weap[1] is ammo.
   if(weap[0] == 22 || weap[0] == 23 || weap[0] == 24)
   {
             GivePlayerMoney(playerid, -200);
             SetPlayerAmmo(playerid, GetPlayerWeapon(playerid), weap[1]+20);
   }
   else
   {
         SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
   }
Reply
#8

Quote:
Originally Posted by wups
Посмотреть сообщение
Ok a little mod, since pistols are always slot 2.
pawn Код:
new weap[2];
   GetPlayerWeaponData(playerid,2,weap[0],weap[1]); // weap[0] is the weapon, and weap[1] is ammo.
   if(weap[0] == 22 || weap[0] == 23 || weap[0] == 24)
   {
             GivePlayerMoney(playerid, -200);
             SetPlayerAmmo(playerid, GetPlayerWeapon(playerid), weap[1]+20);
   }
   else
   {
         SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
   }
Will this script give ammo if player has got 1 of those weapons? Also i noticed that if i hold other weapons this wont give me the ammo for pistols. This gives me ammo only if i hold 1 of those weapons.


I want something like if i'm holding shotgun and i will buy those ammo for pistol my weapon will switch to pistol.
Then i'm holding pistol and i'll buy ammo for shotgun my weapon will switch from pistol to shotgun.
Reply
#9

Quote:
Originally Posted by wups
Посмотреть сообщение
Ok a little mod, since pistols are always slot 2.
pawn Код:
new weap[2];
   GetPlayerWeaponData(playerid,2,weap[0],weap[1]); // weap[0] is the weapon, and weap[1] is ammo.
   if(weap[0] == 22 || weap[0] == 23 || weap[0] == 24)
   {
             GivePlayerMoney(playerid, -200);
             SetPlayerAmmo(playerid, GetPlayerWeapon(playerid), weap[1]+20);
   }
   else
   {
         SendClientMessage(playerid, COLOR_LRED, "You don't have the right weapon for this kind of ammo.");
   }
Use this. U get the weapon but which weapon?
pawn Код:
SetPlayerAmmo(playerid, GivePlayerWeapon(playerid,weap[0], 20), weap[1]+20);
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)