Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

Issues with weapon slot and ammo system I made

$
0
0
For testing purposes, when I use my admin command /agiveweapon to spawn a weapon, it gives the playerid that weapon and if it's say, a pistol (weapon ID: 24), it issues it to a specific slot. I made a primary, secondary and melee weapon slot and I'm trying to have it so you could only hold 3 weapons at a time.

Here's how I wrote the process:
Code:

enum PlayerStatistics
{
    WepSlot1,
    WepSlot2,
    WepSlot3,
    AmmoSlot1,
    AmmoSlot2,
    AmmoSlot3,
};

This is how it's saved when you spawn the weapons:
Code:

public GivePlayerWeaponSave(playerid, weapon, ammo)
{
        switch(weapon)
        {
            case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 41: // Melee Weapons
            {
                Player[playerid][WepSlot1] = weapon;
                Player[playerid][AmmoSlot1] = ammo;
                GivePlayerWeapon(playerid, weapon, ammo);
                }
                case 22, 23, 24: // Secondary Weapons
                {
                    Player[playerid][WepSlot2] = weapon;
                    Player[playerid][AmmoSlot2] = ammo;
                    GivePlayerWeapon(playerid, weapon, ammo);
                }
                case 25, 28, 29, 30, 31, 32, 33, 34: // Primary Weapons
                {
                    Player[playerid][WepSlot3] = weapon;
                    Player[playerid][AmmoSlot3] = ammo;
                    GivePlayerWeapon(playerid, weapon, ammo);
                }
        }
        return 1;
}

I had a problem where when you ran out of ammo, the weapon would still show up in your /stats with no real time update of the ammo & shows it still existing.

Under OnPlayerUpdate I put:
Code:

if(Player[playerid][WepSlot1])
                {
                    GetPlayerWeaponData(playerid, 1, Player[playerid][WepSlot1], Player[playerid][AmmoSlot1]);
                        if(!Player[playerid][AmmoSlot1])
                        {
                            Player[playerid][WepSlot1] = 0;
                            Player[playerid][AmmoSlot1] = 0;
                        }
                }
                if(Player[playerid][WepSlot2])
                {
                    GetPlayerWeaponData(playerid, 2, Player[playerid][WepSlot2], Player[playerid][AmmoSlot2]);
                        if(!Player[playerid][AmmoSlot2])
                        {
                            Player[playerid][WepSlot2] = 0;
                            Player[playerid][AmmoSlot2] = 0;
                        }
                }
                if(Player[playerid][WepSlot3])
                {
                        if(!Player[playerid][AmmoSlot3])
                        {
                            GetPlayerWeaponData(playerid, 4, Player[playerid][WepSlot3], Player[playerid][AmmoSlot3]);
                            Player[playerid][WepSlot3] = 0;
                            Player[playerid][AmmoSlot3] = 0;
                        }
                }

This works well with melee weapons and pistols. However, here's the problem. When I spawn, say, an AK-47 with 100 ammo. I shoot it. I do /stats. AK-47 ammo shows as 100 and it isn't updated. (Works fine for pistols, again). I figured the problem is that I only grab data from weapons in slot 4 here:
Code:

if(Player[playerid][WepSlot3])
                {
                        if(!Player[playerid][AmmoSlot3])
                        {
                            GetPlayerWeaponData(playerid, 4, Player[playerid][WepSlot2], Player[playerid][AmmoSlot2]);

However, a weapon, for example like the MP5 (ID: 29) that uses that slot also doesn't save in like, /stats.

Here's what I mean:


What am I doing wrong or any help on what to improve?

Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>