SA-MP Forums Archive
OnPlayerText - 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 (/showthread.php?tid=503778)



OnPlayerText - DarkLored - 31.03.2014

I am trying to make admin command through OnPlayerText.
The problem is when i type the command wrong sscanf works great but when i type it correctly nothing happens
i am using zcmd and my friend is doing the same as me right now and in his gamemode works we are both using the same method.

here is the code
pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
    {
       if(strcmp(text,"!warn",true,5))
       {
          new ID,reason[50];
          if(sscanf(text,"us[50]",ID,reason))
          {
             SendClientMessage(playerid,COLOR_ERROR,"USAGE: !warn (Player Name/ID) (Reason)");
             return 0;
          }
          if(ID == INVALID_PLAYER_ID)
          {
             format(string,sizeof(string),"ID %d is not connected to the server.",ID);
             return 0;
          }
          if(WarnTimes[ID] >= 2)
          {
             format(string,sizeof(string),"%s(%d) has been auto kicked from the server because he has reached maximum warnings [3/3 Warnings].",GetName(ID),ID);
             SendClientMessageToAll(COLOR_PINK,string);
             
             format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
             GameTextForPlayer(ID ,string, 99999999999999999999999, 3);
             KickTime[ID] = 3;
             return 0;
          }
          else
          {
             WarnTimes[ID]+=1;
             if(WarnTimes[ID]==1)
             {
                format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [1/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason);
                SendClientMessageToAll(COLOR_PINK,string);
                return 0;
             }
             else if(WarnTimes[ID]==2)
             {
                format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [2/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason);
                SendClientMessageToAll(COLOR_PINK,string);
                return 0;
             }
          }
      }
      return 0;
    }



Re: OnPlayerText - DarkLored - 31.03.2014

You just added isnull how is it suppose to help with my problem.
my problem is that when i use the command it doesn't do anything


Re: OnPlayerText - LocMax - 31.03.2014

Because you use return 0; everywhere.

pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
    {
       if(strcmp(text,"!warn",true,5))
       {
          new ID,reason[50];
          if(sscanf(text,"us[50]",ID,reason)) return SendClientMessage(playerid,COLOR_ERROR,"USAGE: !warn (Player Name/ID) (Reason)");
          if(ID == INVALID_PLAYER_ID) return format(string,sizeof(string),"ID %d is not connected to the server.",ID), SendClientMessage(playerid, -1, string);
          if(WarnTimes[ID] >= 2)
          {
             format(string,sizeof(string),"%s(%d) has been auto kicked from the server because he has reached maximum warnings [3/3 Warnings].",GetName(ID),ID);
             SendClientMessageToAll(COLOR_PINK,string);
             
             format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
             GameTextForPlayer(ID ,string, 99999999999999999999999, 3);
             KickTime[ID] = 3;
          }
          else
          {
             WarnTimes[ID]+=1;
             if(WarnTimes[ID]==1)
             {
                format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [1/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason);
                SendClientMessageToAll(COLOR_PINK,string);
             }
             else if(WarnTimes[ID]==2)
             {
                format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [2/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason);
                SendClientMessageToAll(COLOR_PINK,string);
             }
          }
      }
      return 0;
    }
btw I made a bit optimized version, not tested tho.

pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
{
    if(strcmp(text,"!warn",true,5))
    {
        new ID, reason[50];
        if(sscanf(text,"us[50]",ID,reason)) return SendClientMessage(playerid,COLOR_ERROR,"USAGE: !warn (Player Name/ID) (Reason)");
        if(ID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_ERROR, "Target ID is not valid.");
        new string[124], WarnTimes[ID]++;
        if(WarnTimes[ID] >= 3)
        {
            format(string,sizeof(string),"%s(%d) has been automatically kicked. Reason: 3/3 warnings.",GetName(ID),ID);
            SendClientMessageToAll(COLOR_PINK,string);

            GameTextForPlayer(ID, "~W~You have been ~R~kicked ~W~from the server", 99999999, 3);
            KickTime[ID] = 3;
        }
        else if(WarnTimes[ID] < 3)
        {
            format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [%d/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason, WarnTimes[ID]);
            SendClientMessageToAll(COLOR_PINK,string);
        }
    }
    return 0;
}



Re: OnPlayerText - DarkLored - 31.03.2014

Now it doesn't work at all
Any help guys it is my first try to script commands like that for admins


Re: OnPlayerText - Vince - 31.03.2014

One very important thing you are overlooking is that text also contains the command itself; ZCMD's params doesn't. You could probably solve this with a quiet specifier.
pawn Код:
sscanf(text,"{s[10]}us[50]",ID,reason)
Oh, you also forget to send the message if the playerid is invalid, which is probably why nothing happens.


Re: OnPlayerText - DarkLored - 31.03.2014

