Need a plugin where players can only type certain commands in safe zones only. So like /shop can only be used in a safe zone. Plugin could support any number of commands in a config file.
Safe Zone commands
I wrote this up quick but haven't tested. Should work. GL.
using System;
using System.Collections.Generic;
using Oxide;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("SafeZoneCommands", "Segfault", "0.0.1")]
[Description("Commands that can only be used in SafeZone")]
public class SafeZoneCommands : CovalencePlugin
{
private class SafeZoneConfig
{
public List<string> Commands;
}
private SafeZoneConfig SZC;
protected override void LoadDefaultConfig(){
Config.WriteObject<SafeZoneConfig>(new SafeZoneConfig() {
Commands = new List<string>() { "command.example" } }, true, nameof(SafeZoneCommands)
);
}
public void Init() {
SZC = Config.ReadObject<SafeZoneConfig>(nameof(SafeZoneCommands));
}
public object OnPlayerCommand(BasePlayer player, string command, string[] args)
{
if (player != null && !player.IsAdmin && player.InSafeZone() && SZC.Commands.Contains(command))
{
player.ChatMessage("This command can't be used within SafeZone!");
return false;
}
return null;
}
}
}Merged post
Edited.. Noticed I did a few things wrong
using System;
using System.Collections.Generic;
using Oxide;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("SafeZoneCommands", "Segfault", "0.0.1")]
[Description("Commands that can only be used in SafeZone")]
public class SafeZoneCommands : CovalencePlugin
{
private class SafeZoneConfig
{
public List<string> Commands;
}
private SafeZoneConfig SZC;
protected override void LoadDefaultConfig(){
Config.WriteObject<SafeZoneConfig>(new SafeZoneConfig() {
Commands = new List<string>() { "command.example" } }, true, nameof(SafeZoneCommands)
);
}
public void Init() {
SZC = Config.ReadObject<SafeZoneConfig>(nameof(SafeZoneCommands));
}
public object OnPlayerCommand(BasePlayer player, string command, string[] args)
{
if (player != null && !player.IsAdmin && !player.InSafeZone() && SZC.Commands.Contains(command))
{
player.ChatMessage("This command can only be used in SafeZone!");
return false;
}
return null;
}
}
} Thanks for giving it a shot!
I get this error when I try to compile the plugin on the server
(08:49:12) | Could not initialize plugin 'SafeZoneCommands v0.0.1' (Exception: Only access to oxide directory!
Path: /home/rust/pvetest/serverfiles/SafeZoneCommands)
at Oxide.Core.Configuration.DynamicConfigFile.CheckPath (System.String filename) [0x00029] in <50629aa0e75d4126b345d8d9d64da28d>:0
at Oxide.Core.Configuration.DynamicConfigFile.WriteObject[T] (T config, System.Boolean sync, System.String filename) [0x0000c] in <50629aa0e75d4126b345d8d9d64da28d>:0
at Oxide.Plugins.SafeZoneCommands.LoadDefaultConfig () [0x0001e] in <1836c789f64648c78f1db56120da17fe>:0
at Oxide.Core.Plugins.Plugin.LoadConfig () [0x00039] in <50629aa0e75d4126b345d8d9d64da28d>:0
at Oxide.Core.Plugins.Plugin.HandleAddedToManager (Oxide.Core.Plugins.PluginManager manager) [0x0000f] in <50629aa0e75d4126b345d8d9d64da28d>:0
at Oxide.Core.Plugins.CSPlugin.HandleAddedToManager (Oxide.Core.Plugins.PluginManager manager) [0x00000] in <50629aa0e75d4126b345d8d9d64da28d>:0
at Oxide.Plugins.CSharpPlugin.HandleAddedToManager (Oxide.Core.Plugins.PluginManager manager) [0x00000] in <60c318df79ed41688ea59335e48d61ad>:0
at Oxide.Plugins.CovalencePlugin.HandleAddedToManager (Oxide.Core.Plugins.PluginManager manager) [0x000b3] in <60c318df79ed41688ea59335e48d61ad>:0
at Oxide.Core.Plugins.PluginManager.AddPlugin (Oxide.Core.Plugins.Plugin plugin) [0x00027] in <50629aa0e75d4126b345d8d9d64da28d>:0
at Oxide.Core.OxideMod.PluginLoaded (Oxide.Core.Plugins.Plugin plugin) [0x00035] in <50629aa0e75d4126b345d8d9d64da28d>:0 Issue seems to lie in your config handling.
If you remove
nameof(SafeZoneCommands)It compiles
Line 26
public void Init() {
SZC = Config.ReadObject<SafeZoneConfig>();
}However, ideally you wouldn't read the config in Init() instead you would do that in LoadConfig. Example:
using System;
using System.Collections.Generic;
using Oxide;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("SafeZoneCommands", "Segfault", "0.0.1")]
[Description("Commands that can only be used in SafeZone")]
public class SafeZoneCommands : CovalencePlugin
{
private class SafeZoneConfig
{
public List<string> Commands;
}
private SafeZoneConfig SZC;
protected override void LoadConfig()
{
base.LoadConfig();
try
{
SZC = Config.ReadObject<SafeZoneConfig>();
if (SZC == null) throw new Exception();
}
catch
{
LoadDefaultConfig();
}
}
protected override void LoadDefaultConfig()
{
SZC = new SafeZoneConfig()
{
Commands = new List<string> { "command.example" }
};
}
protected override void SaveConfig()
{
Config.WriteObject(SZC);
}
public object OnPlayerCommand(BasePlayer player, string command, string[] args)
{
if (player != null && !player.IsAdmin && !player.InSafeZone() && SZC.Commands.Contains(command))
{
player.ChatMessage("This command can only be used in SafeZone!");
return true;
}
return null;
}
}
} @0x89A thanks for pointing that out. Been a while since i made a plugin, however I've recently started getting back into rust.