Admin Chat
#1

pawn Код:
CMD:a(playerid, params[])
{
     if(PlayerData[playerid][AdminLevel] < 1) return SendClientMessage(playerid,COLOR_RED,"You need to be an administrator to use this command!");
     new text[128];
     if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,COLOR_RED,"-USAGE- /a [text]");
     for(new i = 0;i<MAX_PLAYERS;i++)
 {
        if(!IsPlayerConnected(i)) continue;
        if(PlayerData[playerid][AdminLevel] < 1) continue;
        SendClientMessageEx(i,color_yellow,"ssss","Adminchat: ",PlayerInfo[playerid][Username],": {FFFFFF}",text);
    }
    return 1;
}

Hey guys! Ive got this as a adminchat, but it doesnt work ! :<

and ive got this errors! (Sorry, yes i am a noob)

pawn Код:
C:\Users\Rietz\Desktop\SAMP\gamemodes\gys.pwn(420) : error 017: undefined symbol "SendClientMessageEx"
C:\Users\Rietz\Desktop\SAMP\gamemodes\gys.pwn(420) : warning 215: expression has no effect
C:\Users\Rietz\Desktop\SAMP\gamemodes\gys.pwn(420) : error 001: expected token: ";", but found "]"
C:\Users\Rietz\Desktop\SAMP\gamemodes\gys.pwn(420) : error 029: invalid expression, assumed zero
C:\Users\Rietz\Desktop\SAMP\gamemodes\gys.pwn(420) : fatal error 107: too many error messages on one line
Reply
#2

you cannot use SendClientMessage to format a string
and im not sure why you would use SendClientMessageEx at all in this case

you must format a string first then use it in sendclientmessage

kinda like this

pawn Код:
CMD:a(playerid, params[])
{
     if(PlayerData[playerid][AdminLevel] < 1) return SendClientMessage(playerid,COLOR_RED,"You need to be an administrator to use this command!");
     new text[128],strOut[128];
     if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,COLOR_RED,"-USAGE- /a [text]");
     for(new i = 0;i<MAX_PLAYERS;i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(PlayerData[playerid][AdminLevel] < 1) continue;
        format(strOut,sizeof(strOut),"%s%s%s%s","Adminchat: ",PlayerInfo[playerid][Username],": {FFFFFF}",text);
        SendClientMessage(i,color_yellow,strOut);
    }
    return 1;
}
Reply
#3

Oh, aha, I'll see if it works :>


EDIT1: Im gonna make it so only admins can see it? :<
Reply
#4

everyone makes this mistake early on

good luck with ya code.



~J5
Reply
#5

1) Use 'i' instead of 'playerid' in 'AdminLevel'
2) You don't need to format the string every time, only once and then send it to all admins

pawn Код:
format(strOut,sizeof(strOut),"Adminchat: %s: {FFFFFF}%s",PlayerInfo[playerid][Username],text);
     for(new i = 0;i<MAX_PLAYERS;i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(PlayerData[i][AdminLevel] < 1) continue;
        SendClientMessage(i,color_yellow,strOut);
    }
Reply
#6

Thnak you, but why do I need to use "i" instead of "playerid"?
Reply
#7

Quote:
Originally Posted by RieTzz
Посмотреть сообщение
Thnak you, but why do I need to use "i" instead of "playerid"?
So it will check if the player who will get the message is admin, not the player who sends the message.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)