/////////////////////////////////////////
        // Oxide Hooks
        /////////////////////////////////////////
        BasePlayer.SpawnPoint OnFindSpawnPoint()
        {
            if (!activated)
            {
                return(null);
            }
            var targetpos = Spawns.Call("GetRandomSpawn", new object[] { spawnsname });

            if (targetpos is string)
            {
                return(null);
            }
            BasePlayer.SpawnPoint point = new BasePlayer.SpawnPoint();
            point.pos = (Vector3)targetpos;
            Debug.Log(point.pos.ToString());
            point.rot = new Quaternion(0f, 0f, 0f, 1f);
            RaycastHit hit;

            if (checkDown != 0f)
            {
                if (Physics.Raycast(new Ray(point.pos + vectorUp, Vector3.down), out hit, checkDown, -1063190271))
                {
                    point.pos = hit.point;
                }
            }
            return(point);
        }
Beispiel #2
0
        public static void Respawn(BasePlayer player, bool newPos)
        {
            Player       p  = new Player(player);
            RespawnEvent re = new RespawnEvent(p);

            OnRespawn.OnNext(re);

            ++ServerPerformance.spawns;
            if (newPos)
            {
                BasePlayer.SpawnPoint spawnPoint = ServerMgr.FindSpawnPoint();
                player.transform.position = spawnPoint.pos;
                player.transform.rotation = spawnPoint.rot;
            }
            if (re.ChangePos && re.SpawnPos != Vector3.zero)
            {
                player.transform.position = re.SpawnPos;
            }
            player.supressSnapshots = true;
            player.StopSpectating();
            player.UpdateNetworkGroup();
            player.UpdatePlayerCollider(true, false);
            player.StartSleeping();
            player.metabolism.Reset();
            if (re.GiveDefault)
            {
                player.inventory.GiveDefaultItems();
            }

            player.SendFullSnapshot();
        }
    public static BasePlayer.SpawnPoint FindSpawnPoint()
    {
        if (Object.op_Inequality((Object)SingletonComponent <SpawnHandler> .Instance, (Object)null))
        {
            BasePlayer.SpawnPoint spawnPoint = SpawnHandler.GetSpawnPoint();
            if (spawnPoint != null)
            {
                return(spawnPoint);
            }
        }
        BasePlayer.SpawnPoint spawnPoint1        = new BasePlayer.SpawnPoint();
        GameObject[]          gameObjectsWithTag = GameObject.FindGameObjectsWithTag("spawnpoint");
        if (gameObjectsWithTag.Length != 0)
        {
            GameObject gameObject = gameObjectsWithTag[Random.Range(0, gameObjectsWithTag.Length)];
            spawnPoint1.pos = gameObject.get_transform().get_position();
            spawnPoint1.rot = gameObject.get_transform().get_rotation();
        }
        else
        {
            Debug.Log((object)"Couldn't find an appropriate spawnpoint for the player - so spawning at camera");
            if (Object.op_Inequality((Object)MainCamera.mainCamera, (Object)null))
            {
                spawnPoint1.pos = ((Component)MainCamera.mainCamera).get_transform().get_position();
                spawnPoint1.rot = ((Component)MainCamera.mainCamera).get_transform().get_rotation();
            }
        }
        RaycastHit raycastHit;

        if (Physics.Raycast(new Ray(spawnPoint1.pos, Vector3.get_down()), ref raycastHit, 32f, 1537286401))
        {
            spawnPoint1.pos = ((RaycastHit) ref raycastHit).get_point();
        }
        return(spawnPoint1);
    }
    private void SpawnNewPlayer(Network.Connection connection)
    {
        BasePlayer.SpawnPoint spawnPoint = ServerMgr.FindSpawnPoint();
        BasePlayer            player     = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", spawnPoint.pos, spawnPoint.rot, true).ToPlayer();

        if (Interface.CallHook("OnPlayerSpawn", (object)player) != null)
        {
            return;
        }
        player.health                = 0.0f;
        player.lifestate             = BaseCombatEntity.LifeState.Dead;
        player.ResetLifeStateOnSpawn = false;
        player.limitNetworking       = true;
        player.Spawn();
        player.limitNetworking = false;
        player.PlayerInit(connection);
        if (SleepingBag.FindForPlayer(player.userID, true).Length == 0 && !player.hasPreviousLife)
        {
            player.Respawn();
        }
        else
        {
            player.SendRespawnOptions();
        }
        DebugEx.Log((object)(((object)player.net.get_connection()).ToString() + " joined [" + (object)player.net.get_connection().os + "/" + (object)(ulong)player.net.get_connection().ownerid + "]"), (StackTraceLogType)0);
    }
