SetPlayerSkin will make your players crash anytime randomly even with a valid skin id
#1

Credits: Whitetiger.

You should avoid using SetPlayerSkin anywhere in your code as it was detected to make players crash randomly.

To work around this issue you can do this:
Code:
new bool:IgnoreSpawn[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    IgnoreSpawn[playerid] = false;
    return 1;
}

stock SetPlayerSkinFixed(playerid, skinid)
{
    /*
        // If player is being spectated, force spectators to start spectating again.
        SetTimerEx("ForceRespectate", 1000, false, "i", playerid);
   */
 
    // Store info before re-spawn
    new Float:Pos[4], Float:pHealth[2], CurrWep;
    CurrWep = GetPlayerWeapon(playerid);
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    GetPlayerFacingAngle(playerid, Pos[3]);
    GetPlayerHealth(playerid,pHealth[0]);
    GetPlayerArmour(playerid,pHealth[1]);
   
    // Fixes vehicle bug
    if(IsPlayerInAnyVehicle(playerid))
        SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]+2);
 
    new Weapons[13][2];
    for(new i = 0; i < 13; i++)
        GetPlayerWeaponData(playerid, i, Weapons[i][0], Weapons[i][1]);
 
    // Set spawn info and spawn player
    SetSpawnInfo(playerid, GetPlayerTeam(playerid), skinid, Pos[0], Pos[1], Pos[2]-0.4, Pos[3], 0, 0, 0, 0, 0, 0);
    IgnoreSpawn[playerid] = true;
   
    SpawnPlayer(playerid);
 
    // Set info back after re-spawn
    SetPlayerHealth(playerid, pHealth[0]);
    SetPlayerArmour(playerid, pHealth[1]);
    SetPlayerInterior(playerid, GetPlayerInterior(playerid));
    SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(playerid));
 
    for(new i = 0; i < 13; i ++)
        GivePlayerWeapon(playerid, Weapons[i][0], Weapons[i][1]);
    SetPlayerArmedWeapon(playerid, CurrWep);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(IgnoreSpawn[playerid])
    {
        IgnoreSpawn[playerid] = false;
        return 1;
    }

    // All of your OnPlayerSpawn code goes here...

    return 1;
}
Reply
#2

I'm pretty sure it only crashes if you try to set somebody's skin while entering a vehicle, never had any problems with it.
Reply
#3

No, when I implemented this, people crash a lot less, it's just a total random crash. You can run around or fly with heli and you will crash. It's not an instant one.

I experianced these crashes myself also and this fix helped for not only my gamemode,but for other scripters also.

Maybe it's more common when SetPlayerSkin is used often in the gamemode.
Reply
#4

When I ******d, I found a topic that I think could also be related to this issue:
https://sampforum.blast.hk/showthread.php?tid=96611&page=2
Reply
#5

omg so thats why my players get crashed randomly everytime in my NPC server..
I'll give it a try.


EDIT: I did it!.

Apparently, this really works. Good job whitetiger and thank you beijind for sharing.
Reply
#6

Only set skin while onfoot (check special actions and states)

You'll be fine.
Reply
#7

Quote:
Originally Posted by Kar
View Post
Only set skin while onfoot (check special actions and states)

You'll be fine.
True, but Not True at the same time. (Well at least for me).

For one i've never come across this bug but when i set skin while the player is in a vehicle he/she does an Animation with their legs sticking out the vehicle seems a bit unrealistic lol, What i do is, Set them back in their vehicle in their old seat and it works!

Another one i heard people saying is that when they're entering a vehicle and setplayerskin is used the player tends to crash, (Again never happened to me) And i've tried it, But for example a jumped while setskin is used, He'll Freeze immediately after, Solution is just to toggle their controller back to true and it works!
Reply
#8

So how is what I said is not true for you? lol
Reply
#9

Well, You said only set it while On - foot, So i'm saying it could be set elsewhere without crashes. (At least for me).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)