/move [x] [y] [z]
#1

hey there....

ive been working with DCMD to get a /move command that allows you to move any place you wish...


there are a few errors, and i'm unsure of how to fix.

Code:
dcmd_move(playerid,params[]) {
	  new tmp[256], tmp2[256], tmp3[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index), tmp3 = strtok(params,Index);
	  if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid, POLICE_COLOR, "USAGE: /move [X] [Y] [Z]");
		new X, Y, Z, string[128];
		return SetPlayerPos(playerid, X, Y, Z);
}
C:\PROGRA~1\GAMES\GTASAN~1\GAMEMO~1\NRGSPAWN.pwn(8 : error 017: undefined symbol "strtok"
C:\PROGRA~1\GAMES\GTASAN~1\GAMEMO~1\NRGSPAWN.pwn(8 : error 033: array must be indexed (variable "tmp3")
C:\PROGRA~1\GAMES\GTASAN~1\GAMEMO~1\NRGSPAWN.pwn(9 0) : warning 204: symbol is assigned a value that is never used: "string"
C:\PROGRA~1\GAMES\GTASAN~1\GAMEMO~1\NRGSPAWN.pwn(8 : warning 203: symbol is never used: "Index"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.


cheers,

hazdog
Reply
#2

it says undefined symbol strtok did you define it right?

pawn Code:
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;
}
Reply
#3

Aswell as that use this
pawn Code:
dcmd_move(playerid,params[])
{
  #pragma unused Index
  new tmp[256], tmp2[256], tmp3[256], Index;
  tmp = strtok(params,Index), tmp2 = strtok(params,Index), tmp3 = strtok(params,Index);
  if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid, POLICE_COLOR, "USAGE: /move [X] [Y] [Z]");
  new X, Y, Z;
  return SetPlayerPos(playerid, X, Y, Z);
}
Reply
#4

it gets a perfect compile but just says unknown command in game.
Reply
#5

Quote:
Originally Posted by hazdog
it gets a perfect compile but just says unknown command in game.
You gotta put the dcmd call under OnPlayerCommandText lawl.
Reply
#6

i have...
Reply
#7

sscanf method:

pawn Code:
//bottom of script
dcmd_move( playerid, params[] )
{
  new
    Float:x,
    Float:y,
    Float:z;

  if ( sscanf( params, "fff", x, y, z ) ) return SendClientMessage( playerid, POLICE_COLOR, "USAGE: /move [X] [Y] [Z]" );
  SetPlayerPos( playerid, x, y, z );
  return 1;
}

//OnPlayerCommandText
  dcmd(move, 4, cmdtext);
The Wiki page for sscanf.
Reply
#8

I recommend using Donny's version.
dcmd is made to make commands easier, so is sscanf.
It's kinda strtok's rival, so don't use them together
strcmp & strtok
or
dcmd & sscanf
Reply
#9

Quote:
Originally Posted by brett7
it says undefined symbol strtok did you define it right?

pawn Code:
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;
}
pawn Code:
strtok(const string[], &index, separator = ' ')
{
  new length = strlen(string);
  while ((index < length) && (string[index] <= separator))
  {
    index++;
  }
  new offset = index;
  new result[20];
  while ((index < length) && (string[index] > separator) && ((index - offset) < (sizeof(result) - 1)))
  {
    result[index - offset] = string[index];
    index++;
  }
  result[index - offset] = EOS;
  return result;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)