Detecting 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: Detecting ammo. (
/showthread.php?tid=280122)
Detecting ammo. -
Darnell - 30.08.2011
I have this code, and I can't understand how to script, that if player has more than 1 bullet, it won't let him choose the following thing from the inventory.
pawn Код:
if(itemid == ITEM_COLT45CLIP) {
RemoveItemFromPlayerInventory(playerid, ITEM_COLT45CLIP, 1);
GivePlayerWeapon(playerid,22, 17);
ApplyAnimationEx(playerid, "SILENCED", "Silence_reload", 3.0, 0, 0, 0, 0, 0);
SendClientMessage(playerid, COLOR_GREEN, "You have taken a COLT45 clip from your inventory & reloaded your weapon.");
return 1;
}
I can't understand how to use GetPlayerWeaponData, etc.
Re: Detecting ammo. -
[MWR]Blood - 30.08.2011
pawn Код:
new weapons[13][2];
for (new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]/*this is the ammo*/);
if(weapons[i][1] > 1)
{
//your code here
}
}
Re: Detecting ammo. -
AndreT - 30.08.2011
Judging from
this, pistols are in slot 2 (this would be different for every weapon-specific clip that you take out of your inventory). To get the weapon data of slot 2, do this:
pawn Код:
new weapons, ammo;
GetPlayerWeaponData(playerid, 2, weapons, ammo);
Then, to check if there are no bullets left, just do
pawn Код:
if(!ammo)
// yup, out of bullets
Edit
Why not also use the function
GetPlayerWeaponState and check:
pawn Код:
if(GetPlayerWeaponState(playerid) == WEAPONSTATE_NO_BULLETS)
// same as
if(!GetPlayerWeaponState(playerid))
Re: Detecting ammo. -
Kar - 30.08.2011
pawn Код:
if(itemid == ITEM_COLT45CLIP) {
new ammo;
GetPlayerWeaponData(playerid, 2, ammo, ammo);//ammo is set last
if(ammo > 1) return SendClientMessage(playerid, -1, "You already have colt45 ammo?");
RemoveItemFromPlayerInventory(playerid, ITEM_COLT45CLIP, 1);
GivePlayerWeapon(playerid,22, 17);
ApplyAnimationEx(playerid, "SILENCED", "Silence_reload", 3.0, 0, 0, 0, 0, 0);
SendClientMessage(playerid, COLOR_GREEN, "You have taken a COLT45 clip from your inventory & reloaded your weapon.");
return 1;
}
Quote:
Originally Posted by AndreT
Edit
Why not also use the function GetPlayerWeaponState and check:
pawn Код:
if(GetPlayerWeaponState(playerid) == WEAPONSTATE_NO_BULLETS) // same as if(!GetPlayerWeaponState(playerid))
|
I don't think he wants it for his "current" weapon holding, maybe the colt45 is in his just in his ammo rack (metaphor)
Re: Detecting ammo. -
Darnell - 30.08.2011
Kar, that's excatly what I was looking for, thank you.