Restricting Skin ID's to teams/certain players... -
Abagail - 18.04.2014
This tutorial will show you how you can restrict different skin ID's for different players, or teams/factions. You will need the following for today's tutorial:
- SA:MP Pawn Package
- Basic Scripting Knowledge
Okay, so let's put our includes at the top, which will be...
Okay, so say we want to restrict skin id 280-289(cop skins) to gCops. We will do:
pawn Code:
stock IsACopSkin(skinid)
{
if(skinid >= 280 && skinid <=289) return 1;
else return 0;
}
So basically what that does is detects if the skin id is equal to or higher than 280, and equal to or less than 289. So, now we can actually use it for a purpose. We will make a very simple /getskin command to show this off. We will use ZCMD for it.
pawn Code:
CMD:getskin(playerid, params[])
{
new skinid;
if (sscanf(params, "d", skinid)) return SendClientMessage(playerid, -1, "USAGE: /getskin [skinid]");
if(IsACopSkin && gTeam[playerid] != TEAM_POLICE) return 0;
else {
SetPlayerSkin(playerid, skinid);
return 1;
}
return 1;
}
But what if we only what the skin to be avaliable to a certain player name or IP? Then we can do this!
pawn Code:
stock CanGetSkin(playerid, skinid)
{
if(skinid == 0 && strcmp(playername, "Evan_Abagail", false) return 0;
else SetPlayerSkin(playerid, skinid)
return 1;
}
Basically, it will check if the skin ID is 0(CJ) and will then check if the player's name is "Evan Abagail(Evan_Abagail). If it's not it will return 0 and nothing will happen. If it is how-ever then it will give them the skin.
wiki.sa-mp.com/SetPlayerSkin
If you have any questions, or comments please either PM me or reply. Thanks, and hope this helps,
- Abagail
Re: Restricting Skin ID's to teams/certain players... - Patrick - 18.04.2014
You can add an extra parameter for
CanPlayerGetSkin, so you will not add
strcmp every time you want to add a player's name into the function, the code is shown below.
pawn Code:
CanPlayerGetSkin(playerid, skinid, const PlayerName[])
{
new
pName[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, pName, sizeof( pName) );
if(skinid == 0 && strcmp( pName, PlayerName ) ) return true;
else SetPlayerSkin(playerid, skinid);
return false;
}
also if you are using only 1 argument you don't need sscanf.
pawn Code:
CMD:getskin(playerid, params[])
{
if( isnull( params) )
return SendClientMessage(playerid, -1, "/getskin <skin id>");
new skinid = strval(params);
CanPlayerGetSkin(playerid, skinid, "Name");
return true;
}
All in All - It needs more deep explanation, and you indentation is terrible!
Re: Restricting Skin ID's to teams/certain players... -
Abagail - 18.04.2014
I made this tutorial rather quickly. When I have time, I'll clean it up.