[HELP] Making cmds with strcmp
#1

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

Why not sscanf+I zcmd?

Well anyway https://sampwiki.blast.hk/wiki/Strtok
Reply
#3

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

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?
Reply
#5

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

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;

Reply
#7

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.
Reply
#8

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;
}
Reply
#9

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.
Reply
#10

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)