dbun30 2 Posted October 7, 2020 Hi all. Does anyone have any idea how to make a script to save the game after specific number of enemy kills? For example.. after 10 enemies killed automatically save the game. Or maybe this...after some random time that has passed, save the game. For example...between 1 and 10 minutes randomly save the game. Thanks. Share this post Link to post Share on other sites
stanhope 409 Posted October 7, 2020 Combine https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Killed with a function that's something along the lines of: someFncName = { someGlobalVar = someGlobalVar + 1; if (someGlobalVar % 10 == 0) then { //save game }; }; 2 Share this post Link to post Share on other sites
wogz187 1085 Posted October 7, 2020 @dbun30, Like this, Spoiler after 10 enemies killed automatically, YOU_fnc_killCount= { params [["_caller]]; private _count = _caller getVariable ["you_killCount", 0]; if (_count> 10) then {_caller setVariable ["you_killCount", 0]; savegame;}; _caller setVariable ["you_killCount", _count +1]; }; Make sure the bad guys have a killed EH, this addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; _killer call you_fnc_killCount; }]; After random time, YOU_fnc_saveTimer= { private _rNumber = random 600; private _time = time + _rNumber; [_time] spawn { waitUntil {sleep 1; time> (_this select 0)}; savegame; }; }; [] spawn you_fnc_saveTimer; Will save at maximum 10 minutes Have fun! 1 Share this post Link to post Share on other sites
dbun30 2 Posted October 7, 2020 Thanks guys, i did some testing...but nothing works. Can you explain where to put this code: YOU_fnc_killCount= { params [["_caller]]; private _count = _caller getVariable ["you_killCount", 0]; if (_count> 10) then {_caller setVariable ["you_killCount", 0]; savegame;}; _caller setVariable ["you_killCount", _count +1]; }; And where to put this code: this addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; _killer call you_fnc_killCount; }]; Im playing a mission where units are spawned randomly after mission start, so i can't put any code into individual units in editor. Share this post Link to post Share on other sites
wogz187 1085 Posted October 7, 2020 @dbun30, Spoiler YOU_fnc_killCount= { params [["_caller]]; private _count = _caller getVariable ["you_killCount", 0]; if (_count> 10) then {_caller setVariable ["you_killCount", 0]; savegame;}; _caller setVariable ["you_killCount", _count +1]; }; You can paste this in init.sqf, Attributes init dialog, a units init-- pretty much anywhere code will stick; it just has to be loaded. Quote ... units are spawned randomly after mission start, so i can't put any code into individual units in editor. You can add the event handler in the summon unit script or just apply it to the group after they are spawned. Spoiler { _x addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; _killer call you_fnc_killCount; }]; } forEach units _grp; Have fun! 1 Share this post Link to post Share on other sites