Jump to content

[PAWN] SetSkin Command


D J C
 Share

Recommended Posts

*Changing the Character skin with an command*

 

Today I am going to share my first tutorial, so if you do something wrong and I miss the wrong place, Please Forgive me.

This tutorial is definitely very convenient. So it is better to finish the work as soon as possible and briefly

 

1. Includes required:

 

Includes required to write code:

a_samp

sscanf

Zcmd

 

Zcmd download link: https://github.com/Southclaws/zcmd

For a_samp, sscanf, It is one of the default inclusions and you do not need to download it from anywhere. Because pawn should be always available in Incloud (Itself)

 

Without these include Your code will be incorrect and you will receive many errors and it doesn't compile at all.

In Pawn language, We are using #include function to include files.
Example:
#include <include filename>

The file name must be between < > otherwise the inclusions will not load !!

 

SO, We put the includes in the code:

#include <a_samp>
#include <zcmd>
#include <sscanf>

By the way, Always try to prioritize <a_samp> at First.

 

2. Creating the SetSkin Command

 

Making a Command with ZCMD is one of the easiest parts of our job

Example: 

CMD:mycommand(playerid,params[])
{
   //some code here...
   return 1;
}

 

Now let's move on to writing the code.

First we make the Simple Command at first,

CMD:setskin(playerid,params[])
{
   return 1;
}

 

Who can use this command? Admin(rcon)? If you want only admins to use this command, then we will write this code in the command section.

if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xCC3300FF, "You are not admin!"); //0xCC3300FF = Red color

 

The command has been fixed so far. Now we have to do something that commands It needs to the Name/PlayerID and the Skin ID, otherwise it will give an error:

if(sscanf(params,"ud", params[0],params[1])) return SendClientMessage(playerid, 0x778899FF, "Error: /skin <Name/PlayerID> <SkinID>."); //0x778899FF = Grey color

params[0] related to Name/PlayerID and params[1] related to SkinID

 

Now, for params[1], mean is SkinID, We need to create a numerical limit between 0 and 299 (We have 0-299 skin at all.):

Skin list if needed: https://wiki.multitheftauto.com/wiki/All_Skins_Page

if(params[1] > 299 || params[1] < 1) return SendClientMessage(playerid, 0xCC3300FF, "Error: Invalid skin ID!"); //0xCC3300FF = Red color

 

Now let write the last error, for The player that is Connected on the server or not:

if(!IsPlayerConnected(params[0])) return SendClientMessage(playerid, 0xFFFFFFFF, "The player is not connected"); //0xFFFFFFFF = White color

 

So far, we have fixed all the errors and limitations, Up to this point, if everything was OK, the command would work correctly on the received information,

Now we go to the skin set code

SetPlayerSkin(params[0], params[1]);

As i hope you get it that params[0] Related to the information entered from command that player used. params[0] = Name/PlayerID | params[1] = SkinID

So, the received information will be finally works.

 

The code must be like this:

CMD:setskin(playerid,params[])
{
   if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xCC3300FF, "You are not admin!"); //0xCC3300FF = Red color
   if(sscanf(params,"ud", params[0],params[1])) return SendClientMessage(playerid, 0x778899FF, "Error: /skin <Name/PlayerID> <SkinID>."); //0x778899FF = Grey color
   if(params[1] > 299 || params[1] < 1) return SendClientMessage(playerid, 0xCC3300FF, "Error: Invalid skin ID!"); //0xCC3300FF = Red color
   if(!IsPlayerConnected(params[0])) return SendClientMessage(playerid, 0xFFFFFFFF, "The player is not connected"); //0xFFFFFFFF = White color
   SetPlayerSkin(params[0], params[1]);
   return 1;
}

 

We hope you enjoy this tutorial, wishes best.

Link to comment
Share on other sites

I understand this is your first tutorial and you are probably a beginner, though

 

if(sscanf(params,"ud", params[0],params[1])) return SendClientMessage(playerid, 0x778899FF, "Error: /skin <Name/PlayerID> <SkinID>."); //0x778899FF = Grey color

 

1. d is not to check numbers in the syntax, to check numbers is used i

2. Why use the parameters in the command that are also difficult to remember, when you can use some separate variables specific to the values you want to use in the command

 

new id, skin;
if(sscanf(params, "ui", id, skin)) return SendClientMessage(playerid, 0x778899FF, "Error: /skin <Name/PlayerID> <SkinID>."); //0x778899FF = Grey color

 

Otherwise, it's pretty ok what you tried to achieve, for a start. Please, before posting something try to ask a Programmer if it is correct what you want to post in the section, to avoid misinformed players from a tutorial.

Link to comment
Share on other sites

  • Tupi locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.