Jump to content

Scripting the server&client in JavaScript


Recommended Posts

I meant like:

var HandleResourceStart = function(resource) { 
    if(resource == getThisResource()) { 
        print("Hello world from JavaScript!"); 
        return; 
    } 
    return; 
} 
  
var HandlePlayerJoin = function() { 
    var player = source; 
     
    outputChatBox("This server is completely scripted in JavaScript instead of Lua!", player, 0, 128, 128, false); 
    return; 
} 
  
addEventHandler("onResourceStart", getRootElement(), HandleResourceStart); 
addEventHandler("onPlayerJoin", getRootElement(), HandlePlayerJoin); 

I'm not sure if it's okay to link a link from the other multiplayer mod to show you an example.

Link to comment

In theory it's possible using CEF on the client and a module on the server (as Necktrox suggested).

I would not recommand it though due to the following reasons:

  • It's very slow as the "call chain" on the client would be like: C++ event --> Lua --> CEF --> Lua --> C++ plus the communication between CEF and Lua through IPC (https://en.wikipedia.org/wiki/Inter-pro ... munication) which is additionally slow.
    It would work quite good for minor stuff though (but wrapping/forwarding events like onClientRender would be a pain)
  • as a server module in contrast would reach a pretty good performance (assuming the step through Lua was eliminated) you could use Javascript on the server only alternatively. This is bad in terms of consistency though, because you are not able to share code between server and client then

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...