Jump to content

How to make a script file run in every mission?


Terzi

Recommended Posts

Hello,

 

I was reading a lot on the forum and internet but could not really understand how Hooks and API permissions work. What I want to do is I think quite simple:

 

Using Mist, display a message 'Hello World' for 10 seconds in every mission that you run on a server.

 

Later I will change it for stats tracking purposes. My struggle is to make a script run for every single mission that you start on a server. Not without the need to add it manually using the Mission Editor.

 

I would be grateful if someone can help me do this, so I can edit it further.

[CENTER]

Signum_Signatur.png

[/CENTER]

Link to comment
Share on other sites

The way I understand it is that what you are trying to achieve is currently not possible. Mind you, the MP API is woefully under-documented (is it even documented?) but it currently runs as follows (my own deduction, please take with a grain of salt, and please educate me if I'm wrong)

 

  • when a client starts a game, it downloads the .miz from the server and runs it synchronously with the server
  • (unless you have a dedicated server, the server spawns a server and a client process)

That means that essentially, all clients are running the exact same .miz at the same time, with the server having authority over all units except player-controlled units, which are controlled by their respective clients. So, when for example your script says

 

trigger.action.outText("hi there", 20, true)

 

that line of code is run simultaneously on all clients, and they all act accordingly. (note: this may be different for stand-alone servers)

 

This also means that any modification that you make to the server in terms of code that is running must necessarily also run on all clients. That is why you can't have a separate script or modification running only on your instance. If your instance of DCS was modified to run the additional 'Hello World' line, it would only execute on your instance, not on the other clients, and only you would be able to see it.

 

That is the reason why all code that you want to have executed on all clients has to be part of the miz: the .miz is downloaded and run on all clients. It is also the reason why if you have a MOD installed on your instance (e.g. additional eye candy for airports) and use that in your mission, only those clients who have the same mod installed locally on their instances will be able to use the mod in the mission and have the same visuals as you do.

So, effectively, your line of code that says 'hello world' would constitute a mod, and it would only work on those remote clients that also implement the exact same modification to their local DCS instance.

 

CAVEAT EMPTOR: I'm piecing this together from my own experience with DCS (and writing the occasional MP game on other platforms), so I might be telling you complete bull.

 

-ch


Edited by cfrag
Link to comment
Share on other sites

25 minutes ago, cfrag said:

That is why you can't have a separate script or modification running only on your instance. If your instance of DCS was modified to run the additional 'Hello World' line, it would only execute on your instance, not on the other clients, and only you would be able to see it.

 

Sorry my bad, I forgot to tell it we have a server, and I want to run this script on that server, not on clients. Just to keep track of stats.

[CENTER]

Signum_Signatur.png

[/CENTER]

Link to comment
Share on other sites

Create a .lua file in folder "Saved Games\DCS\Scripts\Hooks" with contents:

myscript = {}

function myscript.onMissionLoadEnd()
  net.dostring_in("mission", "a_do_script(\"loadfile(\\\"D:/myscript.lua\\\")()\");")
end

DCS.setUserCallbacks(myscript)

 

Script "D:\myscript.lua" will run on each mission start.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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