Solved Running a console command? (C#)
Discussion in 'Hurtworld Development' started by ownprox, Dec 7, 2015.
-
Wulf Community Admin
Yes, see Oxide/HurtworldServer.cs at master · OxideMod/Oxide · GitHub.
If your plugin is a CovalencePlugin, you can use:
Code:server.RunCommand("command");
-
thank you
-
Wulf Community Admin
-
yeah figured it out you was too fast at replying is there any way i can do both in one plugin? because i want to make a teleporter so i would need to use a player command then run a server one but if not ill just reference one script from the other
-
Wulf Community Admin
-
oh there is a way that works fine but only in HurtworldPlugin but if i use CovalencePlugin i cannot use player commands
-
Wulf Community Admin
-
no i cant but i found a work around
Code:[Info("HurtPK", "OwnProx", "1.0.0")] class HurtPK : HurtworldPlugin { class Server : CovalencePlugin { public void RunServerCommand(string cmd) { server.RunCommand(cmd); } } Server s; private System.Timers.Timer timer1; void Loaded() { s = new Server(); }void OnPlayerConnected(PlayerIdentity identity, uLink.NetworkPlayer player) { s.RunServerCommand(""); }[ChatCommand("works")] void cmdWorks(PlayerIdentity player, NetworkMessageInfo info, string command, string[] args) { Puts("Works"); } }
-
Wulf Community Admin
Your only issues is with Puts, which isn't available via CovalencePlugin. There is no issue with commands. Also, I'd recommend using Visual Studio 2015, as you're formatting could use some cleanup.
-
my formatting is down to copying and pasting certain parts from the script and ending the open brackets myself hahah yeah but i should, and i did not have puts in it earlier it was just a example, i tried a command under CovalencePlugin where it sent a reply message to the client but ingame it say command not found but when i use a HurtworldPlugin and type the command in game it works
thanks for your help -
Wulf Community Admin
-
fyi to anyone just use a plugin reference saves time
Last edited by a moderator: Dec 8, 2015 -
covalence.Server.RunCommand("addadmin 123356652463");
That valid code? -
Wulf Community Admin
-
Code:
[ChatCommand("test")] void TestCommand(PlayerSession session, string command, string[] args) { switch (args[0]) { case: "as" covalence.Server.RunCommand("addadmin 123356652463"); break } }
Code:5:35 PM [Error] Failed to call hook 'TestCommand' on plugin 'Store v1.0.0' (InvalidCastException: Cannot cast from source type to destination type.) 5:35 PM [Debug] at Oxide.Game.Hurtworld.Libraries.Covalence.HurtworldServer.RunCommand (System.String command, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.Store.StoreCommand (.PlayerSession session, System.String command, System.String[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.Store.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0
-
Wulf Community Admin
-
idem