04.11.2013, 12:18
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?
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!
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"
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.
According to sscanf's specifiers:
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!)
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!
So, let me explain one by one.
6a.
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.
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.
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.
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
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:
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.
Everything is explained in the lesson!
So, let's start our lesson!
1. What we need to do this command?
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
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 Код:
CMD:skin(playerid,params[]) //Our command!
3. After adding this, we shall start with our skin scripting! Let's add something like a "new"
pawn Код:
new skinid, skinnumber, str[100]; //It's useful after this script.
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 Код:
if(sscanf(params, "d", skinid)) SendClientMessage(playerid, -1, "USAGE: /skin (skinid)"); //Shows the player usage IF player doesn't type anything after "/skin"
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 | ******, 42 |
u | User name/id (bots and players) | ******, 0 |
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 Код:
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)
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 Код:
else {
SetPlayerSkin(playerid, skinid);
skinnumber = GetPlayerSkin(playerid);
format(string, sizeof(string), "INFO: You have changed your skin to %d", skinnumber);
SendClientMessage(playerid, -1, string);
}
6a.
pawn Код:
SetPlayerSkin(playerid,skinid);
6b.
pawn Код:
skinnumber = GetPlayerSkin(playerid);
6c.
pawn Код:
format(string, sizeof(string), "INFO: You have changed your skin to %d", skinnumber);
6d.
pawn Код:
SendClientMessage(playerid, -1, string);
7. After doing this part, don't forget to do a
pawn Код:
return 1;
EXTRA:
For the lazy guy, who didn't read in this tutorial:
pawn Код:
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;
}
If you came in to copy, don't come in.
If you came in to learn, you're welcome!
If you came in to learn, you're welcome!