Ammo increased after buying a new weapon(same slot).
#1

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?
Reply
#2

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.
Reply
#3

And what if I want to buy a new same weapon to increase the ammo?
Reply
#4

Check if its the same weapon, if it is, just give to them. it will replace and increase the ammo as actually.
Reply
#5

Well use ResetPlayerWeapon. Then add the new id weapon. once its done. to detect if its the same weapon. use GetPlayerWeapon(playerid)
Reply
#6

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).
Reply
#7

PERFECT!!! Thanks MP2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)