Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 17
» Latest member: DonteStrow
» Forum threads: 8
» Forum posts: 9

Full Statistics

Online Users
There are currently 3 online users.
» 1 Member(s) | 2 Guest(s)
Erdrick{TR}

Latest Threads
TR #1!
Forum: The Common Area
Last Post: Erdrick{TR}
4 minutes ago
» Replies: 0
» Views: 1
New system going up.
Forum: Announcements
Last Post: Erdrick{TR}
6 minutes ago
» Replies: 1
» Views: 99
Hi
Forum: The Common Area
Last Post: Zanon{TR}
Yesterday, 05:58 PM
» Replies: 0
» Views: 38
Vallis Checking In
Forum: The Common Area
Last Post: Vallis{TR}
Yesterday, 05:58 PM
» Replies: 0
» Views: 25
No attacking structures (...
Forum: Game Programming and Modding
Last Post: Hawthorne
Yesterday, 04:44 PM
» Replies: 0
» Views: 62
ROK C# Template
Forum: Game Programming and Modding
Last Post: Hawthorne
Yesterday, 04:27 AM
» Replies: 0
» Views: 34
Reign of Kings Killed by ...
Forum: Game Programming and Modding
Last Post: Hawthorne
Yesterday, 12:41 AM
» Replies: 0
» Views: 36
Down the road.. we will b...
Forum: Announcements
Last Post: Hawthorne
Yesterday, 12:25 AM
» Replies: 0
» Views: 127

 
  No attacking structures (time based)
Posted by: Hawthorne - Yesterday, 04:44 PM - Forum: Game Programming and Modding - No Replies

Here is a script I made for Reign of Kings that will allow you to restrict attacking to in game or real world time.
You can have the script warn, kick or ban after so many kicks.

Update:
Added application rules so that rule will apply to either players or structures or both.

Have Fun!

Code:
using System;
using System.Collections.Generic;
using CodeHatch.Build;
using CodeHatch.Engine.Networking;
using CodeHatch.Networking.Events.Entities;
using CodeHatch.Networking.Events.Players;
using CodeHatch.Engine.Core.Cache;
using UnityEngine;
using CodeHatch.Engine.Core.Networking;
using CodeHatch.Blocks.Networking.Events;
using System.Linq;

namespace Oxide.Plugins
{
    //Need a Script?
    //Patrick Shearon aka Hawthorne
    //www.theregulators.org
    //pat.shearon@gmail.com
    //05-22-2015
    [Info("AttackSchedule", "Hawthorne", "1.0.")]
    public class AttackSchedule : ReignOfKingsPlugin
    {
        public class KickData
        {
            public int count = 0;
            public Player player;
        }
        public static List<KickData> kickCounter = new List<KickData>();

        public enum Time
        {
            Game,
            World
        }
        public enum Applications
        {
            Structures,
            Players,
            Both
        }
        public enum Action
        {
            Warn,
            Kick,
            BanAfterWarn
        }
        //Set to use game time or world time
        Time timeToUse = Time.World;
        //Set action to take when rule is broken.
        Action actionToTake = Action.Warn;
        //Set which objects this applis to
        Applications applications = Applications.Both;
        //Set warning message
        string warningMessage = "[FF0000]No attacking allowed at this time.";
        //If a player gets kicked this many times they will be banned.
        int KickTimesBeforeBan = 5;
        //Set start and end time
        TimeSpan startTime = new TimeSpan(18, 0, 0); //6PM START
        TimeSpan endTime = new TimeSpan(2, 0, 0); //2AM STOP

        bool TimeBetween(TimeSpan start, TimeSpan end)
        {

            TimeSpan now = DateTime.Now.TimeOfDay;
            if (timeToUse == Time.Game)
            {
                int hour = Convert.ToInt32(GameClock.Instance.TimeOfDayAsClockString().Split(':')[0]);
                int min = Convert.ToInt32(GameClock.Instance.TimeOfDayAsClockString().Split(':')[1].Split(' ')[0]);
                string AMPM = GameClock.Instance.TimeOfDayAsClockString().Split(' ')[1];
                if (AMPM.ToUpper() == "PM")
                    hour = hour + 12;
                now = new DateTime(DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, hour, min,0).TimeOfDay;

            }
            if (start < end)
                return start <= now && now <= end;
            return !(end < now && now < start);
        }
        void ApplyRules(Entity entity)
        {
            if (actionToTake == Action.Warn & entity.IsPlayer)
            {
                PrintToChat(entity.Owner, warningMessage);
            }
            if (actionToTake == Action.Kick & entity.IsPlayer)
            {
                Server.Kick(entity.Owner, warningMessage);
            }
            if (actionToTake == Action.BanAfterWarn & entity.IsPlayer)
            {
                PrintToChat(entity.Owner, warningMessage);
                KickData kickData = kickCounter.FirstOrDefault(k => k.player == entity.Owner);
                if (kickData == null)
                {
                    kickData = new KickData();
                    kickData.player = entity.Owner;
                    kickCounter.Add(kickData);
                }

                kickData.count++;
                PrintToChat(entity.Owner, "WARNING YOU WILL BE BANNED.");
                if (kickData.count >= 5)
                    Server.Ban(entity.Owner, warningMessage);
            }
        }
        private void OnEntityHealthChange(EntityDamageEvent damageEvent)
        {            
            if (damageEvent.Entity.IsPlayer & !TimeBetween(startTime, endTime))
            {
                if (!damageEvent.Damage.DamageSource.IsPlayer | (damageEvent.Damage.DamageSource == damageEvent.Entity))
                    return;
                damageEvent.Cancel("No damage area");
                damageEvent.Damage.Amount = 0f;
                if(applications == Applications.Both | applications == Applications.Players)
                    ApplyRules(damageEvent.Damage.DamageSource);
                return;
            }
        }
        private void OnCubeTakeDamage(CubeDamageEvent cubeDamageEvent)
        {            
            if (!TimeBetween(startTime, endTime))
            {
                if (!cubeDamageEvent.Damage.DamageSource.IsPlayer)
                    return;
                cubeDamageEvent.Damage.Amount = 0;
                cubeDamageEvent.Cancel("No damage area");
                if (applications == Applications.Both | applications == Applications.Structures)
                    ApplyRules(cubeDamageEvent.Damage.DamageSource);
                return;
            }
        }
    }
}

Print this item

  ROK C# Template
Posted by: Hawthorne - Yesterday, 04:27 AM - Forum: Game Programming and Modding - No Replies

Code:
using System;
using System.Collections.Generic;
using CodeHatch.Build;
using CodeHatch.Engine.Networking;
using CodeHatch.Networking.Events.Entities;
using CodeHatch.Networking.Events.Players;
using CodeHatch.Engine.Core.Cache;
using UnityEngine;
using CodeHatch.Engine.Core.Networking;
using CodeHatch.Blocks.Networking.Events;

namespace Oxide.Plugins
{
   //Need a Script?
   //Patrick Shearon aka Hawthorne
   //www.theregulators.org
   //pat.shearon@gmail.com
   //05-21-2015
   [Info("Template", "Hawthorne", "1.0.")]
   public class Template : ReignOfKingsPlugin
   {
       private void init()
       {
       }

       private void Unload()
       {
       }

       private void LoadDefaultConfig()
       {
       }

       private void OnServerInitialized()
       {
       }

       private void OnTerrainInitialized()
       {
       }

       private void OnServerSave()
       {
       }

       private void OnServerShutdown()
       {
       }

       private void OnUserApprove(ConnectionLoginData connectionLoginData)
       {
       }

       private void OnPlayerConnected(Player player)
       {
       }

       private void OnPlayerDisconnected(Player player)
       {
       }

       private void OnPlayerChat(PlayerEvent playerEvent)
       {
       }

       private void OnPlayerSpawn(PlayerFirstSpawnEvent playerFirstSpawnEvent)
       {
       }

       private void OnEntityDeath(EntityDeathEvent entityDeathEvent)
       {
       }

       private void OnEntityHealthChange(EntityDamageEvent entityDamageEvent)
       {
       }

       private void OnCubeDestroyed(CubeDestroyEvent cubeDestroyEvent)
       {
       }

       private void OnCubePlacement(CubePlaceEvent cubePlaceEvent)
       {
       }

       private void OnCubeTakeDamage(CubeDamageEvent cubeDamageEvent)
       {
       }
   }
}

Print this item

  Reign of Kings Killed by Script
Posted by: Hawthorne - Yesterday, 12:41 AM - Forum: Game Programming and Modding - No Replies

Code:
using System;
using System.Collections.Generic;
using CodeHatch.Build;
using CodeHatch.Engine.Networking;
using CodeHatch.Networking.Events.Entities;
using CodeHatch.Networking.Events.Players;
using CodeHatch.Engine.Core.Cache;
using UnityEngine;

namespace Oxide.Plugins
{
   //Need a Script?
   //Patrick Shearon aka Hawthorne
   //www.theregulators.org
   //pat.shearon@gmail.com
   //05-21-2015
   [Info("Killed By", "Hawthorne", "1.0.")]
   public class KilledBy : ReignOfKingsPlugin
   {
       private void OnEntityDeath(EntityDeathEvent deathEvent)
       {
           if (deathEvent.Entity.IsPlayer)
           {
               string killer = "[00FF00]" + deathEvent.KillingDamage.DamageSource.Owner.DisplayName;
               string message = "[FFFFFF]SERVER: [FF0000]" + deathEvent.Entity.Owner.DisplayName + " [FFFFFF]was killed by " + killer;
               PrintToChat(message);
           }
       }
   }
}

Print this item

  Down the road.. we will be here.
Posted by: Hawthorne - Yesterday, 12:25 AM - Forum: Announcements - No Replies



Print this item

  New system going up.
Posted by: Hawthorne - 05-21-2015, 11:36 PM - Forum: Announcements - Replies (1)

Gearing up for a new gaming adventure, dusting the cob-webs off old tech and making it new again. Stay tuned!

Print this item