SA-MP Forums Archive
Give ammo to a weapon slot - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Give ammo to a weapon slot (/showthread.php?tid=178859)



Give ammo to a weapon slot - ZamaXor - 24.09.2010

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



Re: Give ammo to a weapon slot - Ash. - 24.09.2010

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.");
}



Re: Give ammo to a weapon slot - ZamaXor - 24.09.2010

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.


Re: Give ammo to a weapon slot - wups - 24.09.2010

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.
   }

}



Re: Give ammo to a weapon slot - ZamaXor - 24.09.2010

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.");
           }



Re: Give ammo to a weapon slot - wups - 24.09.2010

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.");



Re: Give ammo to a weapon slot - wups - 24.09.2010

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.");
   }



Re: Give ammo to a weapon slot - ZamaXor - 24.09.2010

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.


Re: Give ammo to a weapon slot - Cypress - 25.09.2010

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