Jump to content
Sign in to follow this  
VictorFarbau

Addon as background application

Recommended Posts

What I want is simple. I got some scripts I need in every SP/MP mission. I thought I'd wrap them into an addon and off they go during each mission.

So far no luck with my config.cpp. I formerly created addons which were put to use by placing game logic objects or invoked through event handlers. But how do I go about creating an addon where the init script is run each time a mission is started?

CfgPatches is done but to which class or object do I need to attach my class so it is run automatically? Is this possible at all?

Thanks for any ideas,

VictorFarbau

Share this post


Link to post
Share on other sites

yes it is. if i understood the question correct.

use extended eventhandler

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

class CfgPatches {

class MYADDON {

units[] = {x,y,z};

weapons[] = {x,y,z};

requiredVersion = X;

requiredAddons[] = {"Extended_EventHandlers"};

};

};

#include "What\ever\you\need.hpp"

class Extended_Init_EventHandlers

{

class Man

{

MYADDON_Init_Man="_this execVM ""\MYADDON\init.sqf"";";

};

};

;

Share this post


Link to post
Share on other sites

biggrin_o.gif I must say that I deleted some text in my post before submission where I stated "...without abusing XEH and have the script run by each man" smile_o.gif

Honestly, I think this could be problematic. Because I am mostly using a combination of server / client scripts. The point is to run the scripts once on each machine at mission start and not by each man -> this could lead to running the same server script 100 times if 100 men are local to the server e.g.

VictorFarbau

Share this post


Link to post
Share on other sites

You can avoid having multiple instances of your script, by adding this to your init script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if(isNil "MYADDON_initialised") then {

       MYADDON_initialised = true;

       // Your code goes here

};

Or use xehs PreInit or PostInit EHs

(but: PreInit only available in XEH v1.9 and later; PostInit only available in XEH v1.91 and later)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class Extended_PreInit_EventHandlers {

   MYADDON_init = " _this execVM ""\MYADDON\init.sqf""; ";

};

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class Extended_PostInit_EventHandlers {

   MYADDON_init = " _this execVM ""\MYADDON\init.sqf""; ";

};

Quote[/b] ]... running the same server script 100 times if 100 men are local to the server

The init event is global.

Share this post


Link to post
Share on other sites

Using the global var method wouldn't work here - too much risk that still a couple of scripts would run simultaneously due to latency in var distribution.

However, that XEH PostInit stuff sounds awesome. I knew I should have checked and installed the latest version - it is still in my inbox (using 1.8 at present) smile_o.gif

Thanks for the tip, I'll give it a shot asap.

VictorFarbau

Share this post


Link to post
Share on other sites
Using the global var method wouldn't work here - too much risk that still a couple of scripts would run simultaneously due to latency in var distribution.

Then I have to warn you that the Extended_Eventhandler addon is using the exact same technique for Pre- and PostInit!

Share this post


Link to post
Share on other sites

Doh  huh.gif Thanks for the heads up. Well, I can have the addon run once on each machine (like it would be when using a normal addon object). Based on role in an MP environment it will quit or run (isServer statement). But to spawn multiple instances on the same machine would mess up things for sure.

That's why I was wondering if this is possible; so far I only know the concept of tying custom scripts to addon objects on the map so they're run at mission start. Problem is that I want my addon scripts to be run during each mission on each island w/o having to explicitely modify any mission files.

Thanks,

VictorFarbau

Share this post


Link to post
Share on other sites

Here's the compensation for the latency of variable distribution you fear:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if(isNil "MYADDON") then {

        MYADDON = (_this select 0);

        sleep 3;

        if(MYADDON == (_this select 0)) then {

        // Your code goes here

       };

};

Any additional instances that pass the isNil check will either overwrite the already set variable or their value will be overwritten by some other instance. There can only be one instance executing the distribution as the last one. Then all instances will wait to make sure that all other instances have done that as well. After the timeout, the instance that executed it as last will continue, all others will exit.

Share this post


Link to post
Share on other sites
Quote[/b] ]Using the global var method wouldn't work here - too much risk that still a couple of scripts would run simultaneously due to latency in var distribution.

If you call your checking code directly from an objects init event you get no latency, because it's treated as a function:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="If (IsNil ""MyScriptHasBeenCalled"") Then {MyScripthasBeenCalled=True; [_This Select 0] ExecVM ""MyScript.sqs""}"

Share this post


Link to post
Share on other sites
Quote[/b] ]directly from an objects init event

Ehrm, which object's init would that be considering that I might not have access to the mission file upfront?

Thanks,

VictorFarbau

Share this post


Link to post
Share on other sites
Quote[/b] ]Ehrm, which object's init would that be considering that I might not have access to the mission file upfront?

One way, would be to add the init event to say class CAMANBASE, using the Extended Event Handler?

Share this post


Link to post
Share on other sites

For a moment I thought we'd be runnning in circles somehow smile_o.gif Until I came back to your statement:

Quote[/b] ]because it's treated as a function:

Now, time to check whether the engine really waits for functions smile_o.gif

Also thanks to dengibtsschon for your thoughts.

VictorFarbau

Share this post


Link to post
Share on other sites

mpinitorder.jpg

I did this a while back to work out the order of events in SP and MP, can't find the original post I made explaining it in detail. But basicly the horizontal scale represents all the different types of init events, addon, mission editor and init.sqf e.t.c The horizontal scale is the order they are called.

The point is, everything starts from 0, as thats function launched from an objects init event. The rest are scripts and functions from various places like a mission editors init field.

Share this post


Link to post
Share on other sites

Finally back from business travels I got around to test this. Be it because called as a function or because the local variable space is updated in realtime - but it works. Only one instance remains in the end and all works fine now. Thanks guys!

I guess I'll wrap one of my functions into an addon now and throw it onto the market for others to use...

Cheers,

VictorFarbau

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×