SA-MP Forums Archive
Weapon Name by ID - Help? - 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: Weapon Name by ID - Help? (/showthread.php?tid=341981)



Weapon Name by ID - Help? - nGen.SoNNy - 12.05.2012

Hello again guys...i want to make something in /stats to show the Weapon Name by his ID! Can somebody give me an example? REP++;


Re: Weapon Name by ID - Help? - Jonny5 - 12.05.2012

you can use
https://sampwiki.blast.hk/wiki/GetWeaponName

but you have to take in account ids 18, 44 and 45.
https://sampwiki.blast.hk/wiki/Weapons


Re: Weapon Name by ID - Help? - nGen.SoNNy - 12.05.2012

That works in PublicOnPlayerDeath


Re: Weapon Name by ID - Help? - ViniBorn - 12.05.2012

pawn Код:
if(!strcmp(cmdtext,"/myweapon"))
{
    new GunName[32], VBString[64];
    GetWeaponName(GetPlayerWeapon(playerid),GunName,sizeof GunName);
    format(VBString,sizeof VBString,"Your current gun : %s", GunName);
    SendClientMessagel(playerid, -1, VBString);
    return true;
}
\/ He only asked for one example, nothing more


Re: Weapon Name by ID - Help? - Jonny5 - 12.05.2012

that will break on id 18,44,45 Vini

heres a stock i just wrote for this
pawn Код:
stock GetWeaponNameByID(wid)
{
    new gunname[32];
    switch (wid)
    {
        case    1 .. 17,
                22 .. 43,
                46 :        GetWeaponName(wid,gunname,sizeof(gunname));
        case    0:          format(gunname,32,"%s","Fist");
        case    18:         format(gunname,32,"%s","Molotov Cocktail");
        case    44:         format(gunname,32,"%s","Night Vis Goggles");
        case    45:         format(gunname,32,"%s","Thermal Goggles");
        default:            format(gunname,32,"%s","Invalid Weapon Id");
   
    }
    return gunname;
}

//usage

new str[47];
format(str,sizeof str, "Your weapon : %s" ,GetWeaponNameByID(wid));

EDIT:

I updated the stock as it did not account for invalid ID's
should be perfect now, if anyone see's anything wrong please post.