Jump to content

NIOD - A node JS API for your dynamic campaign


ked

Recommended Posts

Hello everyone, today I'm introducing NIOD.

 

 

NIOD is a npm package that lets you use the MOOSE functions with Javascript or TypeScript, it connects to DCS World using a socket. Then you can use some of the functions at your disposal to spawn groups, create triggers, etc... We're still in the early phase of this package so there aren't many functions implemented yet but it will grow !

 

 

How does this work ?

 

The nodejs server stores callbacks linked to a callback id, this id is passed to the lua server which pass it back with the returned data. The dispatcher will then execute the right stored callback

Here's a basic example

const { initNiod, spawnGroup } = require("niod");  

initNiod().then(() => {  

   spawnGroup("template_group", () => console.log("your group has been spawned")   );
});

Instalation

 

 

 

Unsanitize the require function

 

Niod requires DCS to import some functionalities from LUA so it can create a socket, you'll need to "unsanitize" it. To do so go into your DCS installation folder DCS World\Scripts\MissionScripting.lua and edit this line

require = nil
to

--require = nil
Mission Editor

 

Then you need to create a mission that loads the MOOSE lua file (found here: https://github.com/FlightControl-Master/MOOSE/releases) and then loads the NIOD lua file found in the "script" folder.

And there you go ! You're all set, you can import niod in your project and start the server using

const { initNiod } = require("niod"); 

initNiod().then(() => {   // your mission code goes here });

and start coding !

 

 

Typescript support

 

Niod is written in typescript, so the npm package is shipped with all the type declarations. Which means auto-completion depending on your code editor

 

 

API

 

initNiod(): Promise<core.Express>

This function will init Niod and resolve the express server

spawnGroup = (groupName: string, callback: Callback)

This function will spawn a group and execute the callback once it's done, the callback takes one parameter which is the name of the group that was spawned

spawnGroupInZone = (groupName: string, zoneName: string, callback: Callback, randomize?: boolean)

This function will add a "trigger", it means that Niod will execute the callback function when something happens (depending on the trigger). The "type" argument defines the trigger that will be added, the only one implemented at the moment is: "GroupPartlyOrCompletelyInZone"

addTrigger = ( type: string,   groupName: string,   zoneName: string,   frequency: "once" | "repeat",   callback: Callback)

Special thanks

 

Thanks to Drex from Dynamic DCS for all the help on sockets, go check his server out

 

 

Make sure to leave your thougths and suggestions below or as issues on the github repository. I'm also thinking about opening a discord server so we can discuss this more in depth.

 

 

Cheers :pilotfly:


Edited by ked
Link to comment
Share on other sites

  • 1 month later...

Hello everyone ! I know it's been a while but I had some personnal issues and a lot of work to do.

 

 

I'm not abandoning this project, I actualy have redone the whole thing in typescript. There's a lot to do but right now I am able to:

- Send and receive data from/to the DCS server reliably

- Retrieve data from all groups within a coalition

 

 

I know it's not much but it was a huge pain, and I had a lot of work to do to get the foundation mechanisms for the next functionalities !

 

 

Incomming functionalities are:

- Spawning

- Zone retrieval

- Event handling

- API

- Data persistance

- Triggers

- A nice interface to create triggers

- Functionnalities comparable to MOOSE (AI_Dispatcher, etc ...) to create dynamic campaigns

- Statistics

 

 

Stay tuned !


Edited by ked
Link to comment
Share on other sites

  • 2 months later...

Hey guys, I've been working a lot on the API and I have taken a decision: NIOD will now use MOOSE ! It makes my life so much easier. In one night I've already done this:

- Spawn a group from a template

- Spawn a group from a template in a particular zone

- Many improvements on the socket

 

 

There's still some work to do, like triggers, code preparation for npm and npm packaging. You can follow the avancement here: https://github.com/Ked57/NIOD/issues/2

Link to comment
Share on other sites

  • Recently Browsing   0 members

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