ProGEEK

Ability to add event handlers without needing to override Exile core code

5 posts in this topic

I'm developing a script/addon that requires access to the addMissionEventHandler and addEventHandler for when a player is killed or is disconnected/disconnects.

At the moment i need to override ExileClient_object_player_event_hook.sqf to add the following code:
 

player addEventHandler ["Killed", { _this call Epidemic_PlayerKilled; }];

It would be awesome (and easier, plus would result in a smaller mission file) for scripters to have access to a set of functions such as ExileClient_object_player_addEventHandler to add code that would run when a player is created (Bambi or returning player)

Initialization could work such as:

["Killed", { _this call Epidemic_PlayerKilled; }] call ExileClient_object_player_addEventHandler;

which would add the code to an array, then in the ExileClient_object_player_event_hook.sqf file, would loop through and ad the handlers to the player object, such as:

{
  _handler = _x select 0;
  _code = compileFinal (_x select 1);
  player addEventHandler[_handler,_code];
} forEach ExileClientCustomEventHandlers;


Or for Mission handlers, instead of overriding ExileServer_system_process_preInit.sqf to add a HandleDisconnect call:

["HandleDisconnect", { _this call Epidemic_onHandleDisconnect; }] call ExileServer_mission_addEventHandler;

Which would add similar to the following line, executed similar to above:

addMissionEventHandler ["HandleDisconnect", { _this call Epidemic_onHandleDisconnect; }];

So in summary, 5 functions:

  • ExileServer_mission_addEventHandler
  • ExileClient_object_player_addEventHandler
  • ExileClient_object_player_addMPEventHandler
  • ExileServer_object_player_addEventHandler
  • ExileServer_object_player_addMPEventHandler


This would make life so much easier as a scripter, and the Exile team would benefit from less bug reports as they can modify their code and not have bugs reported because server owners have overridden core files.

Just some thoughts as a novice scripter

Edited by ProGEEK
1 person likes this

Share this post


Link to post
Share on other sites
 getText(missionConfigFile >> "CfgCustomEventhandlers" >> "PlayerKilled"

Is it Possible to just add fn_preInit.sqf list of Eventhandlers to check the missionconfigfile like as I show above and if there is a new script or path defined then add that as ProGreek gave an example of?

 

["Killed", { _this call Epidemic_PlayerKilled; }] call ExileClient_object_player_addEventHandler;

 

Just throwing thoughts out there... havent really played around with seeing if it works or anything.

 

Something closer to this?

  if (isText (missionConfigFile >> "CfgCustomEventhandlers" >> "PlayerKilled")) then
    {
        _playerKilled = getText (missionConfigFile >> "CfgCustomEventhandlers" >> "PlayerKilled");
    };


["Killed", {_this call {_x}foreach _playerkilled}] call ExileClient_object_player_addEventHandler;

havent played with calling from config files before so not sure if this is the correct method, but should convey an idea...

Edited by happydayz

Share this post


Link to post
Share on other sites
Advertisement

Only problem i see already is that it would need to check that the file hasnt been overwritten completely first in CfgExileCustomCode before it then adds any custom defined paths...

Share this post


Link to post
Share on other sites

My example won't work out right, needs a few tweaks to have it work right (code will probably need to be passed as a string and have compile or compileFinal run against it), was just there to convey the idea as I'm away from my rig and haven't been able to iron out the exact working code needed. Ideally I wouldn't want to have to define them all in the config as that's more files to modify to add the handlers. My perspective would allow adding the script to the init.sqf and that'd be the end of it, rather than having to add to the init.sqf AND modify the config file as well. Think of my way as a 'drop in' solution, no extra configurations needed. (Nothing worse than trying to add a feature and have to edit alot of files to get it to work)

Share this post


Link to post
Share on other sites

Or how about both? Your code suggestion runs my suggestion in the back end, but the functions are still available to scripters to add the events directly in their code. Let the scripter decide if his or her project uses the config file or direct

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement

  • Recently Browsing   0 members

    No registered users viewing this page.