SA-MP Forums Archive
Help with /weapon command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with /weapon command (/showthread.php?tid=191064)



Help with /weapon command - iTorran - 17.11.2010

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


Re: Help with /weapon command - Grim_ - 17.11.2010

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 ) )



Re: Help with /weapon command - Zh3r0 - 17.11.2010

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....