Announcement

Collapse
No announcement yet.

Script Request - If-Then Action

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script Request - If-Then Action

    This is probably an easy one (my disclaimer) but here is what I am looking for:

    Begin -------------------------

    If an action on an AI-EI team (all get killed) (fire team, Squad TBD, but all in the same "team")

    within given time frame from first killed (say one minute)

    Then no action

    Else <meaning even if one of them is wounded but still alive>

    Call support to their last known location
    <last known location can be location of first killed, or TL - whatever works and won't break>
    <by "call of support" I want a force of men and or armor to move from some designated point to that location to respond, support and suppress all opposing forces in that area>

    ------------------------- End

    I'm still learning the mission thing and I have to believe this is a pretty standard call in the game.

    Thanks,

    Solo

  • #2
    Re: Script Request - If-Then Action

    ill write up a basic script for a predetermined squad and a more versatile and variable one (coming later, i need some more details
    I'll assume you want support to be called in one time when the squad has taken some kind of damage, even if that damage is minor, and the support is already spawned and has been allocated variable names.


    heres the basic one, which is assigned to a squad already created in the editor. use this one as a learning example:
    Code:
    _teamLeader = _this select 0;
    _squad = units (group _teamleader);
    _supportGroup = group (_this select 1);
    _support 	= units _supportGroup;
    _damageCall  = _this select 2;
    
    //note that this script will fire once and once only
    
    _bool = 1;
    _cond = 0;
    
    while {_bool!=_cond} do
    	{
    		{
    			if ((damage _x)>_damageCall) then
    				{
    				_cond = 1;
    				};
    		} foreach _squad;
    		
    		sleep 1;
    	};
    	
    _supportPos = getpos _teamLeader;
    
    _supportGroup setBehaviour "COMBAT";
    
    {
    	_x domove _supportPos;
    } foreach _support;
    i would recommend changing _damageCall to a higher value such as 0.6 or such, because an AI could fall off of a rock and call in the support by accident. you could even do eventhandlers to check if someone is firing at them, but if you want something else just ask.

    heres the line you put on the squad leader:
    Code:
    nul = [this,<supportLeader>,0.5] execVM "support.sqf";
    <supportLeader> needs to be the variable name for a member of the support team. for this script you can only assign one group as the support, but it can be easily modified.

    I could do alot more complicated stuff than this but i just need details on what you need.
    and thanks for the work, i find doing script requests as really enjoyable.
    Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

    Comment


    • #3
      Re: Script Request - If-Then Action

      update: still working on it, but its being done. not tested yet.

      http://pastebin.com/DwjG9Etp
      Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

      Comment


      • #4
        Re: Script Request - If-Then Action

        heres a non tested draft:
        http://pastebin.com/zVVzPyPf
        Code:
        _markers = Markers;
        _squad = group (_this select 0);
        _names = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p"];
        //again this script will fire once for the squad
        num1 = (round(random (count _names))) - 1;
        num2 = ceil(random 99);
        
        _varCreate = [] call compile format["%1%2 = 0;%1%2 = _numVar;",num1,num2];
        
        
        varAlgo =
        {
        	_killed = _this select 0;
        	_killer = _this select 1;
        	_time 	= _this select 2;
        	_killers = units (group _killer);
        	_types = [ ];
        	_processed = [ ];
        	
        	_tempNum1 = _killed getvariable "support";
        	
        	if (_tempNum1 == 1) then {
        			{	_x setvariable ["support",0];
        			} 
        			foreach units (group _killed);
        		
        		_killedGroup = units (group _killed);
        		_temp1 = 0;
        		sleep _time;
        		{
        			if (alive _x) then {
        				_temp1 = _temp1 + 1;
        			};
        		}
        		foreach _killedGroup;
        		
        		if (_temp1>0) exitwith { };
        		
        		{
        		
        			if (!((vehicle _x) in _processed)) then {
        				_processed = _processed + [(vehicle _x)];
        				_tempNum2 = 1;
        				_passedIn = 0;
        				_tempVeh = _x;
        				
        				{
        				if ((typeof _tempVeh)==(_x select 0)) then
        					{
        					_passedIn = 1;
        					};
        				}
        				forEach _types;
        				
        				if (_passedIn==0) then {
        						_types = _types + [[(typeof _veh),1]];
        				} else {
        						{	if ((_x select 0)==(typeof _tempVeh) then {
        								_x set [1,(_x select 1) + 1];
        							};
        						}
        						foreach _types;
        				};
        						
        			};
        		
        		} foreach _killers;
        		//killers (friendly) array created
        		
        		//block for closest marker select
        	_closest = (getmarkerpos (supMarkers select 0)) distance (getpos _killed);
        	_closestMarker = 0;
        		{
        			if (((getpos _killed) distance (getMarkerPos _x))< _closest) then {
        				_closestMarker = _forEachIndex;
        			};
        		}
        		forEach supMarkers;
        		
        		//spawn support units
        	
        		//set general amounts for each type
        		_supportType = [["Man",0],["Car",0],["Tank",0],["Helicopter",0],["Plane",0]];
        		
        		{
        		_tempVeh = _x;
        			
        			{
        				if ((_x select 0) isKindOf (_tempVeh select 0)) then {
        					while {(_x select 1)>0} do {
        						_tempVeh set [1,(_tempVeh select 1) + 1];
        						_x set [1,(_x select 1) - 1];
        					};
        				};
        			} foreach _types;
        			
        			_fixAmount = ceil(((_x select 1)^2)/2 + (_x select 1));
        			_x set [1,_fixAmount];
        			
        		}
        		foreach _supportType;
        		
        		//set counter unit by random chance. for example, a tank thread might have an AT squad spawned or another tank.
        		
        		_spawnforces = {
        			_side 	= _this select 0;
        			_opforSup = {
        				_group = creategroup opfor;
        				_classInf 	= "O_Soldier_F";
        				_classInfAT	= "O_Soldier_AT_F";
        				_classInfAA	= "O_Soldier_AA_F";
        				_classTank	= "B_MBT_01_cannon_F";
        				_classCar 	= "O_MRAP_02_hmg_F";
        				_classAPC 	= "O_APC_Tracked_02_cannon_F";
        				_classAA	= "O_APC_Tracked_02_AA_F";
        				_classTHelo	= "O_Heli_Light_02_unarmed_F";
        				_classAHelo = "O_Heli_Attack_02_F";
        				_classCAP	= "I_Plane_Fighter_03_AA_F";
        				_classCAS	= "O_Plane_CAS_02_F";
        			};
        			_bluforSup = {
        				_group = creategroup blufor;
        				_classInf 	= "B_Soldier_F";
        				_classInfAT	= "B_Soldier_AT_F";
        				_classInfAA	= "B_Soldier_AA_F";
        				_classTank	= "B_MBT_01_cannon_F";
        				_classCar 	= "B_MRAP_01_hmg_F";
        				_classAPC 	= "B_APC_Wheeled_01_cannon_F";
        				_classAA	= "B_APC_Tracked_01_AA_F";
        				_classTHelo	= "B_Heli_Transport_01_camo_F";
        				_classAHelo = "B_Heli_Attack_01_F";
        				_classCAP	= "I_Plane_Fighter_03_AA_F";
        				_classCAS	= "B_Plane_CAS_01_F";
        			};
        			
        			_sideDet = {
        				switch (_side) do {
        					case opfor 	: {
        						[] call _opforSup
        					};
        					case blufor : {
        						[] call _bluforSup
        					};
        				};
        			};
        			
        			_infSpawn = {
        				for [{_a = _this select 0},{_a>0},{_a=_a-1}] do {
        					(_this select 1) createUnit [getmarkerpos (supMarkers select _closestMarker), _group, "", ((round(random 9))+1)/10,"private"];
        				};
        					[1,_classTHelo] call _airSpawn;
        					_veh1 = _veh;
        					{
        						_x moveInCargo _veh1;
        					}
        					foreach (units _group);
        					waituntil{unitReady _veh};
        					_veh1 land "GET OUT";
        					doGetOut ((units _group)-(driver _veh1));
        					waituntil{(count (crew _veh1))==1};
        					_veh1 domove (getmarkerpos (supMarkers select _closestMarker));
        					waituntil{unitready _veh1};
        					deletevehicle _veh1;
        			};
        			
        			_vehSpawn = {
        				for [{_a = _this select 0},{_a>0},{_a=_a-1}] do {
        					_veh = (_this select 1) createVehicle (getmarkerpos (supMarkers select _closestMarker));
        					createVehicleCrew _veh;
        					(crew _veh) joinSilent _group;
        					(units _group) doMove (getpos _killed);
        				};
        			};
        			
        			_airSpawn = {
        				for [{_a = _this select 0},{_a>0},{_a=_a-1}] do {
        					_veh = createVehicle [(_this select 1),_closestMarker, [], 0, "FLY"];
        					createVehicleCrew _veh;
        					(crew _veh) joinSilent _group;
        					(units _group) doMove (getpos _killed);
        				};
        			};
        			
        			_manCheck = {
        				[] call _sideDet;
        				_number = (_supportType select 0) select 1;
        				_ran1 = round(random 2);
        				switch (_ran1) do {
        					case 0: {[_number,_classInf] call _infSpawn};
        					case 1: {[ceil(_number/5),_classCar] call _vehSpawn};
        					case 2: {[1,_classAHelo] call _airSpawn};
        				};
        			};
        			
        			_carCheck = {
        				[] call _sideDet;
        				_number = (_supportType select 1) select 1;
        				_ran1 = round(random 3);
        				switch (_ran1) do {
        					case 0: {[_number+2,_classInfAT] call _infSpawn};
        					case 1: {[ceil(_number),_classCar] call _vehSpawn};
        					case 2: {[ceil(_number/10),_classAHelo] call _airSpawn};
        					case 3: {[ceil(_number)/1.25,_classAPC] call _airSpawn};
        				};
        			};
        
        			_tankCheck = {
        				[] call _sideDet;
        				_number = (_supportType select 2) select 1;
        				_ran1 = round(random 3);
        				switch (_ran1) do {
        					case 0: {[_number+4,_classInfAT] call _infSpawn};
        					case 1: {[ceil(_number),_classTank] call _vehSpawn};
        					case 2: {[ceil(_number/10),_classAHelo] call _airSpawn};
        					case 3: {[ceil(_number/10),_classCAS] call _airSpawn};
        				};
        			};
        
        			_heloCheck = {
        				[] call _sideDet;
        				_number = (_supportType select 3) select 1;
        				_ran1 = round(random 3);
        				switch (_ran1) do {
        					case 0: {[_number+2,_classInfAA] call _infSpawn};
        					case 1: {[ceil(_number),_classAA] call _vehSpawn};
        					case 2: {[_number,_classAHelo] call _airSpawn};
        					case 3: {[1,_classCAP] call _airSpawn};
        				};
        			};
        			_airCheck = {
        				[] call _sideDet;
        				_number = (_supportType select 3) select 1;
        				_ran1 = round(random 3);
        				switch (_ran1) do {
        					case 0: {[_number+4,_classInfAA] call _infSpawn};
        					case 1: {[ceil(_number),_classAA] call _vehSpawn};
        					case 2: {[_number + 1,_classAHelo] call _airSpawn};
        					case 3: {[ceil(_number/1.5),_classCAP] call _airSpawn};
        				};
        			};
        			[_side] spawn _manCheck;
        			[_side] spawn _carCheck;
        			[_side] spawn _tankCheck;
        			[_side] spawn _heloCheck;
        			[_side] spawn _airCheck;
        		};
        	};
        	[side _killed] call _spawnedForces;
        };
        
        
        
        	{
        	_x setVariable ["supportCall",1];
        	}
        	foreach units (group _squad);
        		
        };	
        	
        	
        	{
        	_eHNum = _x addEventHandler 
        		[
        			"killed",
        			{
        			_varCall = (_this +[reinTime]) call varAlgo;
        			
        				{
        					_x removeEventHandler ["killed",_eHNum];		
        				}
        				foreach units (group _x);
        			}
        		]
        	}
        	foreach units _squad;
        executing line:
        Code:
        nul = [this] execVM "support.sqf";
        Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

        Comment


        • #5
          Re: Script Request - If-Then Action

          update: working and needs to be optimized. one more version and it will be mission ready.
          http://pastebin.com/YAEyUiHd
          Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

          Comment


          • #6
            Re: Script Request - If-Then Action

            Ok Yink, adding this to my second mission (still building the first, but it's all but done). Ready to test this on a skeleton of the second mission. I'd like to add two different squads and responding forces to make sure it works when only one fires (and the other remains on alert but does not respond until THAT squad is attacked).

            Thanks for all the awesome code work. Looks good to me (like I know) and I can wait to try it out.

            Solo

            Comment


            • #7
              Re: Script Request - If-Then Action

              ya I've just been re-re-re-re optimizing it. IT MUST BE PERFECT
              Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

              Comment


              • #8
                Re: Script Request - If-Then Action

                See . . . there is that whole "coder" thing . . let's try it and make sure you like the "not re-re-re perfected" one first.

                LOL, thanks Yink for all the work on this already.

                Solo

                Comment


                • #9
                  Re: Script Request - If-Then Action

                  Hey Yink by any chance do you know cfg for addons making some vehicles and need some help with

                  Comment


                  • #10
                    Re: Script Request - If-Then Action

                    No sorry liquid I dont.
                    Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

                    Comment

                    Connect

                    Collapse

                    TeamSpeak 3 Server

                    Collapse

                    Advertisement

                    Collapse

                    Twitter Feed

                    Collapse

                    Working...
                    X