SA-MP Forums Archive
GetPlayerName (Im a failure)Rep+ For help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: GetPlayerName (Im a failure)Rep+ For help (/showthread.php?tid=297399)



GetPlayerName (Im a failure)Rep+ For help - Azzeto - 15.11.2011

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


Re: GetPlayerName (Im a failure)Rep+ For help - [MG]Dimi - 15.11.2011

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;




Re: GetPlayerName (Im a failure)Rep+ For help - [NoV]LaZ - 15.11.2011

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.


Re: GetPlayerName (Im a failure)Rep+ For help - Azzeto - 15.11.2011

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!


Re: GetPlayerName (Im a failure)Rep+ For help - fiki574 - 15.11.2011

Код:
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;
}



Re: GetPlayerName (Im a failure)Rep+ For help - [MG]Dimi - 15.11.2011

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