Hello,
Is there any chance in the near future that an RoK section can be added to the guide under "Docs"? I'd like to try my hand at learning to create a plugin, and RoK is the only game I have a server for. Thanks!
Solved Plugin creation tutorial?
Discussion in 'Reign of Kings Discussion' started by Andrew D, May 7, 2015.
-
The docs need some work but you could have a look at https://github.com/OxideMod/Oxide/blob/master/Oxide.Game.ReignOfKings/Plugins/HooksTest.cs where I have most stuff in already as an example
Last edited by a moderator: May 20, 2015 -
Thanks so much! It's pretty daunting to look at the code for the first time.
-
The link above is dead, anyone else have a tutorial from scratch? So far, Iv downloaded and ran every plugin available for ROK and ran it with no problems "I think"
-
Well guys, I've started scripting about a week ago. I knew a really small knowledge regarding C#. But, it's not that hard to learn how to do it. It is, though, time-consuming.
Download some plugins and start looking at their code - that is literally the best way.
Also, you'll need at one point or another decompile the Assemply-CSharp.dll found at your server's directory (where you have installed oxide)/ROK_Data/Managed/Assembly-CSharp.dll. Just use dotPeek and extract the decompiled stuff to a folder in your desktop for example. Once you have, you can begin to explore the assembly. Most of the things you need will be in a folder called CodeHatch.
You can always use the search option in windows explorer to search for specific stuff (e. "Server", "ThronesCommand", etc..). By the way, "Thrones" is the way reign of kings is refered as in the assembly, but most of the things you need won't necessarily be under the thrones folder (which, is in the CodeHatch folder. You will need to navigate into a lot of folders here...). Some stuff should be in CodeHatch/Engine/Core, just take your time and explore the assembly.
Once you think you can start scripting, just make a simple command or a snippet for a callback(hook) and see how it goes. I advise you to keep your game running at all time because you'll need your server and test things quite frequently. -
1. "Use dotPeek and extract the decompiled stuff to a folder in your desktop"
I dragged the Assembly-CSharp.dll into Jetbrains, now looking at all this familiar code I see in the plugins, how do I extract to desktop ? I'm guessing export to Project or Phb -
-
1. any other dlls needed to decompile under \ROK_Data\Managed or Managed\x64 ?
Teaching myself as I go, I would like to translate the Rust Jail Mod to ROK
2. So right now im going to just guess and say I need to find matching Plugin hooks"not sure if that's the right word" and replace them with what ROK uses right?
From rust jail mod:----------
Code:// Reference: Oxide.Ext.Rust using System.Collections.Generic; using System; using System.Reflection; using System.Data; using UnityEngine; using Oxide.Core; using Oxide.Core.Plugins; using Rust; namespace Oxide.Plugins
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using Oxide.Core; using CodeHatch.Engine.Networking; using CodeHatch.Inventory.Blueprints.Components; using CodeHatch.ItemContainer; using CodeHatch.Permissions; using UnityEngine; namespace Oxide.Plugins
[DOUBLEPOST=1432134000][/DOUBLEPOST]Crest Attacking Mod looks better to build on
Code:using System; using System.Collections.Generic;using CodeHatch.Build; using CodeHatch.Engine.Networking;using CodeHatch.Engine.Core.Networking; using CodeHatch.Blocks; using CodeHatch.Blocks.Networking.Events; using CodeHatch.Networking.Events.Entities; using CodeHatch.Networking.Events.Entities.Players; using CodeHatch.Networking.Events.Players; using CodeHatch.Networking.Events.Social;namespace Oxide.Plugins
Last edited by a moderator: May 20, 2015 -
Wulf Community Admin
-
Just answered most of my own questions using the link provided above by Mughisi
"The docs need some work but you could have a look at https://github.com/OxideMod/Oxide/blob/master/Oxide.Game.ReignOfKings/Plugins/HooksTest.cs where I have most stuff in already as an example " -
I'll work on the server logs soon.
[DOUBLEPOST=1432149643][/DOUBLEPOST]well sword, as for what you've asked. I rarely played Rust and it was way before I discovered oxide. I haven't really gone through the plugins over there because it's all LUA and other things my mind translates to chinese.
once you get your hand on C#, the only thing that can stop you is your imagination limit!!!!!
(and bugs) -
I'm trying to track down the line of code responsible for showing the name and guild symbol above your head in Reign of Kings.
In JetBrains I search for gesture and open all the .cs related lines, that uncovers more search terms like AnimationGestureBase.
I'm looking for the timer that makes it disappear and would like to make it permanent.
Am I go about this the right way? I'm thinking I need to decompile more than the Assembly-Csharp -
-
Can you show me an example on what simple snippet or callback looks like in the most simple form with a working hook.
My snippet called "Player and Enemy Health Change" has the following errors
HealthTest plugin failed to compile!
9:09 AM [Error] HealthTest.cs(43,13): error CS0103: The name `HookCalled' does not exist in the current context
I started with the HooksTest.cs
Code:using System.Collections.Generic; using System.Linq;using CodeHatch.Build; using CodeHatch.Engine.Core.Networking; using CodeHatch.Engine.Networking; using CodeHatch.Blocks.Networking.Events; using CodeHatch.Networking.Events.Entities; using CodeHatch.Networking.Events.Entities.Players; using CodeHatch.Networking.Events.Players; using CodeHatch.Networking.Events.Social;namespace Oxide.Plugins { [Info("Player and Enemy Health Change", "Swords", 0.1)] public class HealthTest : ReignOfKingsPlugin { private void OnPlayerConnected(Player player) { HookCalled("OnPlayerConnected"); Puts(player.DisplayName + " has connected to the server."); PrintToChat(player.DisplayName + " has joined the server!"); SendReply(player, "Welcome to the server {0}! We hope you enjoy your stay!", player.DisplayName); } private void OnPlayerChat(PlayerEvent e) { if (e is PlayerChatEvent) { var chat = (PlayerChatEvent)e; HookCalled("OnPlayerChat"); Puts(chat.PlayerName + " : " + chat.Message); } if (e is GuildMessageEvent) { var chat = (GuildMessageEvent)e; HookCalled("OnPlayerChat"); Puts("[Guild: " + chat.GuildName + "] " + chat.PlayerName + " : " + chat.Message); } } private void OnEntityHealthChange(EntityDamageEvent e) { HookCalled("OnEntityHealthChange"); if (e.Damage.Amount > 0) Puts($"{e.Entity} took {e.Damage.Amount} {e.Damage?.DamageTypes} damage from {e.Damage?.DamageSource} ({e.Damage?.Damager?.name})"); if (e.Damage.Amount < 0) Puts($"{e.Entity} gained {e.Damage.Amount} health."); } } }
Last edited by a moderator: May 21, 2015 -
Wulf Community Admin
-
Code:using System.Collections.Generic; using System.Linq;using CodeHatch.Build; using CodeHatch.Engine.Core.Networking; using CodeHatch.Engine.Networking; using CodeHatch.Blocks.Networking.Events; using CodeHatch.Networking.Events.Entities; using CodeHatch.Networking.Events.Entities.Players; using CodeHatch.Networking.Events.Players; using CodeHatch.Networking.Events.Social;namespace Oxide.Plugins { [Info("Player and Enemy Health Change", "Swords", 0.1)] public class HealthTest : ReignOfKingsPlugin { private void OnPlayerChat(PlayerEvent e) { if (e is PlayerChatEvent) { var chat = (PlayerChatEvent)e; Puts(chat.PlayerName + " : " + chat.Message); } if (e is GuildMessageEvent) { var chat = (GuildMessageEvent)e; Puts("[Guild: " + chat.GuildName + "] " + chat.PlayerName + " : " + chat.Message); } } private void OnEntityHealthChange(EntityDamageEvent e) { if (e.Damage.Amount > 0) Puts($"{e.Entity} took {e.Damage.Amount} {e.Damage?.DamageTypes} damage from {e.Damage?.DamageSource} ({e.Damage?.Damager?.name})"); if (e.Damage.Amount < 0) Puts($"{e.Entity} gained {e.Damage.Amount} health."); } } }
-
-
Trying to understand the thought process of C#, correct me if im worng here
1. Looking at Logs.cs, we must log every event before we can have it display?Last edited by a moderator: May 21, 2015 -
Code:
foreach(player i in Server.ClientPlayers) if(PlayerExtensions.GetGuild(i)) == PlayerExtensions.GetGuild(player)) SendMessage(i, "Message");
Last edited by a moderator: May 21, 2015 -
Thanks, a couple more hours of googling and I'll more questions for you.
Last edited by a moderator: May 21, 2015