SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/11/2013, 01:18 PM   #1
LeeXian99
Huge Clucker
 
LeeXian99's Avatar
 
Join Date: Feb 2013
Location: Malaysia
Posts: 329
Reputation: 34
Default Making a command "/skin [ID]" [ZCMD + SSCANF]

Hello guys, this is my very very first tutorial, if this tutorial means a lot to you, remember to +rep me (Not necessary). If I haven't explain anything or it's not clear to you, I'm sorry, I'm not quite good in explaining.

Everything is explained in the lesson!

So, let's start our lesson!
1. What we need to do this command?
pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
Question: Why do you need ZCMD and SSCANF but not STRCMP or w/e it is?
Answer: ZCMD is the fastest command processor besides Y_Command, and I use SSCANF so we can make our job easier!

2. Alright, after including the includes, let's start scripting!
pawn Code:
CMD:skin(playerid,params[]) //Our command!
Alright, if you're using new.pwn, remove the "public OnPlayerCommandText" because we don't need it. We just use this instead of using STRCMP.

3. After adding this, we shall start with our skin scripting! Let's add something like a "new"
pawn Code:
new skinid, skinnumber, str[100]; //It's useful after this script.
Question: Why do you add these new's?
Answer: This is because we're going to add some stuff and use it in this command, if we don't use this, the /skin command is gonna be hard to do.

4. Alright, just start with a sentence, maybe.
pawn Code:
if(sscanf(params, "d", skinid)) SendClientMessage(playerid, -1, "USAGE: /skin (skinid)"); //Shows the player usage IF player doesn't type anything after "/skin"
According to sscanf's specifiers:

Specifier(s) Name Example values
b Binary 01001, 0b1100
c Character a, o, *
f Float 0.7, -99.5
g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
h, x Hex 1A, 0x23
i, d Integer 1, 42, -10
l Logical true, false
n Number 42, 0b010, 0xAC, 045
o Octal 045 12
q Bot name/id ShopBot, 27
r Player name/id Y_Less, 42
u User name/id (bots and players) Y_Less, 0

We can use "d" or "i" because SKINID is a number!

5. Now it's time to do some prevention for the /skin that can make you crash! (If skin ID is below than 0, or above 299!)
pawn Code:
else if(skinid < 0 || skinid > 299) SendClientMessage(playerid, 0xFF000000, "ERROR: You must choose a skin ID between 0 to 299"); //After you doing this, the player can't choose -1, or 300 (or above/below)
Question: Why? Why you do this?
Answer: It's because if you choose a skin below 0, or above 299, it can crash your client (If not wrong).

6. After doing our first part, let's getting deep into the script!
pawn Code:
else {
    SetPlayerSkin(playerid, skinid);
    skinnumber = GetPlayerSkin(playerid);
    format(string, sizeof(string), "INFO: You have changed your skin to %d", skinnumber);
    SendClientMessage(playerid, -1, string);
}
So, let me explain one by one.

6a.
pawn Code:
SetPlayerSkin(playerid,skinid);
Explanation: This will set player's skin to the ID, for example: /skin 167. And the script will respond and change the skin to the ID!

6b.
pawn Code:
skinnumber = GetPlayerSkin(playerid);
Explanation: We're doing this because we're going to make a message and show it to player that the player has change the skin successfully!

6c.
pawn Code:
format(string, sizeof(string), "INFO: You have changed your skin to %d", skinnumber);
Explanation: We're not using SendClientMessage because it contains a string (%d), we must convert the string before we go on to our SendClientMessage!

6d.
pawn Code:
SendClientMessage(playerid, -1, string);
Explanation: Now we're using the "format" and the string has been converted to the ID. (For example: "INFO: You have change your skin to 167")

7. After doing this part, don't forget to do a
pawn Code:
return 1;
Explanation: If you don't do this, the server will show: "SERVER: Unknown command" although you've successfully changed your skin!

EXTRA:
For the lazy guy, who didn't read in this tutorial:
pawn Code:
CMD:skin(playerid,params[])
{
    new skinnumber, skinid, string[128];
    if(sscanf(params, "d", skinid)) SendClientMessage(playerid, -1, "{ffff00}=USAGE=: {ffffff}/skin <skinid>");
    else if(skinid < 0 || skinid > 299) SendClientMessage(playerid, 0xFF000000, "{ff0000}=ERROR=: {ffffff}Choose a skin between 0 to 299!");
    else
    {
        SetPlayerSkin(playerid, skinid);
        skinnumber = GetPlayerSkin(playerid);
        format(string, sizeof(string), "{ffff00}=INFO=: {ffffff}You have changed your skin to %d", skinnumber);
        SendClientMessage(playerid, -1, string);
    }
    return 1;
}