Beispiel #5
0
    public static bool GetSpawnPoint(BasePlayer.SpawnPoint spawnPoint, float searchHeight)
    {
        SpawnHandler instance = SingletonComponent <SpawnHandler> .Instance;

        if (TerrainMeta.HeightMap == null || instance == null)
        {
            return(false);
        }
        LayerMask placementMask        = instance.PlacementMask;
        LayerMask placementCheckMask   = instance.PlacementCheckMask;
        float     placementCheckHeight = instance.PlacementCheckHeight;
        LayerMask radiusCheckMask      = instance.RadiusCheckMask;
        float     radiusCheckDistance  = instance.RadiusCheckDistance;

        for (int i = 0; i < 10; i++)
        {
            Vector3    vector = FindSpawnPoint(searchHeight);
            RaycastHit hitInfo;
            if ((int)placementCheckMask != 0 && Physics.Raycast(vector + Vector3.up * placementCheckHeight, Vector3.down, out hitInfo, placementCheckHeight, placementCheckMask))
            {
                if (((1 << hitInfo.transform.gameObject.layer) & (int)placementMask) == 0)
                {
                    continue;
                }
                vector.y = hitInfo.point.y;
            }
            if ((int)radiusCheckMask == 0 || !Physics.CheckSphere(vector, radiusCheckDistance, radiusCheckMask))
            {
                spawnPoint.pos = vector;
                spawnPoint.rot = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f);
                return(true);
            }
        }
        return(false);
    }
Beispiel #6
0
    private void SpawnNewPlayer(Network.Connection connection)
    {
        BasePlayer.SpawnPoint spawnPoint = ServerMgr.FindSpawnPoint();
        BasePlayer            player     = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", spawnPoint.pos, spawnPoint.rot, true).ToPlayer();

        if (Interface.CallHook("OnPlayerSpawn", player) != null)
        {
            return;
        }
        player.health                = 0f;
        player.lifestate             = BaseCombatEntity.LifeState.Dead;
        player.ResetLifeStateOnSpawn = false;
        player.limitNetworking       = true;
        player.Spawn();
        player.limitNetworking = false;
        player.PlayerInit(connection);
        if (SleepingBag.FindForPlayer(player.userID, true).Length != 0 || player.hasPreviousLife)
        {
            player.SendRespawnOptions();
        }
        else
        {
            player.Respawn();
        }
        DebugEx.Log(string.Concat(new object[] { player.net.connection.ToString(), " joined [", player.net.connection.os, "/", player.net.connection.ownerid, "]" }), StackTraceLogType.None);
    }
Beispiel #7
0
    public static BasePlayer.SpawnPoint FindSpawnPoint()
    {
        RaycastHit raycastHit;

        if (SingletonComponent <SpawnHandler> .Instance != null)
        {
            BasePlayer.SpawnPoint spawnPoint = SpawnHandler.GetSpawnPoint();
            if (spawnPoint != null)
            {
                return(spawnPoint);
            }
        }
        BasePlayer.SpawnPoint spawnPoint1     = new BasePlayer.SpawnPoint();
        GameObject[]          gameObjectArray = GameObject.FindGameObjectsWithTag("spawnpoint");
        if (gameObjectArray.Length == 0)
        {
            UnityEngine.Debug.Log("Couldn't find an appropriate spawnpoint for the player - so spawning at camera");
            if (MainCamera.mainCamera != null)
            {
                spawnPoint1.pos = MainCamera.mainCamera.transform.position;
                spawnPoint1.rot = MainCamera.mainCamera.transform.rotation;
            }
        }
        else
        {
            GameObject gameObject = gameObjectArray[UnityEngine.Random.Range(0, (int)gameObjectArray.Length)];
            spawnPoint1.pos = gameObject.transform.position;
            spawnPoint1.rot = gameObject.transform.rotation;
        }
        if (UnityEngine.Physics.Raycast(new Ray(spawnPoint1.pos, UnityEngine.Vector3.down), out raycastHit, 32f, 1537286401))
        {
            spawnPoint1.pos = raycastHit.point;
        }
        return(spawnPoint1);
    }
Beispiel #8
0
        void RandomSpawns()
        {
            spawns.Clear();
            int failed = 0;

            while (failed < 1000 && spawns.Count < spawnsCount)
            {
                BasePlayer.SpawnPoint spawnPoint = SpawnHandler.GetSpawnPoint();

                if (spawnPoint == null)
                {
                    failed++;
                    continue;
                }
                if (!IsValidSpawn(spawnPoint.pos))
                {
                    failed++;
                    continue;
                }
                spawns.Add(spawnPoint.pos);
            }
            if (failed >= 1000)
            {
                Puts("FAILED > 1000");
            }
            Puts("CREATED " + spawns.Count.ToString());
            spawnsFile.WriteObject(JsonConvert.SerializeObject(spawns, converter));
        }
