Bandicoot 0 Posted January 10, 2009 Hi, I hope someone can help me with this one. I'm having troubles creating a way when a unit(blufor/opfor) fires a weapon and a nearby civilian will flee in a random 100 mtrs direction. Â I'm using an eventhandler as a condition to set the ball rolling. Example: Init field of unit firing: this addEventHandler ["fired",{_this execVM "flee.sqf"}] Flee.sqf file: Quote[/b] ]_unit = _this select 0; _list = position _unit nearObjects 25; {if (side _x == civilian) then {_x domove [(getpos _x select 0)+(Random 100 - (random 100)),(getpos _x select 1)+(Random 100 - (random 100)),0]}}foreach _list; if (true) exitWith {}; This does work in SP setup, but the MP Dedicated server setup it doesn't. Â I think its to do with the AI not being a client controlled thing, but I 'm lost otherwise. Btw I had used "this Allowfleeing 1" and this just makes the AI go to one location in town in this example. Â You end up with a huddle of civilians instead of fleeing the fire zone. Share this post Link to post Share on other sites
johnnyboy 3789 Posted January 10, 2009 I believe the Fired event handler is local, and you may need to run your script on the server only. Here's a thread that tells you how to use the PublicVariable command to call function that runs everywhere (server and all clients): http://www.ofpec.com/forum/index.php?topic=32741.0 Using that technique you could call your civilian scatter function. Then add the following line at the top of your scatter function so it only runs on the server: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (!isServer) exitWith {} I have been struggling with MP issues myself lately on the Molotov cocktail scripts. It's a royal b*tch sometimes. I don't know for sure if this will work for you, but its worth a try. Good luck. Share this post Link to post Share on other sites
Bandicoot 0 Posted January 13, 2009 Still no luck, Â this is what I've tried in trying to understand Publicvariable of this kind in MP. Init.sqf: Quote[/b] ]"Unit_flee" addPublicVariableEventHandler { _unit = _this select 1; {_x domove [(getpos _x select 0)+(Random 100 - (random 100)),(getpos _x select 1)+(Random 100 - (random 100)),0]}foreach _unit; }; Unit's Init: Quote[/b] ]this addEventHandler ["fired",{_this execVM "flee.sqf"}] Flee.sqf: Quote[/b] ]_unit = _this select 0;_list = position _unit nearObjects 25; _Unit_flee = []; {{if (side _x == civilian) then {_Unit_flee = _Unit_flee + [_x]}}}foreach _list ; {if (side _x == civilian) then {_x domove [(getpos _x select 0)+(Random 100 - (random 100)),(getpos _x select 1)+(Random 100 - (random 100)),0]}}foreach _list; Unit_flee = _Unit_flee; publicVariable "Unit_flee"; as per this Example. Regards, Bandicoot Share this post Link to post Share on other sites
Bandicoot 0 Posted January 14, 2009 Finally, for the record a working example. Init.sqf: Quote[/b] ]Fired_Gun_handler = {_this exec "fleeCiv.sqf" }; Fired_Gun addPublicVariableEventHandler { [((_this select 1) select 0)] call Fired_Gun_handler }; Unit Init or make a trigger for all units: Quote[/b] ]this addEventHandler ["fired",{_this execVM "flee.sqf"}] Flee.sqf: Quote[/b] ]_unit = _this select 0; Fired_Gun = _unit; //hint format["Flee.sqf fired eventhandler  %1",Fired_Gun]; Publicvariable "Fired_Gun"; Fired_Gun call Fired_Gun_handler; if (true) exitWith {}; FleeCiv.sqf: Quote[/b] ]_unit = Fired_gun; Hint format["%1\n Fired gun.",_unit]; _list = position _unit nearObjects 25; {if (side _x == civilian) then {_x domove [(getpos _x select 0)+(Random 100 - (random 100)),(getpos _x select 1)+(Random 100 - (random 100)),0]}}foreach _list; Fired_gun= nil; publicVariable "Fired_gun"; if (true) exitWith {}; Fired_gun variable was where I was having issues in "FleeCiv.sqf", I had it as "_unit = _this select 0;". I hope this helps someone else as another example for addPublicVariableEventHandler usage. Thank you for reading. Bandicoot Share this post Link to post Share on other sites
johnnyboy 3789 Posted January 14, 2009 Bandicoot, thanks for posting the working example (and in a very easy-to-follow fashion). That is key to saving others time in the future. Nice work. In your case, civilians fleeing is probably a one time only (infrequent event), so this solution works great for that. In a case I'm working on, I need to process multiple fired eventhandlers. Since these may occur simultaneously, I think its possible that the FiredGun global variable can get overwritten before its used by the called script, and have unintended consequences (i.e., passing parameters intended for one occurrence of the script to a different occurrence of the script). This is just a warning for those handling repeated events that may occur simultaneously... I'm not sure what the solution is, as I am still an MP handling noob... Share this post Link to post Share on other sites
Bandicoot 0 Posted January 15, 2009 In your case, civilians fleeing is probably a one time only (infrequent event), so this solution works great for that.In a case I'm working on, I need to process multiple fired eventhandlers. Â Since these may occur simultaneously, I think its possible that the FiredGun global variable can get overwritten before its used by the called script, and have unintended consequences (i.e., passing parameters intended for one occurrence of the script to a different occurrence of the script). This is just a warning for those handling repeated events that may occur simultaneously... Â I'm not sure what the solution is, as I am still an MP handling noob... No, Â its repeatable. Â The last part for "FleeCiv.sqf", says Fired_gun= nil; publicVariable "Fired_gun"; So that means the variable is ready again to make known if a new unit is firing a shot. Â Plus the eventhandler "Fired" is a repeatable event. Â A lot of the times too the Civilians will drop prone before moving, which I think can be a realism factor before running off. Â I don't think its a big issue the simultaneously part as the civilians will go prone first in most cases. I have a demo on my server and I'll make a link to download a copy of the mission. Â So in a busy town with bluefor and Opfor firing in town some civilians may get caught in the cross fire which is what I wanted to happen. Demo_Fleeing_Civilians.Intro.zip Regards, Bandicoot Share this post Link to post Share on other sites
Jex =TE= 0 Posted February 10, 2009 This is brilliant. Thanks for posting up the detail on how to implement this script - this should be an SOP here at BI as it helps out so much - not just in allowing less experienced mission designers to implement things like this with ease but it's also an invluable learning tool - Thanks to you I now have a grasp on event handlers and how they work so today I took another step forward in scripting. Many thanks Share this post Link to post Share on other sites