A /color command
#1

i want to make a /color and /colour command for my server so when you are in a car you typ /color or /colour 670 60 the vehcile will change in those colours but i dont know how make one i searched and tried but it didn't help can somebody help me?
Reply
#2

You need to use strcmp to get the additional two parameters, color 1 and color 2.
pawn Код:
if(strcmp(cmd, "/color", true) == 0 || strcmp(cmd, "/colour", true) == 0)
    {
      new color1, color2, tmp[256];
      tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /carcolor [color1] [color2]");
      color1 = strval(tmp);
      tmp = strtok(cmdtext, idx);
      if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /carcolor [color1] [color2]");
      color2 = strval(tmp);
      ChangeVehicleColor(GetPlayerVehicleID(playerid), color1, color2);
        return 1;
    }
Reply
#3

ty i will try

EDIT:

i get those erros and warnings

Код:
c:/----(315) : error 017: undefined symbol "cmd"
c:/----(318) : error 017: undefined symbol "strtok"
c:/----(318) : error 033: array must be indexed (variable "tmp")
c:/----(319) : warning 217: loose indentation
c:/----(320) : warning 217: loose indentation
c:/----(321) : error 017: undefined symbol "strtok"
c:/----(321) : error 033: array must be indexed (variable "tmp")
c:/----(325) : warning 217: loose indentation
Reply
#4

Install strtok.
https://sampwiki.blast.hk/wiki/Strtok
Reply
#5

Quote:
Originally Posted by player007
I looked but i dont understand it :/
Reply
#6

Quote:
Originally Posted by security
Quote:
Originally Posted by player007
I looked but i dont understand it :/
just add
Код:
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;
}
to your script, and add:
pawn Код:
new cmd[256];
new tmp[256];
on top of OnPlayerCommand (below it)
Reply
#7

where to put:
Код:
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;
}
those
new cmd[256];
new tmp[256];
At the top of the script? at the others with new?
Reply
#8

No, put the strtok function to the bottom of your script, and put the new cmd, new tmp to the top of OnPlayerCommandText
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)