1. As the title says, I'm trying to get started with plugin development for Oxide and I have a few questions. The only language of the ones supported by Oxide that I know is javascript, but I've been seeing around the forums that a JS plugin does not have the same impact in the performance of the server that a c# one. Since i learned java by creating plugins for minecraft, I though that it would be a good idea to learn c# with rust development. I downloaded Visual Studio(Community) and most of the times that I copy/paste a snippet of code. I get the following error showed in the screenshot. I think I'm missing to "Import" some class(At least, we call it import in java). I also find that I should decompile Assembly-CSharp.dll. So, I downloaded JustDecompile and I was like: "What the heck am I looking?"

    So, here are my questions:
    • Does the use of JS/lua/Phyton have that big impact on peformance to a point that I should learn c#?
    • How can I find wich classes to import?
    • Should I learn c# before Oxide development?
     

    Attached Files:

  2. Wulf

    Wulf Community Admin

    The "rust." prefix you are trying to use comes from Oxide.Game.Rust.dll, not Rust itself. It's a library helper meant mainly for the scripted languages we support (lua, js, and python), but it will work with C# too. In terms of performance, C# would be the fastest and recommended, as it's essentially native code once compiled, and you'll be able to use Visual Studio and its IntelliSense feature if you setup a proper project with your plugins.

    For which classes/namespaces to use, that varies greatly based on what you are trying to do. I'd recommend taking a look at some of the existing plugins for some examples, though there aren't a ton of examples for .js plugins.

    I'd definitely recommend C# if you wanted to learn one. It's not too hard to handle C#, especially if you have a project setup with Visual Studio.

    If you'd like to compare the languages with performance, C# > Lua > JavaScript/CoffeeScript > Python.
     
  3. If you need some c# general help, or help on how to use VS2015 feel free to hit me up on ts3.agngaming.com or drop me a PM, people willing to learn a new programming language are always welcome in my book.

    Here is a direct link for VS2015 Community Edition:
    Thank you for downloading Visual Studio

    When installing VS2015, if you do not want to create websites using IIS (ugh...) then select Custom Install and un tick the web section and proceed.

    Some helpful steps to getting you started:
    VS ("Visual Studio") needs to know where the external Oxide and Rust/Unity libs are, as you mentioned "Rust." does nothing as VS cannot find this library, what i do here is a grab some files from the .\RustDedicated_Data\Managed directory into a separate libraries directory from which I can work.

    The files you may need at some point, including the ones you will need are:
    • Assembly-CSharp.dll
    • UnityEngine.UI.dll
    • UnityEngine.dll
    • Oxide.Game.Rust.dll
    • Oxide.Core.dll
    • Facepunch.UnityEngine.dll
    • Facepunch.System.dll
    • Facepunch.Network.dll
    • Oxide.Ext.CSharp.dll
    References for your project can be added easily by right clicking 'References' in the Solution panel of VS2015
    [​IMG]

    Copy these files to a new location, the reason that i do this is sometimes i found that the RustDedicated.exe lcoks these files and VS is unable to load them when you need to open a project, remember that every time Oxide and Rust is updated, you should copy these files back again - you could create a simple batch script to do this for you.

    Creating my first plugin
    I have created a VS2015 project template, you can download it here: AGN File Browser

    The Zip file needs to be installed to your VS2015 Templates directory, here: .\Documents\Visual Studio 2015\Templates\ProjectTemplates (do not extract the ZIP, just place it here)

    Now, the template should appear in VS2015 when you click on 'Visual C#' at the bottom.
    [​IMG]

    In order to work on your plugin while the server is running, you need to have the project Location set to the plugin directory on your testing Rust Server installation which may involve moving the project folder back a level as loading pluigins from sub directories does not seem to work.

    You can also perform the above a better way than having your plugin directory littered with VS stuff, in your projects Build Events properties section, select 'Run the post-build event' Always, and enter the following into the Post-Build event command line:
    Code:
    copy "$(ProjectDir)\FILENAME.cs" "G:\Rust_Server\Server\rustds\server\my_server_identity\oxide\plugins\FILENAME.cs"
    Change the paths and FILENAME accordingly, now whenver you build your solution, it will copy itself to the plugins directory, doing it this way keeps the plugins directory clean of unwanted files.

    Note:
    Your class name (aka the output .cs file) name MUST match the name given to the class itself, for example of you have "public class MySpookyPlugin : RustPlugin", your class file must be called MySpookyPlugin.cs
     
    Last edited by a moderator: Dec 23, 2015
  4. Wulf

    Wulf Community Admin

    @AlienX, UnityEngine.Networking.dll would never be needed, but Oxide.Ext.CSharp.dll will always be needed for C# plugins.
     
  5. Apologies, got confused with FacePunch.Network :)
     
  6. Thank you guys so much for the help.
     
  7. I have another question on this topic. What are de differences between programming in JS and C#(Of course, besides the syntax)?

    I'm having a pretty specific scenario.
    Why I can call:
    Code:
    player.inventory.GiveItem(ItemManager.CreateByName("hatchet", 1), player.inventory.containerBelt);
    fine in c#(The code does work) and when I try the exact same code in JS it throws the following error:
    Code:
    [Oxide] 9:07 PM [Error] Failed to call hook 'OnRunCommand' on plugin 'rustcore v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
    [Oxide] 9:07 PM [Debug]   at Oxide.Ext.JavaScript.JavaScriptExtension.<JavaScriptExtension>m__0 (System.Exception ex) [0x00000] in <filename unknown>:0
      at Oxide.Core.ExceptionHandler.FormatException (System.Exception ex) [0x00000] in <filename unknown>:0
      at Oxide.Core.Logging.Logger.WriteException (System.String message, System.Exception ex) [0x00000] in <filename unknown>:0
      at Oxide.Core.OxideMod.LogException (System.String message, System.Exception ex) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Game.Rust.Libraries.Command+<AddChatCommand>c__AnonStorey0.<>m__0 (.BasePlayer player, System.String command, System.String[] args) [0x00000] in <filename unknown>:0
      at Oxide.Game.Rust.Libraries.Command+ChatCommand.HandleCommand (.BasePlayer sender, System.String name, System.String[] args) [0x00000] in <filename unknown>:0
      at Oxide.Game.Rust.Libraries.Command.HandleChatCommand (.BasePlayer sender, System.String name, System.String[] args) [0x00000] in <filename unknown>:0
      at Oxide.Game.Rust.RustCore.OnRunCommand (.Arg arg) [0x00000] in <filename unknown>:0
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    ?
     
  8. Wulf I could really use your help with something. can u message me.
     
  9. Hei, Ive tryed everything but still i get the message ingame "You dont have premission for this command". What to do?
     
  10. Wulf

    Wulf Community Admin

    What exactly is this related to? If you are having an issue with a plugin, please post in its support thread.