Difference between revisions of "Server Plugins"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
(Some small additions)
(Related Engine Functions)
Line 47: Line 47:
 
</tt>
 
</tt>
 
== Related Engine Functions ==
 
== Related Engine Functions ==
These are the functions which can be used to interact with your plugin.
+
These are the engine functions which can be used to interact with your plugin from Lua.
 
There is example Lua code in the Tutorial plugin you can use.
 
There is example Lua code in the Tutorial plugin you can use.
 
<tt>
 
<tt>

Revision as of 21:17, 15 August 2018

Introduction

It is possible to write plugins in C# and use these from Lua.

These plugins must implement a certain Interface to be usable.

In the moment there is no extensive written documentation, but there exists a tutorial plugin which is well commented and which can be used as a starting point.

CAVEAT: 
Server plugins are officially not supported and you can seriously shoot yourself in the foot with them. 
You need to know what you are doing to really use them.

Compiled plugins need to be placed into

\build\base\plugins

If you use LuaTableProxy types to return Lua tables your plugin also must be linked against Shardsserver.exe, which means you probably have to update it a lot.

IPlugin

Every plugin must implement this interface. Check out the Tutorial Plugin to see how it is done.

using System.Collections.Concurrent;
namespace Gameplay.Plugin
{
   public class LuaRequest
   {
       public string EventId;
       public object[] Data;
   }

   public class LuaResponse
   {
       public string EventId;
       public ulong DestinationObjectId;
       public object[] Data;
   }

   public interface IPlugin
   {
       void Init(ConcurrentQueue<LuaResponse> _responseQueue);
       void Start();
       bool IsReadyForServerStartup();
       void Shutdown();
       bool IsShutDown();
       void MessageFromLua(LuaRequest _request);
       object[] DirectRequestFromLua(object[] _requestData);
       string GetPluginName();
   }
}

Related Engine Functions

These are the engine functions which can be used to interact with your plugin from Lua. There is example Lua code in the Tutorial plugin you can use.

SendMessageToPlugin(...)
Description: Sends a message to a C# gameplay plugin.
Params:
   (string) - Plug-in name to send to.
   (string) - EventId name.
   (...) One or more object arguments to be passed to the plug-in.
Returns:
   None
----------------------------------
SendRequestToPlugin(...)
Description: Sends a direct request to a C# gameplay plugin.
Params:
   (string) - Plug-in name to send to.
   (...) One or more object arguments to be passed to the plug-in.
Returns:
   A single value, or an array of values.
----------------------------------
IsPluginLoaded(...)
Description: Ask if a c# gameplay plug-in has been loaded or not
Params:
   (string) - Plug-in name to send to.
Returns:
   true or false
----------------------------------

Tutorial Plugin Download Link

https://www.legendsofaria.com/downloads/u3d2bdea/LoA_TutorialPlugin.zip