SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
88 stars 18 forks source link

player to be born at the special location when he connected server instead of the location where the player left the server last time. #3473

Closed makeloffve closed 2 years ago

makeloffve commented 2 years ago

I want player to be born at the special location when he connected server instead of the location where the player left the server last time

I tried to call player.Teleport in onConnect event, but teleport cannot work.

code:

        private void OnPlayerConnected(UnturnedPlayer player)
        {
            Helper.ClearClothes(player);
            Helper.ClearInv(player);
            Vector3 position = new Vector3(100.0f, 100.0f, 100.0f);
            player.Teleport(position, player.Rotation);
        }
GazziFX commented 2 years ago

try this one, maybe it can help a bit player.Player.teleportToLocationUnsafe(position, player.Rotation);

SDGNelson commented 2 years ago

There is an event specifically for this: Provider.onLoginSpawning

makeloffve commented 2 years ago

There is an event specifically for this: Provider.onLoginSpawning

Can I loop in thread onLoginSpawning? I need the player to spawn on the position bound by the button after clicking the custom effect button (different buttons are bound to different points) my code: in the thread onLoginSpawning loop detect button click. but will it affect the main thread of the game?

        private void OnLoginSpawningHandler(SteamPlayerID playerID, ref Vector3 point, ref float yaw, ref EPlayerStance initialStance, ref bool needsNewSpawnpoint)
        {
            string teamName;
            while (!GroupManager.PlayerTeamCache.TryGetValue(playerID.steamID.m_SteamID, out teamName))
            {
                Rocket.Core.Logging.Logger.Log("[OnLoginSpawningHandler] " + playerID.playerName + " loop 1s for waiting groupInfo");
                Thread.Sleep(1000);
            }
            Rocket.Core.Logging.Logger.Log("[OnLoginSpawningHandler] " + playerID.playerName + " end loop!!!");
            if (Configuration.Instance.EnableRespawnSpecialPoint)
            {
                RespawnPoint respawnPoint;
                if (RespawnPointManger.Instance.RespawnPoints.TryGetValue(teamName, out respawnPoint))
                {
                    point = new Vector3(respawnPoint.X, respawnPoint.Y, respawnPoint.Z);
                    needsNewSpawnpoint = true;
                }
            }
        }
rube200 commented 2 years ago

No, it will block the server. A better solution is to spawn the player in safezone and wait for him to choose then teleport him

makeloffve commented 2 years ago

No, it will block the server. A better solution is to spawn the player in safezone and wait for him to choose then teleport him

Yes, guess that all handlers run in a small and fixed thread pool, loop is forbidden