Ammunition of the player's current weapon - 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: Ammunition of the player's current weapon (
/showthread.php?tid=664000)
Ammunition of the player's current weapon -
Volumen - 17.02.2019
How can I detect the player's current ammunition and the remaining ammunition to recharge the weapon? Example: "7/14", "7" are the bullets that the weapon currently has and '14' is the available ammunition that the weapon has at this moment to be able to recharge it.
I already used 'GetPlayerAmmo' and 'GetPlayerWeaponData' but both functions show the total number of bullets (which can be fired by the weapon + the refills).
Re: Ammunition of the player's current weapon -
d3Pedro - 17.02.2019
switching the weapon OnPlayerWeaponShot and using a variable to save ammo whenever you give them weapon or they buy it.
Re: Ammunition of the player's current weapon -
Volumen - 17.02.2019
Quote:
Originally Posted by ConnorW
switching the weapon OnPlayerWeaponShot and using a variable to save ammo whenever you give them weapon or they buy it.
|
Is it the only way to do that?
Re: Ammunition of the player's current weapon -
ComDuck - 17.02.2019
https://sampwiki.blast.hk/wiki/GetPlayerWeaponData
https://sampwiki.blast.hk/wiki/GetPlayerAmmo
If both of those functions give you the total ammunition per weapon, then for each weapon's total ammo divide it with the amount of rounds it can shoot per clip.
Deagle with 56 ammo, 7 rounds per clip: 56/7 = 8 clips remaining
If you don't get a whole number, then assume that:
Deagle with 52 ammo, 7 rounds per clip: 7.4285.. clips left = 7, ammo left = 0.4285... * 7 (rounds per clip, not the clips left) = 2.99 (round to 3)
Re: Ammunition of the player's current weapon -
TheToretto - 17.02.2019
I'd rather opt to make it manually, as some weapons don't have a magazine, I mean maximum shots before reload, as the Shotgun Sniper Country Rifle etc. I'd've done something like that:
Код:
ReloadWeapon(playerid, weaponid, ammo)
{
switch(weaponid)
{
case 24:
{
SetPlayerAmmo(playerid, weaponid, ammo + 7);
magInfo[playerid][Deagle]--;
}
}
}