Results 1 to 8 of 8

Thread: Need help How to delete a replacemnet gunner from a script!

  1. #1
    Master Gunnery Sergeant
    Join Date
    Oct 9 2008
    Location
    New york & Florida
    Posts
    1,100

    Need help How to delete a replacemnet gunner from a script!

    I will attempt to explain this lol. I am using a great script that allows you to replace static weapon personal if the original gunner is killed however if the gun is destroyed the respawn of the gunner does not occur (All is good)

    I have a trigger telling me when all the original gunners are killed
    I have a second trigger telling me when all the static weapons are destroyed. This trigger will set a timer that will reset the publicvariable that will allow the commander to recall the both of the scripts via action menu (only the commander can use) that I am using to spawn the static weapons and spawn/respawn the gunners. I have a third trigger via addaction that will only both of the game commanders to recall both of the scripts which will delete the static weapons and delete the original gunners from the battlefield and reset the call in SQF's for the scripts. My issue is I have no clue how to delete the replacement gunners that the script spawn in after the original gunners are killed. This is not a script killed but I would like to delete the replacement gunners and not have them static in locations throughout the mission after the FOB's move to a new location during the mission.

    Here is the script that call in the gunners


    Code:
    //Outpost Sparrow 2 East Static Weapon Squad
    
    [] execVM "AVIBIRD\menu\ci_menu2_close.sqf";
    EastStaticmanHQ2 = false;
    publicvariable "EastStaticmanHQ2";
    
    hq2d removeaction hq2SWME; 
    
    if (isServer) then {
    
        MoveGunner = {
            private ["_vcl","_deg","_dir","_unit"];
            _vcl = _this select 0;_deg = _this select 1;_dir = getdir _vcl;_unit = (gunner (vehicle _vcl));
            while {(alive _unit) && (alive _vcl)} do {
                _unit setformdir _dir +((random -(_deg)+(_deg/2)));
                sleep 3+(random 6);
            };
        };
    
        ReplaceGunner = {
            private ["_unit","_gun","_grp"];
    	    _unit = _this select 0;_gun = _this select 1;_grp = _this select 2;
    	    while {alive _unit} do {sleep 1};
    		if !(alive _unit) then {
    		   sleep 10+random 10;
               _unit = _grp createUnit ["BAF_Soldier_DDPM", getPos _gun, [], 0.6, "form"];
               _unit assignAsGunner _gun;
               _unit moveInGunner _gun;
               _unit addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
    	      [_unit,_gun,_grp] spawn ReplaceGunner;
    	   };
        };
    
        ReloadGun = {
            private ["_gun"];
            _gun = _this select 0;
            while {alive _gun} do {
              sleep 30;
              _gun setVehicleAmmo 1;
    	    };
        };
    
    	
       _grp = createGroup WEST;
    
       hq2gunner_1 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_1, [], 0.6, "form"];
       hq2gunner_1 assignAsGunner FOB2gun_1;
       hq2gunner_1 moveInGunner FOB2gun_1;
       hq2gunner_1 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_1 setSkill 0.4+(random 0.3);
       hq2gunner_1 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
       if (hq2gunner_1 hasWeapon "NVGoggles") then {hq2gunner_1 removeWeapon "NVGoggles"};
       hq2gunner_1 addWeapon "NVGoggles";
       sleep 0.3;
       
       hq2gunner_2 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_2, [], 0.6, "form"];
       hq2gunner_2 assignAsGunner FOB2gun_2;
       hq2gunner_2 moveInGunner FOB2gun_2;
       hq2gunner_2 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_2 setSkill 0.4+(random 0.3);
       hq2gunner_2 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
       if (hq2gunner_2 hasWeapon "NVGoggles") then {hq2gunner_2 removeWeapon "NVGoggles"};
       hq2gunner_2 addWeapon "NVGoggles";
       sleep 0.3;
       
       hq2gunner_3 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_3, [], 0.6, "form"];
       hq2gunner_3 assignAsGunner FOB2gun_3;
       hq2gunner_3 moveInGunner FOB2gun_3;
       hq2gunner_3 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_3 setSkill 0.4+(random 0.3);
       hq2gunner_3 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
       if (hq2gunner_3 hasWeapon "NVGoggles") then {hq2gunner_3 removeWeapon "NVGoggles"};
       hq2gunner_3 addWeapon "NVGoggles";
       sleep 0.3;
       
       hq2gunner_4 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_4, [], 0.6, "form"];
       hq2gunner_4 assignAsGunner FOB2gun_4;
       hq2gunner_4 moveInGunner FOB2gun_4;
       hq2gunner_4 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_4 setSkill 0.4+(random 0.3);
       hq2gunner_4 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
       if (hq2gunner_4 hasWeapon "NVGoggles") then {hq2gunner_4 removeWeapon "NVGoggles"};
       hq2gunner_4 addWeapon "NVGoggles";
       sleep 0.3;
       
       hq2gunner_5 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_5, [], 0.6, "form"];
       hq2gunner_5 assignAsGunner FOB2gun_5;
       hq2gunner_5 moveInGunner FOB2gun_5;
       hq2gunner_5 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_5 setSkill 0.4+(random 0.3);
       hq2gunner_5 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
       if (hq2gunner_5 hasWeapon "NVGoggles") then {hq2gunner_5 removeWeapon "NVGoggles"};
       hq2gunner_5 addWeapon "NVGoggles";
       sleep 0.3;
    
      
       hq2gunner_6 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_6, [], 0.6, "form"];
       hq2gunner_6 assignAsGunner FOB2gun_6;
       hq2gunner_6 moveInGunner FOB2gun_6;
       hq2gunner_6 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_6 setSkill 0.4+(random 0.3);
       hq2gunner_6 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
       if (hq2gunner_6 hasWeapon "NVGoggles") then {hq2gunner_6 removeWeapon "NVGoggles"};
       hq2gunner_6 addWeapon "NVGoggles";
       sleep 0.3;
       
       hq2gunner_7 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_7, [], 0.6, "form"];
       hq2gunner_7 assignAsGunner FOB2gun_7;
       hq2gunner_7 moveInGunner FOB2gun_7;
       hq2gunner_7 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_7 setSkill 0.4+(random 0.3);
       hq2gunner_7 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}]; 
       if (hq2gunner_7 hasWeapon "NVGoggles") then {hq2gunner_7 removeWeapon "NVGoggles"};
       hq2gunner_7 addWeapon "NVGoggles";
       sleep 0.3;
    
       hq2gunner_8 = _grp createUnit ["BAF_Soldier_FAC_DDPM", getPos FOB2gun_8, [], 0.6, "form"];
       hq2gunner_8 assignAsGunner FOB2gun_8;
       hq2gunner_8 moveInGunner FOB2gun_8;
       hq2gunner_8 setVariable ["BIS_noCoreConversations", true];
       hq2gunner_8 setSkill 0.4+(random 0.3);
       hq2gunner_8 addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}]; 
       if (hq2gunner_8 hasWeapon "NVGoggles") then {hq2gunner_8 removeWeapon "NVGoggles"};
       hq2gunner_8 addWeapon "NVGoggles";
       sleep 0.3;
            
       (leader _grp) setRank "LIEUTENANT";
       
       //FOB2gun_1 allowDamage false;
       [FOB2gun_1,360] spawn MoveGunner;
       [FOB2gun_1] spawn ReloadGun;
       [hq2gunner_1,FOB2gun_1,_grp] spawn ReplaceGunner;
       sleep 0.3;
       
       //FOB2gun_2 allowDamage false;
       [FOB2gun_2,360] spawn MoveGunner;
       [FOB2gun_2] spawn ReloadGun;
       [hq2gunner_2, FOB2gun2,_grp] spawn ReplaceGunner;
       sleep 0.3;
       
       //FOB2gun_3 allowDamage false;
       [FOB2gun_3,360] spawn MoveGunner;
       [FOB2gun_3] spawn ReloadGun;
       [hq2gunner_3, FOB2gun_3,_grp] spawn ReplaceGunner;
       sleep 0.3;
       
       //FOB2gun_4 allowDamage false;
       [FOB2gun_4,180] spawn MoveGunner;
       [FOB2gun_4] spawn ReloadGun;
       [hq2gunner_4, FOB2gun_4,_grp] spawn ReplaceGunner;
       sleep 0.3;
       
       //FOB2gun_5 allowDamage false;
       [FOB2gun_5,180] spawn MoveGunner;
       [FOB2gun_5] spawn ReloadGun;
       [hq2gunner_5,FOB2gun_5,_grp] spawn ReplaceGunner;
       sleep 0.3;
         
       //FOB2gun_6 allowDamage false;
       [FOB2gun_6,360] spawn MoveGunner;
       [FOB2_6] spawn ReloadGun;
       [hq2gunner_6, FOB1gun_6,_grp] spawn ReplaceGunner;
       
       //FOB2gun_7 allowDamage true;
       [FOB2gun_7,60] spawn MoveGunner;
       [FOB2gun_7] spawn ReloadGun;
       [hq2gunner_7, FOB2gun_7,_grp] spawn ReplaceGunner;
       sleep 0.3;
       
       //FOB2gun_8 allowDamage false;
       [FOB2gun_8,180] spawn MoveGunner;
       [FOB2gun_8] spawn ReloadGun;
       [hq2gunner_8, FOB2gun_8,_grp] spawn ReplaceGunner;
       sleep 0.3;
    
    sleep 3;
    hint "East Static Weapons are now manned in fortification positions Sir"; 
          
    };
    
    if (true) exitwith {};

    This is the code that calls the static weapons

    Code:
    //Outpost Sparrow 2 Static Weapons setup East 8 weapons 
    
    [] exec "AVIBIRD\menu\ci_menu2_close.sqf";
    EastStaticgunHQ2 = false;
    publicvariable "EastStaticgunHQ2";
    
    hq2d removeaction hq2SWE; 
    
    _pos = [(getPosATL Player select 0) + (20 * sin(90)), (getPosATL Player select 1) + (20 * cos(90)), 0];
    FOB2StaticGunEast = CreateGroup WEST; 
    
    FOB2gun_1 = createVehicle ["M119", _pos, [], 0, "FORM"];
    FOB2gun_1 setPosATL [(getPosATL Player select 0) + (20 * sin(84)), (getPosATL Player select 1) + (20 * cos(84)), 0];
    FOB2gun_2 = createVehicle ["BAF_L2A1_Tripod_D", _pos, [], 0, "FORM"];
    FOB2gun_2 setPosATL [(getPosATL Player select 0) + (20 * sin(92)), (getPosATL Player select 1) + (20 * cos(92)), 0];
    FOB2gun_3 = createVehicle ["TOW_TriPod_US_EP1", _pos, [], 0, "FORM"];
    FOB2gun_3 setPosATL [(getPosATL Player select 0) + (20 * sin(94)), (getPosATL Player select 1) + (20 * cos(94)), 0];
    FOB2gun_4 = createVehicle ["BAF_GMG_Tripod_D", _pos, [], 0, "FORM"];
    FOB2gun_4 setPosATL [(getPosATL Player select 0) + (20 * sin(96)), (getPosATL Player select 1) + (20 * cos(96)), 0];
    FOB2gun_5 = createVehicle ["Stinger_Pod_US_EP1", _pos, [], 0, "FORM"];
    FOB2gun_5 setPosATL [(getPosATL Player select 0) + (20 * sin(98)), (getPosATL Player select 1) + (20 * cos(98)), 0];
    FOB2gun_6 = createVehicle ["TOW_TriPod_US_EP1", _pos, [], 0, "FORM"];
    FOB2gun_6 setPosATL [(getPosATL Player select 0) + (20 * sin(100)), (getPosATL Player select 1) + (20 * cos(100)), 0];
    FOB2gun_7 = createVehicle ["BAF_GPMG_Minitripod_D", _pos, [], 0, "FORM"];
    FOB2gun_7 setPosATL [(getPosATL Player select 0) + (20 * sin(102)), (getPosATL Player select 1) + (20 * cos(102)), 0];
    FOB2gun_8 = createVehicle ["ZU23_CDF", _pos, [], 0, "FORM"];
    FOB2gun_8 setPosATL [(getPosATL Player select 0) + (20 * sin(110)), (getPosATL Player select 1) + (20 * cos(110)), 0];
    //
    sleep 3;
    hint "East Static Weapons Deployment completed please precede with gun placement of fortifications before maning weapons with Squad"; 
    
    
    FOB2StaticGunEastTD= createTrigger ["EmptyDetector", getPos player]; 
    FOB2StaticGunEastTD setTriggerArea [0, 0, 0, false];
    FOB2StaticGunEastTD setTriggerActivation ["NONE", "NOT PRESENT", false];
    FOB2StaticGunEastTD setTriggerStatements ["!(alive FOB2gun_1)  && !(alive FOB2Egun_2)  && !(alive FOB2Egun_3)  && !(alive FOB2Egun_4)  && !(alive FOB2Egun_5)  && !(alive FOB2Egun_6)  && !(alive FOB2Egun_7)  && !(alive FOB2Egun_8)","player sideChat ""Outpost Sparrow REPORTS: All East Defensive Static weapon Fortifications have been destroyed Sir""; FOB2StaticGunEast execVM ""lkscripts\fob-bu2\doneHQ2StaticGunEast.sqf""" , ""];

    this is the code that resets both of them

    Code:
    //Outpost Sparrow 2 Static Weapons setup East 8 weapons 
    
    {deleteVehicle _x} forEach (units FOB2StaticGunEast);
    deleteVehicle FOB2gun_1;
    deleteVehicle FOB2gun_2;
    deleteVehicle FOB2gun_3;
    deleteVehicle FOB2gun_4;
    deleteVehicle FOB2gun_5;
    deleteVehicle FOB2gun_6;
    deleteVehicle FOB2gun_7;
    deleteVehicle FOB2gun_8;
    deletevehicle FOB2EgunTD;
    deletevehicle hq2gunner_1;
    deletevehicle hq2gunner_2;
    deletevehicle hq2gunner_3;
    deletevehicle hq2gunner_4;
    deletevehicle hq2gunner_5;
    deletevehicle hq2gunner_6;
    deletevehicle hq2gunner_7;
    deletevehicle hq2gunner_8;
    
    
    
    hint "Outpost East Static weapon section has been pulled off the frontlines by The British Secretary of Defence";
    
    sleep 60;                                                                                       //unlimited spawns of this Group at FOB2 unslash
                                                                    
    EastStaticgunHQ2 = true;                                                                        //unslash
    
    publicVariable "EastStaticgunHQ2";                                                              //unslash
    
    EastStaticmanHQ2 = true;                                                                        //unslash
    
    publicVariable "EastStaticmanHQ2";                                                              //unslash
    
     
    hint "New East Static Weapons now available for Deployment from Outpost Sparrow 2";             //unslash
    Last edited by AVIBIRD 1; Apr 16 2014 at 03:58.
    AVIBIRD 1

    When playing this game, Keep Chuck Norris home!
    If they make this game, They will play!
    The truth is out there, If you look!

  2. #2
    in most case you could just use
    PHP Code:
    {deleteVehicle _x} foreach  crew _gun+[vehicle _gun]; 
    but if the gun is damaged the gunner gets out and so won't be deleted with the vehicle.


    if you place this at the end of ReplaceGunner section, it will store the name of the spawned unit in variable space so when you need to remove the gun and the created unit it knows who it needs to delete.

    place after [_unit,_gun,_grp] spawn ReplaceGunner;
    PHP Code:
    _gun setvariable ["crew",_unit]; 

    then to delete vehicle and crew the code will only need to know the gun name your deleting
    PHP Code:
    {deleteVehicle _x} foreach  [_gun getvariable "crew",vehicle _gun]; 
    it works in editor so it should work in script, although that was using just one spawned unit.

  3. #3
    Master Gunnery Sergeant
    Join Date
    Oct 9 2008
    Location
    New york & Florida
    Posts
    1,100
    Author of the Thread
    @Fel Sel I will check it out to see if that is the fix I need.
    I don't fully understand the whole use of _grp for the group. Can you explain what does the _grp _unit _gun mean and how the script uses it and call it within the script. AVIBIRD.

  4. #4
    I suck at explaining but here goes.

    PHP Code:
    FOB2gun_1 createVehicle ["M119"getpos player, [], 0"FORM"];

     
    _grp createGroup WEST;// creates a  West group  named  _grp 

     
    hq2gunner_1 _grp createUnit ["BAF_Soldier_DDPM"getPos _gun, [], 0.6"form"]; 
    what you have now is a static gun named FOB2gun_1
    You have a group named _grp
    and a unit named FOB2gun_1


    In your script they are spawning various scripts and are called using a spawn

    PHP Code:
    [hq2gunner_1FOB2gun_1,_grpspawn ReplaceGunner
    In the spawned script they have been retrieved using _unit = _this select 0 ,_gun = _this select 1 ect

    PHP Code:
        ReplaceGunner = {
            private [
    "_unit","_gun","_grp"];

            
    _unit _this select 0;//  hq2gunner_1 
                 
    _gun _this select 1;// FOB2gun_1
                 
    _grp _this select 2;//  _grp name

            
    while {alive _unit} do {sleep 1};
            if !(
    alive _unitthen {
               
    sleep 10+random 10;
               
    _unit _grp createUnit ["BAF_Soldier_DDPM"getPos _gun, [], 0.6"form"];
               
    _unit assignAsGunner _gun;
               
    _unit moveInGunner _gun;
               
    _unit addEventHandler ["killed",{_this execVM "scripts\dead.sqf"}];
              [
    _unit,_gun,_grpspawn ReplaceGunner;
           };
        }; 
    The reason to change the name to a local variable _unit,_gun ect is so that you can call that script multiple times as it allows variable names.
    If you used hq2gunner_1,FOB2gun_1 you'd have to have a different script for each object.

    I'm not sure that will help but as I said I suck at explanations.

  5. #5
    Master Gunnery Sergeant
    Join Date
    Oct 9 2008
    Location
    New york & Florida
    Posts
    1,100
    Author of the Thread
    Quote Originally Posted by F2k Sel View Post
    in most case you could just use
    PHP Code:
    {deleteVehicle _x} foreach  crew _gun+[vehicle _gun]; 
    but if the gun is damaged the gunner gets out and so won't be deleted with the vehicle.


    if you place this at the end of ReplaceGunner section, it will store the name of the spawned unit in variable space so when you need to remove the gun and the created unit it knows who it needs to delete.

    place after [_unit,_gun,_grp] spawn ReplaceGunner;
    PHP Code:
    _gun setvariable ["crew",_unit]; 

    then to delete vehicle and crew the code will only need to know the gun name your deleting
    PHP Code:
    {deleteVehicle _x} foreach  [_gun getvariable "crew",vehicle _gun]; 
    it works in editor so it should work in script, although that was using just one spawned unit.
    @F2K Sel IT works fine for the original gunners but not for the replacement gunners that the script respawn in after the original gunners are killed. any more direction where to go from here? like I said it is not a script killer and most likely the replacement gunners will get killed but if the commander recalls the static weapon section and move the FOB you will have 8 replacement gunners just sitting around the old FOB site

  6. #6
    Actually it may be much easier, when deleting crew you delete the crew first and then the vehicle so try it this way around


    {deleteVehicle _x} forEach (units FOB2StaticGunEast);


    deletevehicle hq2gunner_1;
    deletevehicle hq2gunner_2;
    deletevehicle hq2gunner_3;
    deletevehicle hq2gunner_4;
    deletevehicle hq2gunner_5;
    deletevehicle hq2gunner_6;
    deletevehicle hq2gunner_7;
    deletevehicle hq2gunner_8;
    deletevehicle FOB2EgunTD;
    deleteVehicle FOB2gun_1;
    deleteVehicle FOB2gun_2;
    deleteVehicle FOB2gun_3;
    deleteVehicle FOB2gun_4;
    deleteVehicle FOB2gun_5;
    deleteVehicle FOB2gun_6;
    deleteVehicle FOB2gun_7;
    deleteVehicle FOB2gun_8;

  7. #7
    Master Gunnery Sergeant
    Join Date
    Oct 9 2008
    Location
    New york & Florida
    Posts
    1,100
    Author of the Thread
    @F2k Sel I will try to put the gunners first (: do you want this {deleteVehicle _x} forEach (units FOB2StaticGunEast); or {deleteVehicle _x} foreach [_gun getvariable "crew",vehicle _gun]; at the top of the SQF that recalls the units and sets the timer for the new variables.

  8. #8
    Just had another look and I think it's sorted.


    spawns had some wrong names that I fixed.
    Spoiler:




    Clean up.
    Spoiler:
    Last edited by F2k Sel; Today at 01:49.

Similar Threads

  1. DMZ Delete [script]
    By Demonized in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 31
    Last Post: Mar 10 2012, 22:28
  2. Unit Delete Script [Help]
    By Asung in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 3
    Last Post: Mar 7 2012, 02:34
  3. Delete Trigger via script
    By psvialli in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 5
    Last Post: Aug 5 2011, 20:38
  4. script for M240 gunner to have an assistant gunner?
    By pstennisace in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 2
    Last Post: Sep 14 2010, 04:04
  5. Delete vehicles script
    By wld427 in forum ARMA - MISSION EDITING & SCRIPTING
    Replies: 1
    Last Post: Jan 16 2009, 05:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •