Jump to content
Sign in to follow this  
malkekoen

Adding ID and deleting a spawned unit?

Recommended Posts

I have a helicopter spawning script, taken from Demonized. It uses the BIS functions module; I have modified it a bit suit my needs:

waituntil {!isnil "bis_fnc_init"};

// create drophelo with full crew at 100 altitude, setting heli to spawn at high altitude sometimes causes nosedive to fiery death when alot of scripts are running, works fine if not. set 100 to 0 if issues arise in your mission
_sv = [[getMarkerPos "marker1" select 0, getMarkerPos "marker1" select 1, 100], random 360, "AH1Z", WEST] call BIS_fnc_spawnVehicle;

// Name the vehicle and group
_gunship = _sv select 0;  // vehicle spawned.
_gunshipgroup = _sv select 2;  // group of vehicle so waypoints work.
_helopilot1 = (driver _gunship);  // get pilot of drophelo
_helopilot1 setSkill 1;  // set high skill on pilot.
_helopilot2 = (gunner _gunship);  // get pilot of drophelo
_helopilot2 setSkill 1;  // set high skill on pilot.


// set what height drophelo will fly in: this seems to fix the crash when spawned at altitude
_gunship flyInHeight 100;

// go to random Position 3000m from center of city marker, flyby..
_wp0 = _gunshipgroup addWaypoint [getMarkerPos "marker2", 500];
_wp0 setWaypointType "SAD";
_wp0 setWaypointSpeed "LIMITED";
_wp0 setWaypointBehaviour "STEALTH";  // set to "CARELESS" if trouble with enemys distracting heli.
_wp0 setWaypointFormation "LINE";
_wp0 setWaypointCombatMode "RED";


_wp1 = _gunshipgroup addWaypoint [getMarkerPos "marker3", 0];
_wp1 setWaypointType "MOVE";
_wp1 setWaypointSpeed "FULL";
_wp1 setWaypointBehaviour "STEALTH";  // set to "CARELESS" if trouble with enemys distracting heli.
_wp1 setWaypointFormation "LINE";
_wp1 setWaypointCombatMode "RED";

// activate first move for pilot incase something stops 1st wp to be executed somehow
_helopilot1 doMove (getWPPos _wp0); 


//Thanks to Demonized for this script (Bohemia forums).
//UncleFu22

Now my first question is how can I add a name to this group, and make it talk (in ie. sidechat format).

I have tried this:

// Name the vehicle and group
_gunship = _sv select 0;  // vehicle spawned.
_gunshipgroup = _sv select 2;  // group of vehicle so waypoints work.
_helopilot1 = (driver _gunship);  // get pilot of drophelo
_helopilot1 setSkill 1;  // set high skill on pilot.
_helopilot2 = (gunner _gunship);  // get pilot of drophelo
_helopilot2 setSkill 1;  // set high skill on pilot.
_gunshipgroup setGroupId ["Blah","GroupColor4"]

And I tried:
_helopilot1 setGroupId ["Blah","GroupColor4"]

But no luck. Anyone know how to do it correctly?

Also I would like it to delete itself when reaching wp1. I'm not sure if I'm supposed to add a waypoint statement or how to do it, but I tried this with no luck:

_wp1 = _gunshipgroup addWaypoint [getMarkerPos "marker3", 0];
_wp1 setWaypointType "MOVE";
_wp1 setWaypointSpeed "FULL";
_wp1 setWaypointBehaviour "STEALTH";  // set to "CARELESS" if trouble with enemys distracting heli.
_wp1 setWaypointFormation "LINE";
_wp1 setWaypointCombatMode "RED";
_wp1 setWaypointStatements deleteVehicle _gunship;

I have also tried to delete the pilots and the group, but no luck. I'm not sure what command to use, but it should be the equivilant of On Act in the editor.

Share this post


Link to post
Share on other sites

Hi, you can give the helicopter's group a name by using the setVehicleInit command right after the helo is created, like this...

_gunship setVehicleInit "gunshipgroup = group this";
processInitCommands;

you can also give the helicopter itself a name by adding this...

_gunship setVehicleInit "gunshipgroup = group this;gunship = this";
processInitCommands;

To delete the helicopter within a waypointStatement though, you don't need to have the helicopter's name, it would look something like this...

_wp1 setWaypointStatements ["true", "{deletevehicle _x} foreach crew (vehicle this);deleteVehicle (vehicle this);deleteVehicle this"];

That will delete the crew, the helicopter, and the waypoint.

Hope that helps,

-AD

EDIT: Have to correct myself here, the gunshipgroup name would have to be given to the leader's init and not the vehicle's so something like this..

_gunshipgroupleader = leader _gunshipgroup
_gunshipgroupleader setVehicleInit "gunshipgroup = group this";
processInitCommands;

