Easy; Name color problem
#1

Код:
CMD:namecolor(playerid, params[])
{
    if(IsPlayerAdmin(playerid) || status[playerid][admin] >= 5)
    {
        new id; new color;
        if(sscanf(params, "us", id, color))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /namecolor <ID> <COLOR>");
   return 1;
        }
  else if(color == 1) return SetPlayerColor(id, COLOR_BLUE);
  else if(color == 2) return SetPlayerColor(id, COLOR_YELLOW);
  else if(color == 3) return SetPlayerColor(id, COLOR_PINK);
  else if(color == 4) return SetPlayerColor(id, COLOR_WHITE);

    }
 else
 {
  SendClientMessage(playerid, 0xFFFFFFFF, "You aren't an admin");
 }
 return 1;
}
This code gives me no errors, but it isn't working. Help
Reply
#2

PHP код:
CMD:namecolor(playeridparams[])
{
if(!
IsPlayerAdmin(playerid) || status[playerid][admin] < 5) return  SendClientMessage(playerid0xFFFFFFFF"You aren't an admin");
new 
id;
new 
color;
if(
sscanf(params,"ud",id,color)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /namecolor <ID> <COLOR>");
if(
color == 1) return SetPlayerColor(idCOLOR_BLUE);
else if(
color == 2) return SetPlayerColor(idCOLOR_YELLOW);
else if(
color == 3) return SetPlayerColor(idCOLOR_PINK);  
else if(
color == 4) return SetPlayerColor(idCOLOR_WHITE); 
return 
1;

"s" in sscanf is for string !
Reply
#3

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
PHP код:
CMD:namecolor(playeridparams[])
{
if(!
IsPlayerAdmin(playerid) || status[playerid][admin] < 5) return  SendClientMessage(playerid0xFFFFFFFF"You aren't an admin");
new 
id;
new 
color;
if(
sscanf(params,"ud",id,color)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /namecolor <ID> <COLOR>");
if(
color == 1) return SetPlayerColor(idCOLOR_BLUE);
else if(
color == 2) return SetPlayerColor(idCOLOR_YELLOW);
else if(
color == 3) return SetPlayerColor(idCOLOR_PINK);  
else if(
color == 4) return SetPlayerColor(idCOLOR_WHITE); 
return 
1;

"s" in sscanf is for string !
I made it string before like /nametag 0 COLOR_RED

Anyways, will try it
Reply
#4

How you made it string ?
See
PHP код:
if(color == 1) return SetPlayerColor(idCOLOR_BLUE); 
else if(
color == 2) return SetPlayerColor(idCOLOR_YELLOW); 
else if(
color == 3) return SetPlayerColor(idCOLOR_PINK);   
else if(
color == 4) return SetPlayerColor(idCOLOR_WHITE); 
If = "1" !!
If = "2" !!
If = "3" !!
If = "4" !!
Where is it ?!
Reply
#5

nah, I meant I re-edited the whole script, and when changing it to "i" because it will be easier, I forgot to edit it.
Reply
#6

Sorry for double posting.

Okay so, /namecolor [ID] 1/2/3/4 works fine, but I want to change the numbers to Red/Blue/Yellow/White.
It says undefined symbol "Blue" / "Yellow" "Red" "White". Not sure how I should define them.

Quote:

CMD:namecolor(playerid, params[])
{
if(IsPlayerAdmin(playerid) || status[playerid][admin] >= 5)
{
new id; new color;
if(sscanf(params, "us[30]", id, color))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /namecolor <ID> <COLOR>");
return 1;
}
else if(color == Blue) return SetPlayerColor(id, COLOR_BLUE);
else if(color == Yellow) return SetPlayerColor(id, COLOR_YELLOW);
else if(color == Pink) return SetPlayerColor(id, COLOR_PINK);
else if(color == White) return SetPlayerColor(id, COLOR_WHITE);

}
else
{
SendClientMessage(playerid, 0xFFFFFFFF, "You aren't an admin");
}
return 1;
}

Reply
#7

PHP код:
CMD:namecolor(playeridparams[])
{
if(
IsPlayerAdmin(playerid) || status[playerid][admin] >= 5)
{
new 
id; new color[30];
if(
sscanf(params"us[30]"idcolor))
{
SendClientMessage(playeridCOLOR_WHITE"USAGE: /namecolor <ID> <COLOR>");
return 
1;
}
else if(
color == "Blue") return SetPlayerColor(idCOLOR_BLUE);
else if(
color == "Yellow") return SetPlayerColor(idCOLOR_YELLOW);
else if(
color == "Pink") return SetPlayerColor(idCOLOR_PINK);
else if(
color == "White") return SetPlayerColor(idCOLOR_WHITE);

}
else
{
SendClientMessage(playerid0xFFFFFFFF"You aren't an admin");
}
return 
1;

Reply
#8

array must be indexed (variable "color")
Reply
#9

try
PHP код:
else if(color[30] == "Blue") return SetPlayerColor(idCOLOR_BLUE);
else if(
color[30] == "Yellow") return SetPlayerColor(idCOLOR_YELLOW);
else if(
color[30] == "Pink") return SetPlayerColor(idCOLOR_PINK);
else if(
color[30] == "White") return SetPlayerColor(idCOLOR_WHITE); 
Reply
#10

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
try
PHP код:
else if(color[30] == "Blue") return SetPlayerColor(idCOLOR_BLUE);
else if(
color[30] == "Yellow") return SetPlayerColor(idCOLOR_YELLOW);
else if(
color[30] == "Pink") return SetPlayerColor(idCOLOR_PINK);
else if(
color[30] == "White") return SetPlayerColor(idCOLOR_WHITE); 
I hope I'm not bothering, but still the same.

Код:
C:\Users\User\Desktop\SERVER\gamemodes\Untitled.pwn(1461) : error 032: array index out of bounds (variable "color")
C:\Users\User\Desktop\SERVER\gamemodes\Untitled.pwn(1462) : error 032: array index out of bounds (variable "color")
C:\Users\User\Desktop\SERVER\gamemodes\Untitled.pwn(1463) : error 032: array index out of bounds (variable "color")
C:\Users\User\Desktop\SERVER\gamemodes\Untitled.pwn(1464) : error 032: array index out of bounds (variable "color"
--------

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
Use strcmp to compare 2 strings.
https://sampwiki.blast.hk/wiki/Strcmp
Since I never used it before, can you tell me how to add it in this command?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)