GetWeaponNamefromId
#1

I just resume my work after 1month, so I think i forgot almost

Problem:


I got the function from fsdebug:
pawn Код:
GetWeaponModelIDFromName(wname[])
{
    for(new i = 0; i < 48; i++) {
        if (i == 19 || i == 20 || i == 21) continue;
        if (strfind(aWeaponNames[i], wname, true) != -1) {
            return i;
        }
    }
    return -1;
}
I don't have problems in aWeaponNames because they are only weapon names.

pawn Код:
new wName = GetWeaponModelIDFromName(istr);

format(str8, sizeof(str8), "Weapon: %s", wName);
TextDrawSetString(Text:Textdraw8, str8);
I don't know where is the problem :S

It should be:
"Weapon: MP5"

but it shows my name
Reply
#2

The function returns a number (integer) of the weapon ID, not a weapon name. You're asking the function to get the weapon number from the weapons name. Which is clearly not what you're trying to do.

pawn Код:
new wName = GetWeaponModelIDFromName(istr);

format(str8, sizeof(str8), "Weapon: %s", wName); // < it returns a number, not a weapon *name*
If you want a function that does the opposite and gets the weapon name from its ID, then use aWeaponNames along with the weapon ID.

pawn Код:
format(str8, sizeof(str8), "Weapon: %s", aWeaponNames[GetPlayerWeapon(playerid)]);
That should work, but I've not seen the weapon names array so I can't confirm it will.
Reply
#3

Thanks! It worked! <3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)