Jump to content
Sign in to follow this  
Rouen58

Approach to MP Editing

Recommended Posts

Hi guys,

I've started writing my own scripts for my squad missions. I've been researching and found numerous approaches to multiplayer scripting, but I'm looking to use the "multiplayer framework" approach. I need some hints as to whether this approach should work, on the whole.

At the moment I'm making strictly coop missions with squad vs ai, on a dedicated server. Triggers etc. in the editor are great as they run code on all machines, but for scripts the locality issue comes in to play. Also, I don't tend to need scripts running on the squad players, as the majority of scripting is to influence the AI environment (which is local to the server).

My approach:

1) Run all scripts exclusively on server using (isServer).

2) Use the Multiplayer Framework to issue RE commands where I need stuff doing on all client machines

I.e at the moment I have a script that is called from a gamelogic:

if (isServer) then {

// disableai only needs to run on the server

enemy1 disableai "anim";

// playmove needs to run on all clients

[objNull, enemy1, rplaymove, "examplemovesitdown"] call RE;

};

Later on, a similar script is called from an eventhandler:

if (isServer) then {

// enableai only needs to run on the server

enemy1 enableai "anim";

// End current move. Playmove needs to run on all clients

[objNull, enemy1, rplaymove, ""] call RE;

};

Is this a sound basis going forward, i.e run ALL Scripts on the server and then cherrypick what needs to be run on the clients?

It's difficult at the moment to test missions as uploading a mission to our server, starting it and then checking if little bits work (and if they don't, repeating the proccess) is very time consuming.

Share this post


Link to post
Share on other sites

Thanks Demonized,

Does this mean I can start a dedi server and then start a normal ARMA 2 session and connect to the server, without owning 2 copies of the game?

Share this post


Link to post
Share on other sites
Thanks Demonized,

Does this mean I can start a dedi server and then start a normal ARMA 2 session and connect to the server, without owning 2 copies of the game?

Yes it works well.

Share this post


Link to post
Share on other sites

Brilliant,

Up and running.

However, heartbroken that my mission is pretty much broken on dedi server :-(

Is there a way to show script errors on DS?

Thanks

Share this post


Link to post
Share on other sites

Thanks, the rpt file is longer than my thesis! : - O n00b coding skills

---------- Post added at 16:10 ---------- Previous post was at 15:04 ----------

Ok sorted the scripts, everything working OK!

Except my titletext isn't working - anyone know the remote execution call I need to make for title text?

Thanks

Share this post


Link to post
Share on other sites

Also,

When a script is executed by a human player on dedicated server from an "add action" attached to a vehicle local to the server, how do I switch out of the local machine and get code to run on the server?

Last nights mission I had:

1) an addaction running a script that set a variable to true, and then publicvariabled it

2) In game I had a trigger waiting for this variable to become true, and on activation it executed code that ran on the server.

Does public variable event handler work on both server and client sides? How could I get the client to trigger some code to run on the server?

Share this post


Link to post
Share on other sites

On the server you would do:

"myVar" addPublicVariableEventHandler {
   private ["_newVal"];
   _newVal = _this select 1;
   //Do whatever here, eg.:
   hint format ["MSG: %1", _newVal];
};

The above code would run on any machine where you added the handler when you public var something.

On a client for example:

myVar = "Important information here";
publicVariable "myVar";

Share this post


Link to post
Share on other sites

Sweet :-)

I'm building up a picture of MP editing now.

So on server, use remote execution for player based actions (i.e sideradio or hint).

On client, make a global variable public and catch it with a publicvariableeventhandler.

Where would the server side catch go? Do I whack it in a script and then call that script at the start of the game from the init? And does that script subsequently just "wait" until the public variable is "caught"?

Muzzleflash, Sickboy, Pelham and Demonized - thanks

Edited by regulator86

Share this post


Link to post
Share on other sites

Yes you would use the addPublicVariableEventHandler in your init or likewise in an:

if (isServer) then {
   "myVar" addPublicVariableEventHandler {
   private ["_newVal"];
   _newVal = _this select 1;
   //Do whatever here, eg.:
   hint format ["MSG: %1", _newVal];
   };  
};

Also publicVariable isn't an one time thing. You can change it afterwards and publicVar it again:

