09.05.2014, 15:39
GetWeaponName returns 0 (success)/1 (failure).
The first argument is the weaponid which is integer and you used a string. Assuming GetWeaponIDFromName returns the weaponid from the name (from an array):
Edit this line with the name of the array you use for the weapon names:
Also make sure that IsValidWeapon function will block a weaponid greater than 46 or negative so it won't cause any run time error 4.
The first argument is the weaponid which is integer and you used a string. Assuming GetWeaponIDFromName returns the weaponid from the name (from an array):
pawn Код:
CMD:giveweapon(playerid,params[])
{
if (pInfo[playerid][Adminlevel] < 4) return SCM(playerid, COLOR_RED, ERROR_MESSAGE);
new TargetID, weaponname[32], weaponammo;
if (sscanf(params, "rs[32]d", TargetID, weaponname, weaponammo)) return SCM(playerid, COLOR_RED, "Usage: /giveweapon [playerid] [weapon id/weapon name] [ammo]");
if (!IsPlayerConnected(TargetID)) return SCM(playerid, COLOR_RED, "** Player is not connected");
new wea;
if (!isNumeric(weaponname)) wea = GetWeaponIDFromName(weaponname);
else wea = strval(weaponname);
if (!IsValidWeapon(wea)) return SCM(playerid, COLOR_RED, "Invalid Weapon ID or Name");
new targetname[MAX_PLAYER_NAME], string[128];
GetPlayerName(TargetID, targetname, sizeof (TargetID));
format(string, sizeof (string), "**Weapon: %s (%d) (Admin Weapon) %s (%d) with %d rounds of ammo", targetname, TargetID, WEAPON_NAME_ARRAY[wea], wea, weaponammo);
SCMA(COLOR_HOTPINK, string);
GivePlayerWeapon(TargetID, wea, weaponammo);
return 1;
}
pawn Код:
format(string, sizeof(string), "**Weapon: %s (%d) (Admin Weapon) %s (%d) with %d rounds of ammo", targetname, TargetID, WEAPON_NAME_ARRAY[wea], wea, weaponammo);