Comrades in Arms Discussion Board
AddMPeventhandler help needed. - Printable Version

+- Comrades in Arms Discussion Board (http://forum.ciahome.net)
+-- Forum: Comrades in Arms Life (http://forum.ciahome.net/forumdisplay.php?fid=3)
+--- Forum: Mission Making (http://forum.ciahome.net/forumdisplay.php?fid=8)
+--- Thread: AddMPeventhandler help needed. (/showthread.php?tid=2097)



AddMPeventhandler help needed. - Bubba - 10-18-2011

Okay, so I'm trying to create a Simple script to keep an eye on the players ROE. So I'm trying to create
an MPEventhandler with the command "AddMPEventHandler".

And I've understood that the script should look something like this (correct??):
grp addmpeventhandler ["killed", text "a friendly has died"]

Where; grp is an variable which consists of an array of all of the friendlies. (Can it be used this way, or do I need to use it "foreach"?)

But how can I make it so, that when one unit out of a certain array of units kills one out of another array, it gives a text and then ends the mission?


Re: AddMPeventhandler help needed. - Zwobot - 10-18-2011

No to multiple things:
Quote:grp addmpeventhandler ["killed", text "a friendly has died"]
1. with addMPEventHandler you have to use the corresponding eventhandler types, so instead of "killed" you have to use "MPKilled", see biki for reference.
2. grp has to be the name of the unit you want to add the eventhandler to or you have to use something like:
Code:
{_x addMPEventHandler ["MPKilled", _this execVM "killed.sqf"]} forEach allUnits;
This will add the eventhandler to all units present in the mission; allUnits in the biki.

I suggest you start with a more simple setup for your mission because I can tell you that scripting multiplayer missions is particularly complicated to get right. Start with basic attack/defend missions with minimal scripting and work your way up from there.


Re: AddMPeventhandler help needed. - Bubba - 10-18-2011

yeah, I guess I should, though I've done missions which have been a bit more complicated! Tongue And to be honest, this thing is not used in most of the missions available. I mean a Script that watches is a friendly has been killed. So why should I go the hard way! Big Grin

I think I'll do the mission just without the thingy. Tongue


Re: AddMPeventhandler help needed. - Pulverizer - 10-29-2011

Something like

groupA = [guy1, guy2];
groupB = [civ1, civ2, civ3];
ROEhandler = { if(_this select 1 in groupA) then {activateMyEndTrigger=true; hint format [{%1 killed a civ and the mission will now end.}, _this select 1];} else {hint {A civilian has died!};};};

{_x addMPeventhandler [{MPKilled}, {foo=_this call ROEhandler;}]} foreach units groupB;

Then make a trigger that ends the mission with condition activateMyEndTrigger with some time delay so you can actually read the hint message.


Re: AddMPeventhandler help needed. - Bubba - 10-30-2011

Is this MP compatible if I just make the variables public?


Re: AddMPeventhandler help needed. - Pulverizer - 10-31-2011

Running that script in init.sqf or some init line should be enough.

I assume MPeventhandlers only trigger where the unit is local but the code string is executed on all machines.


Re: AddMPeventhandler help needed. - Bubba - 10-31-2011

Okay, thanks for all the help!  Wink


Re: AddMPeventhandler help needed. - Overlord - 11-01-2011

Something like This?


Re: AddMPeventhandler help needed. - Pulverizer - 11-04-2011


On another thought, this will probably not work because _this might not be transmitted as an array but as a code string from the eventhandler. So the clients will be all like "hey what's _this supposed to be?  ???" Big Grin

Changing the handler like this might work:
{_x addMPeventhandler [{MPKilled}, format [{foo=%1 call ROEhandler;}, _this]]} foreach units groupB;


Re: AddMPeventhandler help needed. - Overlord - 11-18-2011

How's this project going Bubba?


Re: AddMPeventhandler help needed. - Bubba - 11-21-2011

It has been, sadly enough (once again), been postponed due to school and other life.

As you may have noticed, I haven't even been able to join most of the the coop nights lately.
But this is to what I'll return to when I'm able to continue!

Thanks again for the help so far!