Problem with /checkweapons
#1

hi there everybody!
I have a problem,
My /checkweapons only returns slot 1.

What am I doing wrong?

pawn Код:
CMD:checkweapons(playerid, params[])
{
    if(PlayerInfo[playerid][AdminLevel] >= 2)
    {
        new id;
        if(!sscanf(params, "u", id))
        {
            new weaponid, ammo, weapon[24];
            new string[128];
            for (new c = 0; c < 13; c++)
            for (new i = 0; i < 13; i++)
            {
                GetPlayerWeaponData(i, c, weaponid, ammo);
                if (weaponid != 0 && ammo != 0)
                {
                    GetWeaponName(weaponid, weapon, 24);
                    format(string, sizeof(string), "Slot %d:    %s    [ID: %d    Ammo: %d]", i, weapon, weaponid, ammo);
                    SendClientMessage(playerid, COLOR_RED, string);
                    return 1;
                }
            }
            return 1;
        }
        else return SendClientMessage(playerid, COLOR_GREY, "USAGE: /checkweapons [Player ID]");
    }
    else return SendClientMessage(playerid, COLOR_GREY, "You are not allowed to use that command!");
}
Reply
#2

Try this.

pawn Код:
CMD:checkweapons(playerid, params[])
{
    if(PlayerInfo[playerid][AdminLevel] >= 2)
    {
        if(params[0])
        {
            new
                id = strval(params);
               
            if(IsPlayerConnected(id))
            {
                new
                    weaponid,ammo,weapon[24];
                new
                    string[128];

                for (new c = 0; c < 13; c++)
                {
                    GetPlayerWeaponData(id, c, weaponid, ammo);
                    if (weaponid != 0 && ammo != 0)
                    {
                        GetWeaponName(weaponid, weapon, 24);
                        format(string, sizeof(string), "Slot %d:    %s    [ID: %d    Ammo: %d]", c, weapon, weaponid, ammo);
                        SendClientMessage(playerid, COLOR_RED, string);
                    }
                }
                return 1;
            }
            else return SendClientMessage(playerid, COLOR_GREY, "Given Player ID is not connected.");
        }
        else return SendClientMessage(playerid, COLOR_GREY, "USAGE: /checkweapons [Player ID]");
    }
    else return SendClientMessage(playerid, COLOR_GREY, "You are not allowed to use that command!");
}
Reply
#3

You don't have any loop for going through all players.

EDIT: ^^^^
Reply
#4

I dont want to loop trough all players?

I want to loop trough one player

EDIT:
thanks will test
Reply
#5

In that case, loop through all the weapon slots.
Reply
#6

Here's the function for getting weapon slots, use the cases for sending messages, or whatever.
Код:
stock GetWeaponSlot(weapon)
{
    new slot;
    switch (weapon)
    {
        case 0: slot = 0;
        case 1: slot = 0;
        case 2: slot = 1;
        case 3: slot = 1;
        case 4: slot = 1;
        case 5: slot = 1;
        case 6: slot = 1;
        case 7: slot = 1;
        case 8: slot = 1;
        case 9: slot = 1;
        case 22: slot = 2;
        case 23: slot = 2;
        case 24: slot = 2;
        case 25: slot = 3;
        case 26: slot = 3;
        case 27: slot = 3;
        case 28: slot = 4;
        case 29: slot = 4;
        case 32: slot = 4;
        case 30: slot = 5;
        case 31: slot = 5;
        case 33: slot = 6;
        case 34: slot = 6;
        case 35: slot = 7;
        case 36: slot = 7;
        case 37: slot = 7;
        case 38: slot = 7;
        case 16: slot = 8;
        case 17: slot = 8;
        case 18: slot = 8;
        case 39: slot = 8;
        case 41: slot = 9;
        case 42: slot = 9;
        case 43: slot = 9;
        case 10: slot = 10;
        case 11: slot = 10;
        case 12: slot = 10;
        case 13: slot = 10;
        case 14: slot = 10;
        case 15: slot = 10;
        case 44: slot = 11;
        case 45: slot = 11;
        case 46: slot = 11;
        case 40: slot = 12;
    }
    return slot;
}
Reply
#7

That's very inefficient. An array should be used.

pawn Код:
new WeaponSlots[] = {
0,
0,
1,
1,
1,
// etc.
};
Then use

pawn Код:
WeaponSlots[weaponid]
to get the slot of weaponid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)