set player color
#1

how can i do if the player type etc. this: /color yellow or /color trans etc. the player color will change? ;o
Reply
#2

hmm, you first need to have some colours, ofcourse..

Код:
#define COLOR_YELLOW 0xFFDD0000
#define COLOR_GREEN 0x00990000
#define COLOR_RED 0x99000000
// etc...
Код:
// command time!
if (strcmp(cmdtext,"/color",true) == 0)
{
  new params[128];
  strmid(params, cmdtext, strfind(cmdtext, " ", true)); // these two lines would do the same as strtok, you can use that if you prefer it!

  if (!strlen(params))
     return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /color [color]");

  if (strcmp(params, "yellow", true) == 0)
     SetPlayerColor(playerid, COLOR_YELLOW;
  else if (strcmp(params, "green", true) == 0)
     SetPlayerColor(playerid, COLOR_GREEN;
  else if (strcmp(params, "red", true) == 0)
     SetPlayerColor(playerid, COLOR_GREEN;

  [....]

  else
     SendClientMessage(playerid, COLOR_YELLOW, "What color is that? There's only yellow, green and red in this example");
}
Reply
#3

Код:
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(3) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(6) : error 021: symbol already defined: "strmid"
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(8) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(9) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(11) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(13) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(15) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(17) : error 010: invalid function or declaration
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(20) : warning 203: symbol is never used: "params"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


8 Errors.
Reply
#4

put these where they belong..

so the command goes

Код:
public OnPlayerCommamdText(playerid, cmdtext[])
{
if (strcmp(cmdtext,"/color",true) == 0)
{
  new params[128];
  strmid(params, cmdtext, strfind(cmdtext, " ", true)); // these two lines would do the same as strtok, you can use that if you prefer it!

  if (!strlen(params))
     return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /color [color]");

  if (strcmp(params, "yellow", true) == 0)
     SetPlayerColor(playerid, COLOR_YELLOW);
  else if (strcmp(params, "green", true) == 0)
     SetPlayerColor(playerid, COLOR_GREEN);
  else if (strcmp(params, "red", true) == 0)
     SetPlayerColor(playerid, COLOR_RED);
  else
     SendClientMessage(playerid, COLOR_YELLOW, "What color is that? There's only yellow, green and red in this example");

  return 1;
}
}
the colour defines go somewhere in the top of your script
Reply
#5

ok, i edited it a bit, and now i got this:

Код:
#include <a_samp>

public OnPlayerCommandText(playerid,cmdtext[]) {
{
if (strcmp(cmdtext,"/color",true) == 0)
{
new params[128];
strmid(params, cmdtext, strfind(cmdtext, " ", true));
{
if (!strlen(params))
return SendClientMessage(playerid, 0xFF0000AA, "[USAGE]: /color [YELLOW/GREEN/RED]");
}
if (strcmp(params, "yellow", true) == 0)
SetPlayerColor(playerid, 0xFFFF00AA);
else if (strcmp(params, "green", true) == 0)
SetPlayerColor(playerid, 0x33FF33AA);
else if (strcmp(params, "red", true) == 0)
SetPlayerColor(playerid, 0xFF0000AA);
else
SendClientMessage(playerid, 0xFF0000AA, "[ERROR]: Invalid color.");
return 1;
}
return 0;
}
and i got these errors:

Код:
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(8) : warning 202: number of arguments does not match definition
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(25) : error 030: compound statement not closed at the end of file (started at line 4)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#6

please indent code, this is making it hard to read


Код:
public OnPlayerCommamdText(playerid, cmdtext[])
{
   if (strcmp(cmdtext,"/color",true) == 0)
   {
     // these two lines would do the same as strtok, you can use that if you prefer it!
     new params[128];
     strmid(params, cmdtext, strfind(cmdtext, " ", true), strlen(params)); 

     if (!strlen(params))
        return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /color [color]");

     if (strcmp(params, "yellow", true) == 0)
        SetPlayerColor(playerid, COLOR_YELLOW);
     else if (strcmp(params, "green", true) == 0)
        SetPlayerColor(playerid, COLOR_GREEN);
     else if (strcmp(params, "red", true) == 0)
        SetPlayerColor(playerid, COLOR_RED);
     else
        SendClientMessage(playerid, COLOR_YELLOW, "What color is that? There's only yellow, green and red in this example");

     return 1;
   }
}
Reply
#7

i dont know what u mean with hard to read, but now i got this:

Код:
#include <a_samp>

public OnPlayerCommandText(playerid,cmdtext[])
{
if(strcmp(cmdtext, "/color", true) == 0)
{
new params[128];
strmid(params, cmdtext, strfind(cmdtext, "", true));
{
if (!strlen(params))
return SendClientMessage(playerid, 0xFF0000AA, "[USAGE]: /color [YELLOW/GREEN/RED]");
}
if (strcmp(params, "yellow", true) == 0)
SetPlayerColor(playerid, 0xFFFF00AA);
else if (strcmp(params, "green", true) == 0)
SetPlayerColor(playerid, 0x33FF33AA);
else if (strcmp(params, "red", true) == 0)
SetPlayerColor(playerid, 0xFF0000AA);
else
SendClientMessage(playerid, 0xFF0000AA, "[ERROR]: Invalid color.");
return 1;
}
return 0;
}
and 1 warning:

Код:
C:\Users\Martin\Desktop\PUTDETHERINTILSA-MP\colorcmds.pwn(8) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Reply
#8

replace

Код:
strmid(params, cmdtext, strfind(cmdtext, "", true));
with

Код:
strmid(params, cmdtext, strfind(cmdtext, "", true), strlen(params));
Reply
#9

it says "SERVER: Unknown command." when i use /color red etc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)