[Tutorial] Making Simple Commands The Same Way
#1


***THREAD UPDATED INTO STRCMP AND ZCMD TUTORIALS***

Im making this tutorial mainly for "Newbie" scripters to show them how to make simple commands,Instead of making ridiculous threads named "How do i make a /help command?" etc cause in-fact these types of commands are as basic as it gets and indicates thay have no knowlage of scripting and can be frustrating to try and explain it to them..



Before i start i must state that STRCMP is the slowest processor as ZCMD is the faster,I recommend you learn the ZCMD part also taking note how STRCMP works..

Now im going to show you how to make the most typically used commands on a server such as:

/help /info /rules /credits /heal /teleport /kill


*I will also show you how to make these commands assigned to a team/class or admins only*

Im going to show you how to make all of these commands using the same "Basics" (Which thay all contain)

Ok we must start with understanding what i call the "Basics" of the commands.

These commands are obviously "Input" commands meaning a player has to type the command before anything happens resulting in all commands of this type being under the callback:


STRCMP:

Code:
public OnPlayerCommandText(playerid, cmdtext[])
Now we will start with making a /rules..We start with the "Basics" as allways..

Code:
if(!strcmp(cmdtext,"/commandgoeshere",true))
                      {
                      //Functions Here
		      return 1;
}
This is the basics of all these commands:

Code:
if(!strcmp(cmdtext,"/commandgoeshere",true))
This tells the server what to do after a player types this command(/commandgoeshere)

Code:
{
you allways open the command with a opening brace..

Code:
return 1;
Commands need to return 1 a command with a return 0 means the command does nothing(Its disabled)

Code:
}
And always close the command with a closing brace..

ZCMD:

NOTE: ZCMD commands do not go under OnPlayerCommandText,Thay are individual, place anywhere in your script but NOT in a callback! And the only diffrence in coding is ZCMD has params and we return with true/false

Also you MUST have the ZCMD include here: http://forum.sa-mp.com/showthread.ph...highlight=zcmd

Code:
#include <zcmd>//To Of Script


Code:
CMD:commandgoeshere(playerid, params[])
{
    //Functions Here
    return true;
}
Lets look closer:

Code:
CMD:commandgoeshere(playerid, params[])
This tells the server what to do after a player types this command(/commandgoeshere)

Code:
{
you allways open the command with a opening brace..

Code:
return true;
Commands need to return true a command with a return false means the command does nothing(Its disabled)

Code:
}
And always close the command with a closing brace..

Now we know what the basics is all about we need to turn it into a /rules,We edit our command to /rules first..

STRCMP:

Code:
if(!strcmp(cmdtext,"/rules",true))
ZCMD:

Code:
CMD:help(playerid, params[])
We then open the command with a opening brace,Then place the function "SendClientMessage"(this function sends the player a message when thay do the command) return it and close it with a closing brace like so..

STRCMP:

Code:
if(!strcmp(cmdtext,"/rules",true))
                      {
                      SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!");
		      return 1;
}
ZCMD:

Code:
CMD:rules(playerid, params[])
{
    SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!");
    return true;
}
Code:
SendClientMessage
the function
Code:
playerid
tells the server to send the message to the playerid that does the command
Code:
0x0
This is color define,Use a color define you want the message to appear as(Use define 0xFF0000FF for red text)
Code:
"Message"
The message you want them to see,In this case the rules


That commands done,To add Rule 2/3 etc simply make another SendClientMessage function like so..


STRCMP:

Code:
if(!strcmp(cmdtext,"/rules",true))
                      {
                      SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!");
                      SendClientMessage(playerid, 0x0,"Rule 2. No Spamming!");//And so on..
		      return 1;
}
ZCMD:

Code:
CMD:help(playerid, params[])
{
    SendClientMessage(playerid, 0x0,"Message Here");
    return true;
}
Now you should be able to figer out now how to convert these to /credits /info and /help commands,You simply edit the /command and message functions..A /info and /rules looks like this..

STRCMP:

Code:
if(!strcmp(cmdtext,"/rules",true))
                      {
                      SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!");
                      SendClientMessage(playerid, 0x0,"Rule 2. No Spamming!");//And so on..
		      return 1;
}
if(!strcmp(cmdtext,"/info",true))
                      {
                      SendClientMessage(playerid, 0x0,"Info goes here");
		      return 1;
}
ZCMD:

Code:
CMD:rules(playerid, params[])
{
                      SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!");
                      SendClientMessage(playerid, 0x0,"Rule 2. No Spamming!");//And so on..
                      return true;
}
CMD:info(playerid, params[])
{
                      SendClientMessage(playerid, 0x0,"Info Goes Here");
                      return true;
}
And so on..

Now all we do is use a different function for /teleport that function is SetPlayerPos which sets a players position..

Ofcourse we start with the "Basics"..


STRCMP:

