SA-MP Forums Archive
How to get the text a player typed? - 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: How to get the text a player typed? (/showthread.php?tid=318594)



How to get the text a player typed? - jessejanssen - 15.02.2012

Hello reader,

I am really new to PAWN but my final goal is to create a RP server, I just try to script things and get them working etc etc. Now my problem is, I don't know how to get a player's text. Like the player types "/me walks" and then "/me" is the command and the typed text behind the command would be " walks".

This is the currently used code:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

if (strcmp("/me", cmdtext, true, 3) == 0)
	{
	new string[128];
    GetPlayerName(playerid, name, sizeof(name));
	format(string, sizeof(string), "%s .", RemoveUnderScore(playerid));
    SendClientMessage(playerid, COLOR_PURPLE, string);
    return 1;
	}
	
if (strcmp("/act", cmdtext, true, 4) == 0)
	{
	new string[128];
    GetPlayerName(playerid, name, sizeof(name));
	format(string, sizeof(string), ". (( %s ))", RemoveUnderScore(playerid));
    SendClientMessage(playerid, COLOR_PURPLE, string);
    return 1;
	}
return 0;
}
Yes I am aware that with this code it will send the command text only to the player who typed it and that I have to add a radius how far players around the players who typed the command see it etc etc but for now my only concern is to get the player's typed text so it would work. I hope someone can help me with this .

Best regards,
Jesse


Re: How to get the text a player typed? - Dripac - 15.02.2012

Here a full cmd
pawn Код:
if(strcmp(cmd, "/me", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You are not logged in!");
                return 1;
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, " /me [action]");
                return 1;
            }
            format(string, sizeof(string), "* %s %s", sendername, result);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            printf("%s", string);
        }
        return 1;
    }



Re: How to get the text a player typed? - Vince - 15.02.2012

^ Don't use that. Get ZCMD.


Re: How to get the text a player typed? - jessejanssen - 15.02.2012

Quote:
Originally Posted by Dripac
Посмотреть сообщение
Here a full cmd
pawn Код:
if(strcmp(cmd, "/me", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You are not logged in!");
                return 1;
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, " /me [action]");
                return 1;
            }
            format(string, sizeof(string), "* %s %s", sendername, result);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            printf("%s", string);
        }
        return 1;
    }
I didn't got that to work, ( Yes I know a few things weren't ( and still aren't ) defined in my script. ) whatever I tried it didn't work.

Quote:
Originally Posted by Vince
Посмотреть сообщение
^ Don't use that. Get ZCMD.
I don't know how to work with that properly.

Thank you both for your reaction but for now it is still not the solution.

Best regards,
Jesse

EDIT:
I've been looking/working with ZCMD & sscanf and it is easier to script then strcmp but I still do not know how to get a player's typed text.


Re: How to get the text a player typed? - L0zaix - 16.02.2012

here is one. you don't need sscanf to make /me

pawn Код:
#define COLOR_YELLOW 0xFFFF00FF //top of script after include

CMD:me(playerid, params[])
{
    new string[128],pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    if(isnull(params)) return SendClientMessage(playerid, COLOR_RED, "SYNTAX: /me <text>");
    format(string, sizeof(string), "%s %s", pname, params);
    SendClientMessageToAll(COLOR_YELLOW, string);
    return 1;
}
hope i helped! , you can put in the bottom or somewhere else except near in Include!