SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 09/03/2012, 11:37 AM   #1
Gangs_Rocks
Big Clucker
 
Join Date: Feb 2012
Location: Mars
Posts: 114
Reputation: 13
Default Making basic commands [ZCMD]

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: http://wiki.sa-mp.com/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
Gangs_Rocks is offline   Reply With Quote
Old 19/03/2012, 06:09 PM   #2
Alexy_Dramon
Big Clucker
 
Alexy_Dramon's Avatar
 
Join Date: Feb 2012
Posts: 126
Reputation: 2
Default Re: Making basic commands [ZCMD]

very COOL
__________________
If my help helped so Rep me!!!!

Server hosted be Hamachi
PM me if you wanna Join to my server!
Address: 5.84.197.75:7777
Alexy_Dramon is offline   Reply With Quote
Old 19/03/2012, 06:44 PM   #3
BetaLaxx
Big Clucker
 
BetaLaxx's Avatar
 
Join Date: Sep 2011
Location: Oman.
Posts: 125
Reputation: 13
Default Re: Making basic commands [ZCMD]

ResetPlayerWeapons(playerid) //Disarms the player - WRONG
ResetPlayerWeapons(playerid) //Resets Players Weapons.
__________________
Are you bored?
BetaLaxx is offline   Reply With Quote
Old 19/03/2012, 07:22 PM   #4
Max_Coldheart
Gangsta
 
Max_Coldheart's Avatar
 
Join Date: Dec 2011
Location: Finland
Posts: 667
Reputation: 88
Default Re: Making basic commands [ZCMD]

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.
__________________
Max_Coldheart is offline   Reply With Quote
Old 01/07/2013, 10:15 AM   #5
mubashir
Little Clucker
 
mubashir's Avatar
 
Join Date: May 2013
Posts: 37
Reputation: -2
Default Re: Making basic commands [ZCMD]

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 (c) 1997-2006, ITB CompuPhase


2 Errors.
when i compiled
mubashir is offline   Reply With Quote
Old 01/07/2013, 10:20 AM   #6
mubashir
Little Clucker
 
mubashir's Avatar
 
Join Date: May 2013
Posts: 37
Reputation: -2
Default Re: Making basic commands [ZCMD]

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 (c) 1997-2006, ITB CompuPhase


2 Errors.
mubashir is offline   Reply With Quote
Old 04/07/2013, 10:37 AM   #7
Raaf
Little Clucker
 
Raaf's Avatar
 
Join Date: Dec 2012
Location: The Netherlands, The Hague
Posts: 34
Reputation: 1
Default Re: Making basic commands [ZCMD]

Quote:
Originally Posted by mubashir View Post
well i fixed that part but now it says
Please past the full code here.
Raaf is offline   Reply With Quote
Old 06/07/2013, 06:06 AM   #8
Team_PRO
High-roller
 
Join Date: Aug 2012
Location: Philippines
Posts: 1,819
Reputation: 87
Default Re: Making basic commands [ZCMD]

nice tutorial explained better rep+
Team_PRO is offline   Reply With Quote
Old 06/07/2013, 09:10 PM   #9
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,079
Reputation: 112
Default Re: Making basic commands [ZCMD]

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Login/Register using ZCMD SSCANF & Y_INI.( Admin commands + VIP System + VIP Commands! ) Zh3r0 Filterscripts 116 09/01/2015 10:57 AM
[Tutorial] Making a easy /setadmin command with some admin commands (zcmd & sscanf) Tanush123 Tutorials 41 30/07/2013 05:54 AM
Somewhere in this piece of code is making all zcmd commands stop working? Donya Help Archive 0 02/07/2011 06:10 PM
DCMD Commands not working after adding some ZCMD commands :S [L3th4l] Help Archive 4 20/01/2010 09:57 PM


All times are GMT. The time now is 10:29 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.