[Tutorial] /saveskin & /delskin
#1

Hello guys, This is my second tutorial, If this tutorial helped you remember to rep me.

Let's start.

What includes are we going to use?
pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf>
Question:Why are you using specially ZCMD?
Answer:ZCMD is the fastest command processor.

After Defining the includes.
Let's start scripting!
We will need to define "PlayerInfo" And "p_info" So we can save the player skin.
pawn Code:
enum p_Info
{
eSkin
}
Now we defined p_info.
We are going to define PlayerInfo now.
pawn Code:
new PlayerInfo[MAX_PLAYERS][p_Info];
Now we defined Playerinfo & p_info.
We will also need to define a variable which is " SkinSaving "
pawn Code:
new SkinSaving[MAX_PLAYERS];
Question: Where should i add this?
Answer: You should add this at the top of your script.
Let's start creating the commands!
As we are using ZCMD We will need to add this.
pawn Code:
CMD:saveskin(playerid,params[]) //The command we are going to use to save the player skin
Now, lets add something like " new "
pawn Code:
new skinid = GetPlayerSkin(playerid);
Question: Why did you add this?
Answer: I added this so we the script will get the player skin id and set his skin to it every time he spawn!
Now lets add something so the player wont keep saving skin ids when he already have one saved.
As we defined the variable as SkinSaving above, we will use this.
pawn Code:
if(SkinSaving[playerid] == 1)
    {
    SendClientMessage(playerid,COLOR_GREY,"You already saved a skin before! to delete it you can use /delskin !");
    }
According to sscanf specifiers
Code:
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
Question:Why did you mention this here?
Answer: Because ill let the player know what skin id he saved.
Now lets start scripting if the player doesn't have a skin saved.
pawn Code:
else if(SkinSaving[playerid] == 0)
    {
    PlayerInfo[playerid][eSkin] = skinid;
    SkinSaving[playerid] = 1;
    SendClientMessage(playerid,COLOR_GREY,"You have saved your skin, Every time you spawn your skin will be %d",skinid);
    }
return 1;
}
Now we did the /saveskin command!
Lets do /delskin.
Firstly we will need to prevent people from using the command if they didnt save their skin!
pawn Code:
if(SkinSaving[playerid] == 0)
    {
    SendClientMessage(playerid,COLOR_GREY,"You don't have a skin saved to delete it!");
    }
Now, The players wont be able to use this command if they didn't use /saveskin.
Let's add if the player used saveskin command!
pawn Code:
else if(SkinSaving[playerid] == 1)
    {
    SendClientMessage(playerid,COLOR_GREY,"You have deleted your skin.");
    SkinSaving[playerid] = 0;
    }
Question:Why do we always use else if?
Answer: We are using else if because at the top of the command we used if.
Now, last step.
We need to add this under onplayerspawn so it will check if he has saved skin and auto sets him to it if he has.
pawn Code:
if(SkinSaving[playerid] = 1)
    {
    SetPlayerSkin(playerid,PlayerInfo[playerid][eSkin]);
    }
Now, I am going to give an example for /saveskin & /delskin & /skin

/saveskin :
pawn Code:
CMD:saveskin(playerid,params[])
{
    new skinid = GetPlayerSkin(playerid);
    if(SkinSaving[playerid] == 1)
    {
    SendClientMessage(playerid,COLOR_GREY,"You already saved a skin before! to delete it you can use /delskin !");
    }
    else if(SkinSaving[playerid] == 0)
    {
    PlayerInfo[playerid][eSkin] = skinid;
    SkinSaving[playerid] = 1;
    SendClientMessage(playerid,COLOR_GREY,"You have saved your skin, Every time you spawn your skin will be %d",skinid);
    }
    return 1;
}
/delskin :

pawn Code:
CMD:delskin(playerid,params[])
{
    if(SkinSaving[playerid] == 0)
    {
    SendClientMessage(playerid,COLOR_GREY,"You don't have a skin saved to delete it!");
    }
    else if(SkinSaving[playerid] == 1)
    {
    SendClientMessage(playerid,COLOR_GREY,"You have deleted your skin.");
    SkinSaving[playerid] = 0;
    }
    return 1;
}
/skin :

pawn Code:
CMD:skin(playerid, params[]) // Creating the /skin command.
{
    new skinid;
    // If you want make this command only available for Rcon Admins, then remove // characters below this.
    //if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You aren't allowed to use this command.");
    if(sscanf(params, "d", skinid)) // d or i = integer, s = string and f = float! As you know skinid is an integer and i defined 'd'
        return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /skin (skinid)"); // Player has used the command without params, then we send him a message.

    // Now the variable 'skinid' contains the value that player has gave as params.
    // Example /skin 294 and the variable contains now the value '294'

    if(skinid > 299 || skinid < 0) // There are only from 0 - 299 skin id's and it should send a warning message
        return SendClientMessage(playerid, 0xFF0000FF, "Invalid Skin ID!");

    else if(skinid == 74)
    return SendClientMessage(playerid, 0xFF0000FF, "Invalid Skin ID!"); //Added Line By Rittik.

    SetPlayerSkin(playerid, skinid); // As you know the 'skinid' contains the value of player's given params.


    return 1; // Of course we need return a value.
}
Oh, I forgot to define the COLOR_GREY !
Here you go with the define.
pawn Code:
#define COLOR_GREY                  (0x808080FF)
Reply


Messages In This Thread
/saveskin & /delskin - by Ghazal - 22.05.2014, 16:48
Re: /saveskin & /delskin - by Youssef214 - 22.05.2014, 16:54
Re: /saveskin & /delskin - by Ghazal - 22.05.2014, 16:57
Re: /saveskin & /delskin - by iAnonymous - 22.05.2014, 18:26
Re: /saveskin & /delskin - by Ghazal - 22.05.2014, 19:44
Re: /saveskin & /delskin - by Rittik - 23.05.2014, 04:45
Re: /saveskin & /delskin - by Ghazal - 23.05.2014, 18:57
Re: /saveskin & /delskin - by Alex Magaсa - 23.05.2014, 19:02
Re: /saveskin & /delskin - by jihadmeneer - 23.05.2014, 19:05
Re: /saveskin & /delskin - by Ghazal - 23.05.2014, 21:14
Re: /saveskin & /delskin - by NaClchemistryK - 24.05.2014, 08:07
Re: /saveskin & /delskin - by Ghazal - 24.05.2014, 13:01
Re: /saveskin & /delskin - by Dangjai - 26.05.2014, 21:51
Re: /saveskin & /delskin - by Ghazal - 27.05.2014, 08:49

Forum Jump:


Users browsing this thread: 1 Guest(s)