Beispiel #9
0
        /*
         * // In future create an Event, allow people to adjust certain resources to give certain amounts!
         * public static void ResourceGatherMultiplier(int amount, BaseEntity receiver, ItemAmount itemAmt)
         * {
         *  int newAmt = amount;
         *  if (receiver.ToPlayer() != null)
         *      newAmt = (int)((double)amount * World.GetInstance().ResourceGatherMultiplier);
         *
         *  Item item = ItemManager.CreateByItemID(itemAmt.itemid, newAmt);
         *  receiver.GiveItem(item);
         * }*/

        public static void Respawn(BasePlayer player, bool newPos)
        {
            Player       p  = Server.GetPlayer(player);
            RespawnEvent re = new RespawnEvent(p);

            OnRespawn.OnNext(re);

            ++ServerPerformance.spawns;
            if (newPos)
            {
                BasePlayer.SpawnPoint spawnPoint = ServerMgr.FindSpawnPoint();
                player.transform.position = spawnPoint.pos;
                player.transform.rotation = spawnPoint.rot;
            }
            if (re.ChangePos && re.SpawnPos != Vector3.zero)
            {
                player.transform.position = re.SpawnPos;
            }
            player.SetPlayerFlag(BasePlayer.PlayerFlags.Wounded, false);
            player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, true);
            player.SetFieldValue("lastTickTime", 0f);
            player.CancelInvoke("DieFromWounds");
            player.StopSpectating();
            player.UpdateNetworkGroup();
            player.UpdatePlayerCollider(true, false);
            player.StartSleeping();
            player.Invoke("LifeStoryStart", 0f);
            player.metabolism.Reset();

            if (re.StartHealth < Single.Epsilon)
            {
                player.InitializeHealth(player.StartHealth(), player.StartMaxHealth());
            }
            else
            {
                player.InitializeHealth(re.StartHealth, player.StartMaxHealth());
            }

            if (re.GiveDefault)
            {
                player.inventory.GiveDefaultItems();
            }

            if (re.WakeUp)
            {
                player.EndSleeping();
            }
        }
Beispiel #10
0
 public static BasePlayer.SpawnPoint GetSpawnPoint()
 {
     if (Object.op_Equality((Object)SingletonComponent <SpawnHandler> .Instance, (Object)null) || ((SpawnHandler)SingletonComponent <SpawnHandler> .Instance).CharDistribution == null)
     {
         return((BasePlayer.SpawnPoint)null);
     }
     BasePlayer.SpawnPoint spawnPoint = new BasePlayer.SpawnPoint();
     for (int index = 0; index < 60; ++index)
     {
         if (((SpawnHandler)SingletonComponent <SpawnHandler> .Instance).CharDistribution.Sample(out spawnPoint.pos, out spawnPoint.rot, false, 0.0f))
         {
             return(spawnPoint);
         }
     }
     return((BasePlayer.SpawnPoint)null);
 }
 public static BasePlayer.SpawnPoint GetSpawnPoint()
 {
     if (SingletonComponent <SpawnHandler> .Instance == null || SingletonComponent <SpawnHandler> .Instance.CharDistribution == null)
     {
         return(null);
     }
     BasePlayer.SpawnPoint spawnPoint = new BasePlayer.SpawnPoint();
     for (int i = 0; i < 60; i++)
     {
         if (SingletonComponent <SpawnHandler> .Instance.CharDistribution.Sample(out spawnPoint.pos, out spawnPoint.rot, false, 0f))
         {
             return(spawnPoint);
         }
     }
     return(null);
 }
        /////////////////////////////////////////
        // Oxide Hooks
        /////////////////////////////////////////
        BasePlayer.SpawnPoint OnFindSpawnPoint()
        {
            if (!activated)
            {
                return(null);
            }
            var targetpos = Spawns.Call("GetRandomSpawn", new object[] { spawnsname });

            if (targetpos is string)
            {
                return(null);
            }
            BasePlayer.SpawnPoint point = new BasePlayer.SpawnPoint();
            point.pos = (Vector3)targetpos;
            point.rot = new Quaternion(1f, 0f, 0f, 0f);
            return(point);
        }
Beispiel #13
0
 public static void Respawn(BasePlayer player, bool newPos)
 {
     ++ServerPerformance.spawns;
     if (newPos)
     {
         BasePlayer.SpawnPoint spawnPoint = ServerMgr.FindSpawnPoint();
         player.transform.position = spawnPoint.pos;
         player.transform.rotation = spawnPoint.rot;
     }
     player.supressSnapshots = true;
     player.StopSpectating();
     player.UpdateNetworkGroup();
     player.UpdatePlayerCollider(true, false);
     player.StartSleeping();
     player.metabolism.Reset();
     player.inventory.GiveDefaultItems();
     player.SendFullSnapshot();
 }
        private BasePlayer.SpawnPoint FindSpawnPoint(BasePlayer basePlayer)
        {
            var player     = basePlayer.IPlayer;
            var spawnPoint = new BasePlayer.SpawnPoint();
            var bags       = FindSleepingBags(basePlayer);

            #if DEBUG
            LogWarning($"# of sleeping bags for {player.Name}: {bags.Length}");
            #endif

            if (config.SleepingBags && bags.Length >= 1)
            {
                var bag = bags[random.Next(0, bags.Length - 1)];
                # if DEBUG
                LogWarning($"Original location for {player.Name}: {player.Position()}");
                LogWarning($"Target location for {player.Name}: {bag.transform.position}");
                #endif
                var pos = bag.transform.position;
                spawnPoint.pos = new Vector3(pos.x, pos.y + 0.3f, pos.z);
                spawnPoint.rot = bag.transform.rotation;
            }