Jump to content
Sign in to follow this  
Drongo69

AI air bombing help

Recommended Posts

I am writing a module to give players control over AI craft for bombing runs. I am not using spawned bombs, I am making the AI fire their onboard bombs. I am capturing the bombs with the fired eventhandler, but I am having trouble with the following points:

  • parsing the target position to the script called by the eventhandler
  • guiding the bomb to hit the target position

Here is the bombing script (this is very WIP code):

_group = _this select 0;
_targetPos = _this select 1;
_IPpos = _this select 2;

_vehicle = vehicle (leader _group);
_distance = 99999;

_vehicle SwitchCamera "Group";

_distance = [_targetPos,_IPpos] call das_fnc_GetDistance;
_group setSpeedMode "Limited";
hint "bomb run";
while {(_distance > 500)} do {
sleep 1;
_distance = [(getPos _vehicle),_IPpos] call das_fnc_GetDistance;
player sideChat format ["%1",_distance];
if (_group in dasAbort) then {_distance = -1};
};

if (_group in dasAbort) exitWith {};
//if (_distance == -1) exitWith {hint "abort"};

hint "At IP";
_group setSpeedMode "Normal";
//_distance = [(getPos _vehicle),_targetPos] call das_fnc_GetDistance;
_distance = 999;
while {(_distance > 200)} do {
if (_group in dasAbort) then {_distance = -1};
sleep 0.1;
_distance = [(getPos _vehicle),_targetPos] call das_fnc_GetDistance;
//	if (_group in dasAbort) then {_distance = -1};
player sideChat format ["in %1",time];
};

player sideChat "*** BOMB ***";
hint "Attack";

_logic = "Logic" createVehicleLocal _targetPos;

// None of these work
//_bombEH = _vehicle addEventHandler ["fired",{nul = _this execVM "DAS\Scripts\Control\Fired.sqf"}];
//_bombEH = _vehicle addEventHandler ["fired",{nul = [_this,_targetPos,_logic] execVM "DAS\Scripts\Control\Fired.sqf"}];
_unit = objNull;
_ammo = objNull;
//_bombEH = _vehicle addEventHandler ["fired",{_unit = _this select 0;_ammo = _this select 4}];
_bombEH = _vehicle addEventHandler ["fired","hint format ['unit: %1',_this select 0]"];
_bombEH = _vehicle addEventHandler ["fired",{_unit = _this select 0}];
//this addEventHandler ["killed", "hint format ['Killed by %1',_this select 1]"]

_tube = "Bomb_03_Plane_CAS_02_f";
_vehicle fire _tube;
sleep 0.5;
//_bomb = nearestobject [_unit,_ammo];

// This works
player sideChat format ["UNIT: %1",_unit];
// This doesn't
//player sideChat format ["B: %1  %2   %3",_bomb,_unit,_ammo];

sleep 3;
_vehicle removeEventHandler ["fired",_bombEH];

sleep 1;
nul = [group] execVM "DAS\Scripts\Control\RTB.sqf";

Here is the script called by the eventhandler (Fired.sqf):

_inputArray = _this select 0;
_targetPos = _this select 1;

// check if everything is parsed properly
// This is parsed
player sideChat format ["IA: %1",_inputArray];
// This isn't
player sideChat format ["TP: %1",_targetPos];
// Bomb guidance stuff will go here

Can anybody tell me how to:

a) parse _targetPos to Fired.sqf

b) guide the bomb to _targetPos (maybe with setVelocity?)

Thanks.

Share this post


Link to post
Share on other sites

I think your going to have to make _targetPos a global variable, because I don't believe there is a way to pass local variables into the scope of the code ran by the EH. You could do something with get/set variable however:

_targetPos = whatever;

missionNamespace setVariable ["targetPosition",_targetPos];

//fired.sqf
_targetPos = missionNamespace getVariable "targetPosition";

Edited by JShock

Share this post


Link to post
Share on other sites

Looking forward to this script..sounds good.

best of luck with it drongo

Share this post


Link to post
Share on other sites
Can anybody tell me how to:

a) parse _targetPos to Fired.sqf

You need to format the _targetPos into the code statement before it gets sent to the event handler. Something like ...

_bombEH = _vehicle addEventHandler ["fired", compile format [ "nul = [ _this, %1] execVM 'DAS\Scripts\Control\Fired.sqf'", _targetPos] ];

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  

×