Code:
if(!strcmp(cmdtext,"/commandgoeshere",true))
                      {
		      return 1;
}
After adding the SetPlayerPos function and editing it to /teleport it should look like this..

Code:
if(!strcmp(cmdtext,"/teleport",true))
                      {
                      SetPlayerPos(playerid,X,Y,Z);//Change X,Y,Z
		      return 1;
}


Code:
CMD:teleport(playerid, params[])
{
    SetPlayerPos(playerid,X,Y,Z);//Change X,Y,Z
    return true;
}
And to asign this teleport only to a admin(RCON Admin) you add the function IsPlayerAdmin like so..

**This can be done the same way with any other command**


STRCMP:

Code:
if(!strcmp(cmdtext,"/teleport",true))
                      {
                      if(IsPlayerAdmin(playerid));//If the player is admin he will be teleported
                      SetPlayerPos(playerid,X,Y,Z);//Change X,Y,Z
                      else SendClientMessage(playerid, 0x0, "You are not an admin");//If there not a admin you send them a message using else
		      return 1;
}
And the exact same way with teams with the function gTeam(Global teams meaning all the teams ur server has)

Code:
if(!strcmp(cmdtext,"/teleport",true))
                      {
                      if(gTeam[playerid] == THE_TEAM)//If the player is in THE_TEAM he will be teleported
                      SetPlayerPos(playerid,X,Y,Z);
                      else SendClientMessage(playerid, RED, "You are not an admin");//If there not in THE_TEAM you send them a message using else
		      return 1;
}


ZCMD:

Admins Only:

Code:
CMD:teleport(playerid, params[])
{
                      if(!IsPlayerAdmin(playerid));//If the player is admin he will be teleported
                      SetPlayerPos(playerid,X,Y,Z);//Change X,Y,Z
	return true;
}
Team Only:

Code:
CMD:teleport(playerid, params[])
{
                      if(gTeam[playerid] == THE_TEAM)//If the player is in THE_TEAM he will be teleported
                      SetPlayerPos(playerid,X,Y,Z);//Change X,Y,Z
	return true;
}
Now you may notice that all you change is the functions,Functions can be found on WIKI here: https://sampwiki.blast.hk/wiki/Useful_Functions

Im going to finish with a /heal and a /kill command...For the /heal and /kill command we use the the same function SetPlayerHealth and just 1 extra for /kill to send them to Class Selection the function ForceClassSelection,As always we start with basics..


STRCMP:

Code:
if(!strcmp(cmdtext,"/commandgoeshere",true))
                      {
		      return 1;
}
And convert it to this for /heal..

Code:
if(!strcmp(cmdtext,"/heal",true))
                      {
                      SetPlayerHealth(playerid,100);//Sets Health to 100
		      return 1;
}

And we do the same but a another function ForceClassSelection for the /kill...


Code:
if(!strcmp(cmdtext,"/kill",true))
                      {
                      SetPlayerHealth(playerid,0.0);//Sets Health to 100
                      ForceClassSelection(playerid);//Forces the player to class selection
		      return 1;
}


ZCMD:

Code:
CMD:heal(playerid, params[])
{
                      SetPlayerHealth(playerid,100);//Sets Health to 100
	return true;
}
Code:
CMD:kill(playerid, params[])
{
                      SetPlayerHealth(playerid,0.0);//Sets Health to 100
                      ForceClassSelection(playerid);//Forces the player to class selection
	return true;
}
That includes my tutorial,Hope this helps people understand these simple commands alot easier



Reply
#2

nice for beginners
Reply
#3

Quote:
Originally Posted by Mr.BaXx
View Post
Nice tutorial
Quote:
Originally Posted by dark_clown
View Post
nice for beginners
Thanks..Just got tired of answering these questions in Discussion,Because thay acually dont know ANY scripting if thay ask that...Hope thay will read this then have a very good idea what scriptings all about xD
Reply
#4

pawn Code:
if(!strcmp(cmdtext,"/kill",true))
                      {
                      SetPlayerHealth(playerid,100);//Sets Health to 100
                      ForceClassSelection(playerid);//Forces the player to class selection
              return 1;
}
should be

pawn Code:
if(!strcmp(cmdtext,"/kill",true))
                      {
                      SetPlayerHealth(playerid,0.0);//Sets Health to 0
                      ForceClassSelection(playerid);//Forces the player to class selection
              return 1;
}
Reply
#5

nice it will help those who starts in scripting !!
Reply
#6

sorry for double post but there isa mistake here :
Quote:

if(!strcmp(cmdtext,"/teleport",true))
{
iif(gTeam[playerid] == THE_TEAM)//If the player is in THE_TEAM he will be teleported
SetPlayerPos(playerid,X,Y,Z);
else SendClientMessage(playerid, RED, "You are not an admin");//If there not in THE_TEAM you send them a message using else
return 1;
}

