[Tutorial] Making basic commands [ZCMD]
#1

Okay. This is my first tutorial and I'm still a noob so I'd appreciate help but criticism will NOT be appreciated.

Getting started


First of all, You need a SA-MP server kit, SA-MP, ZCMD installed. Firstly, you open your script and go to the place where you mostly do your commands made with ZCMD's. If you're new to this, All you gotta do is scroll down where the script ends and there is where you start your cmds with you're using ZCMD. For strcmp, Go to:
public OnPlayerCommandText.

Okay, Now i'll start the serious shit


Some functions that are important


Okay, now before we start, You all may think that you want something like you type /dm and boom, you get teleported to a location and you give the player some guns and set his health, armour and stuff like that.

We'll be using the follow Callbacks below:


SetPlayerPos(playerid, X, Y, Z) // XYZ = co-ordinates. Debug guide in sampwiki will help.
GivePlayerWeapon(playerid, Weaponid, ammo) //For giving weapons
SetPlayerHealth(playerid, AMOUNTOFHEALTH) // For setting health
SetPlayerArmour(playerid, AMOUNTOFARMOUR) // For setting armour
SetPlayerSkin(playerid, SKINID) // For setting Skin ID's
SetPlayerInterior(playerid, Interiorid) // MOST IMPORTANT if you're making teleport command for interior
ResetPlayerWeapons(playerid) //Disarms the player
SendAllClientMessage(HEXCOLOR, "Message")



Starting the serious shit


Okay, what you saw was getting ready. Now we're going to start the serious shit.

First, we start with a very basic healme and armourme command.

Quote:

CMD:healme(playerid,params[])

That line basically defines the usage of the command. Note: This is case sensitive. Healme won't work but healme will.

Now:
Quote:

