Jump to content
Sign in to follow this  
murraywcourt

Lots of triggers generated from an array.

Recommended Posts

I am tryng to create a trigger for each of a range of vehicles. The idea is that speedboats approach the shore and drop men off, however they always come in too fast when under fire and end up launching themselves up the beach where the sit on their sides at a slight angle and cant use their weapons properly. My solution is the creation of a trigger for each speedboat that will slow it down just before it hits the coast. Here it is:

_boats = [boat_1, boat_2, boat_3, boat_4, boat_5]; //group name of speedboats
_physboats = [b_1, b_2, b_3, b_4, b_5]; //names of the speedboats
_b_lands = ["b_land_1", "b_land_2", "b_land_3", "b_land_4", "b_land_5"]; //markers of landing sites 
_b_brakes = ["b_brake_1", "b_brake_2", "b_brake_3", "b_brake_4", "b_brake_5"]; // markers for 'slow down' sites. 
_bwp1 = [];
_btrig = [];
{
// head to shore and drop off marines, this part definitely works
   _wp = _x addWaypoint [markerPos (_b_lands select _forEachIndex), 0];
   _bwp1 set [ _forEachIndex,  _wp ];
   _wp  setWaypointType "TR UNLOAD";
   _wp setWaypointBehaviour "AWARE";
   _wp setWaypointSpeed "LIMITED";

// slow down just before reaching shoreline. 
  _trg=createTrigger["EmptyDetector", markerPos (_b_brakes select _forEachIndex)];
  _btrig set [ _forEachIndex,  _trg ];
  _trg setTriggerArea[100,20,90,true];
  _trg setTriggerActivation[ (_physboats select _forEachIndex),"PRESENT",false]; //activated by speedboat entering area
  _trg setTriggerStatements["this", "(_physboats select _forEachIndex) setvelocity [3, 0, 0]", ""]; //on act speedboat slows down

}forEach _boats;

The triggers don't work, however when I create them individually in the editor they do work. Can anyone see what is going wrong here?

Share this post


Link to post
Share on other sites

_boats = [b_1, b_2, b_3, b_4, b_5]; //names of the speedboats
_b_lands = ["b_land_1", "b_land_2", "b_land_3", "b_land_4", "b_land_5"]; //markers of landing sites 
_b_brakes = ["b_brake_1", "b_brake_2", "b_brake_3", "b_brake_4", "b_brake_5"]; // markers for 'slow down' sites. 
_bwp1 = [];
_btrig = [];
{
// head to shore and drop off marines, this part definitely works
   _wp = (group _x) addWaypoint [getMarkerPos (_b_lands select _forEachIndex), 0];
   _bwp1 set [ _forEachIndex,  _wp ];
   _wp  setWaypointType "TR UNLOAD";
   _wp setWaypointBehaviour "AWARE";
   _wp setWaypointSpeed "LIMITED";

// slow down just before reaching shoreline. 
  _trg = createTrigger["EmptyDetector", getMarkerPos (_b_brakes select _forEachIndex)];
  _btrig set [ _forEachIndex,  _trg ];
  _trg setTriggerArea[100,20,90,true];
  _trg setTriggerActivation[ "VEHICLE","PRESENT",false];
  _trg triggerAttachVehicle [_x];
  _trg setTriggerStatements["this", "(thisList select 0) setvelocity [3, 0, 0]", ""];

}forEach _boats;

Removed the group array, we can get the group for the waypoint by group _x.

Set the trigger activation to "VEHICLE". this gives the trigger the same options as when you group a vehicle to a trigger in the editor.

Added triggerAttachVehicle this groups the boat to the trigger.

Changed the trigger statements, (thislist select 0) As the trigger can only be activated by the grouped vehicle (boat) then select 0 from the list that activated the trigger MUST be the boat.

Think thats about right, untested though

___________________________________________

{
// head to shore and drop off marines, this part definitely works
 _marker = format["b_land_%1", (_forEachIndex + 1)];
   _wp = (group _x) addWaypoint [getMarkerPos _marker, 0];
   _wp  setWaypointType "TR UNLOAD";
   _wp setWaypointBehaviour "AWARE";
   _wp setWaypointSpeed "LIMITED";

// slow down just before reaching shoreline.
_marker = format["b_brake_%1", (_forEachIndex + 1)];
  _trg = createTrigger["EmptyDetector", getMarkerPos _marker];
  _trg setTriggerArea[100,20,90,true];
  _trg setTriggerActivation[ "VEHICLE","PRESENT",false];
  _trg triggerAttachVehicle [_x];
  _trg setTriggerStatements["this", "(thisList select 0) setvelocity [3, 0, 0]; deleteVehicle thisTrigger", ""];

}forEach [b_1, b_2, b_3, b_4, b_5];

Cleaned the script up a little,

Removed all arrays, boats array is now on the end of the forEach command.

No need to store waypoints, if the boats get deleted waypoints are automatically deleted aswell.

Triggers delete themselves after applying velocity to boats.

Markers are all named the same just with a sequential number so formatted marker name instead of needing arrays holding the names.

Edited by Larrow

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  

×