Search the Community
Showing results for tags 'panda'.
Found 2 results
-
Hey folks. I don't spend much time here anymore, pretty busy with work and what not, but occasionally I come with treats for you all, and today is no exception. This is thanks to Rob|Homesick, just a little boy with a dream, a wish for a panda helmet, and I delivered! https://steamcommunity.com/sharedfiles/filedetails/?id=1632653995
- 14 replies
-
- 18
-
BASIC eachFrame mission event framework
das attorney posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hi, For those who don't know, Arma has a framework to check for an event on each frame of the game (similar to the sleep/sleepUI commands but unscheduled, so higher priority). Currently, there's no easy way to make it consider objects (or indeed any other data) that does not have a global name. This basic framework can let you add events easily based on time (it uses diag_tickTime fyi). Also, you can pass custom functions to it not based on time and write out the outcomes yourself (bit more advanced). If you specify a timeout parameter (in seconds), it will only execute your code once the timeout is up. Without a timeout specified, it will execute your code on each frame. FORMAT This is the format for using it: _thisEventHandler = [arguments,code,timeout (optional)] call horde_fnc_addMissionEventHandler; The rules are that the arguments you pass to it must be in an array. So these are ok: [[player],myFunction,10] call horde_fnc_addMissionEventHandler; [["string"],myFunction,10] call horde_fnc_addMissionEventHandler; [[player,"string"],myFunction,10] call horde_fnc_addMissionEventHandler; Using a single argument is NOT ok: [player,myFunction,10] call horde_fnc_addMissionEventHandler; // bad ["string",myFunction,10] call horde_fnc_addMissionEventHandler; // bad There's no error checking currently* so as long as you stick to the format, then you're ok. EXAMPLES ein) _fnc = { player sideChat format ["%1",_this select 0] }; [["hello"],_fnc,2] call horde_fnc_addMissionEventHandler; [["poopy"],_fnc,3] call horde_fnc_addMissionEventHandler; [["fluffy paws"],_fnc,4] call horde_fnc_addMissionEventHandler; Prints "hello" on screen after 2 seconds, then "poopy" a second later, then "fluffy paws" a second after that. drei) _fnc = { missionNamespace getVariable ("horde_gv_eachFrameArgs_" + (_thisEventHandler toFixed 0)) params ["_unit","_moving","_notMoving"]; if (vectorMagnitude velocity vehicle _unit > 1) then { systemChat format ["%1 is %2",_unit,_moving] } else { systemChat format ["%1 %2",_unit,_notMoving] } }; TAG_movingIndicatorID = [[player,"moving","not moving"],_fnc] call horde_fnc_addMissionEventHandler; Infinite loop informing player if he/she is moving or not by systemChat. Note that we no not define the timeout (3rd parameter in the arguments). You can stop it in this example by using the return (TAG_movingIndicatorID) TAG_movingIndicatorID call horde_fnc_removeMissionEventHandler; // stops the sideChat zwei) _fnc = { missionNamespace getVariable ("horde_gv_eachFrameArgs_" + (_thisEventHandler toFixed 0)) params ["_unit","_moving"]; if (vectorMagnitude velocity vehicle _unit > 1) then { systemChat format ["%1 is %2 - deleting EventHandler",_unit,_moving]; _thisEventHandler call horde_fnc_removeMissionEventHandler } }; [[player,"moving"],_fnc] call horde_fnc_addMissionEventHandler; This is a function that is not dependent on time so the 3rd parameter of the arguments does not need to be defined. If the unit passed to it moves, then it prints a message and then quits. Note that the deletion is specified in the function. CBA I just wanted to mention cba as they have a great system for this sort of thing, but if you want to use it, then you have to be comfortable with mod dependencies. This is a poor man's system that lets you manage an unscheduled event system without mods. ALWAYS DO BETTER If you can write something faster/better than this then please comment and post your code in here so we can all benefit. My code's not great but works ok I think. I'm sure there's better ways of doing it but I can't think of them right now. FUNCTIONS horde_fnc_addMissionEventHandler = { params ["_args","_code","_timeout"]; private _thisEventHandler = -1; if (isNil "_timeout") then { _thisEventHandler = addMissionEventHandler [ 'EachFrame', _code ]; } else { _thisEventHandler = addMissionEventHandler [ 'EachFrame', horde_fnc_missionEventHandlerTimeout ]; _args pushBack [_code,diag_tickTime + _timeout] }; missionNamespace setVariable ["horde_gv_eachFrameArgs_" + (_thisEventHandler toFixed 0),_args]; _thisEventHandler }; horde_fnc_missionEventHandlerTimeout = { private _args = missionNamespace getVariable ("horde_gv_eachFrameArgs_" + (_thisEventHandler toFixed 0)); _args select (count _args - 1) params ["_code","_timeout"]; if (diag_tickTime > _timeout) then { _args deleteAt (count _args - 1); _args call _code; removeMissionEventHandler ["EachFrame",_thisEventHandler]; missionNamespace setVariable ["horde_gv_eachFrameArgs_" + (_thisEventHandler toFixed 0),nil]; }; true }; horde_fnc_removeMissionEventHandler = { removeMissionEventHandler ["EachFrame",_this]; missionNamespace setVariable ["horde_gv_eachFrameArgs_" + (_this toFixed 0),nil]; true }; Ta * = I could put this in if required but it will slow the execution down a bit