samp-streamer-plugin icon indicating copy to clipboard operation
samp-streamer-plugin copied to clipboard

Map dissapear in player class selection

Open RaphaelCapone opened this issue 3 years ago • 1 comments

Hello, I got a problem streaming objects in a specific interior while player class selection. So every time I prevent the player to spawn a class he don't have enough level for it, or /reclass, my class selection map seems to just disappear after few miliseconds. The map selection class is set to a specific interior, as is shown in the code below:

stock CreateDynamicObjectPartyIsland(modelid, Float:posX, Float:posY, Float:posZ, Float:rX, Float:rY, Float:rZ, worldid = -1, interiorid = 100){
    return CreateDynamicObject(modelid, posX, posY, posZ, rX, rY, rZ, worldid, interiorid);
}

My class selection code:

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerCameraPos(playerid, -1087.9360,3421.1138,3.9115);
    SetPlayerCameraLookAt(playerid, -1085.1716,3421.0928,3.9765);
    SetPlayerSkin(playerid, skin);
    SetPlayerPosEx(playerid, -1085.1716,3421.0928,3.9765, 100, playerid + 1);
    Streamer_UpdateEx(playerid, -1085.1716,3421.0928,3.9765, playerid + 1, 100, -1, 1, 1);//update the "class selection" map
    SetPlayerFacingAngle(playerid, -268.9880); 
    if(PlayerInfo[playerid][pScore] >= minLevel){
        PlayerInfo[playerid][pClass] = classID;
    }
    else{
        SCM(playerid, -1, "You don't have enough score for this class.");
        PlayerInfo[playerid][pClass] = 0;
    }
	return 1;
}

My spawn player code:

public OnPlayerSpawn(playerid)
{
	if(PlayerInfo[playerid][pClass] == 0){
//		SetPlayerPosEx(playerid, -1085.1716,3421.0928,3.9765, 100, playerid + 1);
		Streamer_UpdateEx(playerid, -1085.1716,3421.0928,3.9765, playerid + 1, 100, -1, 1, 1);//update map again
		SetPlayerCameraPos(playerid, -1087.9360,3421.1138,3.9115);
		SetPlayerCameraLookAt(playerid, -1085.1716,3421.0928,3.9765);
		SetPlayerFacingAngle(playerid, -268.9880);
		ForceClassSelection(playerid);
		TogglePlayerSpectating(playerid, true);
		TogglePlayerSpectating(playerid, false);
	}
	return 1;
}

My reclass command code:

CMD:reclass(playerid){
	ForceClassSelection(playerid);
	TogglePlayerSpectating(playerid, true);
	TogglePlayerSpectating(playerid, false);
	return 1;
}

Video demonstration of the bug: https://youtu.be/q75OJAPDwEU

I'm using the latest version of streamer.

RaphaelCapone avatar May 12 '21 14:05 RaphaelCapone

If you still need a solution for this...

When a player connects, your code may be somewhere setting Streamer_ToggleItemUpdate to false for STREAMER_TYPE_OBJECT. When the Streamer Plugin streams items, by default it uses player's position. When the player is in class selection, the position is retrieved as being 0.0, 0.0, 0.0, which is incorrect. Because of this, in OnPlayerRequestClass we have to call Streamer_UpdateEx, but it has to be used after Streamer_ToggleItemUpdate is set to false, otherwise the objects restreaming code would be triggered after a maximum of 50 miliseconds (by default) and the objects may disappear (as it happens in your case). So, my assumption is that your code sets Streamer_ToggleItemUpdate again to true somewhere when the player spawns, but when the player is forced back to the request class selection screen, it isn't toggling it back to false. If I'm not forgetting something, then this would fix it for you.

Also, as a suggestion, instead of checking if the player can use the selected class after he's spawning and then forcing him back, you may want to use OnPlayerRequestSpawn. Returning 0 in this callback prevents spawning the player at all:

public OnPlayerRequestSpawn(playerid)
{
	if(PlayerInfo[playerid][pClass] == 0)
		return SendClientMessage(playerid, -1, "Nope"), 0;

	return 1;
}

IstuntmanI avatar Sep 03 '21 03:09 IstuntmanI