bendy303 4 Posted October 4 Hi... I keep losing the team colours of my AI units after they go unconcious.... I thought if I can add an eventHandler to monitor player command input, I can store the colour to a variable, then recall it after revive. This link here is overwhelming:https://community.bistudio.com/wiki/User_Interface_Event_Handlers help appreciated cheers Bendy Share this post Link to post Share on other sites
soldierXXXX 107 Posted October 4 Hi, Bendy, handling such system through UIEH would be really hard. Fortunately we have also user eventhandlers that can do all sorts of things. I prepared a quick example code that should be able to do what you need. But multiplayer scripting is not my cup of tea if you understand. Maybe you would also need to add functionality that would handle respawning, adding units to your group and so on. I hope that this code could help you at least a little bit. 🙂 Spoiler /* function that restores assigned team color when unit gets unconcious, it is also an example how to handle actions from command menu with eventhandlers Might slightly affect FPS, because it's checked every time unit changes animation. if Bohemia would add unconcious eventhandler, that would be great Also i'm not sure if addUserActionEventHandler is persistent or needs to be added every time player respawns-check yourself */ //===================== //handlers for team assinging-key interaction { addUserActionEventHandler [_x, "Activate", { if (groupSelectedUnits player isEqualTo []) exitWith {}; hint "you assigned team color by key"; [] spawn soldierXXXX_fnc_assignTeam; }]; } forEach ["SetTeamRed","SetTeamGreen","SetTeamBlue","SetTeamYellow","SetTeamWhite"]; //handler for team assigning-menu interaction addUserActionEventHandler ["ActionContext", "Activate", { if (commandingMenu isEqualTo "RscTeam") then { hint "assigned by menu"; [] spawn soldierXXXX_fnc_assignTeam; }; }]; //function that assigns team color soldierXXXX_fnc_assignTeam = { scriptName "soldierXXXX_fnc_assignTeam"; sleep 0.001;//needs a little pause for changes to be applied if ((commandingMenu isEqualTo "RscSelectTeam")) exitWith {}; { private _color = assignedTeam _x; _x setVariable ["pickedTeamColor",_color,TRUE];//team color is now saved in object variable "pickedTeamColor" } forEach units group player; { systemChat str assignedTeam _x; } forEach units group player; }; //==================== //Handling unconcious soldierXXXX_fnc_addIncHandler = { params ["_unit"]; _unit addEventHandler ["AnimStateChanged", { params ["_unit", "_anim"]; if (!alive _unit) exitWith {}; if (lifeState _unit isEqualTo "INCAPACITATED") then { hint ("unit:" + str _unit + "is incapacitated"); [_unit] call soldierXXXX_fnc_addRevHandler; _unit removeEventHandler [_thisEvent,_thisEventHandler]; }; }]; }; soldierXXXX_fnc_addRevHandler = { params ["_unit"]; _unit addEventHandler ["AnimStateChanged", { params ["_unit","_anim"]; if (!alive _unit) exitWith {}; if (lifeState _unit isNotEqualTo "INCAPACITATED") then { [_unit] spawn soldierXXXX_fnc_restoreTeamColor; [_unit] call soldierXXXX_fnc_addIncHandler; _unit removeEventHandler [_thisEvent,_thisEventHandler]; }; }]; }; soldierXXXX_fnc_restoreTeamColor = { params ["_unit"]; private _color = _unit getVariable ["pickedTeamColor","MAIN"]; _unit assignTeam _color; systemChat ("color restored for " + str _unit); }; { [_x] call soldierXXXX_fnc_addIncHandler; } forEach units group player; 1 Share this post Link to post Share on other sites