it's if not iif
thanks
Reply
#7

Quote:
Originally Posted by [FU]Victious
View Post
pawn Code:
if(!strcmp(cmdtext,"/kill",true))
                      {
                      SetPlayerHealth(playerid,100);//Sets Health to 100
                      ForceClassSelection(playerid);//Forces the player to class selection
              return 1;
}
should be

pawn Code:
if(!strcmp(cmdtext,"/kill",true))
                      {
                      SetPlayerHealth(playerid,0.0);//Sets Health to 0
                      ForceClassSelection(playerid);//Forces the player to class selection
              return 1;
}
Quote:
Originally Posted by Miado_Hulk
View Post
sorry for double post but there isa mistake here :


it's if not iif
thanks
Thanks typos fixed,Tutorial edited..
Reply
#8

DO NOT USE THIS TUTORIAL

Seriously? You know better, "Weaponz", ZCMD and SSCANF. Why make a tutorial on using the slowest command processor? Just... Re-do it with ZCMD and SSCANF.
Reply
#9

Quote:
Originally Posted by RealCop228
View Post
DO NOT USE THIS TUTORIAL

Seriously? You know better, "Weaponz", ZCMD and SSCANF. Why make a tutorial on using the slowest command processor? Just... Re-do it with ZCMD and SSCANF.
Sorry thats how i script...Also thats how Wiki teaches you...So thay will understand Wiki easier,Later updating it to DCMD/ZCMD if thay want..All i have done is explain the basics..Which Wiki contains..Which "Newbies" use..

Would be great if you could translate this Tutorial into DCMD/ZCMD ?

BTW:I plan to learn DCMD/ZCMD etc soon...I will release knowlage i know then...
Reply
#10

Quote:
Originally Posted by <Weponz>
View Post
Sorry thats how i script...Also thats how Wiki teaches you...So thay will understand Wiki easier,Later updating it to DCMD/ZCMD if thay want..All i have done is explain the basics..Which Wiki contains..Which "Newbies" use..

Would be great if you could translate this Tutorial into DCMD/ZCMD ?

BTW:I plan to learn DCMD/ZCMD etc soon...I will release knowlage i know then...
I think I'll update (or add a page) on the Wiki.
Reply
#11

Quote:
Originally Posted by RealCop228
View Post
I think I'll update (or add a page) on the Wiki.
Will be usefull and might teach me how to use DCMD/ZCMD...
Reply
#12

Quote:
Originally Posted by RealCop228
View Post
DO NOT USE THIS TUTORIAL

Seriously? You know better, "Weaponz", ZCMD and SSCANF. Why make a tutorial on using the slowest command processor? Just... Re-do it with ZCMD and SSCANF.
Wow chill. I know for a fact that every beginner scripter starts off with strcmp. Also when someone is beginning there is really no need for major efficiency because they will likely not have a large player base at the beginning. DCMD and ZCMD usually comes much later such as myself.
Reply
#13

Quote:
Originally Posted by BP13
View Post
Wow chill. I know for a fact that every beginner scripter starts off with strcmp. Also when someone is beginning there is really no need for major efficiency because they will likely not have a large player base at the beginning. DCMD and ZCMD usually comes much later such as myself.
I disagree. If you start off learning the faster and more efficient libraries, systems and functions you could actually make a decent script. I know 75% of the people who join this community and (attempt to) open a server, use a GF edit. The 25% of the other people who come here and (attempt to) open a server and try to make a script themselves should benefit. Its a hell of a lot more work to do it the 'bad way', then optimize your code and end up needing to redo the commands or change command processors. (ultimately redoing the commands) My two cents...
Reply
#14

Quote:
Originally Posted by RealCop228
View Post
I disagree. If you start off learning the faster and more efficient libraries, systems and functions you could actually make a decent script. I know 75% of the people who join this community and (attempt to) open a server, use a GF edit. The 25% of the other people who come here and (attempt to) open a server and try to make a script themselves should benefit. Its a hell of a lot more work to do it the 'bad way', then optimize your code and end up needing to redo the commands or change command processors. (ultimately redoing the commands) My two cents...
Thank goodness that we both of us have our own opinions. I slightly agree with yours too but it can be confusing to try something else for first use.
Reply
#15

**Thread Updated Into ZCMD**
Reply
#16

I don't see much explaining into the ZCMD part, you simply converted the code. I guess it's better then nothing.
Reply
#17

Quote:
Originally Posted by RealCop228
View Post
I don't see much explaining into the ZCMD part, you simply converted the code. I guess it's better then nothing.
Considering i just learnt ZCMD 5 secs ago and i stated what has changed between the 2 and how you do it,Theres not much diffrence between them,But i updated it because i agree with you that the faster processer should be shown..
Reply
#18

With ZCMD if I wanted to make a command like /rob [playerid] then how do I do that?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)