SA-MP Forums Archive
Getting amount of ammo in a weapon through the weaponid? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting amount of ammo in a weapon through the weaponid? (/showthread.php?tid=268441)



Getting amount of ammo in a weapon through the weaponid? - [IL]HeHu - 12.07.2011

Title, is it possible?


Re: Getting amount of ammo in a weapon through the weaponid? - [IL]HeHu - 12.07.2011

I thought of that, but wouldn't be kind of slow, for example to get the player's ammo on OnPlayerDisconnect?


Re: Getting amount of ammo in a weapon through the weaponid? - [IL]HeHu - 12.07.2011

Alright, made it, if anyone needs it, here it is:
PHP код:
stock GetWeaponAmmoThroughID(playerid,weaponid)
{
    new
        
ammo,
        
weapslot
    
;
    
weapslot GetWeaponSlot(weaponid);
    
GetPlayerWeaponData(playeridweapslotweaponidammo);
    return 
ammo;




Re: Getting amount of ammo in a weapon through the weaponid? - BigETI - 12.07.2011

pawn Код:
#define INVALID_WEAPON_SLOT_ID -1
stock GetWeaponSlot(weaponid)
{
    new slot;
    switch(weaponid)
    {
        case 0,1: slot = 0;
        case 2..9: slot = 1;
        case 22..24: slot = 2;
        case 25..27: slot = 3;
        case 28,29,32: slot = 4;
        case 30,31: slot = 5;
        case 33,34: slot = 6;
        case 35..38: slot = 7;
        case 16..18,39: slot = 8;
        case 41..43: slot = 9;
        case 10..15: slot = 10;
        case 44..46: slot = 11;
        case 40: slot = 12;
        default: slot = INVALID_WEAPON_SLOT_ID;
    }
    return slot;
}

stock GetPlayerAmmoFromWeapon(playerid, weaponid)
{
    new weapon, ammo;
    GetPlayerWeaponData(playerid, GetWeaponSlot(weaponid), weapon, ammo);
    return ammo;
}