Hope this tutorial helps you in your script! +rep me or ask me anything if you don't understand which part, or you can just give me some feedback or criticize so I can improve myself in teaching.

If you came in to copy, don't come in.
If you came in to learn, you're welcome!
LeeXian99 is offline   Reply With Quote
Old 04/11/2013, 01:31 PM   #2
Private200
High-roller
 
Private200's Avatar
 
Join Date: May 2012
Posts: 1,229
Reputation: 206
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Whatever, it's up to people if they want to read the tutorial or not. I saw the whole tutorial, I didn't see anything wrong at all, but whatever, don't order people

Good job though, and also don't ask for rep, earn it. Rep+
__________________
just a signature
Private200 is offline   Reply With Quote
Old 04/11/2013, 01:33 PM   #3
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 933
Reputation: 35
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Nice to see this as your first tutorial. Although I noticed some mistakes, but since this is your first I won't be that rude.
The "new's" are actually called variables. Just to mention it.
And the 6c. is a bit incorrect.
Quote:
Explanation: We're not using SendClientMessage because it contains a string (%d), we must convert the string before we go on to our SendClientMessage!
Actaully it doesn't contain a string, but an integer. (Correct me if i'm wrong )
But don't take it so badly .

Almost forgot it, one more thing that the last why do you have:

pawn Code:
else
    {
        SetPlayerSkin(playerid, skinid);
        skinnumber = GetPlayerSkin(playerid);
        format(string, sizeof(string), "{ffff00}=INFO=: {ffffff}You have changed your skin to %d", skinnumber);
        SendClientMessage(playerid, -1, string);
    }
In my opinion i don't see why you wanted to add the else statement, but (not sure about this) you could just have removed it. It is actually hard to explain in words so i'll just show you the way I would have done this command.

YOURS:
pawn Code:
CMD:skin(playerid,params[])
{
    new skinnumber, skinid, string[128];
    if(sscanf(params, "d", skinid)) SendClientMessage(playerid, -1, "{ffff00}=USAGE=: {ffffff}/skin <skinid>");
    else if(skinid < 0 || skinid > 299) SendClientMessage(playerid, 0xFF000000, "{ff0000}=ERROR=: {ffffff}Choose a skin between 0 to 299!");
    else
    {
        SetPlayerSkin(playerid, skinid);
        skinnumber = GetPlayerSkin(playerid);
        format(string, sizeof(string), "{ffff00}=INFO=: {ffffff}You have changed your skin to %d", skinnumber);
        SendClientMessage(playerid, -1, string);
    }
    return 1;
}
MINE:
pawn Code:
CMD:skin(playerid,params[])
{
    new skinnumber, skinid, string[128];
    if(sscanf(params, "d", skinid)) return SendClientMessage(playerid, -1, "{ffff00}=USAGE=: {ffffff}/skin <skinid>");
    if(skinid < 0 || skinid > 299) return SendClientMessage(playerid, 0xFF000000, "{ff0000}=ERROR=: {ffffff}Choose a skin between 0 to 299!");
    SetPlayerSkin(playerid, skinid);
    skinnumber = GetPlayerSkin(playerid);
    format(string, sizeof(string), "{ffff00}=INFO=: {ffffff}You have changed your skin to %d", skinnumber);
    SendClientMessage(playerid, -1, string);
    return 1;
}

It's actually pretty similar to yours, but still a bit different.

Anyway my conclusion would be nice tutorial! Just gonna 'hit' the star today
CrazyChoco is offline   Reply With Quote
Old 04/11/2013, 01:34 PM   #4
LeeXian99
Huge Clucker
 
LeeXian99's Avatar
 
Join Date: Feb 2013
Location: Malaysia
Posts: 329
Reputation: 34
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Thanks for the feedback, both!

