multi functions onplayertext
#1

Hello, I'm pretty new on scripting and I've tried to make an admin chat and a custom chat color for players.
This is my code:
Код:
public OnPlayerText(playerid, text[])
{
new chat[200], name[MAX_PLAYER_NAME], msg[128];
if(IsPlayerAdmin(playerid) && text[0] == '#')
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(msg, sizeof(msg), "[ADMIN CHAT]%s(%d): %s", pName, playerid, text[1]);
SendMessageToAdmins(msg);
}
else
{
GetPlayerName(playerid, name, sizeof(name));
format(chat, sizeof(chat), "(%d): {EBFF00}%s{FFFFFF}",playerid, text);
SendPlayerMessageToAll(playerid, chat);
return 0;
}
The problem is when I'm trying to talk in admin chat it shows up also in the main chat.
I need to make them both to return 0; I guess but I just couldn't do it without getting unreachable code errors.

If some experienced guy could help me with that I'll be thankful with a rep.
Thanks, rakinz.

EDIT: fixed
Reply
#2

try this

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
chat[200], name[MAX_PLAYER_NAME], msg[128];
    if(
IsPlayerAdmin(playerid) && text[0] == '#')
    {
        new 
pName[MAX_PLAYER_NAME];
        
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
        
format(msgsizeof(msg), "[ADMIN CHAT]%s(%d): %s"pNameplayeridtext[1]);
        
SendMessageToAdmins(msg);
    }
    else
    {
        
GetPlayerName(playeridnamesizeof(name));
        
format(chatsizeof(chat), "(%d): {EBFF00}%s{FFFFFF}",playeridtext);
        
SendPlayerMessageToAll(playeridchat);
    }
    return 
0;

Reply
#3

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
chat[128], pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
    if(
IsPlayerAdmin(playerid) && text[0] == '#')
    {
        
format(chatsizeof(chat), "[ADMIN CHAT] %s(%d): %s"pNameplayeridtext);
        
SendMessageToAdmins(chat);
        return 
0;
    }
    
format(chatsizeof(chat), "(%d): {EBFF00}%s{FFFFFF}"playeridtext);
    
SendPlayerMessageToAll(playeridchat);
    return 
0;

In case this didn't work, Show me the function 'SendMessageToAdmins'.
Reply
#4

Quote:
Originally Posted by IceBilizard
Посмотреть сообщение
try this

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
chat[200], name[MAX_PLAYER_NAME], msg[128];
    if(
IsPlayerAdmin(playerid) && text[0] == '#')
    {
        new 
pName[MAX_PLAYER_NAME];
        
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
        
format(msgsizeof(msg), "[ADMIN CHAT]%s(%d): %s"pNameplayeridtext[1]);
        
SendMessageToAdmins(msg);
    }
    else
    {
        
GetPlayerName(playeridnamesizeof(name));
        
format(chatsizeof(chat), "(%d): {EBFF00}%s{FFFFFF}",playeridtext);
        
SendPlayerMessageToAll(playeridchat);
    }
    return 
0;

I've tried your code, and for some reason it's just giving me tons of errors.
Here are my errors lines:
Код:
C:\Users\User\Desktop\SCRIPT\my creation\pawno\include\sscanf2.inc(305) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\pawno\include\sscanf2.inc(305) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\pawno\include\sscanf2.inc(365) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\pawno\include\sscanf2.inc(365) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(115) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(129) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(236) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(250) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(317) : warning 219: local variable "pName" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(331) : error 010: invalid function or declaration
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(333) : error 010: invalid function or declaration
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(335) : error 010: invalid function or declaration
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(341) : error 021: symbol already defined: "GetPlayerName"
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(353) : error 010: invalid function or declaration
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(454) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(482) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(550) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(567) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(803) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(1140) : warning 203: symbol is never used: "pName"
C:\Users\User\Desktop\SCRIPT\my creation\gamemodes\smile.pwn(1140) : warning 203: symbol is never used: "string"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#5

Quote:
Originally Posted by oMa37
Посмотреть сообщение
PHP код:
public OnPlayerText(playeridtext[])
{
    new 
chat[128], pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
    if(
IsPlayerAdmin(playerid) && text[0] == '#')
    {
        
format(chatsizeof(chat), "[ADMIN CHAT] %s(%d): %s"pNameplayeridtext);
        
SendMessageToAdmins(chat);
        return 
0;
    }
    
format(chatsizeof(chat), "(%d): {EBFF00}%s{FFFFFF}"playeridtext);
    
SendPlayerMessageToAll(playeridchat);
    return 
0;

In case this didn't work, Show me the function 'SendMessageToAdmins'.
This does the same errors like the privious guy code, this is my sendmessagetoadmins function:
Код:
stock SendMessageToAdmins(text[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerAdmin(i))
        {
            SendClientMessage(i, COLOR_RED, text);
        }
    }
}
EDIT:
I just found out that I'd more lines for my reaction test.

Here they are:
Quote:

public OnPlayerText(playerid, text[])
{
new chat[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);

if(IsPlayerAdmin(playerid) && text[0] == '#')
{
format(chat, sizeof(chat), "[ADMIN CHAT] %s(%d): %s", pName, playerid, text);
SendMessageToAdmins(chat);
return 0;
}

format(chat, sizeof(chat), "(%d): {EBFF00}%s{FFFFFF}", playerid, text);
SendPlayerMessageToAll(playerid, chat);
return 0;
}
//================================================== ==========================//
switch(xTestBusy)
{
case true:
{
if(!strcmp(xChars, text, false))
{
new
string[128],
pName[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "{FFFFFF}[{00CED1}REACTION{FFFFFF}]: {F81414}%s {FFFFFF}has won the reaction test!", pName);
SendClientMessageToAll(GREEN, string);
format(string, sizeof(string), "You have earned $%d + %d score.", xCash, xScore);
SendClientMessage(playerid, COLOR_YELLOW, string);
GivePlayerMoney(playerid, xCash);
SetPlayerScore(playerid, GetPlayerScore(playerid) + xScore);
xReactionTimer = SetTimer("xReactionTest", TIME, 1);
xTestBusy = false;
}
}
}
return 1;
}

I'll fix it by myself, sorry for bothering you guys and thanks for helping me out!
Reply
#6

I've one more problem now, since I've used your code guys, I'm getting the word # inside the admin message.
like [ADMIN CHAT]nickname(id): #(chat)

EDIT: fixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)