tortuosit 486 Posted April 22, 2017 Hi guys, the old story - the joys of surviving a savegame. There are some tricks with diag_ticktime, but it takes more time to understand... cannot afford. Devbranch here. I've got the below code in an init.sqf, very much at start of a mods code. I have checked the variable handle1, it is existing and set to 5. I am expecting to see the below message "Music re-init done" in systemchat area after loading the mission from a savegame, but no message appears. EDIT: Looks like it never worked. EDIT2: https://feedback.bistudio.com/T124597 handle1 = addMissionEventHandler ["Loaded",{systemchat "Music re-init done."}]; Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted March 27, 2019 On 4/22/2017 at 1:53 PM, tortuosit said: EDIT: Looks like it never worked. Hello there tortuosit ! I was facing a problem with the : displayAddEventHandler["KeyDown" in SP and MP once i was closing the server ( with a save ) then entering again the script was not running . So i tried with the EH and it's working. Both for spawn or execVM. addMissionEventHandler ["Loaded", { params ["_saveType"]; If(_saveType isEqualto "continue") then{ [] execVM "GF_Holster\GF_Holster.sqf"; }; }]; [] execVM "GF_Holster\GF_Holster.sqf"; How did you tried this ? because i tried also your simple example and it seems that it's not working this way. tortuosit: Spoiler // I have added this to a mods init.sqf: handle1 = addMissionEventHandler ["Loaded",{systemchat "BLAH"}]; Share this post Link to post Share on other sites
Vandeanson 1677 Posted December 7, 2019 hi george, I tried to apply this, but however i do it, it seems that Restarting a SP game will multiplicate my keydown eventhander. after a restart, the Eventhandler will fire twice. init.sqf addMissionEventHandler ["Loaded", { params ["_saveType"]; If(_saveType isEqualto "continue") then{ [] execvm "\VDA\VD_Script_Pack\Functions\fnc_VA_addKeyF.sqf"; }; }]; [] execvm "\VDA\VD_Script_Pack\Functions\fnc_VA_addKeyF.sqf"; fnc_VA_addKeyF.sqf if (!hasinterface) exitwith {}; findDisplay 46 displayAddEventHandler ["KeyDown", { params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"]; if ((_this select 1) == 20) then { systemchat "T pressed"; [] spawn fnc_VABB_addactions; }; } ]; No idea why it can do this.. any clue? Cheers VD Share this post Link to post Share on other sites
killzone_kid 1330 Posted December 8, 2019 7 hours ago, Vandeanson said: init.sqf init.sqf happens after preinit so it naturally will be too late as loading of game save happens before that. Both the feedback ticket and documentation have the suggestion on how to use this event handler 1 Share this post Link to post Share on other sites
pierremgi 4862 Posted December 8, 2019 I'm using a pre-init cfg Function I named EH_loaded then in sqf: Spoiler addMissionEventHandler ["Loaded", { params ["_saveType"]; [] spawn { waitUntil {!isNull player}; enableEnvironment [false, true]; private _stamina = "stamina" call BIS_fnc_getParamValue; player enableStamina ([false,true] select _stamina); if (_stamina == 0) then {player setCustomAimCoef 0}; }; if (_saveType == "continue") then { removeMissionEventHandler ["Loaded",_thisEventHandler]; }; }]; That seems to work for managing stamina and mainly custom aim coef, which was always lost. The bad thing is when I open a new scenario (new mission), the sqf is now missing and throws an error. Nothing really bad but I'd like to avoid that. Is there anything to do for terminating pre-init functions and start a new scenario without this error? Tks Share this post Link to post Share on other sites
Vandeanson 1677 Posted December 8, 2019 (edited) 2 hours ago, killzone_kid said: init.sqf happens after preinit so it naturally will be too late as loading of game save happens before that. Both the feedback ticket and documentation have the suggestion on how to use this event handler Thank you. I have tried everything described there also before (to my best knowledge), below version should include all the suggestions from the feedback ticket and the documentation. The mission EH "load" is working. Spoiler fnc_VA_KeydownEH = { waituntil {!isnull (finddisplay 46)}; if (!isnil "VA_keydown_ID") then {(findDisplay 46) displayRemoveEventHandler ["KeyDown", VA_keydown_ID];}; VA_keydown_ID = [] spawn { VA_keydown_ID = findDisplay 46 displayAddEventHandler ["KeyDown", { params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"]; if ((_this select 1) == 20) then { systemchat "T pressed"; hint formatText ["%1",VA_keydown_ID]; }; } ]; }; }; addMissionEventHandler ["Loaded", { params ["_saveType"]; If(_saveType isEqualto "continue") then{ [] spawn fnc_VA_KeydownEH; }; }]; [] spawn fnc_VA_KeydownEH; However, my displayeventhandler still gets duplicated on SP restart, at SP restart, VA_keydown_ID gets assigned the next ID (0,1,2,...). now the keydown EH ID 0 and 1 are fired at keydown. I believe that my issue is that I do not understand how the displayeventhandler gets saved, I do not understand why the previous displayeventhandler persists through the SP restart. Is it because I finddisplay 46 remains true in that case (SP restart) and the displayeventhandler is saved to display # 46? how would I reset that? EDIT: this does not happen in MP btw - no duplication. Cheers VD Edited December 8, 2019 by Vandeanson this issue does not appear on MP Share this post Link to post Share on other sites
killzone_kid 1330 Posted December 8, 2019 I think there is a bug with UI event handlers that do not get removed from display or something when you load from save 1 Share this post Link to post Share on other sites
Dedmen 2703 Posted December 10, 2019 On 12/8/2019 at 10:16 AM, killzone_kid said: I think there is a bug with UI event handlers that do not get removed from display Would make me happy if there was a ticket with repro :3 Share this post Link to post Share on other sites
pierremgi 4862 Posted May 5, 2022 For some reason, my addMissionEventHandler "loaded" works in SP but not in MP. I tested it on a very basic mission (just a player on Stratis, no mod, no script) So, Mission.sqm is very light: Spoiler version=54; class EditorData { moveGridStep=1; angleGridStep=0.2617994; scaleGridStep=1; autoGroupingDist=10; toggles=1; class ItemIDProvider { nextID=2; }; class Camera { pos[]={1743.3146,36.526146,5685.0508}; dir[]={0,-0.70710683,0.70710683}; up[]={0,0.70710677,0.70710677}; aside[]={0.99999994,0,0}; }; }; binarizationWanted=0; sourceName="aaa%20EH%20loaded"; addons[]= { "A3_Characters_F" }; class AddonsMetaData { class List { items=1; class Item0 { className="A3_Characters_F"; name="Arma 3 Alpha - Characters and Clothing"; author="Bohemia Interactive"; url="https://www.arma3.com"; }; }; }; randomSeed=1388757; class ScenarioData { author="PierreMGI"; }; class CustomAttributes { class Category0 { name="Scenario"; class Attribute0 { property="EnableDebugConsole"; expression="true"; class Value { class data { class type { type[]= { "SCALAR" }; }; value=2; }; }; }; nAttributes=1; }; }; class Mission { class Intel { timeOfChanges=1800.0002; startWeather=0.30000001; startWind=0.1; startWaves=0.1; forecastWeather=0.30000001; forecastWind=0.1; forecastWaves=0.1; forecastLightnings=0.1; year=2035; month=7; day=6; hour=12; minute=0; startFogDecay=0.014; forecastFogDecay=0.014; }; class Entities { items=1; class Item0 { dataType="Group"; side="West"; class Entities { items=1; class Item0 { dataType="Object"; class PositionInfo { position[]={3321.6997,176.61656,4915.687}; }; side="West"; flags=7; class Attributes { isPlayer=1; }; id=1; type="B_Soldier_A_F"; }; }; class Attributes { }; id=0; }; }; }; Of course, I also built a description.ext for a function with preInit, like this: author = "Pierre MGI"; onLoadName = ""; onLoadMission = ""; overviewPicture = ""; loadScreen = ""; enableDebugConsole = 2; respawnonstart = -1; class CfgFunctions { class MGI { class test { class EhLoading {preinit = 1;}; }; }; }; The function (fn_EhLoading.sqf) is recorded into functions\test subfolder from root, so there is no problem with that. fn_EhLoading.sqf : systemChat " THE FUNCTION for EH is OK "; diag_log " THE FUNCTION for EH is OK "; //removeAllMissionEventHandlers "loaded"; addMissionEventHandler ["loaded",{ params ["_saveType"]; diag_log "<<<<<<<<<<<< inside EH loaded >>>>>>>>>>>>"; [] spawn { sleep 3; systemChat "<<<<<<<<<<<< inside EH loaded >>>>>>>>>>>>"; hint "<<<<<<<<<<<< inside EH loaded >>>>>>>>>>>>"; player setDamage 0.7 }; }]; Then I export the mission to SP and MP in editor, creating the pboed file as usual. When I run the mission (only one PC), that works fine in SP: - I can see systemChat and diag_log "The function for EH is OK" at first launch, - then saving, resuming the mission, the EH fires and the player is hurt. So far, so good. When I run the mission in MP (as hosted only): - I can see systemChat and diag_log "The function for EH is OK" at first launch, - then saving, resuming the mission (immediately or closing Arma and restarting), there is no way to read any <<< inside EH loaded >>>> and the player is not hurt. Perhaps, I'm missing something but this EH is not easy to work. Help please. Share this post Link to post Share on other sites