myVar = "First Msg";
publicVariable "myVar";  
//... later
myVar = "Second Msg";
publicVariable "myVar";

You might want to consider using CBA instead since handle most of "lower level" stuff for you. Heres the same using CBA:

["msg_received", {
   hint format ["MSG: %1", _this select 0];
}] call CBA_fnc_addEventHandler;

And "activate" it:

["msg_received", ["My Message"]] call CBA_fnc_globalEvent;

There are reasons why this would be considered better:

- More high level.

- If you add a publicVariableHandler on machine A and then publicVar something on A, then the handler is NOT run for A but is run for all others. No such issues using CBA.

- Only uses one global variable. If you have to set up 2 different things using publicVariable you will have to use 2 global variables. CBA only uses 1 internally.

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

Awesome... Will give CBA a go and read up the documentation.

Do I need it initalise CBA in my init (I have it installed already) or is it automatically included if it's in my commandline

Thanks Muzzleflash!

Share this post


Link to post
Share on other sites

In terms of neatness and de-cluttering, is it ok to have multiple pveh sitting in "init.sqf" waiting for client-side actions to call them? Will it have impact in terms of performance?

Is it preferable to call a seperate script from the init.sqf once the variable is made public, or can the code go directly in the init.sqf?

Funny thing is, I have a 2:1 B.Sc in Computing Science from a top 20 UK uni (but by some twist of fate, ended up working in finance after I graduated). I hated every minute of my studies.

I could never get my head around Java, which was core to my degree - I passed by memorising long chunks of code for exams, and just working extra hard on coursework.

Yet ARMA 2 is making me enjoy coding for the first time in my life.

Share this post


Link to post
Share on other sites

Very interesting thread!

Since I'm trying to get back into this stuff I visited the CBA docs but could not find any demos or similar? Does anyone know if there exists some simple "bare bones" missions showing of some of what CBA can do in terms of making things easier when scripting for MP?

/KC

Share this post


Link to post
Share on other sites

@KeyCat

I've made some missions which make use of CBA (and also XEH in description.ext).

Might not be the best show case missions and they ACE and ACRE too but you should get the idea how it works.

The mission pack can b downloaded here:

http://dl1.armed-assault.de/a2oa/mishuns/mp/tacsat_mp190811.7z

(Please not not all of them are from me and all missions are missions without respawn, check for example ts_co@32_NightsIWS_1_02.Chernarus or ts_co@32_Hill_367_1_02.Chernarus or ts_co@32_One_1_01.Celle, etc).

Xeno

Share this post


Link to post
Share on other sites

Thanks Xeno, I will take a closer look this weekend and try to "dechiper" the German ;)

Looking at the CBA docs you guys have been busy, some of the stuff is still above my head but what I can tell there is lot's of good stuff in there....

Thanks for making and sharing (and that goes to everyone involved)!

/KC

Share this post


Link to post
Share on other sites
Thanks Xeno, I will take a closer look this weekend and try to "dechiper" the German ;)

Yeah, the missions were made for german events :D

Though I think it is quite easy to understand how the CBA stuff works.

Xeno

Share this post


Link to post
Share on other sites

Maybe someone can help me with this. I have been trying to understand PVEHs. I found this thread and thought I would try the cba functions. What I am trying to do is setcurrenttask for all players. I have it working using PV and triggers, but I would like to use less PVs and triggers.

I have tried this


["tasks", {
  player setcurrenttask (_this select 0)];
}] call CBA_fnc_addEventHandler;   


//I also tried this  ["tasks", {
 { _x setcurrenttask (_this select 0)} foreach playableunits;];
}] call CBA_fnc_addEventHandler;   


Whenever I have a task change:
["tasks", ["MYtaskname"]] call CBA_fnc_globalEvent;  

I put the CBA_fnc_addEventHandler in my init.sqf and it kicks out errors. I have also tried combinations of PVEH and so far no luck with anything. I know there is a simple solution but it seems to be eluding me.

I have managed to get this to do what I was looking for. threw up on a server using Tophes dedicated server tool and it seems to work


[-2,{{_x setcurrenttask Task_sweep} foreach playableunits;}] call CBA_fnc_globalExecute;

Thanks

Nomadd

Edited by Nomadd

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  

×