[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
#2

Good Job.
Reply
#3

Quote:
Originally Posted by Youssef214
View Post
Good Job.
Thanks.
Reply
#4

Good work mate
Reply
#5

Quote:
Originally Posted by iAnonymous
View Post
Good work mate
Thanks.
Reply
#6

Nice Job but skin 74 is an invalid skin id.
Code:
CMD:skin(playerid, params[])
{
    new skinid;
    if(sscanf(params, "d", skinid)) 
        return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /skin (skinid)"); 

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

    SetPlayerSkin(playerid, skinid); 

    Player_HasSkin[playerid] = true;
    Player_Skin[playerid] = skinid;
    return 1;
}
REP+
Reply
#7

Quote:
Originally Posted by Rittik
View Post
Nice Job but skin 74 is an invalid skin id.
Code:
CMD:skin(playerid, params[])
{
    new skinid;
    if(sscanf(params, "d", skinid)) 
        return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /skin (skinid)"); 

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

    SetPlayerSkin(playerid, skinid); 

    Player_HasSkin[playerid] = true;
    Player_Skin[playerid] = skinid;
    return 1;
}
REP+
Thanks
Reply
#8

Great job you done!
Reply
#9

Code:
if(SkinSaving[playerid] = 1)
{
    SetPlayerSkin(playerid,PlayerInfo[playerid][eSkin]);
}
Has to be

Code:
if(SkinSaving[playerid] == 1) // or if(SkinSaving[playerid]) {
{
    SetPlayerSkin(playerid,PlayerInfo[playerid][eSkin]);
}
Nice tutorial.
Reply
#10

Thanks all.
Reply
#11

your script should work, but I have a little advice for you.
Instead of making so many if and elses, you can return the client messages. That will make your script shorter.
example with /saveskin...
pawn Code:
CMD:saveskin(playerid,params[])
{
    new skinid = GetPlayerSkin(playerid);
    if(SkinSaving[playerid] == 1) return SendClientMessage(playerid,COLOR_GREY,"You already saved a skin before! to delete it you can use /delskin !");//this is what I am talking about. Simply return it to save some typing mayhem... Esecially in long scripts.
    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;
}
the same goes for /delskin.
And you haven't added the stuff Rittik said, skin id 74 is really a invalid skin id. You shold add it in your tut.
Otherwise great job.
Reply
#12

Quote:
Originally Posted by NaClchemistryK
View Post
your script should work, but I have a little advice for you.
Instead of making so many if and elses, you can return the client messages. That will make your script shorter.
example with /saveskin...
pawn Code:
CMD:saveskin(playerid,params[])
{
    new skinid = GetPlayerSkin(playerid);
    if(SkinSaving[playerid] == 1) return SendClientMessage(playerid,COLOR_GREY,"You already saved a skin before! to delete it you can use /delskin !");//this is what I am talking about. Simply return it to save some typing mayhem... Esecially in long scripts.
    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;
}
the same goes for /delskin.
And you haven't added the stuff Rittik said, skin id 74 is really a invalid skin id. You shold add it in your tut.
Otherwise great job.
I will edit it on Tuesday when im back to home.
Anyways thanks.
Reply
#13

Thanks all it will be bump
Reply
#14

Updated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)