[Tutorial] setskin
#1

Hey Guys


Today we are making an SetSkin command.

We need 2 includes, zcmd and sscanf. (They are no made by me!)

Are you ready? Ok let's start.
We will do it like this(put it on the top of your script), and the color what we will use.
pawn Код:
#define COLOR_RED       0xFF0000FF
Now also under #include <a_samp> add:
pawn Код:
#include <zcmd>
#include <sscanf2>
Thats why we downloaded ZCMD and SSCANF.
Ok when you finished all this lets start making the command
pawn Код:
CMD:setskin(playerid, params[])
{
     
     return 1;
}
So what we did here we added "return 1;" which stands for that the command is succesfuly exicuted.
Now lets do this:
pawn Код:
CMD:setskin(playerid, params[])
{
     new pID,sID,name[MAX_PLAYER_NAME];
     return 1;
}
Why we added pID? pID=TargetID the target of setskin, sID=SkinID the skin that we will set the target and name= PlayerName= SenderName we are getting the sender name and str= string. You are asking why ? You will know later.
Now we will add more stuff to it:
pawn Код:
CMD:setskin(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))return 0;
    new pID,sID, name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return 1;
}
We added IsPlayerAdmin = If the player is Rcon Admin if not that the command return false(0) and GetPlayerName= Getting the sendername/playername.
Ok you are not cunfused any more ? Greate lets add more stuff:
pawn Код:
CMD:setskin(playerid, params[])
{
    if(IsPlayerAdmin(playerid))return 0;
    new pID,sID, name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "ui",pID,sID))return SendClientMessage(playerid, COLOR_RED,"INFO: /setskin [PlayerID/Name] [SkinID]");
    return 1;
}
We added SSCANF= Params if the player writes setskin only its shows /setskin [PlayerID/Name] [SkinID].
Ok lets finish the command:
pawn Код:
CMD:setskin(playerid, params[])
{
    if(IsPlayerAdmin(playerid))return 0;
    new pID,sID, name[MAX_PLAYER_NAME], str[128];
    GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "ui",pID,sID))return SendClientMessage(playerid, COLOR_RED,"INFO: /setskin [PlayerID/Name] [SkinID]");
    if(pID == INVALID_PLAYER_ID)return SendClientMessage(playerid, COLOR_RED, "Player not found.");
    if(sID > 299)return SendClientMessage(playerid, COLOR_RED, "Skin not found.");
    SetPlayerSkin(pID,sID);
    format(str, sizeof(str), "Admin %s has set your skin to %i.", name, sID);
    SendClientMessage(pID, COLOR_RED,str);
    return 1;
}
We added SetPlayerSkin , and used sscanf and formated the message to use in SCM(SendClientMessage) also checked if the pID is connected and the sID is valid.
Now we are ready to use the command in our server!
Reply


Messages In This Thread
setskin - by MatriXgaMer - 09.01.2014, 12:29
Re: setskin - by Konstantinos - 09.01.2014, 12:49
Re: setskin - by MatriXgaMer - 09.01.2014, 12:52
Re: setskin - by Vince - 09.01.2014, 13:10
Re: setskin - by newbie scripter - 09.01.2014, 15:16
Respuesta: setskin - by Swedky - 09.01.2014, 15:21
Re: Respuesta: setskin - by Konstantinos - 09.01.2014, 15:31

Forum Jump:


Users browsing this thread: 1 Guest(s)