error Help
#1

Ok i have this team chat command
Код:
if(!strcmp("/d", cmdtext, true))
{
	new PlayerName[MAX_PLAYERS];
	new playername[MAX_PLAYER_NAME];
	new string[128];
	GetPlayerName(playerid, playername, sizeof(playername));
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	format(string, sizeof(string), "Police [%s]: ", playername)
 	if(gTeam[playerid] == TEAM_LSPD)
 	{
	SendClientMessage(playerid, COLOR_GOLD, string);
	}
	return 1;
	}
 	return 0;
}
I get this annoying error

Код:
 error 001: expected token: ";", but found "if"
Reply
#2

The Error message says it all. The compiler was looking for a ";" but instead it found an "if" statement.

Change:
pawn Код:
format(string, sizeof(string), "Police [%s]: ", playername)
to:
pawn Код:
format(string, sizeof(string), "Police [%s]: ", playername);
Hope that helps.
Reply
#3

Quote:
Originally Posted by [B2K
Hustler ]
The Error message says it all. The compiler was looking for a ";" but instead it found an "if" statement.

Change:
pawn Код:
format(string, sizeof(string), "Police [%s]: ", playername)
to:
pawn Код:
format(string, sizeof(string), "Police [%s]: ", playername);
Hope that helps.
That will fix your errors, but remember to indent your code. (Not sure if it's just the conversion)
Reply
#4

Ok thanks i have no errors, but when i use /d 'isaysomething' it shows up like [LSPD] Pinehole ,over
i want it to be chat for to do '/d hello' then it shows up like [LSPD] Pinehole: hello, over, please help
Reply
#5

you didnt format your string correctly to display the text.

Try this:

pawn Код:
if(!strcmp(cmdtext,"/d",true,2))
{
    if(!strlen(cmdtext[2])) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /d [text]");
    new playername[MAX_PLAYER_NAME], string[128];
    GetPlayerName(playerid, playername, sizeof(playername));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        format(string, sizeof(string), "Police [%s]: %s, over", playername, cmdtext[2])
        if(gTeam[playerid] == TEAM_LSPD)
        {
            SendClientMessage(playerid, COLOR_GOLD, string);
        }
    }
    return 1;
}
I'd recommend using sscanf and zcmd. Hope that helps. Good Luck.
Reply
#6

Thanks it works , but it spams
Reply
#7

try this
pawn Код:
if(!strcmp("/d", cmdtext, true))
{
    new PlayerName[MAX_PLAYERS];
    new playername[MAX_PLAYER_NAME];
    new string[128];
    GetPlayerName(playerid, playername, sizeof(playername));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    format(string, sizeof(string), "Police [%s]: %s",playername,cmdtext);
    if(gTeam[playerid] == TEAM_LSPD)
    {
    SendClientMessage(playerid, COLOR_GOLD, string);
    }
    return 1;
    }
    return 0;
}
Reply
#8

Nope it doesnt' work, can someone help me when i do /d <text> it spams
Reply
#9

Try this:

pawn Код:
if(!strcmp(cmdtext,"/d",true,2))
{
    if(!strlen(cmdtext[2])) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /d [text]");
    if(gTeam[playerid] != TEAM_LSPD) return SendClientMessage(playerid, 0xAFAFAFAA, "You must be a cop to use this command!");
    new playername[MAX_PLAYER_NAME], string[128];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "Police [%s]: %s, over", playername, cmdtext[2])
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(gTeam[playerid] == TEAM_LSPD)
        {
            SendClientMessage(playerid, COLOR_GOLD, string);
        }
        return 1;
    }
    return 0;
}
Reply
#10

Works, thanks but will the TEAM_LSPD will be able to see it? or will the person whop typed it will see it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)