@CrazyChoco, everyone has their own style to do their script, don't take it as offensive language.
LeeXian99 is offline   Reply With Quote
Old 04/11/2013, 01:37 PM   #5
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 933
Reputation: 35
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Quote:
Originally Posted by LeeXian99 View Post
Thanks for the feedback, both!

@CrazyChoco, everyone has their own style to do their script, don't take it as offensive language.
Yeah, Of course. But it was just a little tip . But i don't see anything wrong with your code!
CrazyChoco is offline   Reply With Quote
Old 04/11/2013, 01:42 PM   #6
Sublime
High-roller
 
Sublime's Avatar
 
Join Date: Jul 2013
Location: 6ix god
Posts: 1,036
Reputation: 223
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Isn't there supposed to be a return at before SendClientMessage at the lines of if and else if?

pawn Code:
if(sscanf(params, "d", skinid)) return SendClientMessage(playerid, -1, "{ffff00}=USAGE=: {ffffff}/skin <skinid>");
    if(skinid < 0 || skinid > 299) return SendClientMessage(playerid, 0xFF000000, "{ff0000}=ERROR=: {ffffff}Choose a skin between 0 to 299!");
__________________
Quote:
Originally Posted by Zorono View Post
Becuase its the best mod of GTA SA
and itsn't dead, Kalcor is having some proplems on his real life so he is busy now and release the new version now so shut your fucking mouse !!!!!!!!
Sublime is offline   Reply With Quote
Old 04/11/2013, 01:45 PM   #7
LeeXian99
Huge Clucker
 
LeeXian99's Avatar
 
Join Date: Feb 2013
Location: Malaysia
Posts: 329
Reputation: 34
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Quote:
Originally Posted by Sublime View Post
Isn't there supposed to be a return at before SendClientMessage at the lines of if and else if?

pawn Code:
if(sscanf(params, "d", skinid)) return SendClientMessage(playerid, -1, "{ffff00}=USAGE=: {ffffff}/skin <skinid>");
    if(skinid < 0 || skinid > 299) return SendClientMessage(playerid, 0xFF000000, "{ff0000}=ERROR=: {ffffff}Choose a skin between 0 to 299!");
Oops, my bad! Fixed.
LeeXian99 is offline   Reply With Quote
Old 04/11/2013, 02:06 PM   #8
fonetic
Little Clucker
 
fonetic's Avatar
 
Join Date: Sep 2012
Location: Latvia
Posts: 36
Reputation: 1
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Very good tutorial, but what should i add to make it like admin command and ussage would be /skin <playerid> <skinid>?
fonetic is offline   Reply With Quote
Old 04/11/2013, 03:27 PM   #9
newbie scripter
Gangsta
 
newbie scripter's Avatar
 
Join Date: Apr 2012
Location: Heaven <3
Posts: 809
Reputation: 34
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Quote:
Originally Posted by fonetic View Post
Very good tutorial, but what should i add to make it like admin command and ussage would be /skin <playerid> <skinid>?
I may make a tut about that
__________________
SUGGESTION FOR FUTURE SA-MP
pawn Code:
forward SetWeaponRange(weaponid, maxrange); // if weapon is fist and 100 range, it may give a warn or super punch xD
forward SetWeaponRecoil(weapoinid, maxrecoil);
newbie scripter is offline   Reply With Quote
Old 04/11/2013, 03:32 PM   #10
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 933
Reputation: 35
Default Re: Making a command "/skin [ID]" [ZCMD + SSCANF]

Quote:
Originally Posted by fonetic View Post
Very good tutorial, but what should i add to make it like admin command and ussage would be /skin <playerid> <skinid>?
Try to play around with the SSCANF2.INC. Anyway i founded you a link: http://forum.sa-mp.com/showthread.php?t=272670
CrazyChoco 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
ZCMD command returns some of the string and "Unknown command message". total3clipse Scripting Help 15 05/04/2013 10:44 PM
[Tutorial] How to create an command without "zcmd" Jaggy Tutorials 23 28/01/2013 07:24 PM
How to do a custom "wrong command" with zcmd? 101 Scripting Help 4 22/12/2012 10:29 PM
ZCMD command gives "invalid name" warning Biesmen Help Archive 8 27/05/2011 01:42 PM
[Question]: "YCMD" or "ZCMD + sscanf" Fastest ? iCMDX Help Archive 17 14/02/2011 12:08 AM


All times are GMT. The time now is 11:55 AM.


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