Edited by ADuke

Share this post


Link to post
Share on other sites

Very interesting. Thank you very much ADuke, I will give it a try once I get back to my PC on monday.

Share this post


Link to post
Share on other sites

Hi ADuke. I just tested you're scripts, but I'm not sure I placed them right in the script.

This is how my script looks:

waituntil {!isnil "bis_fnc_init"};

// create drophelo with full crew at 100 altitude, setting heli to spawn at high altitude sometimes causes nosedive to fiery death when alot of scripts are running, works fine if not. set 100 to 0 if issues arise in your mission
_sv = [[getMarkerPos "marker1" select 0, getMarkerPos "marker1" select 1, 100], random 360, "AH1Z", WEST] call BIS_fnc_spawnVehicle;

// Name the vehicle and group
_gunship = _sv select 0;  // vehicle spawned.
_gunshipgroup = _sv select 2;  // group of vehicle so waypoints work.
_helopilot1 = (driver _gunship);  // get pilot of drophelo
_helopilot1 setSkill 1;  // set high skill on pilot.
_helopilot2 = (gunner _gunship);  // get pilot of drophelo
_helopilot2 setSkill 1;  // set high skill on pilot.

[color="DarkRed"]_gunshipgroupleader = leader _gunshipgroup
_gunshipgroupleader setVehicleInit "gunshipgroup = group this"; this setIdentity "AH-1Z/A";
processInitCommands;[/color]


// set what height drophelo will fly in: this seems to fix the crash when spawned at altitude
_gunship flyInHeight 100;

// go to random Position 3000m from center of city marker, flyby..
_wp0 = _gunshipgroup addWaypoint [getMarkerPos "marker2", 500];
_wp0 setWaypointType "MOVE";
_wp0 setWaypointSpeed "LIMITED";
_wp0 setWaypointBehaviour "STEALTH";  // set to "CARELESS" if trouble with enemys distracting heli.
_wp0 setWaypointFormation "LINE";
_wp0 setWaypointCombatMode "RED";


_wp1 = _gunshipgroup addWaypoint [getMarkerPos "marker3", 0];
_wp1 setWaypointType "MOVE";
_wp1 setWaypointSpeed "FULL";
_wp1 setWaypointBehaviour "STEALTH";  // set to "CARELESS" if trouble with enemys distracting heli.
_wp1 setWaypointFormation "LINE";
_wp1 setWaypointCombatMode "RED";
[color="DarkRed"]_wp1 setWaypointStatements ["true", "{deletevehicle _x} foreach crew (vehicle this);deleteVehicle (vehicle this);deleteVehicle this"];[/color]


// activate first move for pilot incase something stops 1st wp to be executed somehow
_helopilot1 doMove (getWPPos _wp0); 


//Thanks to Demonized for this script (Bohemia forums).
//UncleFu22

Funny actually, if I keep this part:

[color="DarkRed"]_gunshipgroupleader = leader _gunshipgroup
_gunshipgroupleader setVehicleInit "gunshipgroup = group this"; this setIdentity "AH-1Z/A";
processInitCommands;[/color]

it spawns fine but just hovers at the spawn point.

If I delete the above and keeps this:

[color="DarkRed"]_wp1 setWaypointStatements ["true", "{deletevehicle _x} foreach crew (vehicle this);deleteVehicle (vehicle this);deleteVehicle this"];[/color]

it will move to the last waypoint and hover, then drop backwards and crash. Every time. So it deletes itself alright :rolleyes:

How should the code go into the script then?

Share this post


Link to post
Share on other sites

The syntax is probably like this....

_gunshipgroupleader setVehicleInit "gunshipgroup = group this; this setIdentity ""AH-1Z/A""";

or.... same thing but single quotes for AH-1Z/A....

_gunshipgroupleader setVehicleInit "gunshipgroup = group this; this setIdentity 'AH-1Z/A'";

Both should work.

Share this post


Link to post
Share on other sites

It works fine!

Thanks a lot.

By the way, the trouble with deleting the group is also fixed. I named the vehicle like this:

_wp1 setWaypointStatements ["true", "{deletevehicle [color="DarkRed"]_gunship[/color]} foreach crew (vehicle this);deleteVehicle (vehicle this);deleteVehicle this"];

and it did it. Deletes itself nicely on the waypoint.

Thank you so much all of you guys. It's a fantastic community here!

Edit:

Ok I noticed that the aircraft deletes itself, and also the pilot (i suppose) but one crewman is left hanging in the air, and falls to his death. How can you delete that last crew member?

I also tested, it doesn't matter if you put _gunship, _gunshipgroup, or gunshipgroup into the script. It does the same.

Edited by malkekoen
Problems deleting crew

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×