GetWeaponName

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 08:57, 19 January 2015
Threshold (Talk | contribs)
(Weapon IDs in 'GetWeaponNameEx' were incorrect.)
← Previous diff
Revision as of 20:45, 12 May 2015
MP2 (Talk | contribs)
(Example wouldn't work)
Next diff →
Line 6: Line 6:
{{Param|weaponid|The [[Weapons|ID of the weapon]] to get the name of.}} {{Param|weaponid|The [[Weapons|ID of the weapon]] to get the name of.}}
{{Param|const name[]|An array to store the weapon's name in, passed by reference.}} {{Param|const name[]|An array to store the weapon's name in, passed by reference.}}
-{{Param|len|The length of the weapon name.}}+{{Param|len|The maximum length of the weapon name to store. Should be sizeof(name).}}
{{ReturnsSuccess||The weapon specified does not exist.}} {{ReturnsSuccess||The weapon specified does not exist.}}
Line 26: Line 26:
</pawn> </pawn>
-Fix for returns null IDs for 18, 44, and 45.{{dubious}}+Fix for returns null IDs for 18, 44, and 45.
<pawn> <pawn>
// Now use GetWeaponNameEx // Now use GetWeaponNameEx
stock GetWeaponNameEx(weaponid, weapon[], len = sizeof(weapon)) stock GetWeaponNameEx(weaponid, weapon[], len = sizeof(weapon))
{ {
- switch(weaponid)+ switch(weaponid)
- {+ {
- case 18: return strcat(weapon, "Molotov Cocktail", len);+ case 18: strcat(weapon, "Molotov Cocktail", len);
- case 44: return strcat(weapon, "Night Vision Goggles", len);+ case 44: strcat(weapon, "Night Vision Goggles", len);
- case 45: return strcat(weapon, "Thermal Goggles", len);+ case 45: strcat(weapon, "Thermal Goggles", len);
- default: return GetWeaponName(weaponid, weapon, len);+ default: GetWeaponName(weaponid, weapon, len);
- }+ }
- return false;+ return weapon
} }
</pawn> </pawn>

Revision as of 20:45, 12 May 2015



Description:

Get the name of a weapon.


Parameters:
(weaponid, const weapon[], len)
weaponidThe ID of the weapon to get the name of.
const name[]An array to store the weapon's name in, passed by reference.
lenThe maximum length of the weapon name to store. Should be sizeof(name).


Return Values:

  • 1: The function executed successfully.
  • 0: The function failed to execute. The weapon specified does not exist.


Image:32px-Circle-style-warning.png

Important
Note

Returns a null string for IDs 18, 44 and 45.


Example Usage:

public OnPlayerDeath(playerid,killerid,reason)
{
    new gunname[32], string[64], fName[MAX_PLAYER_NAME], sName[MAX_PLAYER_NAME];
    GetWeaponName(reason,gunname,sizeof(gunname));
    GetPlayerName(playerid,fName,MAX_PLAYER_NAME);
    GetPlayerName(killerid,sName,MAX_PLAYER_NAME);
    format(string, sizeof(string), "%s has wasted %s using a %s.", sName, fName, gunname);
    SendClientMessageToAll(0xFFFFFFAA,string);
    return 1;
}

Fix for returns null IDs for 18, 44, and 45.

// Now use GetWeaponNameEx
stock GetWeaponNameEx(weaponid, weapon[], len = sizeof(weapon))
{
    switch(weaponid)
    {
        case 18: strcat(weapon, "Molotov Cocktail", len);
        case 44: strcat(weapon, "Night Vision Goggles", len);
        case 45:  strcat(weapon, "Thermal Goggles", len);
        default: GetWeaponName(weaponid, weapon, len);
    }
    return weapon
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.