GetPlayerName (Im a failure)Rep+ For help
#1

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
string[128],pName[MAX_PLAYER_NAME];
    if(
PlayerInfo[playerid][pAdmin] < 6)
     
GetPlayerName(playerid,pName,sizeof(pName));
    
format(string,sizeof(string),""COL_RED"[Server Owner]"COL_WHITE" %s: %s",pName,text);
    
SendClientMessageToAll(COLOR_WHITE,string);
    return 
0;

Pretty much is the player is server owner ( admin level 6 ) I want it to say
[php[Server Owner] %s[Playername]:%s[text][/php] but the issue is when I go ingame and chat it just comes up as

[Server Owner]: Hi [For example]

Rep+ For help
Reply
#2

PHP код:
public OnPlayerText(playeridtext[])
{
    new 
string[128],pName[24];
    if(
PlayerInfo[playerid][pAdmin] < 6) return 1;
    
GetPlayerName(playerid,pName,sizeof(pName));
    
format(string,sizeof(string),""COL_RED"[Server Owner]"COL_WHITE" %s: %s",pName,text[0]);
    
SendClientMessageToAll(COLOR_WHITE,string);
    return 
0;

Reply
#3

You'd need to used braces in your if condition.
Код:
if (playerid info level >= 6)
{
    // get player name, format, sendclientmessage
    return 0;
}
Also be careful how you use comparisons in your conditions.
Reply
#4

It worked! Repped, but could you comment out of what you changed? I see you added [24] to the pName and [0] to the text but I tryed to manually change that and I failed , But then I copy and paste yours and it works fine, soycould you show me what you changed in a comment? Thanks!
Reply
#5

Код:
public OnPlayerText(playerid, text[]) 
{ 
    new string[256], pname[MAX_PLAYER_NAME];
    if(PlayerInfo[playerid][pAdmin] < 6) 
    {
       GetPlayerName(playerid, pname, sizeof(pname));
       format(string, sizeof(string), "[Server Owner] %s: %s", pname,text);
       SendClientMessageToAll(COLOR_WHITE, string);
    }
return 0;
}
Reply
#6

Quote:
Originally Posted by fiki574_CRO
Посмотреть сообщение
Код:
public OnPlayerText(playerid, text[]) 
{ 
    new string[256], pname[MAX_PLAYER_NAME];
    if(PlayerInfo[playerid][pAdmin] < 6) 
    {
       GetPlayerName(playerid, pname, sizeof(pname));
       format(string, sizeof(string), "[Server Owner] %s: %s", pname,text);
       SendClientMessageToAll(COLOR_WHITE, string);
    }
return 0;
}
Would block other player messages.

@Azzeto Look on my if statement. I check is his level than 6. If it is less than 6 it will return 1 which means messages will be sent in main chat. Because I returned 1 it skips rest of code under that callback which means other part of callback is called only if his level is >= 6. For array of 24 I just set it like that coz I work with 24 size array for name. And for 0 at text variable same. Returning 0 at the end of code means his original message wont be sent in main chat. Only formated one sent using SendClientMessageToAll

Quote:
Originally Posted by SA-MP Wiki
Returns Returning 0 in this callback will stop the text from being sent
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)