{
//Code here

After the CMD: line, we always do the { bracket in order to define the starting of what our command will actually do

Okay, So we'll be using the SetPlayerHeatlh callback now as this is the healme command.

Quote:

CMD:healme(playerid,params[])
{
SetPlayerHeatlh(playerid, 100); // This sets the health of the player to 100
SendClientMessage(playerid, 0xFF8000FF, "You have been healed! "); // Sends the player message

[OPTIONAL]Now you may want to add a price to your healme command. This is quite easy and we'll be using GivePlayerMoney callback for this.

Quote:

CMD:healme(playerid,params[])
{
SetPlayerHeatlh(playerid, 100);
GivePlayerMoney(playerid, -500); // -500 means it will take 500$ frmo the player. You can change this.
SendClientMessage(playerid, 0xFF8000FF, "You have been healed for 500$! ");

Now you think this is done. But no no, wait. Before we complete a command, we must add a } bracket to define that we closed the command. And in the end, add return 1;

Quote:

CMD:healme(playerid,params[])
{
SendClientMessage(playerid, 0x33CCFFAA, " Health restored for 500$! ");
SetPlayerHealth(playerid, 100);
GivePlayerMoney(playerid, -500);
return 1;
}

Voila! That's our code for /healme. Quite the same way,just copy that code,now just change SetPlayerHealth to SetPlayerArmour, change CMD:healme to CMD:armourme and There it is! Your healme and armourme commands are ready Try it out ingame right now!


Questions you may have regarding this:

Q:I want to make a shortcode for this command. How do I do that?
Ans:You want armourme and ame to do the same thing. Now instead of copying and renaming the same code, we can add this line:

Quote:

CMD:ame(playerid, params[]) return cmd_armourme(playerid, params);

I'll explain now:

Quote:

CMD: (Shortenedcmd)(playerid,params[]) return cmd_(orignal cmd name)(playerid,params[])

First, you just name the shortened command. Then, you add return cmd_orignalcmdname. Orignal cmd name = Cmd name you used for the big command. Like healme or armourme.



Q: How many callbacks can a command hold?
Ans: Unlimited until and unless they disturb each others usage.



Okay, now an example of a teleporting command:

In this command, one basically teleports the player to grovestreet, sets the player skin to a grove street gang member, sends the player a message welcoming him to grove st. and sends a message to all players alerting that the player has joined /grovestreet.


Quote:

CMD:grovestreet(playerid,params[])
{
SetPlayerPos(playerid, 2493.9133, -1682.3986, 13.3382);
SendClientMessage(playerid, 0xFF8000FF, "Welcome to grove street!");
SetPlayerSkin(playerid, 107);
new pname[MAX_PLAYER_NAME], string[50 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has joined the grove gang area! Join him and have fun at /grovestreet", pname);
SendClientMessageToAll(-1, string);
return 1;
}
CMD:gs(playerid, params[]) return cmd_grovestreet(playerid, params);

You must have noticed that I've used a string here. A string is used when the information that has to be submitted has to be filled at the time of the usage of the command. It's cool and a bit hard to understand though. This string gets the player name on spot and sends the message to all players. And no, I'm not explaining how to use a string since I'm teaching how to make commands, not strings and how to script etc.


And another example of making commands with string is this:

Quote:

CMD:myinfo( playerid, params[ ] )
{
new p_IP[ 16 ], sz_msg[ 128 ];
GetPlayerIp( playerid, p_IP, 16 );
format( sz_msg, sizeof( sz_msg ), "IP: (%s) Skin: (%d) Score: (%d) Money: (%d) Weapon: (%d) Ammo: (%d) Ping: (%d)", p_IP, GetPlayerSkin( playerid ), GetPlayerScore( playerid ), GetPlayerMoney( playerid ), GetPlayerWeapon( playerid ), GetPlayerAmmo( playerid ), GetPlayerPing( playerid ) );
SendClientMessage( playerid, -1, sz_msg );
return 1;
}

In this command, you basically give the player some basic info about himself in-game. His IP is stated and instead of a string, I've used the format.




Now, I'll tell you how to make animations work through commands:

We'll use ApplyAnimation callback here. Find it on SA-MP wiki if you need help regarding it.

ApplyAnimation(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync)
That's how we gotta use it. Okay, Now we gotta know one definite thing: If we make a command that starts an animation we gotta make a command that stops it/them since some are unstoppable. Later, I'll show you how to make a command /stopanim command.

Quote:

CMD:drunk(playerid,params[])
{
ApplyAnimation(playerid,"PED","WALK_DRUNK",4.1,1,1 ,1,1,1,1);
SendClientMessage(playerid,0xFFFF00AA,"Be careful! You're drunk! Use /stopanim to stop this animation" );
return 1;
}

So first we do the ApplyAnimation, the anim library is PED and the anim name is WALK_DRUNK. Capitals are important, note that. There's nothing much to explain since its very simple. If you need the list of anim libs and their names, you can check them here: https://sampwiki.blast.hk/wiki/Animations. Headings = Library names and options = Anim names.


Now you got a /drunk command which helps you walk drunk. But what if you wanna return to normal? That creates a problem. No no no, No need to apply your special old tricks to stop some problem. We'll do a code for this. We have a callback called ClearAnimations which we will use now:

Quote:

CMDtopanim(playerid,params[])
{
ClearAnimations(playerid);
SendClientMessage(playerid, 0xFFFF00AA, "Animations cleared!");
return 1;
}

Clean and simple, We just use 2 callbacks. ClearAnimations to do the work and SendClientMessage to inform that player. It's easy creating commands. All you gotta do is use some important callbacks.



This is my first tutorial and I began scripting around 2-3 weeks ago. I hope this helps
Reply
#2

very COOL
Reply
#3

ResetPlayerWeapons(playerid) //Disarms the player - WRONG
ResetPlayerWeapons(playerid) //Resets Players Weapons.
Reply
#4

Quote:
Originally Posted by BetaLaxx
View Post
ResetPlayerWeapons(playerid) //Disarms the player - WRONG
ResetPlayerWeapons(playerid) //Resets Players Weapons.
pawn Code:
forward DisarmPlayer(playerid);
public DisarmPlayer(playerid)
{
    return ResetPlayerWeapons(playerid); // Disarms player
}
Happy now? Disarms player.
He can call it disarming as it removes the weapons anyway.
Reply
#5

hi i tried to make the cmds /healme but it gave
by adding this line
Quote:

//---------------------------------
CMD:"healme(playerid,params[])
{
SendClientMessage(playerid, 0x33CCFFAA, " Health restored for 500$! ");
SetPlayerHealth(playerid, 100);
GivePlayerMoney(playerid, -500);
return 1;
}
//----------------------------------

but it gave me a error
Quote:

C:\games\GTA SanAndreas\SeRveR SaMp\gamemodes\letstestyou.pwn(334) : error 037: invalid string (possibly non-terminated string)
C:\games\GTA SanAndreas\SeRveR SaMp\gamemodes\letstestyou.pwn(339) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.

when i compiled
Reply
#6

well i fixed that part but now it says
Quote:

C:\games\GTA SanAndreas\SeRveR SaMp\gamemodes\letstestyou.pwn(334) : error 001: expected token: "-string end-", but found "-identifier-"
C:\games\GTA SanAndreas\SeRveR SaMp\gamemodes\letstestyou.pwn(339) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.

Reply
#7

Quote:
Originally Posted by mubashir
View Post
well i fixed that part but now it says
Please past the full code here.
Reply
#8

nice tutorial explained better rep+
Reply
#9

Quote:
Originally Posted by mubashir
View Post
well i fixed that part but now it says
You probably are missing a semicolon ";".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)