A function wich returns all the players weapons wont work.
#1

Hello there,

As the title says i made a little function that returns all the players weapons;
pawn Код:
stock GetAllPlayerWeapons(playerid)
{
    new weapons[13],ammo;

    for (new w = 0; w <= 12; w++)
    {
    GetPlayerWeaponData(playerid,w, weapons[w], ammo);
    }
    return 1;//weapons;
}
I am doing something wrong though because when i want to use the function in a command like here;
pawn Код:
new outcome[13];
        format(outcome,sizeof(outcome),"%d",GetAllPlayerWeapons(playerid));
        SendClientMessage(playerid,COLOR_GREEN,outcome);
it returns just a 0 or a 1...must be something wrong with the string im missing here i guess
Reply
#2

return shouldnt be 1 or 0 it should be something that you want to get for ex. player weapon id.
Reply
#3

i did try
pawn Код:
return weapons;
wich didnt work

Edit: it seems that a format made inside the stock returns the correct number

pawn Код:
format(wepstr,sizeof(wepstr),weapons[w]);
printf(wepstr);
Reply
#4

How about this.Because you didnt define which slot to return.

pawn Код:
return weapons[v];
Reply
#5

that returns 1 :S
Reply
#6

Try this;

pawn Код:
stock GetAllPlayerWeapons(playerid)
{
    new weapons[13],ammo;
    for(new i=0;i<13;i++)
    {
        GetPlayerWeaponData(playerid, i, weapon, ammo);
        if(weapon != 0)
        {
            format(message, sizeof(message), "Player %s's weapons: Slot(%d): Weapon ID(%d) Ammo(%d)", GetName(Player),i, weapon, ammo);
            SendClientMessage(playerid, -1, message);
        }
    }
    return weapon;//weapons;
}
Reply
#7

your function gave me the same problem.

tried it from a less efficient angle now;

pawn Код:
stock GetAllPlayerWeapons(playerid)
{
    new weapons[13],ammo;
    new wepstr[12];
    GetPlayerWeaponData(playerid,0,weapons[0],ammo);
    GetPlayerWeaponData(playerid,1,weapons[1],ammo);
    GetPlayerWeaponData(playerid,2,weapons[2],ammo);
    GetPlayerWeaponData(playerid,3,weapons[3],ammo);
    GetPlayerWeaponData(playerid,4,weapons[4],ammo);
    GetPlayerWeaponData(playerid,5,weapons[5],ammo);
    GetPlayerWeaponData(playerid,6,weapons[6],ammo);
    GetPlayerWeaponData(playerid,7,weapons[7],ammo);
    GetPlayerWeaponData(playerid,8,weapons[8],ammo);
    GetPlayerWeaponData(playerid,9,weapons[9],ammo);
    GetPlayerWeaponData(playerid,10,weapons[10],ammo);
    GetPlayerWeaponData(playerid,11,weapons[11],ammo);
    GetPlayerWeaponData(playerid,12,weapons[12],ammo);
    //remove under here later ..its just for test
    format(wepstr,sizeof(wepstr),"%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
    weapons[0],
    weapons[1],
    weapons[2],
    weapons[3],
    weapons[4],
    weapons[5],
    weapons[6],
    weapons[7],
    weapons[8],
    weapons[9],
    weapons[10],
    weapons[11],
    weapons[12]);

    printf("weapons for player:");
    printf(wepstr);

    return 1;
}
The print returns the number correctly like this; "0220000000000" means i have a pistol (id 22) and the rest is empty.

but again if i use the actual function in a format like here;

pawn Код:
if(!strcmp(cmdtext, "/checkit", true))
    {
        new outcome[13];
        format(outcome,sizeof(outcome),"%d",GetAllPlayerWeapons(playerid));
        SendClientMessage(playerid,COLOR_GREEN,outcome);
        return 1;
    }
returns me just a green '0'
Reply
#8

pawn Код:
return wepstr;
Let everything as it is at moment and just use the return i gave you.

pawn Код:
CMD:getweapons(playerid, params[])
{
* * new string[128], pID, *pname[MAX_PLAYER_NAME];
* * if(pInfo[playerid][Level] < 1) return 0;
* * if(sscanf(params, "u", pID)) return SendClientMessage(playerid, 0xFF0000AA, "[USAGE]: /getweapons");
* * GetPlayerName(pID, pname, sizeof(pname));
* * format(string, sizeof(string), "============ Checking %s's Current Weapons =============", pname);
* * SendClientMessage(playerid, 0xFF0000AA, string);
* * for(new i; i< 12; i++)
* * {
* * * * GetPlayerWeaponData(pID, i, pgun[i][0]);
* * * * format(string ,sizeof(string), "[WEAPON: %s][AMMO: %d]", guns[pgun[i][0]], guns[pgun[i][1]]);
* * * * SendClientMessage(playerid, 0xFF0000AA, string);
* * }
* * return 1;
}
Also you can use something like this to let it show up. (I found this somewhere on the forum.)
Reply
#9

For some reason the clientmessage inside my stock returned the correct value (i did return webstr)
and the string i get returned from the command returns the number 48.

Thanks i saw some commands like that before, but i realy need the actual function itself to work.
Reply
#10

pawn Код:
stock GetAllPlayerWeapons(playerid)
{
    new fstr[175], count, weapons[13][2];
    for(new w = 0; w < 13; w++)
    {
        GetPlayerWeaponData(playerid, w, weapons[w][0], weapons[w][1]);
        if(weapons[w][0])
        {
            new str[21];
            GetWeaponName(weapons[w][0], str, sizeof(str));
            format(str, sizeof(str), ((count) ? (", %s") : ("%s")), str);
            strcat(fstr, str);
            count++;
        }
    }
    return fstr;
}
Example:
pawn Код:
SendClientMessage( ADMIN, -1, GetAllPlayerWeapons( TARGET ));
Take note that GetAllPlayerWeapons can be longer than 128 cells if the target has a lot of weapons. So make sure you consider using a function that will make the one line into two.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)