GetWeaponNamefromId - 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)
+--- Thread: GetWeaponNamefromId (
/showthread.php?tid=297925)
GetWeaponNamefromId -
Gazmull - 18.11.2011
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
Re: GetWeaponNamefromId -
Calgon - 18.11.2011
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.
Re: GetWeaponNamefromId -
Gazmull - 18.11.2011
Thanks! It worked! <3