Detecting ammo.
#1

I have this code, and I can't understand how to script, that if player has more than 1 bullet, it won't let him choose the following thing from the inventory.
pawn Код:
if(itemid == ITEM_COLT45CLIP) {
        RemoveItemFromPlayerInventory(playerid, ITEM_COLT45CLIP, 1);

        GivePlayerWeapon(playerid,22, 17);
        ApplyAnimationEx(playerid, "SILENCED", "Silence_reload", 3.0, 0, 0, 0, 0, 0);

        SendClientMessage(playerid, COLOR_GREEN, "You have taken a COLT45 clip from your inventory & reloaded your weapon.");
        return 1;
    }
I can't understand how to use GetPlayerWeaponData, etc.
Reply
#2

pawn Код:
new weapons[13][2];
    for (new i = 0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]/*this is the ammo*/);
        if(weapons[i][1] > 1)
        {
            //your code here
        }
    }
Reply
#3

Judging from this, pistols are in slot 2 (this would be different for every weapon-specific clip that you take out of your inventory). To get the weapon data of slot 2, do this:
pawn Код:
new weapons, ammo;
GetPlayerWeaponData(playerid, 2, weapons, ammo);
Then, to check if there are no bullets left, just do
pawn Код:
if(!ammo)
    // yup, out of bullets
Edit
Why not also use the function GetPlayerWeaponState and check:
pawn Код:
if(GetPlayerWeaponState(playerid) == WEAPONSTATE_NO_BULLETS)
// same as
if(!GetPlayerWeaponState(playerid))
Reply
#4

pawn Код:
if(itemid == ITEM_COLT45CLIP) {
        new ammo;
        GetPlayerWeaponData(playerid, 2, ammo, ammo);//ammo is set last
        if(ammo > 1) return SendClientMessage(playerid, -1, "You already have colt45 ammo?");
        RemoveItemFromPlayerInventory(playerid, ITEM_COLT45CLIP, 1);

        GivePlayerWeapon(playerid,22, 17);
        ApplyAnimationEx(playerid, "SILENCED", "Silence_reload", 3.0, 0, 0, 0, 0, 0);

        SendClientMessage(playerid, COLOR_GREEN, "You have taken a COLT45 clip from your inventory & reloaded your weapon.");
        return 1;
    }
Quote:
Originally Posted by AndreT
Посмотреть сообщение
Edit
Why not also use the function GetPlayerWeaponState and check:
pawn Код:
if(GetPlayerWeaponState(playerid) == WEAPONSTATE_NO_BULLETS)
// same as
if(!GetPlayerWeaponState(playerid))
I don't think he wants it for his "current" weapon holding, maybe the colt45 is in his just in his ammo rack (metaphor)
Reply
#5

Kar, that's excatly what I was looking for, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)