SA-MP Forums Archive
OnPlayerText & sscanf for @ - 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: OnPlayerText & sscanf for @ (/showthread.php?tid=611047)



OnPlayerText & sscanf for @ - TwinkiDaBoss - 01.07.2016

Alright so Im trying to make a simple system that will work like
@SomePlayerName Hey bro

and then it would display the GameText to the other player, now my problem is quite simple, it will constantly reproduce the "Player is not connected". Now I know that its because first character is @ inside the string so it will basically check
if(IsPlayerConnected(@)

or for example if u type in @Twinki it will check if @Twinki is connected, how to resolve this?
PHP код:
public OnPlayerText(playeridtext[])
{
    
     if(
text[0] == '@') {
         new 
otherplayer;
        if(
sscanf(text,"u",otherplayer)) return SendClientMessage(playerid,COLOR_RED,"Usage: @Player_Name [message]");
        if(!
IsPlayerConnected(otherplayer)) return SendClientMessage(playeridCOLOR_RED,"Invalid playerid / not connected");
        new 
string[128];
        
format(string,sizeof(string),"%s mentioned you in the chat",GetName(playerid));
        
GameTextForPlayer(otherplayer,string,2000,4);
     }
    return 
1;




Re: OnPlayerText & sscanf for @ - Vince - 01.07.2016

Then either start from text[1] or put the @ in the specifier: "'@'u". You also need to add a string specifier to capture the chat. You can use a quiet specifier (enclose it in curly braces) if you're not interested in the text itself.


Re: OnPlayerText & sscanf for @ - TwinkiDaBoss - 01.07.2016

Quote:
Originally Posted by Vince
Посмотреть сообщение
Then either start from text[1] or put the @ in the specifier: "'@'u". You also need to add a string specifier to capture the chat. You can use a quiet specifier (enclose it in curly braces) if you're not interested in the text itself.
Yeaaah I forgot about the '@' inside sscanf, damn been long time haha. Thanks a lot bud