SA-MP Forums Archive
[HELP] strtok problem. - 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] strtok problem. (/showthread.php?tid=88527)



[HELP] strtok problem. - kukars22 - 27.07.2009

Hello, I got a problem with defining strtok plus array index problem as you see:

Код:
C:\GTA.DECODER.LV\gamemodes\decoder.pwn(4099) : error 017: undefined symbol "strtok"
C:\GTA.DECODER.LV\gamemodes\decoder.pwn(4099) : error 033: array must be indexed (variable "cmd")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Heres the code to that lines:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{		new cmd[256];
 		cmd = strtok(cmdtext, idx); // Line 4099

//------------------------------------------------------------------------------
//=====================[ TELEPORT COMMANDS ]====================================
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
		if(!strcmp(cmd, "/ammunations",true) || !strcmp(cmd, "/ammunations",true))
 		{
	 		ShowMenuForPlayer(Ammunations,playerid);
	 		SendClientMessage(playerid, COLOR_YELLOW, "Laipni lugti municijas izvelne, izmanto lidzeklus un iegadajies ko velies.");
	  		TogglePlayerControllable(playerid, 0);
			return 1;
 		}



Re: [HELP] strtok problem. - MenaceX^ - 27.07.2009

The error says everything tought...


Re: [HELP] strtok problem. - kukars22 - 27.07.2009

I dont know how to fix it..


Re: [HELP] strtok problem. - kukars22 - 27.07.2009

So anyone can help somehow?


Re: [HELP] strtok problem. - Djiango - 27.07.2009

You need to add the strtok function, to your script.
Also add a
pawn Код:
new idx;
under your cmd[256];

Edit: Hint: You don't need strtok, for these kind of commands.


Re: [HELP] strtok problem. - RyDeR` - 27.07.2009

pawn Код:
new cmd[256],tmp[256],idx;// at top of script

// at bottom of script.
strtok(const string[], &index)
{
  new length = strlen(string);
  while ((index < length) && (string[index] <= ' '))
  {
    index++;
  }
  new offset = index;
  new result[20];
  while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  {
    result[index - offset] = string[index];
    index++;
  }
  result[index - offset] = EOS;
  return result;
}