openmultiplayer / open.mp

Open Multiplayer, a multiplayer mod fully backwards compatible with SA-MP
https://open.mp
Mozilla Public License 2.0
466 stars 98 forks source link

SetSpawnInfo #717

Closed nexquery closed 9 months ago

nexquery commented 1 year ago

If you try to use a skin added with AddCharModel, you will sometimes spawn with the CJ skin. But this is not always the case. To solve this problem, you need to reuse the SetPlayerSkin function.

sa-mp-044

ksenonadv commented 1 year ago

Repro steps?

nexquery commented 1 year ago
  1. Set TogglePlayerSpectating to true when connected to the server.
    public OnPlayerConnect(playerid)
    {
    TogglePlayerSpectating(playerid, true);
    return 1;
    }
  2. Load the character data after providing the necessary checks.
    new fmt[64], hesapid;
    mysql_format(gSQL, fmt, sizeof(fmt), "SELECT * FROM karakterler WHERE id = %d;", hesapid);
    mysql_tquery(gSQL, fmt, "Karakter_Yukle", "d", playerid);
  3. Load character data from the callback and use the codes below.

    callback::Karakter_Yukle(playerid)
    {
    if(cache_num_rows())
    {
        new
            Float:x,
            Float:y,
            Float:z,
            Float:a
        ;
    
        cache_get_value_name_float(0, "px", x);
        cache_get_value_name_float(0, "py", y);
        cache_get_value_name_float(0, "pz", z);
        cache_get_value_name_float(0, "pa", a);
        cache_get_value_name_int(0, "skin", Karakter[playerid][karakter_skin]);
    
        TogglePlayerSpectating(playerid, false);
    
        SetSpawnInfo(playerid, NO_TEAM, Karakter[playerid][karakter_skin], x, y, z, a, WEAPON_FIST, 0, WEAPON_FIST, 0, WEAPON_FIST, 0);
        SpawnPlayer(playerid);
    }
    return 1;
    }
Vince0789 commented 1 year ago

Toggling spectating off already implicitly spawns the player, an extra call to SpawnPlayer should not be necessary. The SetSpawnInfo call should probably occur before the player actually spawns, so before spectating is toggled off.

PazzOnee commented 1 year ago

@nexquery close

callback::Karakter_Yukle(playerid)
{
    if(cache_num_rows())
    {
        new
            Float:x,
            Float:y,
            Float:z,
            Float:a
        ;

        cache_get_value_name_float(0, "px", x);
        cache_get_value_name_float(0, "py", y);
        cache_get_value_name_float(0, "pz", z);
        cache_get_value_name_float(0, "pa", a);
        cache_get_value_name_int(0, "skin", Karakter[playerid][karakter_skin]);

        SetSpawnInfo(playerid, NO_TEAM, Karakter[playerid][karakter_skin], x, y, z, a, WEAPON_FIST, 0, WEAPON_FIST, 0, WEAPON_FIST, 0);

        TogglePlayerSpectating(playerid, false);
    }
    return 1;
}
nexquery commented 1 year ago

I edited the codes as you said, I will test it for a while since the problem does not always occur, if it persists I will write again.

PazzOnee commented 1 year ago

@nexquery Close if you done with testing