i have searched high and low, don't understand how to write C# plugins.
How would enable a cooldown on a chat command?
#region Core
[ChatCommand("nuke")]
void chatNuke(BasePlayer player, string command, string[] args) {
if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use")) {
var foundPlayer = rust.FindPlayer(args[0]);
if (foundPlayer == null) {
PrintToChat(player, $"We couldn't find a player named {args[0]}");
return;
} else {
DoNuke(foundPlayer);
}
}
}
void DoNuke(BasePlayer player) {
System.Random r = new System.Random();
int intensityValue = r.Next(800, 1500);
int durationValue = r.Next(50, 150);
int radiusValue = r.Next(164, 165);
int timeLeft = 0;
Im after a cooldown on the /nuke chat command.
Adding a cooldown to a command?
Discussion in 'Rust Development' started by Squire, Jun 23, 2017.
-
list<userid> cooldowns = ....
command[''']
void ...(userid, ...){
if (colldowns.contains(userid)){
sendreply('Fucked cooldown');
return
}
....
} -
thats a great help... not
-
I'd probably have a hashset or a list to put players in that have run the command, and a timer. So when they run the command, it checks the list for their ID, if not found then add them to the list, create a new timer which at the end will remove them from the list, the rest containing all the actions you need to carry out.
Last edited by a moderator: Jun 23, 2017 -
this means nothing to me, like i said i don't write C# so more or less looking for a example thats very close to what im looking for.
I found a plugin that im trying to change to suit my needs. -
Last edited by a moderator: Jun 23, 2017
-
i wasnt asking to be spoon fed, but i tend to learn better if things are actually explained, methods etc.
i can code php, python, bash & tcl but C# seems quite hard to follow or its the doc's that has been supplied for oxide being alittle slim of the technical info side.. -
Code:
using System.Collections.Generic; //Using directive containing the HashSet classnamespace Oxide.Plugins //Namespace where plugins must go { [Info("TestPlugin", "JoeSheep", "1.0.0")] [Description("A Test Plugin.")] class TestPlugin : RustPlugin { HashSet<ulong> Cooldowns = new HashSet<ulong>(); //Create our list to store the players currently in cooldown const string Perm = "TestPlugin.test"; //Create the permission void OnServerInitialized() { permission.RegisterPermission(Perm, this); //Register the permission when the server initializes } [ChatCommand("test")] //Create the chat command to do the following void cmdTestCommand(BasePlayer player, string cmd) { if (permission.UserHasPermission(player.UserIDString, Perm)) //Check if the player has the permission "Perm" { if (!Cooldowns.Contains(player.userID)) //Check if the player is listed in the HashSet "Cooldowns", if not continue { Cooldowns.Add(player.userID); //Add the player to the Cooldowns HashSet so they cannot run the command again until removed timer.Once(10, () => Cooldowns.Remove(player.userID)); //Create and start a timer for 10 seconds, when it expires remove the player from the Cooldowns HashSet SendReply(player, "Test command."); //Send a chat message to the player saying "Test command." } else SendReply(player, "Cooldown in effect."); //If the player is in the Cooldowns HashSet send this chat message to them } else SendReply(player, "You do not have permission to run this command"); //If the player doesn't have the permission Perm then send this chat message to them } } }
-
hmm no. i've tried and can't do it, anyone want to be paid to insert a timeout to this plugin i have please PM me.
-
Don't pay for such a simple task that you can learn yourself.
Look at other plugins on Oxide for examples. You can look in one of mine: PermRewards for Rust | Oxide
Have a data file containing all the cooldowns of players, store the time when they used the command. Add the time of the cooldown you want to the time when they used it, if that time is more than the current time of when they try to use the command, then don't let them use it. -
-
-
[DOUBLEPOST=1498348114][/DOUBLEPOST]here is the first part of the plugin, i have no clue in what im doing, where i place things, i assume the plugin reads from top to bottom.
Code:class NukePlayer : RustPlugin { private static readonly int playerLayer = LayerMask.GetMask("Player (Server)"); private static readonly Collider[] colBuffer = (Collider[])typeof(Vis).GetField("colBuffer", (BindingFlags.Static | BindingFlags.NonPublic))?.GetValue(null); private List<ZoneList> RadiationZones = new List<ZoneList>(); void Loaded() { permission.RegisterPermission("nukeplayer.use", this); } #region Core [ChatCommand("nuke")] void chatNuke(BasePlayer player, string command, string[] args) { if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use")) { var foundPlayer = rust.FindPlayer(args[0]); if (foundPlayer == null) { PrintToChat(player, $"We couldn't find a player named {args[0]}"); return; } else { DoNuke(foundPlayer); } } } void DoNuke(BasePlayer player) { System.Random r = new System.Random(); int intensityValue = r.Next(800, 1500); int durationValue = r.Next(50, 150); int radiusValue = r.Next(164, 165); int timeLeft = 0; string intensityMsg = $"<color=#e67e22>{intensityValue.ToString()}</color> <color=#f1c40f>kiloton nuke incoming on {player.displayName}</color>"; // string statsMsg = $"<color=#f1c40f>The fallout radius is </color><color=#e67e22>{radiusValue.ToString()}</color> <color=#f1c40f>and will last for</color> <color=#e67e22>{durationValue.ToString()}</color> <color=#f1c40f>seconds.</color>"; // Let everyone know doom is coming. ConsoleNetwork.BroadcastToAllClients("chat.add", new object[] { null, intensityMsg}); // ConsoleNetwork.BroadcastToAllClients("chat.add", new object[] { null, statsMsg}); timer.Once(timeLeft, () => { // Do damage and add radiation Detonate(player); // Set off effects around the player NukeEffects(player); }); } #endregion Core
Last edited by a moderator: Jun 25, 2017 -
-
Error while compiling: nuketest.cs(102,30): error CS1525: Unexpected symbol `System'
Don't know what that means and no doubt its all in the wrong places.
Code:HashSet<ulong> Cooldowns = new HashSet<ulong>(); //Create our list to store the players currently in cooldown const string Perm = "nukeplayer.use"; //Create the permission private static readonly int playerLayer = LayerMask.GetMask("Player (Server)"); private static readonly Collider[] colBuffer = (Collider[])typeof(Vis).GetField("colBuffer", (BindingFlags.Static | BindingFlags.NonPublic))?.GetValue(null); private List<ZoneList> RadiationZones = new List<ZoneList>(); public static string Perm1 => Perm; void Loaded() { permission.RegisterPermission("nukeplayer.use", this); } #region Core [ChatCommand("nuke")] void chatNuke(BasePlayer player, string command, string[] args) { if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use")) { if (!Cooldowns.Contains(player.userID)) //Check if the player is listed in the HashSet "Cooldowns", if not continue { Cooldowns.Add(player.userID); //Add the player to the Cooldowns HashSet so they cannot run the command again until removed timer.Once(10, () => Cooldowns.Remove(player.userID)); //Create and start a timer for 10 seconds, when it expires remove the player from the Cooldowns HashSet var foundPlayer = rust.FindPlayer(args[0]); if (foundPlayer == null) { PrintToChat(player, $"We couldn't find a player named {args[0]}"); return; } else { SendReply(player, "Cooldown in effect."); //If the player is in the Cooldowns HashSet send this chat message to them } } else SendReply(player, "You do not have permission to run this command"); //If the player doesn't have the permission Perm then send this chat message to them } else DoNuke(foundPlayer); } } void DoNuke(BasePlayer player) { System.Random r = new System.Random(); int intensityValue = r.Next(800, 1500); int durationValue = r.Next(50, 150); int radiusValue = r.Next(164, 165); int timeLeft = 0;
-
If you dont upload the full script we cant help
-
ok so this is what i have so far with no errors..
Code:class NukePlayer : RustPlugin { #region Config private ConfigFile configFile; public class ConfigFile { public float Cooldown { get; set; } public static ConfigFile DefaultConfig() { return new ConfigFile { Cooldown = 60 }; } } protected override void LoadDefaultConfig() { PrintWarning("Generating default configuration file..."); configFile = ConfigFile.DefaultConfig(); } protected override void LoadConfig() { base.LoadConfig(); configFile = Config.ReadObject<ConfigFile>(); } protected override void SaveConfig() { Config.WriteObject(configFile); } #endregion HashSet<ulong> Cooldowns = new HashSet<ulong>(); //Create our list to store the players currently in cooldown const string Perm = "nukeplayer.use"; //Create the permission private static readonly int playerLayer = LayerMask.GetMask("Player (Server)"); private static readonly Collider[] colBuffer = (Collider[])typeof(Vis).GetField("colBuffer", (BindingFlags.Static | BindingFlags.NonPublic))?.GetValue(null); private List<ZoneList> RadiationZones = new List<ZoneList>(); public static string Perm1 => Perm; void Loaded() { permission.RegisterPermission("nukeplayer.use", this); } #region Core [ChatCommand("nuke")] void chatNuke(BasePlayer player, string command, string[] args) { if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use")) { if (!Cooldowns.Contains(player.userID)) //Check if the player is listed in the HashSet "Cooldowns", if not continue { Cooldowns.Add(player.userID); //Add the player to the Cooldowns HashSet so they cannot run the command again until removed timer.Once(configFile.Cooldown, () => Cooldowns.Remove(player.userID)); //Create and start a timer for 10 seconds, when it expires remove the player from the Cooldowns HashSet } else SendReply(player, "Cooldown in effect."); //If the player is in the Cooldowns HashSet send this chat message to them } else { var foundPlayer = rust.FindPlayer(args[0]); if (foundPlayer == null) { PrintToChat(player, $"We couldn't find a player named {args[0]}"); return; } else { DoNuke(foundPlayer); } } }
Code:using Newtonsoft.Json; using System.Collections.Generic; using UnityEngine; using System.Linq; using Facepunch; using System; using Oxide.Core; using Oxide.Core.Configuration; using Oxide.Game.Rust.Cui; using Oxide.Core.Plugins; using System.Reflection; using System.Collections; using System.IO; using Rust;namespace Oxide.Plugins { [Info("NukePlayer", "wski", 1.0)] [Description("Nuke players in an epic way.")] class NukePlayer : RustPlugin { #region Config private ConfigFile configFile; public class ConfigFile { public float Cooldown { get; set; } public static ConfigFile DefaultConfig() { return new ConfigFile { Cooldown = 60 }; } } protected override void LoadDefaultConfig() { PrintWarning("Generating default configuration file..."); configFile = ConfigFile.DefaultConfig(); } protected override void LoadConfig() { base.LoadConfig(); configFile = Config.ReadObject<ConfigFile>(); } protected override void SaveConfig() { Config.WriteObject(configFile); } #endregion HashSet<ulong> Cooldowns = new HashSet<ulong>(); //Create our list to store the players currently in cooldown const string Perm = "nukeplayer.use"; //Create the permission private static readonly int playerLayer = LayerMask.GetMask("Player (Server)"); private static readonly Collider[] colBuffer = (Collider[])typeof(Vis).GetField("colBuffer", (BindingFlags.Static | BindingFlags.NonPublic))?.GetValue(null); private List<ZoneList> RadiationZones = new List<ZoneList>(); public static string Perm1 => Perm; void Loaded() { permission.RegisterPermission("nukeplayer.use", this); } #region Core [ChatCommand("nuke")] void chatNuke(BasePlayer player, string command, string[] args) { if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use")) { if (!Cooldowns.Contains(player.userID)) //Check if the player is listed in the HashSet "Cooldowns", if not continue { Cooldowns.Add(player.userID); //Add the player to the Cooldowns HashSet so they cannot run the command again until removed timer.Once(configFile.Cooldown, () => Cooldowns.Remove(player.userID)); //Create and start a timer for 10 seconds, when it expires remove the player from the Cooldowns HashSet } else SendReply(player, "Cooldown in effect."); //If the player is in the Cooldowns HashSet send this chat message to them } else { var foundPlayer = rust.FindPlayer(args[0]); if (foundPlayer == null) { PrintToChat(player, $"We couldn't find a player named {args[0]}"); return; } else { DoNuke(foundPlayer); } } } void DoNuke(BasePlayer player) { System.Random r = new System.Random(); int intensityValue = r.Next(800, 1500); int durationValue = r.Next(50, 150); int radiusValue = r.Next(164, 165); int timeLeft = 0; string intensityMsg = $"<color=#e67e22>{intensityValue.ToString()}</color> <color=#f1c40f>kiloton nuke incoming on {player.displayName}</color>"; // string statsMsg = $"<color=#f1c40f>The fallout radius is </color><color=#e67e22>{radiusValue.ToString()}</color> <color=#f1c40f>and will last for</color> <color=#e67e22>{durationValue.ToString()}</color> <color=#f1c40f>seconds.</color>"; // Let everyone know doom is coming. ConsoleNetwork.BroadcastToAllClients("chat.add", new object[] { null, intensityMsg}); // ConsoleNetwork.BroadcastToAllClients("chat.add", new object[] { null, statsMsg}); timer.Once(timeLeft, () => { // Do damage and add radiation Detonate(player); // Set off effects around the player NukeEffects(player); }); } #endregion Core #region Effects private void Detonate(BasePlayer player) { Rust.DamageTypeEntry dmg = new Rust.DamageTypeEntry(); dmg.amount = 70; dmg.type = Rust.DamageType.Generic; HitInfo hitInfo = new HitInfo() { Initiator = null, WeaponPrefab = null }; hitInfo.damageTypes.Add(new List<Rust.DamageTypeEntry> { dmg }); DamageUtil.RadiusDamage(null, null, player.transform.position, 5, 10, new List<Rust.DamageTypeEntry> { dmg }, 133376, true); // Init Radiation on the players location InitializeZone(player.transform.position, 10, 150, 60, false); } private void NukeEffects(BasePlayer player) { System.Random r = new System.Random(); // How many explosions within radius to set off int explosionCount = 35; int explosionRadius = 15; for (int i = 1; i <= explosionCount; i++) { Vector3 plusOffset = new Vector3(r.Next(1, explosionRadius), r.Next(1, explosionRadius), r.Next(1, explosionRadius)); Vector3 minusOffset = new Vector3(r.Next(1, explosionRadius), r.Next(1, explosionRadius), r.Next(1, explosionRadius)); Vector3 explosionLocation = player.transform.position + plusOffset - minusOffset; string[] prefabEffects = new string[12] { "assets/bundled/prefabs/fx/fire/fire_v2.prefab", "assets/bundled/prefabs/fx/ricochet/ricochet1.prefab", "assets/bundled/prefabs/fx/ricochet/ricochet2.prefab", "assets/bundled/prefabs/fx/ricochet/ricochet3.prefab", "assets/bundled/prefabs/fx/ricochet/ricochet4.prefab", "assets/prefabs/tools/c4/effects/c4_explosion.prefab", "assets/bundled/prefabs/fx/weapons/landmine/landmine_explosion.prefab", "assets/prefabs/npc/patrol helicopter/effects/rocket_explosion.prefab", "assets/bundled/prefabs/fx/explosions/explosion_01.prefab", "assets/bundled/prefabs/fx/explosions/explosion_02.prefab", "assets/bundled/prefabs/fx/explosions/explosion_03.prefab", "assets/bundled/prefabs/fx/explosions/explosion_core.prefab" }; foreach (string prefabEffect in prefabEffects){ Effect.server.Run(prefabEffect, explosionLocation, Vector3.up); } } } #endregion Effetcs // Credits to k1lly0u for code within this region #region Radiation Control private void InitializeZone(Vector3 Location, float intensity, float duration, float radius, bool explosionType = false) { if (!ConVar.Server.radiation) ConVar.Server.radiation = true; if (explosionType) Effect.server.Run("assets/prefabs/tools/c4/effects/c4_explosion.prefab", Location); else Effect.server.Run("assets/prefabs/npc/patrol helicopter/effects/rocket_explosion.prefab", Location); var newZone = new GameObject().AddComponent<RadZones>(); newZone.Activate(Location, radius, intensity); var listEntry = new ZoneList { zone = newZone }; listEntry.time = timer.Once(duration, () => DestroyZone(listEntry)); RadiationZones.Add(listEntry); } private void DestroyZone(ZoneList zone){ if (RadiationZones.Contains(zone)) { var index = RadiationZones.FindIndex(a => a.zone == zone.zone); RadiationZones[index].time.Destroy(); UnityEngine.Object.Destroy(RadiationZones[index].zone); RadiationZones.Remove(zone); } } public class ZoneList { public RadZones zone; public Timer time; } public class RadZones : MonoBehaviour { private int ID; private Vector3 Position; private float ZoneRadius; private float RadiationAmount; private List<BasePlayer> InZone; private void Awake() { gameObject.layer = (int)Layer.Reserved1; gameObject.name = "NukeZone"; var rigidbody = gameObject.AddComponent<Rigidbody>(); rigidbody.useGravity = false; rigidbody.isKinematic = true; } public void Activate(Vector3 pos, float radius, float amount) { ID = UnityEngine.Random.Range(0, 999999999); Position = pos; ZoneRadius = radius; RadiationAmount = amount; gameObject.name = $"RadZone {ID}"; transform.position = Position; transform.rotation = new Quaternion(); UpdateCollider(); gameObject.SetActive(true); enabled = true; var Rads = gameObject.GetComponent<TriggerRadiation>(); Rads = Rads ?? gameObject.AddComponent<TriggerRadiation>(); Rads.RadiationAmountOverride = RadiationAmount; Rads.radiationSize = ZoneRadius; Rads.interestLayers = playerLayer; Rads.enabled = true; if (IsInvoking("UpdateTrigger")) CancelInvoke("UpdateTrigger"); InvokeRepeating("UpdateTrigger", 5f, 5f); } private void OnDestroy() { CancelInvoke("UpdateTrigger"); Destroy(gameObject); } private void UpdateCollider() { var sphereCollider = gameObject.GetComponent<SphereCollider>(); { if (sphereCollider == null) { sphereCollider = gameObject.AddComponent<SphereCollider>(); sphereCollider.isTrigger = true; } sphereCollider.radius = ZoneRadius; } } private void UpdateTrigger() { InZone = new List<BasePlayer>(); int entities = Physics.OverlapSphereNonAlloc(Position, ZoneRadius, colBuffer, playerLayer); for (var i = 0; i < entities; i++) { var player = colBuffer[i].GetComponentInParent<BasePlayer>(); if (player != null) InZone.Add(player); } } } #endregion } };
[DOUBLEPOST=1498393222][/DOUBLEPOST]/nuke < player > doesnt work -
-
notepad++ but i do have VS
-
notepad++ you joking please ask one of the coders to help write it for you or you will be here all day