The Script Market
Would you like to react to this message? Create an account in a few clicks or log in to continue.


The Script Market dedicated to the advertisement and sales of all gaming scripts/maps and servers!
 
HomeLatest imagesSearchRegisterLog in

 

 [TUT]Making Simple Commands The Same Way[SAMP]

Go down 
AuthorMessage
Weponz
Founder/BETA Developer
Weponz


Posts : 62
Active Points : 157
Join date : 2010-10-21
Age : 35
Location : Australia

[TUT]Making Simple Commands The Same Way[SAMP] Empty
PostSubject: [TUT]Making Simple Commands The Same Way[SAMP]   [TUT]Making Simple Commands The Same Way[SAMP] EmptyFri Oct 29, 2010 7:11 am


***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 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.php?t=91354&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:help(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:help(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: http://wiki.sa-mp.com/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 Very Happy



Back to top Go down
http://thescriptmarket.betaboard.net
 
[TUT]Making Simple Commands The Same Way[SAMP]
Back to top 
Page 1 of 1
 Similar topics
-
» [SAMP] Pickup ID's
» [SAMP] Weather ID's
» [SAMP] Grafix MOD
» [SAMP] Weapon List
» [SAMP] Interior ID's And (X,Y,Z) Coordinates

Permissions in this forum:You cannot reply to topics in this forum
The Script Market :: Site Archives :: Scripting/Mapping Tutorials[NEW]-
Jump to: