[Tutorial] y_commands /me
#1

Tonight before i go to bed i thought i'd through this up here. You will need the y_commands inc from ****** , that comes with YSI. Now we can start coding.

At the top under #include <a_samp> we need to put
Код:
#include <YSI\y_commands>
Then go to the bottom of your script(prefferably). Since YCMD cant use OnPlayerCommandText

So to start off
Код:
YCMD:me(playerid, params[], help)
Which replaces
Код:
if(strcmp("/me", cmdtext, true) == 0)
As you can tell alot shorter, the "playerid" well is self explanitory. The params is whatever you type after the cmd.
And we won't be using the "help" feature, since it inteferes with our cmd.

So next were gonna set up some things. sendername
Код:
new sendername;
GetPlayerName(playerid, sendername sizeof(sendername));
This basicly is just getting the players name that types the command so it doesn show up as an id.

Now we are going to use the if(isnull(params)) feature in YCMD.
This checks if the player typed anything after the command..So
Код:
if(isnull(params)) return SendClientMessage(playerid, WHITE, "[USAGE]: /me(action));
Now that checked if it was empty, if it was it sends them a message on how to use it.
Next were gonna use "format" to set up the message.
Код:
format(string, sizeof(string), "*%s %s*", sendername, params);
This uses the sendername we set up earlier and the params the player typed.
Then we use a ProxDetector.
Код:
ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
Incase you dont have the Proxdetector i'll put one in a notesbin.Dont forget to forward it(its a public).

Now for the final thing:
Код:
return 1;
And this is what our whole code looks like
Код:
YCMD:me(playerid, params[])
{
	new sendername[MAX_PLAYER_NAME];
	new string[128];
	GetPlayerName(playerid, sendername, sizeof(sendername));
  	if(isnull(params)) return SendClientMessage(playerid, WHITE, "Use /me to do an action.");
	format(string, sizeof(string), "**%s %s**", sendername, params);
	ProxDetector(10.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
	return 1;
}
Also the colors i used:
Код:
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
#define WHITE 0xFFFFFFAA
As you can see hell of alot shorter than the one ravens uses for example:
Код:
if(strcmp(cmd, "/me", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_GREY, "   You havent logged in yet !");
	            return 1;
	        }
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[128];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GREY, "USAGE: /me [action]");
				return 1;
			}
			format(string, sizeof(string), "* %s %s", sendername, result);
			ProxDetector(3.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
			new y,m,d;
			new h,mi,s;
			getdate(y,m,d);
			gettime(h,mi,s);
			format(string, sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s (Me): %s",d,m,y,h,mi,s, sendername, result);
			ChatLog(string);
		}
		return 1;
	}
Reply
#2

Hmmm... it's allright.
Reply
#3

Quote:
Originally Posted by alpha500delta
Посмотреть сообщение
Hmmm... it's allright.
Thanks i know its kinda n00bish, just started YCMD yesterday
Reply
#4

Nice.
Reply
#5

Good tutorial, very usefull and clear
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)