[Tutorial] ZCMD - Your first time scripting a command!
#1

First Word
What's up everyone, I've been scripting for about four days right now and I did already learn some stuff. I'd like to share my knowledge with the other newbies who are trying to start with PAWN but can't do it or just want a tutorial. I do already know the basics of ZCMD and scripting some simple things, I'll try to explain everything as clear as possible. Reply on this thread if you've got any questions.

NOTES:
A lot of people miss-understand some things, so read this first:
In pawn playerid means the player himself, I had problem with this, I always thought I had to fill in a ID!
// is used to make notes inside the script, you can see more of this below for example.
You start and end your script with a { and }, and always end lines with a ;.
The most common errors while compiling is failing to end your script, or forgetting to end a line or spelled something wrong.
Press TAB to make some space, this is needed, you'll see it in the examples below aswell, TAB is the same as tabbing 4 times space.




ZCMD? What is that?
You can use ZCMD for making scripts such as commands, when you type a command there will happen something. What will happen is up to you, this can be everything, it can play a song, you can make it heal the player, you can make it to set the hp of the player, anything you want! Now, lets stop talking and lets go to the real part.

Scripting!
Before starting with ZCMD, you need to download the ZCMD include and put it into your gamemode.
The ZCMD file is just a small text file, nothing big.
Download it here: https://sampforum.blast.hk/showthread.php?tid=91354
Put it in [your gamemode map] > [pawno] > [include]
Now put on the top of your script:
pawn Код:
#include <zcmd>
Now continue...

When using ZCMD, you always start with CMD:COMMANDNAME, lets say, we want to make a command that will set your HP to 100 called refill hp. So lets say, when you type /refillhp it restores your hp. Lets script that!
pawn Код:
CMD:refillhp(playerid, params[])
You always got to write (playerid, params[]) behind it, playerid means that the player types the command. About params and the [], no idea but just type it otherwise it wont work.

After typing that, you got to show the computer that you're going to 'start', so place a { under the CMD.
At the end of your script you always but a }, so you do at the start!
pawn Код:
CMD:refillhp (playerid, params[])
{ // The { means the start, when you end the script you do the same but with a } at the end.
Lets tell the computer that this must be typed by a player! We use ' if(PlayerInfo[playerid] for that, it checks the information that it's a player or not. If the player isn't a player (doesn't make sense but just for example) it'll say 'You are not a player', alright, lets go.

pawn Код:
CMD:refillhp (playerid, params[])
{
    if(PlayerInfo[playerid]) return SendClientMessage, COLOR_GREY ''You are not a player.''); //You always end with a ;, but be sure that you wont end the cmd itself with a ;
We told the computer now to check if it's a player, if he isn't a player, he'll get told and he can't use the command.
Now, if everything is alright, we script that his hp gets setted, lets go.

pawn Код:
CMD:refillhp (playerid, params[])
{
    if(PlayerInfo[playerid]) return SendClientMessage, COLOR_GREY ''You are not a player.''); //You always end with a ;, but be sure that you wont end the cmd itself with a ;
    SetPlayerHealth(playerid, 100); //Use 'SetPlayerHealth', it's your choice if it will give 100 hp, more, or less.
That's done, how simple, now we got to end this script by the } and using 'return 1;',
Lets do that.

pawn Код:
CMD:refillhp (playerid, params[])
{
    if(PlayerInfo[playerid]) return SendClientMessage, COLOR_GREY ''You are not a player.''); //You always end with a ;, but be sure that you wont end the cmd itself with a ;
    SetPlayerHealth(playerid, 100); //Use 'SetPlayerHealth', it's your choice if it will give 100 hp, more, or less.
    return 1;
}

//This spaces in front of the lines are needed, use the TAB button to do it.
That's it, I hope you learnt something with this. And I also got a hint with you, be sure that you got a friend on msn, Skype or what-ever that can help you out when you don't know something. It's always handy to have a helping hand!
Reply
#2

NOTE LIST:
(On the top are the newest notes)
READ THIS TO FIX BUGS AND STUFF!!!



* Made clear that you need to include ''ZCMD'' in your script.
* Write after PlayerInfo[playerid] etc, but: [FuncName]
* [playerid] variable must be added for using it.
* Added some notes in the post.
* Changed [code] to [pawn].
Reply
#3

pawn Код:
if(PlayerInfo[playerid]) //Variable isnt added.
Reply
#4

Quote:
Originally Posted by [xB]Lordz
Посмотреть сообщение
pawn Код:
if(PlayerInfo[playerid]) //Variable isnt added.
Thanks, added it to the notes.
Reply
#5

At least this is better then "hOw tO Mkae a kick cmd with zcmd +rep if you like", tutorials.
Reply
#6

Quote:
Originally Posted by Lexi'
Посмотреть сообщение
At least this is better then "hOw tO Mkae a kick cmd with zcmd +rep if you like", tutorials.
Haha, thanks. :P
Reply
#7

Good job very useful

EDITED
Reply
#8

pawn Код:
PlayerInfo[playerid]
- This is a bad example.. by the way change it because it's not filled fully already. It's enum so you need to do this:

pawn Код:
PlayerInfo[playerid][FuncName]
Your code will give an error..
Reply
#9

Checking if a player is a player ?? That's like asking a friend is he human...
Reply
#10

Quote:
Originally Posted by Riddick94
Посмотреть сообщение
pawn Код:
PlayerInfo[playerid]
- This is a bad example.. by the way change it because it's not filled fully already. It's enum so you need to do this:

pawn Код:
PlayerInfo[playerid][FuncName]
Your code will give an error..
Okay thanks, never used that before and all my stuff works, but okay!

Quote:
Originally Posted by MarkoN
Посмотреть сообщение
Checking if a player is a player ?? That's like asking a friend is he human...
Told you it makes no sence but it's just for example.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)