28.10.2010, 21:33
(
Last edited by <Weponz>; 03/11/2010 at 01:24 PM.
)
***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[])
Code:
if(!strcmp(cmdtext,"/commandgoeshere",true)) { //Functions Here return 1; }
Code:
if(!strcmp(cmdtext,"/commandgoeshere",true))
Code:
{
Code:
return 1;
Code:
}
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; }
Code:
CMD:commandgoeshere(playerid, params[])
Code:
{
Code:
return true;
Code:
}
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))
Code:
CMD:help(playerid, params[])
STRCMP:
Code:
if(!strcmp(cmdtext,"/rules",true)) { SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!"); return 1; }
Code:
CMD:rules(playerid, params[]) { SendClientMessage(playerid, 0x0,"Rule 1. No Hacking/Cheating!"); return true; }
Code:
SendClientMessage
Code:
playerid
Code:
0x0
Code:
"Message"
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; }
Code:
CMD:help(playerid, params[]) { SendClientMessage(playerid, 0x0,"Message Here"); return true; }
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; }
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; }
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; }
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; }
**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; }
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; }
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; }
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; }
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; }