SA-MP Forums Archive
[HELP] Making cmds with strcmp - 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: [HELP] Making cmds with strcmp (/showthread.php?tid=612665)



[HELP] Making cmds with strcmp - StrikerZ - 20.07.2016

How to make /jetpack and /announce and /spawn [player id] cmds?


Re: [HELP] Making cmds with strcmp - UltraScripter - 20.07.2016

Why not sscanf+I zcmd?

Well anyway https://sampwiki.blast.hk/wiki/Strtok


Re: [HELP] Making cmds with strcmp - StrikerZ - 20.07.2016

when i use zcmd along with strcmp my pawno crashes while compiling [Im newbie in pawno]


Re: [HELP] Making cmds with strcmp - UltraScripter - 20.07.2016

Use sscanf+izcmd
Izcmd: https://www.******.co.il/search?q=iz...T0BIXfUe6ZqMAM
Sscanf2: https://sampforum.blast.hk/showthread.php?tid=570927

PHP код:
CMD:say(playeridparams)
{
     new 
str[128];
     if(
sscanf(params"s"str)) return SendClientMessage(playeridcolor"usage /say [text]");
     
SendClientMessageToAllcolorstr);
     Return 
1;

That's easier than strcmp and start ok isn't it?


Re: [HELP] Making cmds with strcmp - StrikerZ - 20.07.2016

thx but i always get confused with /spawn [player id] cmd can u make one for me?


Re: [HELP] Making cmds with strcmp - TaiRinsuru - 20.07.2016

PHP код:
CMD:spawn(playeridparams)
{
     new 
str[128], id;
     if(
sscanf(params"u"id)) return SendClientMessage(playeridcolor"usage /spawn player");
     if(
id == INVALID_PLAYER_ID) return SendClientMesage(...)
     
SpawnPlayer(id);
     return 
1;




Re: [HELP] Making cmds with strcmp - SyS - 20.07.2016

PHP код:
CMD:spawn(playerid,params[])
{
new 
giveid
if(
sscanf(params"u",giveid )) return SendClientMessage(playeridcolor"usage /spawn [playerid]"); 
SpawnPlayer(giveid);
return 
1;

Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
Use sscanf+izcmd
Izcmd: https://www.******.co.il/search?q=iz...T0BIXfUe6ZqMAM
Sscanf2: https://sampforum.blast.hk/showthread.php?tid=570927

PHP код:
CMD:say(playeridparams)
{
     new 
str[128];
     if(
sscanf(params"s"str)) return SendClientMessage(playeridcolor"usage /say [text]");
     
SendClientMessageToAllcolorstr);
     Return 
1;

That's easier than strcmp and start ok isn't it?
params is string by default so no need to use sscanf in that case use Isnull and yeah array "[]" size caption missing in the arguement.


Re: [HELP] Making cmds with strcmp - F1N4L - 20.07.2016

Use isnull:
Код:
CMD:say(playerid, params[])
{
     if(isnull(params)) return SendClientMessage(playerid, color, "usage /say [text]");
     
     SendClientMessageToAll(color, params);
     Return 1;
}

CMD:spawn(playerid, params[])
{
     if(isnull(params)) return SendClientMessage(playerid, color, "usage /spawn [id]");
     
     new ID = strval(params);

     if(!IsPlayerConnected(ID) return 0;
     
     SpawnPlayer(ID);

     Return 1;
}



Re: [HELP] Making cmds with strcmp - Stinged - 20.07.2016

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
Use isnull:
Код:
CMD:say(playerid, params[])
{
     if(isnull(params)) return SendClientMessage(playerid, color, "usage /say [text]");
     
     SendClientMessageToAll(color, params);
     Return 1;
}

CMD:spawn(playerid, params[])
{
     if(isnull(params)) return SendClientMessage(playerid, color, "usage /spawn [id]");
     
     new ID = strval(params);

     if(!IsPlayerConnected(ID) return 0;
     
     SpawnPlayer(ID);

     Return 1;
}
Yes, it's better to use isnull and not declare a new string when only a string is needed.
But anything other than that, sscanf is recommended.

sscanf is not only faster than strval, but it also checks if params is numeric.
While using "new ID = strval(params);", ID will be 0 if params is not an actual number.


Re: [HELP] Making cmds with strcmp - F1N4L - 20.07.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
sscanf is not only faster than strval, but it also checks if params is numeric.
While using "new ID = strval(params);", ID will be 0 if params is not an actual number.
Thanks, did not know that!