Creating /commands is super easy:
Doing /test with a mod that has this loaded will output "Test!" in RCON.Code:[ChatCommand("test")] void cmdTest(BasePlayer player, string cmd, string[] args) { Puts("Test!"); }
Solved Writing C# plugins?
Discussion in 'Rust Development' started by sililia, Jun 27, 2015.
-
Just to clarify, I use C# Console Application for new project and then add the references I need in order to get the variables that work with oxide and I guess I input them into "using"?
Would I be needing any of the default references or can I remove them for this project and they will come back when I select new project -
And yes, you add the libraries as references and then you can use "using" to load their namespaces. You don't need to use "using" you can also just use a fully qualified path to the library.
For instance, you could do:
var toto= new System.IO.File("xxxx");
OR
using "System.IO";
var toto= new File("xxxx");
So long as you don't have multiple namespaces loaded that have a definition for a class named "File" you'll be OK.
You can still use fully qualified class paths if you have a "using" statement:
using "System.IO";
var toto= new System.IO.File("xxxx"); -
Also the references I got was all the ones that was listed in the other thread made by you and also the UnityEngine.UI because I took that as User interface and if it is would love to know if we can modify any or even create our own UI in-game for certain plugins for example an admin UI menu instead of having to type all the commands, you press a GUI Button.
UPDATE: I think I now know what you are talking about where XXXX is that is where i put the variable name in of what I want to use.
With saving, do I save the file as a .cs or leave it as is?
What file should I be looking at for player hooks? also like in the old rust do I have any hope in cracking the code for invisibility on command?
For the record, more then happy to share the credit if
also had a look at your plugins code and i don't understand how your using variables when you have no using in the script.
Not to mention how you were able to know what variables to use to get that effect.
This is what the default script looks like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test_Plugin
{
class Program
{
static void Main(string[] args)
{
}
}
} -
[DOUBLEPOST=1435558835][/DOUBLEPOST]
For the references what I do is I have 1 project with all my mods in it. I can cherry pick code here and there if I need to reuse. I create a new plugin by duplicating an existing one then stripping it of what I don't need. -
Yeah I changed it to C#>Windows>Class Library instead of the console application and I know it does not matter, it just clears some code. even though i save it as .cs and with a capital letter at the start, thanks for that tip by the way.
So what is the dos and don'ts of peoples scripts? like considering its there code, how can I even use it?
Right now, I am trying to think of a plugin that we need that is not complex.
Also how which bits of code goes where at the moment I have this
Code:namespace Oxide.Plugins { [Info("Title of Plugin", "Your Name", 0.1, ResourceId = 714)] [Description("This is what the plugin does")] public class PluginName : RustPlugin { // This is where your plugin will do its magic...I know main code goes here but what line of code would I use first to start off the mod? } }
-
Well you have some basic events like OnServerInitialized that run on start. From there you could do some stuff... or not.. depends what you're trying to do.
You could also do like I did with NoDecay and go straight for a hook. In my case I didn't need more than that. In a next version I might add a multiplier instead of completely disabling decay. If I do that I'll want to make a config file from which I'll read the multiplier. You have events to manage config files as well. Look at the doc.. Look at existing mods. -
Is there a couple of mods you could suggest when it comes to looking at some basic code, your one is a prime example, yet still a little complex but is very small to what it does, though you may see that as a small use, I do not lol
I also had a look at AP -> CLICK and even that looks complex like I understand is mainly because of the messages and the security behind it but how would I break it down to simplify it?
Managed to think of a plugin that I would like to learn how to make but I need to know how I go about telling an item once spawned in a chest or a furnace to delete the item and then once its taken over the command stops, I had a look over the command, found some commands to do with items but not sure where to type the item name so it knows what item if deposited it will get rid of or replace?
Of course with all the help I have been given, there will be thanks and some notification on your end.
Update: Looking at the API for Item Hooks at the moment found I think 3 that can be used
1. OnItemCraft 2. OnItemAddedToContainer 3. OnItemRemovedFromContainer
Am I on the right track?
PS. to new people reading. Read the whole thread from start to finish, to get info on how to do things. -
Yes you are on the right track. Start by adding a puts or player msg in these and experiment to see when they are triggered, also look at the structures you receive in them (decompiling to see what they hold is a good idea here).
As for what mods to look at jusy download anything that could possibly relate to what you are trying to achieve. I just have a folder to which I download all the mods and then I search for hooks I want to use in them to see what's possible -
Can you tell me what category to look at for the commands you are talking about so I can have a look at them. with the big list it's hard finding the commands.
For others trying to also get into Plugin Development I recommend this Microsoft Video Guide on C# >LINK<
Update: I realized that I believe I am missing some references but I am not sure what ones
Went >HERE< and copied and pasted the text, and the red squiggly lines for errors showed up and when I click on it said it was not there, I am not sure what DLL file to use to fix it
[ConsoleCommand("sample")] is one of the commands that it does not know. -
Make sure you have references to these:
assembly-CSharp.dll
Oxide.Core.dll
Oxide.Ext.CSharp.dll
Oxide.Game.Rust.dll
UnityEngine.dll
You might need others, I don't have them off the top of my head but I've use other DLL's from the Rust "managed" folder.
The code example in your link also uses Newtonsoft's json lib, that's something you'll want to download if you want to use this lib. It's not something I use in my own plugins but it has it's uses. -
Wulf Community Admin
-
Could someone link me to a thread or link for a list for each DLL file?
that has like some info on what is in each DLL file, even just a couple of hooks. -
Wulf Community Admin
-
Some of these threads helped >HERE< just a simple list. Lets say what Oxide.Core contains for hooks to use, just have a little description of what is in each DLL file.
Just so I have a rough idea on what DLL to look at, for the desired hook to use. -
Wulf Community Admin
Any Rust functions can be found in the decompiled Rust DLLs. -
-
Wulf Community Admin
-
Update: I am using JustDecompile and this is all that is in it
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: PermissionSet(SecurityAction.RequestMinimum, XML="<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFlags=\"SkipVerification\"/>\r\n</PermissionSet>\r\n")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]
Okay upon further research, the way it is looking to me is. The documentation that has the hooks is what you sort of copy and paste into visual and edit to what you want it to do.
And of course the DLL has extra variables that are not listen in the documentation.
Am I on the right track?
Because I am noticing that the game or oxides code has pre built commands so instead of me building a program from scratch per say I am using the reference DLL files for the list of commands for rust oxide.
If I am on the right track this has helped me HEAPS and will save me asking so many stupid question.
The way I was seeing it is I needed to know off by heart all the variables for rust but now know it has it for me because of the references.
I guess now I just need to know the starting blocks of code to use, to get a plugin off the ground.
and also work out what DLL has what references to use.Last edited by a moderator: Aug 1, 2015 -