Help with /weapon command
#1

Hi!

When i type /weapon i get "Error: Invalid Weapon ID",
And i mean just "/weapon" nothing else,

This is my code:
pawn Код:
CMD:weapon(playerid, params[])
{
    new tmp[256], tmp2[256], Index;
    new Weap, Ammo, WeapName[32], String[128];
    tmp = strtok(params, Index), tmp2 = strtok(params, Index);
   
    if(!strlen(tmp)) return SendClientMessage(playerid, colorRed, "Usage: /weapon [WeaponID/PartOfName] [Ammo]");
    if(!IsNumeric(tmp)) Weap = GetWeaponIDFromName(tmp); else Weap = strval(tmp);
    if(!IsValidWeapon(Weap)) return SendClientMessage(playerid, colorRed, "Error: Invalid Weapon ID");
    if(!strlen(tmp2) || !IsNumeric(tmp2) || strval(tmp2) <= 0 || strval(tmp2) > 99999) Ammo = 500; else Ammo = strval(tmp2);
   
    GetWeaponName(Weap, WeapName, 32);
    format(String, sizeof(String), "You have given yourself a %s (%d) with %d rounds of ammo", WeapName, Weap, Ammo);
    SendClientMessage(playerid, colorBlue, String);
    return GivePlayerWeapon(playerid, Weap, Ammo);
}
As you can see its supposed to show usage not error
Reply
#2

Why would you use strtok inside of Zcmd? That is the whole point of Zcmd being created (beside from the fact it is faster)!

You need to re-visit the page and get documentation on Zcmd. To check if the params are empty, you will need to use the isnull function.
pawn Код:
if( isnull( params ) )
Reply
#3

pawn Код:
if(!IsValidWeapon(Weap)) return SendClientMessage(playerid, colorRed, "Error: Invalid Weapon ID");
to
pawn Код:
if(!IsValidWeapon(Weap)) SendClientMessage(playerid, colorRed, "Error: Invalid Weapon ID");

Fuck..I'm wrong, nvm that, i'm sleepy....
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)