Jump to content
Sign in to follow this  
MassDefibrillator

AI Helicopter search light

Recommended Posts

I'm creating a night mission and I want the Opfor helicopter to be flying around with it's search light on. So far however I have only been able to get the AI to fly with collision lights by using safe behavior.

If anyone has worked this out I would love to know how to do it.

thanks in advance

Mass

Share this post


Link to post
Share on other sites

Does Combat or Aware work by any chance?

Share this post


Link to post
Share on other sites

try In Careless. I did see that some one was able to wright some code to go into the init box of the unit. I would do a search of the fourms first.

Share this post


Link to post
Share on other sites

A guy called KNG figured this out, you have to keep turning the light on D:

Share this post


Link to post
Share on other sites

name your helicopter heli1 in the editor and put in the init.sqf

null=[] spawn { while {true} do { player action ["lightOn", heli1]; player action ["collisionlightOn", heli1]; sleep 0.01};};
  • Like 1

Share this post


Link to post
Share on other sites

If you want this script to work without destroying Server CPU for MP missions (the 0.01 sleep): Full credit goes to LECKS from ASOR (also made the gear selector http://www.armaholic.com/page.php?id=26181)

this is a copy paste from my mission script where I want the choppers to surround (but not shoot) for a "capture" mission. Hence the careless and captive true. They also started as simulation disabled, so remove this if your choppers are active to start with. I wait 30 seconds so they can take off the ground prior to the clone thing - sometimes in uneven terrain they will blow up if you dont wait for them to take off and be airborne.

HINT "Lights SCRIPT RUNNING";

(driver _this) setCaptive true;

(group driver _this) setBehaviour "Careless";

(driver _this) setBehaviour "Careless";

_this enablesimulation true; _this enablesimulationglobal true;

sleep 30;

_type = typeOf _this;

_copy = _type createVehicle getPos _this;

_copy setHit [getText(configFile >> "cfgVehicles" >> (typeof _copy) >> "HitPoints" >> "HitHRotor" >> "name"), 1];

_copy attachTo [_this, [0,0,0]];

_copy setPilotLight true;

_copy setCollisionLight true;

_copy engineOn true;

(driver _this) setCaptive true;

Share this post


Link to post
Share on other sites

Where does this go? What mestoth suggested.

Share this post


Link to post
Share on other sites

heli1 setBehaviour "SAFE"; 
["1", "onEachFrame", {player action ["lightOn",heli1];}] call BIS_fnc_addStackedEventHandler;

This would go in any script or into the initialisation field of the helicopter.

Share this post


Link to post
Share on other sites

As of Arma 3 1.32 you don't need to force light on onEachFrame anymore, which tends to affect performance.

The new command setPilotLight does what you need. Works for vehicle headlights and aircraft/helicopter searchlights.

Say you have a heli named BIS_heli, just execute

BIS_heli setPilotLight true;

Share this post


Link to post
Share on other sites
As of Arma 3 1.32 you don't need to force light on onEachFrame anymore, which tends to affect performance.

The new command setPilotLight does what you need. Works for vehicle headlights and aircraft/helicopter searchlights.

Say you have a heli named BIS_heli, just execute

BIS_heli setPilotLight true;

That's good to know, thanks for that!

Share this post


Link to post
Share on other sites

I tried that in a trigger ON ACT. but it didnt turn on the heli's light. I noticed that the spot light tried to turn on, but for a split second. It works fine in the vehicle's init, but I'm trying to get this to work on a trigger or specific waypoint. Light heli arrives at a location it needs to search, turns on it's light, patrols around, then kills the light and moves to some other waypoint.

Edited by RTEK

Share this post


Link to post
Share on other sites
I tried that in a trigger ON ACT. but it didnt turn on the heli's light. I noticed that the spot light tried to turn on, but for a split second. It works fine in the vehicle's init, but I'm trying to get this to work on a trigger or specific waypoint. Light heli arrives at a location it needs to search, turns on it's light, patrols around, then kills the light and moves to some other waypoint.

You're right, this does not work, same problem as with all other commands, the heli turns off the light after a second.

I would suggest to use my method, the performance impact should be negligible.

Share this post


Link to post
Share on other sites

Hi everyone,


 


I had tried all of the suggested work-arounds but still got the flickering. However, I had heard about attaching a vehicle with lights to a helicopter with attachTo command and then turning the lights of the attached vehicle on. This results in no flicker at all.


 


I eventually discovered that the remote controlled drone (AR-2 Darter) is ideal for this purpose as its light is very similar to, for example, the Pawnee search light. It is also very small and so can be virtually hidden in the body of the Pawnee etc. So this is the resulting code:


 


(I created a script called YB_enemyHeliSearchLight.sqf containing the following code and then put it in mission root direcotry and then executed it using: null = _enemyHeliDriver execVM "YB_enemyHeliSearchLight.sqf";  where a driver / pilot of an enemy (i.e. AI) helicopter (of Pawnee body type) has been made equal to _enemyHeliDriver):



if (isServer) then
{ private ["_driver", "_enHeli"];
//Prepare variables:
_driver = _this;
_enHeli = vehicle _this;

while {sleep 60; true} do
{
//Wait until it is night time:
waitUntil {sleep 30; (dayTime > 20 || dayTime < 4)};

//Create "search light" (UAV) and attach it to the helicopter:
_uav = "B_UAV_01_F" createVehicle getPos _enHeli;
_uav attachTo [_enHeli, [0,1.5,-0.5]]; _uav setVectorUp [0, 0.5, 1];

//Wait until helicopter takes off:
waitUntil {sleep random 30; (getPosATL _enHeli select 2) > 5};

//If still night time, turn the search light on:
if (dayTime > 18 || dayTime < 7) then
{
_driver action ["lightOn", _uav];
};

//Wait until helicopter lands, is destroyed, or it is day time:
waitUntil {sleep 3; (getPosATL _enHeli select 2) < 5 || damage _enHeli == 1 || (dayTime < 20 && dayTime > 4)};

//Delete search light:
_driver action ["lightOff", _uav];
deleteVehicle _uav;

//Rinse, repeat via the while-do loop, in case helicopter takes off again / it becomes night again etc.
};
};

Hope this helps.


 


Cheers from Far North Queensland, Australia


 


PS: If you want this enemy helicopter to "stalk" / "hunt" a player, you can set a way point such as this on a regular basis:



//NB: curTargP1 needs to be first set as a player you are wanting the helicopter to pursue
//NB: _driver needs to be first set as the enemy (AI) unit piloting the helicopter

curTargPos = [ ((getPos curTargP1 select 0) + (_enSpreadDist - (random _enSpreadDist * 2))),
((getPos curTargP1 select 1) + (_enSpreadDist - (random _enSpreadDist * 2))),
(getPos curTargP1 select 2)];

deleteWaypoint [group _driver, 0]; //Ensure previous waypoint deleted
_heliWaypoint = group _driver addWaypoint [curTargPos, 0, 0];
_heliWaypoint setWaypointType "LOITER";
_heliWaypoint setWaypointLoiterType "CIRCLE_S";
_heliWaypoint setWaypointLoiterRadius 100;
//Make sure helicopter moves slowly and scarily!:
_heliWaypoint setWaypointSpeed "LIMITED";
_heliWaypoint setWaypointBehaviour "COMBAT";
_heliWaypoint setWaypointCombatMode "RED";
group _driver setCurrentWaypoint _heliWaypoint;

Share this post


Link to post
Share on other sites

It flickers because the helicopter's pilot is constantly turning the light off every time the while-do loop turns the light on. Since Arma 3 v1.92, there is a new disableAI command to work around this problem. Here's what I used:

//helo is the name of my helicopter in the editor.

driver helo disableAI "LIGHTS"; //Stops the driver from turning the searchlight/headlight off (or on, for that matter).
helo setPilotLight true; //turns on the searchlight/headlight of the helo.

 

  • Thanks 1

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  

×