How to get player weapon and ammo? - 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: How to get player weapon and ammo? (
/showthread.php?tid=345631)
How to get player weapon and ammo? -
ricardo178 - 25.05.2012
Hello. I am trying my luck with /inv system, and making the command /putgun, i need to check if player has the weapon and ammo that he is trying to put in inventory.
If it was only weapon, i would use if(GetPlayerWeapon(playerid) == GunId) but i want to get ammo also, and GetPlayerWeaponData confused me a bit...
How could i use GetPlayerWeaponDate, in order to check if the player has a desert eagle(ID 24) with 50 ammo?
Thanks. Today i am just feeling to script. xD
Re: How to get player weapon and ammo? -
milanosie - 25.05.2012
GetPlayerAmmo(playerid)... 0_0
That was hard!
pawn Код:
CMD:checkweapons(playerid, params[])
{
if(PlayerInfo[playerid][AdminLevel] >= 3)
{
new count = 0;
new ammo, weaponid, weapon[24], string[128], id;
if(!sscanf(params, "u", id))
{
for (new c = 0; c < 13; c++)
{
GetPlayerWeaponData(id, c, weaponid, ammo);
if (weaponid != 0 && ammo != 0)
{
count++;
}
}
SCM(playerid, COLOR_ORANGE, "||=============WEAPONS AND AMMO===========||");
if(count > 0)
{
for (new c = 0; c < 13; c++)
{
GetPlayerWeaponData(id, c, weaponid, ammo);
if (weaponid != 0 && ammo != 0)
{
GetWeaponName(weaponid, weapon, 24);
format(string, sizeof(string), "Weapons: %s Ammo: %d", weapon, ammo);
SendClientMessage(playerid, COLOR_GREEN, string);
}
}
}
else
{
SCM(playerid, COLOR_GREY, "This player has no weapons!");
}
return 1;
}
else return SCM(playerid, COLOR_GREY, "USAGE: /checkweapons [ID]");
}
else return SCM(playerid, COLOR_GREY, "You are not allowed to do this");
}
Edit it to your likings
Re: How to get player weapon and ammo? -
MadeMan - 25.05.2012
From this page you can see the slots of weaponids
https://sampwiki.blast.hk/wiki/Weapons
For example Desert Eagle is slot nr 2. Use it in GetPlayerWeaponData
https://sampwiki.blast.hk/wiki/GetPlayerWeaponData
Example:
pawn Код:
new weaponid, ammo;
GetPlayerWeaponData(playerid, 2, weaponid, ammo);
if(weaponid == WEAPON_DEAGLE && ammo == 50)
{
}
Re: How to get player weapon and ammo? -
ricardo178 - 25.05.2012
Wow, didn't even remember about checking for its existence. xD
Once again, Thank youuuuuuuuuuuuuuuuu!