SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/05/2013, 03:26 PM   #1
Nostrum
Big Clucker
 
Join Date: Apr 2013
Posts: 59
Reputation: -2
Default tmp = strtok(cmdtext, idx); Help.

Im trying to convert strcmp commands to zcmd.
Could anyone teach me what to do with
Code:
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
Nostrum is offline   Reply With Quote
Old 15/05/2013, 03:48 PM   #2
jordy.kiesebrink
Big Clucker
 
jordy.kiesebrink's Avatar
 
Join Date: Jun 2008
Location: Netherlands
Posts: 103
Reputation: 5
Default Re: tmp = strtok(cmdtext, idx); Help.

delete this its not needed with zcmd! zcmd is made to write quick commands all of this you need to do with strcmp is included in the .inc file from zcmd you don't have to worry about this anymore
__________________
Developping a server with Nielsbon1, Link comming soon!
jordy.kiesebrink is offline   Reply With Quote
Old 15/05/2013, 03:49 PM   #3
LoLeRo
Big Clucker
 
LoLeRo's Avatar
 
Join Date: May 2013
Location: México
Posts: 73
Reputation: 3
Default Respuesta: tmp = strtok(cmdtext, idx); Help.

Out of OnPlayerCommandText like a new function add this:

Code:
CMD:your_command(playerid, params[])
or

Code:
COMMAND:your_command(playerid, params[])
This is an example of the command: "/helpme". Let's add just some message:

pawn Code:
CMD:helpme(playerid, params[])
{
    SendClientMessage(playerid, 0xFFFFFFF, "My first command ^^ ");
    return 1;
}

If you want to use params:

pawn Code:
CMD:heal(playerid, params[])
{
   new
      tmp[20],
      id;
   tmp = strtok(cmdtext, index);
   if (strlen(tmp))
   {
      id = strval(tmp);
      if (IsPlayerConnected(id))
      {
         new
            string[128],
            name1[MAX_PLAYER_NAME],
            name2[MAX_PLAYER_NAME];
         SetPlayerHealth(id, 100.0);
         GetPlayerName(playerid, name1, sizeof  name1);
         GetPlayerName(id, name2, sizeof name2);
         format(string, sizeof string, "Fuiste curado por %s", name1);
         SendClientMessage(id, 0x00FF00AA, string);
         format(string, sizeof string, "Curaste a %s", name2);
         SendClientMessage(playerid, 0x00FF00AA, string);
      }
      else
      {
         SendClientMessage(playerid, 0xFF0000AA, "Jugador no encontrado");
      }
   }
   else
   {
      SendClientMessage(playerid, 0xFF0000AA, "USO: "/heal ID"");
   }
   return 1;
}
__________________
Talento de Barrio Owner.
LoLeRo is offline   Reply With Quote
Old 15/05/2013, 03:57 PM   #4
CodyCummings
Big Clucker
 
Join Date: Jan 2013
Posts: 61
Reputation: 28
Default Re: tmp = strtok(cmdtext, idx); Help.

strtok, in a sense, splits a string by a delimiter. In this specific case, strtok will go through cmdtext at the index specified by idx, and when it gets to the first space, it will set idx to that location, and put the string into tmp.

With zcmd, it's not very much different, where you would be doing that in a command like this...
pawn Code:
if(strcmp(cmdtext, "/hi", true, 3) == 0)
{
    new idx = 0, tmp[128];
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
}
In zcmd, it's very similar.
pawn Code:
CMD:hi(playerid, params[])
{
    new idx = 0, tmp[128];
    tmp = strtok(params, idx);
    if(!strlen(tmp))
}
So it's not really too much different, as all it does is split a string into multiple strings by spaces.

Now, just a little tip, I suggest you switch to sscanf (use the search function), it will do this process a lot quicker and make it so much easier to do and read.
With sscanf + zcmd:
pawn Code:
CMD:hi(playerid, params[])
{
    new str[128];
    if(sscanf(params, "s[128]", str)) return SendClientMessage(playerid, -1, "usage message here.");
    // your code etc.
}
And that's just the bottom of sscanf, the thread for sscanf holds a lot more info.

Now, the reason to use zcmd and sscanf is to improve speed and readability of your code, it will greatly help you in the future.

Happy coding!
__________________


Byt3
San Andreas Roleplay.
Lead Developer & Senior Administrator.
CodyCummings is offline   Reply With Quote
Old 15/05/2013, 03:58 PM   #5
Vrag
Big Clucker
 
Join Date: Jan 2013
Posts: 186
Reputation: -34
Default Re: tmp = strtok(cmdtext, idx); Help.

Delet it,...
__________________
My works:
Los Angeles Ghetto Wars
Vrag is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[AJUDA] comando strtok(cmdtext, idx) douglasmonteiro Português/Portuguese 2 16/04/2011 07:54 PM
cmd = strtok(cmdtext, idx); problem [HKS]dlegend Help Archive 5 24/11/2009 09:29 PM
Help with tmp = strtok(cmdtext,idx); WardenCS Help Archive 19 22/11/2009 04:23 PM


All times are GMT. The time now is 05:58 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.