Executing script on C2ISTAR Task Complete

  1. 8 years ago

    Congratulations on the new release! Sorry for being irritating with all the questions, they will stop soon I promise. Is there a way to execute a function or script on completion of certain C2ISTAR tasks? I'd like to execute a function if certain conditions are met and an assassination mission has been completed. Wondering if there's a simple way to do this?

  2. Edited 8 years ago by SpyderBlack723

    You posted a day too late :(

    I'll try to remember to log an event when tasks are completed for the next update.

    Will try to look for another way. but I fear there won't be one.

  3. Gutted! Well thank you for answering anyway. Wondering if there is a way to hook into the same thing that increases force pools on task completion...

  4. Edited 8 years ago by SpyderBlack723

    You would have to run a loop that waits until the value increases and that would be your cue to run your code. You wouldn't have access to which task was completed though.

    Will continue to look

    Edit:
    Wait.. mightta got it, will write an example

  5. Alright,

    You need to create a function, I named it Spyder_fnc_taskCatcher but you can name it w/e you want, just make sure to replace every instance of the name - even inside the function itself.

    https://gist.github.com/SpyderBlack723/a771e0d04f6e770353b58466f715bfdd

    Now, you'll need to create and initialize this function, the easiest way is by putting this code in your init.sqf

    if (isServer) then {
        Spyder_taskCatcher = [nil,"create"] call Spyder_fnc_taskCatcher;
        [Spyder_taskCatcher,"init"] call Spyder_fnc_taskCatcher;
        [Spyder_taskCatcher,"start"] call Spyder_fnc_taskCatcher;
    };

    Now, you can run w/e code you wish after

    // task has been completed successfully, run da code

    on line 77.

    Not 100% sure this will work but it's definitely worth a try.

  6. Thank you! I'll give it a go.

  7. Well, this is what I came up with! Will report back if it works. Thanks again Spyder.

       case "onTaskDelete": {
    		
            private _eventData = _args;
    		
    		private _percentage = 30;
    		
            _eventData params ["_taskID","_requestPlayerID","_position","_title","_description","_state","_current","_parent","_source"];
    
            if (_state == "Succeeded") then {
    
                if !((INDEPENDENT knowsAbout underCoverUnit) > 3) then {
    				
    				if (_percentage > (random 100)) then {
    				
    					[ALIVE_civilianHostility,"EAST",-100] call ALIVE_fnc_hashSet;
    					[underCoverUnit, "Looks like the civilians are rising up."] remoteExec ["sideChat"]; 
    				};
    				
    			};
    
            };
    
        };
    
    };
  8. Edited 8 years ago by incontinenetia

    Quick question, what's the best way to set the function in the mission files Spyder? (I'm not quite at the defining functions stage of my script learning just yet!)

    I've just stuck this in the init.sqf: call compile preprocessFileLineNumbers "scripts/Spyder_fnc_taskCatcher.sqf";

    Is that alright do you reckon? Or should define it in description.ext?

  9. Edited 8 years ago by SpyderBlack723

    Easiest way for a beginner imo would be

    description.ext

    class CfgFunctions {
    	#include "functions\cfgfunctions.hpp"
    };

    functions\cfgfunctions.hpp

    class Spyder {
        tag = "Spyder";
        class main {
            file = "";
            class fn_taskCatcher {};
        };
    };

    Then you create the function in the same folder as the cfgfunctions.hpp file -- but you need to prefix it with fn_

    So your function filename is now

    fn_taskCatcher.sqf

    You can now reference the function with Spyder_fnc_taskCatcher

    --------------------
    Explanation:

    #include "functions\cfgfunctions.hpp" tells the game to copy the contents of the cfgfunctions file inside the functions folder to the description.ext.

    tag = "Spyder"; This establishes the function prefix. All of your functions will be tag_fnc_functionname.
    So using "Spyder" evaluates to Spyder_fnc_functionname;

    file = "functions"; simply tells the game to look for the function files in the functions folder

    class taskCatcher {};[/code] tells the game to include the taskCatcher function file.This needs to be in the folder referenced directly above and prefixed with [code]fn

    So class taskCatcher {}; evaluates to the game needing a file named fn_taskCatcher.sqf in the file = "functions"; folder.

    To add more functions:

    class Spyder {
    	tag = "Spyder";
    	class main {
    		file = "functions";
    		class taskCatcher {};
                    class functionTwo {};
                    class functionThree {};
    	};
    };

    Awful at explaining but hopefully that helps you get an immediate idea of what everything is doing.

  10. Mate that's a brilliant explanation. Thank you again. No luck with the function so far unfortunately, I'll have a bit more of a look and see if it's something I've done. This is the code I'm using now:

    case "onTaskDelete": { private _eventData = _args; private _percentage = 100; _eventData params ["_taskID","_requestPlayerID","_position","_title","_description","_state","_current","_parent","_source"]; if (_state == "Succeeded") then { if (_percentage > (random 100)) then { [ALIVE_civilianHostility,"EAST",-100] call ALIVE_fnc_hashSet; [ALIVE_civilianHostility,"INDEPENDENT",-100] call ALIVE_fnc_hashSet; [underCoverUnit, "Looks like the civilians are rising up."] remoteExec ["sideChat"]; }; }; }; }; which runs fine outside the function so could it be that I'm using the auto tasking?

  11. Should work fine whether auto tasked or manual. It's 100% possible the solution just doesn't work. I would put a

    hint "CALLED";

    At the very top of the function. Then complete a task and if the hint never shows, it might not work. Will try to test myself later.

  12. Edited 8 years ago by SpyderBlack723

    Just tested, doesn't look like it works, unless you manually delete the task after it is completed.

    I've added a method for catching this directly for the next update.

    I'll write up a new method hacky method for now.

  13. Woo!

    Finally got it, here's an example mission with the files setup for it. Bugs might be prevalent but it worked well when I tested it. Next ALiVE update will make this much easier and less hacky.

    https://www.dropbox.com/s/q7cvjkx91zv2n7q/SpyderTaskCatcher_Example.rar?dl=0

  14. Good work! Funny, we have the same mission title. Think you maybe beat me by one S. I'll give it a go now. Thanks again dude.

  15. Works brilliantly! Thank you again Spyder. Sometimes on mission startup I get an error about an undefined variable _allTasks (or something like that), presumably that's a result of the function executing before any tasks have been created?

    Cheers again dude!

  16. Try changing the line that says

    waitUntil {!isnil "ALiVE_taskHandler"};

    to

    waitUntil {sleep 5; !isnil "ALiVE_taskHandler"};
  17. Friznit

    21 Jul 2016 Administrator

    Need to add this to our wiki. It's neat!

  18. Confirmed those changes work well, cheers. @Friznit agreed!! Opens up some really cool gameplay possibilities.

  19. What function are you running after completing the HVT task? Increasing the hostility against the HVT side?

  20. Pretty much, I have tried other functions but haven't had much luck just yet. I'm looking into giving all civilians weapons and switching their sides to blue to simulate some kind of uprising but I suspect ALiVE overrides the functions I'm trying to put in place. Hostility is my placeholder until I get a bit better at coding (reading through lots of guides right now!).

    In theory you could stage an entire invasion on task completion but although I know how to pause all OPCOMs at the same time, or all military placement modules, I'm not quite sure how to pause and resume specific ones. (I'm assuming since Arma treats them all as vehicles that maybe it's just a case of using the variable names instead of "ALIVE_MIL_OPCOM", so maybe name the invasion OPCOM or Logs module or whatever to "TriggeredModule" and do ["MILITARY_PLACEMENT_MODULE"] call ALiVE_fnc_unPauseModule;.

    Another possibility is to create a search party / helicopter to come looking for whoever slotted the HVT. So many ideas!

    It works really well though, so thanks again Spyder!

 

or Sign Up to reply!