Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NightyNightYT · Jun 22, 2019 at 02:32 PM · multiplayerserverside

Server-side game "plugins"

Hello, I am currently making a multiplayer server-authoritative survival game. I was wondering how I would go about making the game so server owners/developers could make their own scripts to hook into the server's build (think uMod for Rust). I would include a compiler so the users would only need to drop source code into a folder and it would compile it and everything. I am more confused, however, on how I would let these scripts communicate with the base game. I would want it to be like the Spigot API for Minecraft, where the base game has events that the scripts could hook into, ex. PlayerInteractEvent when interacting with a door, this event would include the player, door, stuff like that, when the script hooks into this it would be able to access all of this but could also cancel this event from happening or call its own events. I'm sorry if this doesn't make sense and I would be more than happy to clarify, but I was wondering if anyone could point me in the right direction or direct me to an example of this being done in Unity/C#. Thank you for your time.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jun 22, 2019 at 03:21 PM

Well, you have to design your own Plugin API. How it should look like, what features it should support is completely up to you and your game. Minecraft is already built upon various events. Most "framework mods" (like Forge) will actually alter the code an put special handling code in between the default code.


Spigot seems to just cancel the default behaviour but still pass the event to all plugins. What behaviour you want if multiple plugins want to handle the same event is also up to you.


In general you would have to route all your relevant calls through a construct like this:

 public class ModEvent
 {
     public System.Action<Parameters> defaultAction;
     public List<System.Func<Parameters>> plugins = new List<System.Func<Parameters>>();
     public ModEvent(System.Action<Parameters> action)
     {
         defaultAction = action;
     }
     public void Execute(Parameters aParams)
     {
         bool executeDefault = true;
         foreach(var action in plugins)
         {
             if (!action(aParams))
                 executeDefault = false;
         }
         if (executeDefault)
             defaultAction(aParams);
     }
 }

This is just a rough example. For any event in your game you can create an instance of the ModEvent class which will handle the execution of the default action. For example

 public ModEvent primaryFire = new ModEvent();
 
 private void DefaultPrimaryFire(Parameters aParams)
 {
     // your default action
 }
 
 public void ExecutePrimaryFire(Parameters aParams)
 {
     primaryFire.Execute(aParams);
 }

A plugin can now simply register a callback for the event primaryFire event by adding a method to it

 yourClass.primaryFire.plugins.Add(PrimaryFireCallback);
 
 bool PrimaryFireCallback(Parameters aParams)
 {
     // do something
     return true; // should the default action be executed or not?
 
 }

Again this is just a very basic example. You may want to be more thoughtful how you design the events, how you pass and handle parameters, how you may chain callbacks if necessary, ...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NightyNightYT · Jun 22, 2019 at 04:35 PM 0
Share

Holy crap, I wasn't expecting this much detail. Thank you so much for the reply, I think this will really help me out!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

183 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

MMO server side programming 0 Answers

Photon Server vs Dedicated Master Client with PUN 1 Answer

Unity networking tutorial? 6 Answers

[Multiplayer] How to make the client get an attribute calculate by the server? 0 Answers

UNET OnCollisionEnter issues 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges