{"action":"created","issue":{"url":"https://api.github.com/repos/CBATeam/CBA_A3/issues/186","labels_url":"https://api.github.com/repos/CBATeam/CBA_A3/issues/186/labels{/name}","comments_url":"https://api.github.com/repos/CBATeam/CBA_A3/issues/186/comments","events_url":"https://api.github.com/repos/CBATeam/CBA_A3/issues/186/events","html_url":"https://github.com/CBATeam/CBA_A3/pull/186","id":112600129,"number":186,"title":"Adding eventhandlers to classes of units in SQF","user":{"login":"commy2","id":6576312,"avatar_url":"https://avatars.githubusercontent.com/u/6576312?v=3","gravatar_id":"","url":"https://api.github.com/users/commy2","html_url":"https://github.com/commy2","followers_url":"https://api.github.com/users/commy2/followers","following_url":"https://api.github.com/users/commy2/following{/other_user}","gists_url":"https://api.github.com/users/commy2/gists{/gist_id}","starred_url":"https://api.github.com/users/commy2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/commy2/subscriptions","organizations_url":"https://api.github.com/users/commy2/orgs","repos_url":"https://api.github.com/users/commy2/repos","events_url":"https://api.github.com/users/commy2/events{/privacy}","received_events_url":"https://api.github.com/users/commy2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-21T14:19:50Z","updated_at":"2015-11-15T11:39:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/CBATeam/CBA_A3/pulls/186","html_url":"https://github.com/CBATeam/CBA_A3/pull/186","diff_url":"https://github.com/CBATeam/CBA_A3/pull/186.diff","patch_url":"https://github.com/CBATeam/CBA_A3/pull/186.patch"},"body":"This PR adds CBA_fnc_addClassEventhandler.\r\n\r\nIdea behind this:\r\nExtended_xx_Eventhandlers are usefull for addon and mission makers, because they fill a specific niche: Adding eventhandlers to entire classes instead of individual units.\r\nThe SQF scripting command `addEventhandler` unfortunately only works on individual objects (which have to already exist) and the `Eventhandlers` class is often used by BI or addon makers and overwrites an eventhandler already added in, for example `CAManBase`.\r\nExtended_xx_Eventhandlers offers a solution for this, but relies on the addon makers to not overwrite the config entries from CBA too. Eventhandlers that are added by BI have to be recreated using XEH and these classes have to be fixed manually. Sometimes eventhandlers are added in new game versions without the changelog ever mentioning it. (remember the FIA soldiers?)\r\nThis new function adds all eventhandlers in SQF. It does so by polling all entities (`entities \"\"`). It does not need any configs at all and works basically on any mission created object.\r\n\r\nuseage:\r\n[\"CAManBase\", \"fired\", {systemChat str _this}] call CBA_fnc_addClassEventhandler;\r\n[\"All\", \"init\", {systemChat str _this}] call CBA_fnc_addClassEventhandler;\r\n\r\nadvantages:\r\n- no configs need\r\n- way less maintenance needed\r\n- automatically compatible with everything (no auto_xeh needed for incompatible addons)\r\n- cleaner code with less overhead compared to XEH (my opinion)\r\n\r\ndisadvantages:\r\n- polling (auto_xeh does this anyway)\r\n- eventhandlers could be accidently removed with `removeAllEventhandlers`\r\n- no backwards compatibility with XEH\r\n\r\nPolling shouldn't be an issue really. `entities \"\"` takes 0.005896ms (on my machine) and is ~1000x times faster than `allMissionObjects \"\"` (although something seems of with that command). Comparing the arrays is really fast too due to `isEqualTo` being a binary comparision even with a large number of objects present. The order of the entities seems to never change for no reason, so useless iterations shouldn't happen.\r\n\r\nnotes:\r\nDue to the nature of polling, init eventhandlers are called one frame after the object is created. Similar things happen with auto_xeh. This way it at least is predictable behaviour, although the config init eventhandler behaver slightly different.\r\nInit eventhandlers have to be put in init box, XEH_preInit, or a XEH_postInit when the PBO is loaded after this (required addons).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/CBATeam/CBA_A3/issues/comments/156806199","html_url":"https://github.com/CBATeam/CBA_A3/pull/186#issuecomment-156806199","issue_url":"https://api.github.com/repos/CBATeam/CBA_A3/issues/186","id":156806199,"user":{"login":"jonpas","id":7935003,"avatar_url":"https://avatars.githubusercontent.com/u/7935003?v=3","gravatar_id":"","url":"https://api.github.com/users/jonpas","html_url":"https://github.com/jonpas","followers_url":"https://api.github.com/users/jonpas/followers","following_url":"https://api.github.com/users/jonpas/following{/other_user}","gists_url":"https://api.github.com/users/jonpas/gists{/gist_id}","starred_url":"https://api.github.com/users/jonpas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonpas/subscriptions","organizations_url":"https://api.github.com/users/jonpas/orgs","repos_url":"https://api.github.com/users/jonpas/repos","events_url":"https://api.github.com/users/jonpas/events{/privacy}","received_events_url":"https://api.github.com/users/jonpas/received_events","type":"User","site_admin":false},"created_at":"2015-11-15T11:39:15Z","updated_at":"2015-11-15T11:39:15Z","body":"We'll have to update it to 1.54 syntax anyways, because I used `local` in my cargo removal PRs. "}}