jarni 2 Posted May 3, 2020 Hello community. For my singleplayer mission I've created several script which run in background and do different stuff periodically. 2 out of 3 works just fine if I do Save&Load. But one is not restarted after loading game. The scripts spawn group from current "spawn level". The spawn coordinates are hard-coded in Altis's Kavala. "Seek&Destroy" WP added to group. WP is located on player. To check script: 1. Run in editor 2. Add player somewhere in Kavala with radio in inventory (logs are done through sidechat) 3. Wait a few update intervals (15 s) to see that script periodically checks the conditions for spawn 4. Save, wait, load and see that script still works 5. Set through debug console the "sad_level" variable in mission namespace to 1, this enabled first spawn level 6. Wait till next update interval that script spawned group. 7. Wait a few update intervals and see that group's WP is updated with player's current position 8. Save&Load 9. No more WP updates happen, no more "[SADs] Loop" messages, nothing By commenting different parts of the script I found out that the problem is with "_group = call _level_script;" line. But I don't get why and how I can work around it. Spoiler //! This script manages Seek&Destroy troops //! Once in 5 minutes it makes following decisions //! 1. If SAD group already exist, reroute it to player //! 2.1. If there is no active SAD group, spawn one //! 2.2. What to spawn (offroad, tank, helicopter) //! 2.3. How many to spawn (min 1, max 3) private _LOG_TYPE = "sad_log"; private _LOG_DBG = 0; private _LOG_INF = 1; private _sad_log = { params [["_log_type", "global"], ["_severity", -1], ["_format", [], []]]; private _level = missionNamespace getVariable [_log_type, 0]; if (_severity >= _level) then { player sideChat format _format; }; }; missionNamespace setVariable [_LOG_TYPE, _LOG_DBG]; missionNamespace setVariable ["sad_enabled", true]; missionNamespace setVariable ["sad_counter", 0]; missionNamespace setVariable ["sad_group", grpNull]; missionNamespace setVariable ["sad_level", 0]; missionNamespace setVariable ["sad_use_stalk", false]; missionNamespace setVariable ["sad_loop_interval", 15]; missionNamespace setVariable ["sad_loop_count", 12]; [_LOG_TYPE, _LOG_INF, ["[SADs] Starts"]] call _sad_log; private _loopCounter = 0; while {true} do { private _use_stalk = missionNamespace getVariable ["sad_use_stalk", false]; private _loop_interval = missionNamespace getVariable ["sad_loop_interval", 15]; private _loop_count = missionNamespace getVariable ["sad_loop_count", 12]; [_LOG_TYPE, _LOG_DBG, ["[SADs] Loop (%1)", str _loopCounter]] call _sad_log; _loopCounter = _loopCounter + 1; private _levels = missionNamespace getVariable "sad_levels"; if (isNil "_levels") then { [_LOG_TYPE, _LOG_DBG, ["[SADs] No levels. Making..."]] call _sad_log; //! Spawns one quad bike with crew private _spawner = { private _sad_group = createGroup east; _this = _sad_group; private _sad_group_v_1 = createVehicle ["O_G_Quadbike_01_F",[3744.39,13411.3,0],[],0,"CAN_COLLIDE"]; _this = _sad_group_v_1; _this setPosWorld [3744.39,13411.3,12.217]; _this setVectorDirAndUp [[0.842799,-0.538225,0.00173237],[0.00134403,0.00532322,0.999985]]; [_this,"[[[[],[]],[[],[]],[[""FirstAidKit""],[4]],[[],[]]],false]"] call bis_fnc_initAmmoBox; private _sad_group_v_1D = _sad_group createUnit ["O_G_Soldier_F",[3744.39,13411.3,0],[],0,"CAN_COLLIDE"]; _sad_group selectLeader _sad_group_v_1D; _this = _sad_group_v_1D; _this setPosWorld [3744.07,13411.5,11.7001]; _this setVectorDirAndUp [[0.842799,-0.538225,0.00173237],[0.00134403,0.00532322,0.999985]]; _this setRank "SERGEANT"; _this setname "Sotiris Papadopoulos";; _this setface "GreekHead_A3_02";; _this setspeaker "Male06GRE";; _this setpitch 0.98;; private _g_sad_group_u_1 = _sad_group createUnit ["O_G_Soldier_F",[3744.39,13411.3,0],[],0,"CAN_COLLIDE"]; _this = _g_sad_group_u_1; _this setPosWorld [3743.77,13411.7,11.6542]; _this setVectorDirAndUp [[0.842799,-0.538225,0.00173237],[0.00134403,0.00532322,0.999985]]; _this setname "Adam Strambopoulos";; _this setface "Mavros";; _this setspeaker "male03gre";; _this setpitch 1.0257;; _this = _sad_group; [_this,0] setWaypointPosition [position leader _this,0]; _this setGroupID ["Alpha 1-1"];; _this setCombatMode "RED"; _this setBehaviour "SAFE"; _this setSpeedMode "NORMAL"; _this deleteGroupWhenEmpty true; _sad_group_v_1D moveInDriver _sad_group_v_1; _g_sad_group_u_1 moveInCargo [_sad_group_v_1,0]; _sad_group }; //! Store spawners for level _levels = []; _levels set [0, []]; _levels set [1, [_spawner]]; //! Store them in mission missionNamespace setVariable ["sad_levels", _levels]; _levels = missionNamespace getVariable "sad_levels"; }; //! Exit SAD if it was disabled private _enabled = missionNamespace getVariable ["sad_enabled", true]; if (!_enabled) exitWith { [_LOG_TYPE, _LOG_DBG, ["[SADs] Not enabled. Exit..."]] call _sad_log; //true; }; //! Retrieve SAD counter private _counter = missionNamespace getVariable "sad_counter"; _counter = _counter + 1; //! Retrieve SAD active group private _group = missionNamespace getVariable "sad_group"; //! SAD group is dead and deleted, spawn new one if (isNull _group) then { [_LOG_TYPE, _LOG_DBG, ["[SADs] SAD group is dead and deleted, spawn new one."]] call _sad_log; //! Select level private _level_idx = missionNamespace getVariable "sad_level"; private _level_arr = _levels select _level_idx; private _level_script = selectRandom _level_arr; if (!isNil "_level_script") then { _group = call _level_script; if (_use_stalk) then { [_LOG_TYPE, _LOG_INF, ["[SADs] use stalk"]] call _sad_log; //! https://community.bistudio.com/wiki/BIS_fnc_stalk //! [stalker, stalked, refresh, radius, endCondition, endDestination] [_group, group player, 60, 100, { BIS_Return }, 1] spawn BIS_fnc_stalk; } else { private _wp = _group addWaypoint [position player, 100]; _wp setWaypointType "SAD"; [_LOG_TYPE, _LOG_DBG, ["[SADs] Added waypoint..."]] call _sad_log; }; [_LOG_TYPE, _LOG_INF, ["[SADs] Group %1 created position to %2", str _group, str (position player)]] call _sad_log; [_LOG_TYPE, _LOG_DBG, ["[SADs] Group pseudo created"]] call _sad_log; } else { [_LOG_TYPE, _LOG_DBG, ["[SADs] No group created"]] call _sad_log; }; _counter = 0; } //! SAD group is alive, make updates else { [_LOG_TYPE, _LOG_DBG, ["[SADs] SAD group is alive, make updates."]] call _sad_log; //! Group is allowed to wander at most 1 hour if (_counter < _loop_count) then { //! Update waypoint position, 1 because 0 is an initial position if (!_use_stalk) then { [_group, 1] setWaypointPosition [position player, 100]; }; //! Refuel {(vehicle _x) setFuel 1} forEach (units _group); [_LOG_TYPE, _LOG_INF, ["[SADs] Group %1 updated position to %2", str _group, str (position player)]] call _sad_log; //! Reset counter if distance to player is less than 200m private _distance = player distance (leader _group); if (_distance <= 200) then { _counter = 0; [_LOG_TYPE, _LOG_INF, ["[SADs] Group %1 reached player. Resetting counter.", str _group]] call _sad_log; }; } else { if (_counter == _loop_count) then { //! Kill all units {_x setDamage 1} forEach (units _group); //! Destroy all vehicles {(vehicle _x) setDamage 1} forEach (units _group); [_LOG_TYPE, _LOG_INF, ["[SADs] Group %1 destroyed", str _group]] call _sad_log; } else { [_LOG_TYPE, _LOG_INF, ["[SADs] Group %1 already destroyed", str _group]] call _sad_log; }; }; }; //! Run once in 5 minutes missionNamespace setVariable ["sad_counter", _counter]; missionNamespace setVariable ["sad_group", _group]; [_LOG_TYPE, _LOG_DBG, ["[SADs] Going to sleep %1 seconds...", str _loop_interval]] call _sad_log; sleep _loop_interval; [_LOG_TYPE, _LOG_DBG, ["[SADs] Sleep finished"]] call _sad_log; }; [_LOG_TYPE, _LOG_INF, ["[SADs] Ends"]] call _sad_log; 1 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4206 Posted May 3, 2020 Hello there @jarni ! This is a way for your script to load in SP/MP. https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#Loaded ex: addMissionEventHandler ["Loaded", { params ["_saveType"]; If(_saveType isEqualto "continue") then{ [] execVM "GF_Earplugs\GF_Earplugs.sqf"; }; }]; [] execVM "GF_Earplugs\GF_Earplugs.sqf"; 4 Share this post Link to post Share on other sites
jarni 2 Posted May 4, 2020 10 hours ago, GEORGE FLOROS GR said: This is a way for your script to load in SP/MP. Thank you! But, is this really necessary? As I've mentioned, I have 2 other scripts done in similar manner and they work just fine. I'd like to avoid spawning script on every load without being sure that the previous instances are not running and consuming scheduler time. All 3 scripts are started in init.sqf: execVM "globals\runAC.sqf";//! Area Control execVM "globals\runGCC.sqf";//! Group Combat Checker execVM "globals\runSAD.sqf";//! Seek&Destroy The last one is the only which stops working after restart. AC has update time 30 seconds, GCC every 1 second, SAD initially 60 seconds (but reduced to 15 seconds for tests). The biggest difference is that neither AC nor GCC make "call" in them. Share this post Link to post Share on other sites