09.03.2012, 11:37
Okay. This is my first tutorial and I'm still a noob so I'd appreciate help but criticism will NOT be appreciated.
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
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")
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.
That line basically defines the usage of the command. Note: This is case sensitive. Healme won't work but healme will.
Now:
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.
[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.
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;
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:
I'll explain now:
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.
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:
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.
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:
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
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[]) |
Now:
Quote:
{ //Code here |
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 |
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$! "); |
Quote:
CMD:healme(playerid,params[]) { SendClientMessage(playerid, 0x33CCFFAA, " Health restored for 500$! "); SetPlayerHealth(playerid, 100); GivePlayerMoney(playerid, -500); return 1; } |
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); |
Quote:
CMD: (Shortenedcmd)(playerid,params[]) return cmd_(orignal cmd name)(playerid,params[]) |
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); |
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; } |
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; } |
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; } |
This is my first tutorial and I began scripting around 2-3 weeks ago. I hope this helps