public OnPlayerText(playerid, text[])
{
new string[MAX_PLAYERS], var = GetPlayerVirtualWorld(playerid);
//
if(text[0] == '@' && Account[playerid][Admin] >= 1)
{
format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && Account[i][Admin] >= 1)
{
SendClientMessage(i, 0x0AFFC9FF, string);
return 0;
}
}
}
if(text[0] == '!' && Account[playerid][Vip] >= 1)
{
format(string, sizeof(string), "~> |Vip Chat| %s: %s <~", IsPlayerName(playerid), text[1]);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && Account[i][Vip] >= 1)
{
SendClientMessage(i, 0xFF0099AA, string);
return 0;
}
}
}
else
{
format(string, sizeof(string), "%s (%d): {FFFFFF}%s", IsPlayerName(playerid), playerid, text);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerVirtualWorld(i) == var)
{
SendClientMessage(i, GetPlayerColor(playerid), string);
return 0;
}
}
}
}
return 1;
}
I cant see my chat and others chat in my server, other player experienced the same situation aswell, I think the problem is from OnPlayerText, but I dont have any clue what is the error
PHP код:
|
public OnPlayerText(playerid, text[]) { new string[144]; // if(text[0] == '@' && Account[playerid][Admin] >= 1) { format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]); for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i) && Account[i][Admin] >= 1) { SendClientMessage(i, 0x0AFFC9FF, string); return 0; } } } if(text[0] == '!' && Account[playerid][Vip] >= 1) { format(string, sizeof(string), "~> |Vip Chat| %s: %s <~", IsPlayerName(playerid), text[1]); for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i) && Account[i][Vip] >= 1) { SendClientMessage(i, 0xFF0099AA, string); return 0; } } } format(string, sizeof(string), "%s (%d): {FFFFFF}%s", IsPlayerName(playerid), playerid, text); SendClientMessageToAll(GetPlayerColor(playerid), string); return 1; }
Код:
public OnPlayerText(playerid, text[]) { new string[144]; // if(text[0] == '@' && Account[playerid][Admin] >= 1) { format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]); for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i) && Account[i][Admin] >= 1) { SendClientMessage(i, 0x0AFFC9FF, string); return 0; } } } if(text[0] == '!' && Account[playerid][Vip] >= 1) { format(string, sizeof(string), "~> |Vip Chat| %s: %s <~", IsPlayerName(playerid), text[1]); for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i) && Account[i][Vip] >= 1) { SendClientMessage(i, 0xFF0099AA, string); return 0; } } } format(string, sizeof(string), "%s (%d): {FFFFFF}%s", IsPlayerName(playerid), playerid, text); SendClientMessageToAll(GetPlayerColor(playerid), string); return 1; } |
what?? can you please explain to me what is the error in my code rather than giving me a raw code that you write back from scratch, I want to learn .
|
if(text[0] == '@' && Account[playerid][Admin] >= 1)
{
format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && Account[i][Admin] >= 1)
{
SendClientMessage(i, 0x0AFFC9FF, string);
}
}
return 0;
}
new string[MAX_PLAYERS], - would likely be too big to send.
change to new string[ 144 ], - this is the largest string you can send with SendClientMessage. ForCop already changed that in his code but he also removed the functionality to send the message within your virtual world and left another mistake. You return 0 every loop iteration within vip, admin and normal chats. Move the return 0; outside of the loops like this. When you return 0; it stops everything so you only want to return after you send the correct messages to everyone you need. PHP код:
|
if(strcmp(text[0],"@",false,1) == 0)
{
text[0] = 25; //removes '@' from text. (replaces with space)
format(text,256, "** |Admin Chat| %s:%s **", IsPlayerName(playerid),text);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(Account[i][Admin] >= 1 && IsPlayerConnected(i))
{
SendClientMessage(i, 0x0AFFC9FF, text);
}
}
format(text,256,""); // clears formatting of 'text' (it's importat for later callback, otherwise players texts will be messed-up)
return 0; // to prevent default text from sending.
}
public OnPlayerText(playerid, text[])
{
new string[144];
if(text[0] == '@' && Account[playerid][Admin] >= 1)
{
format(string, sizeof(string), "** |Admin Chat| %s: %s **", IsPlayerName(playerid), text[1]);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerConnected(i) && Account[i][Admin] >= 1)
SendClientMessage(i, 0x0AFFC9FF, string);
}
return 0;
}
if(text[0] == '!' && Account[playerid][Vip] >= 1)
{
format(string, sizeof(string), "~> |Vip Chat| %s: %s <~", IsPlayerName(playerid), text[1]);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerConnected(i) && Account[i][Vip] >= 1)
SendClientMessage(i, 0xFF0099AA, string);
}
return 0;
}
new var = GetPlayerVirtualWorld(playerid), pl_color = GetPlayerColor(playerid);
format(string, sizeof(string), "%s (%d): {FFFFFF}%s", IsPlayerName(playerid), playerid, text);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(!IsPlayerConnected(i) || GetPlayerVirtualWorld(i) != var) continue;
SendClientMessage(i, pl_color, string);
}
return 0;
}
PHP код:
|
thanks but .. players can use admin chat and vip chat . the only problem is the main chat is not working, maybe i return 0; at the wrong bracket or what?
|
if(strcmp(text[0],"@",false,1) == 0)
{
if(Account[playerid][Admin] < 1) return SendClientMessage(playerid,-1,"You aren't an admin");// prevent normal player from typing in admin chat.
text[0] = 25; //removes '@' from text. (replaces with space)
format(text,256, "** |Admin Chat| %s:%s **", IsPlayerName(playerid),text);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(Account[i][Admin] >= 1 && IsPlayerConnected(i))
{
SendClientMessage(i, 0x0AFFC9FF, text);
}
}
format(text,256,""); // clears formatting of 'text' (it's importat for later callback, otherwise players texts will be messed-up)
return 0; // to prevent default text from sending.
}