Did what you told me too and i removed the Invalid player id to make sure that its not the case
but nothing happens when i type it


Re: OnPlayerText - Jefff - 31.03.2014

pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
{
    if(strcmp(text,"!warn",true,5) == 0)
    {
        new ID,reason[50];
        if(sscanf(text[6],"us[50]",ID,reason))
        {
            SendClientMessage(playerid,COLOR_ERROR,"USAGE: !warn (Player Name/ID) (Reason)");
            return 0;
        }
        if(ID == INVALID_PLAYER_ID)
        {
            format(string,sizeof(string),"ID %d is not connected to the server.",ID);
            SendClientMessage(playerid,COLOR_ERROR,string);
            return 0;
        }
        if(WarnTimes[ID] >= 2)
        {
            format(string,sizeof(string),"%s(%d) has been auto kicked from the server because he has reached maximum warnings [3/3 Warnings].",GetName(ID),ID);
            SendClientMessageToAll(COLOR_PINK,string);

            format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
            GameTextForPlayer(ID ,string, 99999999999999999999999, 3);
            KickTime[ID] = 3;
            return 0;
        }
        else
        {
            ++WarnTimes[ID];
            format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [%d/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason,WarnTimes[ID]);
            SendClientMessageToAll(COLOR_PINK,string);
        }
    }
    return 0;
}
or text[5] because it could be invalid memory access xd


Re: OnPlayerText - DarkLored - 31.03.2014

Thanks man it really helped + rep to everyone that posted here and contributed their time to help me


Re: OnPlayerText - SickAttack - 01.04.2014

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
{
    if(strcmp(text,"!warn",true,5) == 0)
    {
        new ID,reason[50];
        if(sscanf(text[6],"us[50]",ID,reason))
        {
            SendClientMessage(playerid,COLOR_ERROR,"USAGE: !warn (Player Name/ID) (Reason)");
            return 0;
        }
        if(ID == INVALID_PLAYER_ID)
        {
            format(string,sizeof(string),"ID %d is not connected to the server.",ID);
            SendClientMessage(playerid,COLOR_ERROR,string);
            return 0;
        }
        if(WarnTimes[ID] >= 2)
        {
            format(string,sizeof(string),"%s(%d) has been auto kicked from the server because he has reached maximum warnings [3/3 Warnings].",GetName(ID),ID);
            SendClientMessageToAll(COLOR_PINK,string);

            format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
            GameTextForPlayer(ID ,string, 99999999999999999999999, 3);
            KickTime[ID] = 3;
            return 0;
        }
        else
        {
            ++WarnTimes[ID];
            format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [%d/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason,WarnTimes[ID]);
            SendClientMessageToAll(COLOR_PINK,string);
        }
    }
    return 0;
}
or text[5] because it could be invalid memory access xd
That isn't an efficient way to do this. ^^

You should make OnPlayerText forward to a zcmd scripted command. Like below:

pawn Код:
new string[128], cmd[128], params[128]; // Define the parameters with their string size witch will be split.
sscanf(text, "s[128]s[128]", cmd, params); // Split the text into two parameters.
if(pInfo[playerid][AdminLevel] >= 1)
{
      if(strcmp(cmd, "!", true) == 0) return 0; // If player types !, it won't show anything just like when you type /.
      if(strcmp(cmd, "!", true, 1) == 0) // This is needed as it allows the player with admin status chat.
      {
             if(strcmp(cmd, "!nUllstrIngtonoTbeUseddpljmhuyf", true, 31) == 0) return 0; // This fixes the bug when you send a message with a space.
             if(strcmp(cmd, "!warn", true, 5) == 0) {cmd_acmdwarn(playerid, params); return 0;} // This forwards !warn to a zcmd command.
             else
             {
                    format(string,sizeof(string),"{A5FF00}Unknown admin command (%s) | Use !commands to list all available admin commands.", cmd);
                    SendClientMessage(playerid, COLOR_RED, string);
             }
      }
      return 0;
}
If you want to fix the bug with the space for players that don't possess admin status, here it is:
pawn Код:
if(pInfo[playerid][AdminLevel] == 0)
{
     if(strcmp(cmd, " ", true, 1) == 0)
     {
          if(strcmp(cmd, "!nUllstrIngtonoTbeUseddpljmhuyf", true, 31) == 0) return 0;
          return 0;
     }
}
NOTE: If you are going to use the function above put new cmd[128], params[128]; & sscanf(text, "s[128]s[128]", cmd, params); above it.

Good luck buddy!
PS: I'm the friend mentioned above .


Re: OnPlayerText - Threshold - 01.04.2014

And what is the difference between these two statements?:

pawn Код:
if(strcmp(cmd, "!", true) == 0) return 0; // If player types !, it won't show anything just like when you type /.
      if(strcmp(cmd, "!", true, 1) == 0)
Silly.