How about trying your code on a local server? This is a discussion forum not a debugger.
Setting auth level per command?
Discussion in 'Rust Development' started by PaiN, Apr 8, 2015.
-
Wulf Community Admin
-
Okay delete this thread then.. nvm Thanks Wulf 4 help
-
Wulf Community Admin
-
Try and error is the best way to learn stuff. You wont learn much if we just fix your bugs and you dont know whats actually happening in your plugins. -
Code:
function PLUGIN:cmdas2m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end
Code:function PLUGIN:cmdAS(player, command, arg) if not HasPermission(self, player.net.connection) then return end if (args.Length == 0) then return end local seconds = args[0] * 60 local message = "You just set the AUTO-SAVE to {min}min!" message = message:gsub( "{min}", args[0]) local command = "server.saveinterval {sec}" rust.RunServerCommand(command:gsub( "{sec}", seconds)) rust.SendChatMessage(player, "Save-System", message) end
setautosave 30Last edited by a moderator: Apr 9, 2015 -
-
-
Code:
[Oxide] 10:46 AM [Error] Failed to load plugin AdvancedSaveSystem File: AdvancedSaveSystem.lua Line: 26 syntax error near 'or': at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unknown>:0 at NLua.Lua.LoadString (System.String chunk, System.String name) [0x00000] in <filename unknown>:0 at Oxide.Lua.Plugins.LuaPlugin.Load () [0x00000] in <filename unknown>:0 at Oxide.Lua.Plugins.LuaPluginLoader.Load (System.String directory, System.String name) [0x00000] in <filename unknown>:0 at Oxide.Core.OxideMod.LoadPlugin (System.String name) [0x00000] in <filename unknown>:0
Last edited by a moderator: Apr 9, 2015 -
Hint: Its nothing wrong with the function itself, your mistake is simple programming logic. Read the code line by line and think about what every line does, you should see your mistake yourself then. -
PaiN XD
just take my Save system, add your code to it XD
and also put a command like:
/autosave XXX
with XXX being the seconds
why put 10 commands for it when you could just do couple lines XD? -
Wulf Community Admin
-
-
Code:
// Reference: Newtonsoft.Json // Reference: Oxide.Ext.Rustusing System.Collections.Generic; using System.Reflection; using System; using System.Data; using UnityEngine; using Oxide.Core;namespace Oxide.Plugins { [Info("Save", "Reneb", "2.0.1")] class Save : RustPlugin { private int saveAuth; private bool Changed; private string noAccess; private string saved; void Loaded() { LoadVariables(); permission.RegisterPermission("cansave", this); } private object GetConfig(string menu, string datavalue, object defaultValue) { var data = Config[menu] as Dictionary<string, object>; if (data == null) { data = new Dictionary<string, object>(); Config[menu] = data; Changed = true; } object value; if (!data.TryGetValue(datavalue, out value)) { value = defaultValue; data[datavalue] = value; Changed = true; } return value; } private void LoadVariables() { saveAuth = Convert.ToInt32(GetConfig("Settings", "authLevel", 1)); noAccess = Convert.ToString(GetConfig("Messages", "noAccess", "You are not allowed to use this command")); saved = Convert.ToString(GetConfig("Messages", "saved", "World & Players saved")); if (Changed) { SaveConfig(); Changed = false; } } void LoadDefaultConfig() { Puts("Save: Creating a new config file"); Config.Clear(); LoadVariables(); } bool hasPermission(BasePlayer player) { if (player.net.connection.authLevel >= saveAuth) return true; return permission.UserHasPermission(player.userID.ToString(), "cansave"); } [ConsoleCommand("save.all")] void cmdConsoleSave(ConsoleSystem.Arg arg) { if (arg.connection != null) { if (arg.connection.authLevel < saveAuth) { SendReply(arg, noAccess); return; } } SaveRestore.Save(); SendReply(arg, saved); } [ChatCommand("save")] void cmdChatSave(BasePlayer player, string command, string[] args) { if (!hasPermission(player)) { SendReply(player, noAccess); return; } SaveRestore.Save(); SendReply(player, saved); if (args.Length > 0) { float value; if (float.TryParse(args[0], out value)) { ConsoleSystem.Run.Server.Normal("server.saveinterval " + args[0], new object[] { }); SendReply(player, "set: server.saveinterval " + args[0]); } } } } }
-
-
this is an exemple in C#
but look here: https://github.com/strykes/Oxide2Plugins
i may not be the best in lua, but i was able to achieve most of what was needed to code on rust
[DOUBLEPOST=1428603992][/DOUBLEPOST] -
-