protected override void Load()
        {
            Instance = this;

            UnturnedPlayerEvents.OnPlayerRevive += OnRevive;
            U.Events.OnPlayerConnected          += Events_OnPlayerConnected;

            Logger.Log("SpawnProtection loaded!");
        }
        public void Execute(IRocketPlayer caller, string[] command)
        {
            var plr = (UnturnedPlayer)caller;

            if (SpawnProtection.IsExcluded(plr.CSteamID.m_SteamID))
            {
                SpawnProtection.Instance.Configuration.Instance.NoSpawnProtection.Remove(plr.CSteamID.m_SteamID);
                UnturnedChat.Say(caller, SpawnProtection.Instance.Translate("toggled_protection_on"));
            }
            else
            {
                SpawnProtection.Instance.Configuration.Instance.NoSpawnProtection.Add(plr.CSteamID.m_SteamID);
                UnturnedChat.Say(caller, SpawnProtection.Instance.Translate("toggled_protection_off"));
            }
            SpawnProtection.Instance.Configuration.Save();
        }
Ejemplo n.º 3
0
        public void Update()
        {
            if (!protectionEnabled || pluginUnloaded())
            {
                return;
            }

            elapsedProtectionTime         = getTotalDateTimeSeconds(protStart);
            elapsedProtectionMilliseconds = getTotalDateTimeMilliseconds(protStart);

            if (elapsedProtectionMilliseconds <= 300 && SpawnProtection.CheckIfNearBed(Player))
            {
                StopProtection(sendMessage: false);
                return;
            }

            var config = getConfig();

            if (SpawnProtection.Config.EnsureGodmodeWhileProtected && !Player.Features.GodMode)
            {
                Player.Features.GodMode = true;
            }
            if (config.GiveVanishWhileProtected && !vanishExpired && !Player.Features.VanishMode && elapsedProtectionMilliseconds >= config.ProtectionVanishDelayMilliseconds)
            {
                //UnturnedChat.Say(Player, "vanish enabled! " + elapsedProtectionMilliseconds.ToString() + " Milliseconds!");
                Player.Features.VanishMode = true;
            }

            if (config.DisableProtectionBasedOnDist)
            {
                if (spawnSet)
                {
                    if (Vector3.Distance(spawnPosition, Player.Position) >= config.ProtDisableDist)
                    {
                        distanceCanceled = true;
                    }
                }

                if (!spawnSet && elapsedProtectionMilliseconds >= config.SpawnPositionGetDelay)
                {
                    spawnPosition = Player.Position;
                    spawnSet      = true;
                }
            }

            if (Player.CurrentVehicle != null)
            {
                foreach (var passenger in Player.CurrentVehicle.passengers)
                {
                    if (passenger.player != null)
                    {
                        passengerCount++;
                    }
                }

                if (config.AutoRepairProtectedPlayersVehicles)
                {
                    if (Player.CurrentVehicle.health < lastVehHealth && passengerCount == 1)
                    {
                        Player.CurrentVehicle.askRepair(9999);
                    }
                }

                if (config.CancelProtectionIfInVehicleWithOthers && passengerCount > 1)
                {
                    inVehicleWithOthers = true;
                }

                lastVehHealth  = Player.CurrentVehicle.health;
                passengerCount = 0;
            }

            if (config.GiveVanishWhileProtected && !vanishExpired && elapsedProtectionTime >= config.MaxProtectionVanishTime)
            {
                //UnturnedChat.Say(Player, "vanish expired!");
                Player.Features.VanishMode = false;
                vanishExpired = true;
            }

            if (Player.Player.equipment.asset != null)
            {
                if (!config.ForceDequipWhileProtected && config.CancelProtectionOnEquip && !config.WhitelistedItems.Contains(Player.Player.equipment.asset.id))
                {
                    equiptedItem = true;
                }
                else if (config.ForceDequipWhileProtected)
                {
                    Player.Player.equipment.dequip();
                }
            }

            if (elapsedProtectionTime >= config.ProtectionTime)
            {
                protectionEnded = true;
            }

            if (inVehicleWithOthers)
            {
                StopProtection(false);
                sendTranslation("canceled_veh");
                return;
            }

            if (equiptedItem)
            {
                StopProtection(false);
                sendTranslation("canceled_item");
                return;
            }

            if (distanceCanceled)
            {
                StopProtection(false);
                sendTranslation("canceled_dist");
                return;
            }

            if (protectionEnded)
            {
                StopProtection();
                return;
            }
        }
Ejemplo n.º 4
0
 void sendTranslation(string translation, params object[] args)
 {
     if (!getConfig().SendProtectionMessages)
     {
         return;
     }
     UnturnedChat.Say(Player, SpawnProtection.Instance.Translate(translation, args), SpawnProtection.GetProtMsgColor());
 }
Ejemplo n.º 5
0
        void UnturnedPlayerEvents_OnPlayerUpdateGesture(UnturnedPlayer player, UnturnedPlayerEvents.PlayerGesture gesture)
        {
            if (player.CSteamID == Player.CSteamID)
            {
                if (gesture == UnturnedPlayerEvents.PlayerGesture.PunchLeft ||
                    gesture == UnturnedPlayerEvents.PlayerGesture.PunchRight)
                {
                    if (protectionEnabled)
                    {
                        StopProtection(false);

                        if (!getConfig().SendProtectionMessages)
                        {
                            return;
                        }
                        UnturnedChat.Say(Player, SpawnProtection.Instance.Translate("canceled_punch"), SpawnProtection.GetProtMsgColor());
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void StopProtection(bool sendMessage = true)
        {
            ResetVariables();
            Player.Features.GodMode = false;
            var config = getConfig();

            if (config.GiveVanishWhileProtected && Player.Features.VanishMode)
            {
                Player.Features.VanishMode = false;
            }

            if (sendMessage && config.SendProtectionMessages)
            {
                UnturnedChat.Say(Player, SpawnProtection.Instance.Translate("expired"), SpawnProtection.GetProtMsgColor());
            }
        }
Ejemplo n.º 7
0
        public void StartProtection(bool sendMessage = true)
        {
            ResetVariables();

            protectionEnabled = true;
            protStart         = DateTime.Now;

            Player.GodMode = true;
            //spawnLocation = Player.Position;

            if (sendMessage && SpawnProtection.Config.SendProtectionMessages)
            {
                UnturnedChat.Say(Player, SpawnProtection.Instance.Translate("prot_started", SpawnProtection.Config.ProtectionTime), SpawnProtection.GetProtMsgColor());
            }
        }