Ammo increased after buying a new weapon(same slot). -
newbienoob - 11.07.2012
Hey, I got another problem that I can't fix it by myself. So I need your help again. I just made my own ammunation for my gamemode. But the problem is, when I buy a new weapon (same slot), it will increased my ammo. For example,
I've bought a shotgun with 300 ammo, and then a combat shotgun with 300 ammo. Shotgun will be replaced by combat shotgun, but combat shotgun ammo will be increased to 600. Any idea how can I fix this problem?
Re: Ammo increased after buying a new weapon(same slot). -
leonardo1434 - 11.07.2012
Try to get the old weapon + amount of ammo, Get the new weapon and the amount the ammo that were bought. After that set his ammo to 0 Then increase the amount of ammo bought for the new weapon.
Re: Ammo increased after buying a new weapon(same slot). -
newbienoob - 11.07.2012
And what if I want to buy a new same weapon to increase the ammo?
Re: Ammo increased after buying a new weapon(same slot). -
leonardo1434 - 11.07.2012
Check if its the same weapon, if it is, just give to them. it will replace and increase the ammo as actually.
Re: Ammo increased after buying a new weapon(same slot). -
jaami - 11.07.2012
Well use ResetPlayerWeapon. Then add the new id weapon. once its done. to detect if its the same weapon. use GetPlayerWeapon(playerid)
Re: Ammo increased after buying a new weapon(same slot). -
MP2 - 11.07.2012
GTA: SA seems to treat ammo per weaponslot, not per individual weapon, which doesn't really make sense. I'm no gun expert but I don't think a desert eagle uses the same ammo as a 9mm.
Here's a fix I wrote:
pawn Код:
new const weapon_slot[] = {
0,
0,
1,
1,
1,
1,
1,
1,
1,
1,
10, // 10
10,
10,
10,
10,
10,
8,
8,
8,
0,
0, // 20
0,
2,
2,
2,
3,
3,
3,
4,
4,
5, // 30
5,
4,
6,
6,
7,
7,
7,
7,
8,
12, // 40
9,
9,
9,
11,
11,
11
};
stock h_GivePlayerWeapon(playerid, weaponid, ammo)
{
if(!IsPlayerConnected(playerid)) return 0;
new weapon, oldammo;
GetPlayerWeaponData(playerid, weapon_slot[weaponid], weapon, oldammo);
GivePlayerWeapon(playerid, weaponid, ammo);
if(weapon != weaponid && weapon != 0)
{
SetPlayerAmmo(playerid, weaponid, oldammo);
}
else
{
SetPlayerAmmo(playerid, weaponid, oldammo+ammo);
}
return 1;
}
#if defined _ALS_GivePlayerWeapon
#undef GivePlayerWeapon
#else
#define _ALS_GivePlayerWeapon
#endif
#define GivePlayerWeapon h_GivePlayerWeapon
All you need to do is put that before you ever use GivePlayerWeapon. Somewhere above all callbacks like above OnGameModeInit (which should be your first callback tbh).
Re: Ammo increased after buying a new weapon(same slot). -
newbienoob - 11.07.2012
PERFECT!!! Thanks MP2