SetPlayerSkin

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 20:53, 31 March 2015
Drebin (Talk | contribs)

← Previous diff
Revision as of 11:32, 11 May 2015
MP2 (Talk | contribs)
(The CJ skin thing happened before 0.3.7 (0.3d IIRC, when other skins were added). It wasn't new. It was just broken in RC2 IIRC.)
Next diff →
Line 12: Line 12:
{{note2|If a player's skin is set when they are crouching , [[IsPlayerInAnyVehicle|in a vehicle]], or [[GetPlayerAnimationIndex|performing certain animations]], they will become frozen or otherwise glitched. This can be fixed by using [[TogglePlayerControllable]]. Players can be detected as being crouched through [[GetPlayerSpecialAction]] (SPECIAL_ACTION_DUCK).}} {{note2|If a player's skin is set when they are crouching , [[IsPlayerInAnyVehicle|in a vehicle]], or [[GetPlayerAnimationIndex|performing certain animations]], they will become frozen or otherwise glitched. This can be fixed by using [[TogglePlayerControllable]]. Players can be detected as being crouched through [[GetPlayerSpecialAction]] (SPECIAL_ACTION_DUCK).}}
-{{note|Before 0.3.7 RC3 an invalid skin ID will crash the player's game. In 0.3.7 RC3 and above, an invalid skin ID simply sets the player's skin to CJ instead. As of 0.3.7 RC3 skin IDs 300-311 have been added.}} 
{{Example}} {{Example}}
<pawn> <pawn>

Revision as of 11:32, 11 May 2015



Description:

Set the skin of a player. A player's skin is their character model.


Parameters:
(playerid, skinid)
playeridThe ID of the player to set the skin of.
skinidThe skin the player should use.


Return Values:

  • 1: The function executed successfully.
  • 0: The function failed to execute. This means the player specified does not exist.
  • Note that 'success' is reported even when skin ID given is invalid (not 0-299). Invalid skins should cause no issues, but the player's skin won't change.


Image:32px-Circle-style-warning.png

Important
Note

If a player's skin is set when they are crouching , in a vehicle, or performing certain animations, they will become frozen or otherwise glitched. This can be fixed by using TogglePlayerControllable. Players can be detected as being crouched through GetPlayerSpecialAction (SPECIAL_ACTION_DUCK).


Example Usage:

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/fireman", true) == 0)
    {
        // Set the player's skin to ID 277, which is a fireman.
        SetPlayerSkin(playerid, 277);
        return 1;
    }
    return 0;
}
stock SetPlayerSkinFix(playerid, skinid)
{
	new
	    Float:tmpPos[4],
		vehicleid = GetPlayerVehicleID(playerid),
		seatid = GetPlayerVehicleSeat(playerid);
	GetPlayerPos(playerid, tmpPos[0], tmpPos[1], tmpPos[2]);
	GetPlayerFacingAngle(playerid, tmpPos[3]);
	if(skinid < 0 || skinid > 299) return 0;
	if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK)
	{
	    SetPlayerPos(playerid, tmpPos[0], tmpPos[1], tmpPos[2]);
		SetPlayerFacingAngle(playerid, tmpPos[3]);
		TogglePlayerControllable(playerid, 1); // preventing any freeze - optional
		return SetPlayerSkin(playerid, skinid);
	}
	else if(IsPlayerInAnyVehicle(playerid))
	{
	    new
	        tmp;
	    RemovePlayerFromVehicle(playerid);
	    SetPlayerPos(playerid, tmpPos[0], tmpPos[1], tmpPos[2]);
		SetPlayerFacingAngle(playerid, tmpPos[3]);
		TogglePlayerControllable(playerid, 1); // preventing any freeze - important - because of doing animations of exiting vehicle
		tmp = SetPlayerSkin(playerid, skinid);
		PutPlayerInVehicle(playerid, vehicleid, (seatid == 128) ? 0 : seatid);
		return tmp;
	}
	else
	{
	    return SetPlayerSkin(playerid, skinid);
	}
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.