[Tutorial] How To Make A Basic Afk Command
#1

Hey guys today I will tell you how to make a /afk and a /back command..Ok so lets start shall we?

What will I need for this tutorial?

You will only need ZCMD

What Is ZCMD?

ZCMD is a fast and simple command processor made by Zeex

Where can I download ZCMD?

You can get it here http://forum.sa-mp.com/showthread.ph...highlight=zcmd

How can I install ZCMD?

Copy zcmd.inc and paste it into your pawno\includes folder

Remember to add at the top of your game mode :-

Код:
#include <zcmd>
And define this color :-

(Add this below your #includes)

Код:
#define Green 0x33AA33AA
Remember that ZCMD doesn't work inside a callback at all

Here is an example of a callback :-

Код:
public OnGameModeInit()
Remember that using return 0; Wont make the command work so use return 1; .

Now we are ready for the code (I hope I do good here I am new to making tutorials here).

Scroll down to the bottom of your game mode and type this in :-

Код:
CMD:afk(playerid, params[])
{
The CMD format is for Zcmd it can also be COMMAND it doesn't matter at all if you use CMD, or COMMAND, command, and instead of "params" you can just add an "o" not the number zero. Remember that pawno is case sensitive for example if I type in :-

Код:
sendclientmessage(playerid, yellow, "lol");
It wont work at all.

.................................................. ........

Now lets get into the script.

Код:
new name[MAX_PLAYER_NAME], string[128];
Let me explain this :-

Код:
new name[MAX_PLAYER_NAME]
Here were are defining the "name" to MAX_PLAYER_NAME what this basicly does is that it makes pawno understand that "name" is someones ingame name.

Код:
string[128]
Here we are creating a new string with the size of 128. Remeber in a string you can add anything into it for example :- Characters, numbers, symbols...etc. You can name it what ever you like for example :- apple[128].

Код:
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
This part here gets the playerid's name (Which in our case it is your player's name) and assigns it to "name" and its size is MAX_PLAYER_NAME.


Now lets format our string.

Код:
format(string, sizeof(string), "%s is now afk", name);
This basicly formats our string to make it say what we want it to. Remember that this wont send the message to anyone, this is when SendClientMessageToAll comes in handy. Remember that %s is a specifier

Код:
SendClientMessageToAll(Green, string);
Here we are sending to everyone that is connected to the server our string that we just formated.

Now for the last step :-

Код:
TogglePlayerControllable(playerid, 0);
This part makes the player not controllable what I mean by that is that you can't move AT ALL even the camera.

Now lets add return 1; and the right sided curly bracket.
Код:
return 1;
}
Here is the full command :-


Код:
CMD:afk(playerid, params[])
{
  new name[MAX_PLAYER_NAME], string[128]; //Here we area creating a new "name" and a new "string" with the size of 128. What the size basicly means is the amount of words..symbols..etc it can carry.
  GetPlayerName(playerid, name, MAX_PLAYER_NAME); //Here we are getting the name of the "playerid" which is us, and we are assigning/defining it to "name" with the size of max player name.
  format(string, sizeof(string), "%s is now afk", name); //Now here we are formating our string that we just made. What I mean by that is that we are adding our text in the string, and letting pawno add the name of our playerid which again is us..if you look at this part "%s is now afk", name %s means a string and if you test this ingame I think you will get it, after our text there is ",name" at this part we are telling pawno that the %s is the value of "name" that we just defined earlier. 
  SendClientMessageToAll(Green, string); //Now here we are sending our string to everyone in the server.
  TogglePlayerControllable(playerid, 0); //Here we are making the player not moveable what I mean by that is that he can't move at all, he can't even move the camera. 
  return 1; // Here we are making the our code get returned to the player what I mean by that is that it will let the code work. If you choose return 0 it wont return anything, ingame you will get the UNKOWN SERVER COMMAND error
}
Now for the /back command.

Код:
CMD:back(playerid, params[])
{
Again this format is for Zcmd and it doesnt matter if you choose CMD or COMMAND.

Код:
new name[MAX_PLAYER_NAME], string[128];
Again here we are making a new "name" and a new string with the size of [128].

Код:
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
Here we are getting the playerid's name (In our case it is us) and assigns it to "name" and we set its size to MAX_PLAYER_NAME.

Now lets format our string.

Код:
format(string, sizeof(string), "%s is now back from afk", name);
Now we just formated our string now lets make our string get sent to all players in our server.

Код:
SendClientMessageToAll(Green, string);
Here we will send our string to all of the player with the color of green and the text is our "string".

Now lets make the player moveable again shall we?

Код:
TogglePlayerControllable(playerid, 1);
Here we are making the player moveable again. remember 1 = True, 0 = False.

Now lets add the return 1; and the right sided curvey bracket.

Код:
return 1;
}
Full command :-

Код:
CMD:back(playerid, params[])
{
 	new name[MAX_PLAYER_NAME], string[128]; //Again here we are creating a new "name" and a new "string" with the size of 128. 	
 	GetPlayerName(playerid, name, MAX_PLAYER_NAME); //Here we are getting the playerid's name which means us the guy that typed in the command..So now we are getting the name of the player that typed in the command and assigning it to "name" with the size of max player name. 	
 	format(string, sizeof(string), "%s is now back from afk", name); //Now here we are formating our string.
 	SendClientMessageToAll(Green, string); //Here we are sending our string to everyone in the  server.
 	TogglePlayerControllable(playerid, 1); //At this part we are making the player moveable again. 	
 	return 1; //Here we are making the code get returned to the player so it works.
}
Credits :-

Zex for his awesome Zcmd, thanks alot.

Thanks guys I hope my tutorial is good.

Please tell me if I should add anything or if there is a mistake thanks
Reply
#2

Oh look it's this tutorial again the one that has been posted like 50000000 times. Not even explained properly 0/10.
Reply
#3

Doesn't explain stuff that much, looks like something a starter scripter would make. 2/10 for effort.
Reply
#4

I accept what you say, and nvm please admin lock this topic...besides I didn't make this tutorial for complete newbies really.

@Danny :- No I am not really a starter my problem was I didint know how to really explain that much :/
Reply
#5

okay i know how to make this but can some one here explain to me, in the score tab if they type /brb or /afk it says like my ig name [ e5N ]Basse[ AFK ]
[ e5N ]Basse[ BRB ]
Reply
#6

Yet another 'tutorial' about a rEally basic command..
1/1000.
Reply
#7

You could have explained well.
Reply
#8

Thanks for your comments. If I make another tutorial it will be explained better than this.
Reply
#9

The lesson is simple, but good for beginners. But i give you rep+.
Reply
#10

Quote:
Originally Posted by im
Посмотреть сообщение
Yet another 'tutorial' about a rEally basic command..
1/1000.
Why the did you come here then?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)