Jump to content
Nicoman35

How to detect when player gives order to AI?

Recommended Posts

When the player commands an  AI seated as gunner in an artillery turret to fire at a certain position, is it somehow possible to 'catch' this order somehow? I am working on a mod, that displays predicted impact positions of artillery shells. Working good except for two rounds: Guided and laser guided. Those rounds behave different. The moment the player orders to fire a laser guided round at a certain position, that position is memorized . The round will impact at that position, if he laser designation is moved more than 100 m or so away from that memorized position. If the designation is moved within that 100 m radius, the round hits the laser designation.

And here is the problem. I need to know that very position lying in the center of the 100 m radius.

Fired event does not help, as from order to fire, up to the artillery unit actually firing, several seconds pass.

Any ideas?

Share this post


Link to post
Share on other sites

currentCommand returns the fire command when you issue one to the AI gunner (like "FIRE AT POSITION"), so I suppose that could help.
Unfortunately there's no event for that so you need to pol it via some loop.

Share this post


Link to post
Share on other sites

Oh, sorry, I overlooked you answer. Many thanks h, I already knew about currentCommand. Does not help me much, because I would need to know the coordinates the arty gunner was ordered to fire at.

Guess I ran into another game engine limitation here ^^. Funny thing is: The impact prediction for HE rounds works well. I use some physics formula to predict the impact position of the shell based on it's speed and angle. The accuracy is 4 to 5 m. 

For guided and laser guided, it does NOT work. When fired, the round comports EXACTLY like a HE round. It aims a random position 0 to 80m or so from the ordered target position. 3 or 4 seconds before impact, it is 'transformed' into the precision ammo, which then hits the desired spot; or the laser mark.

So, there is no way of getting this position.

With the exception of a loop. And I HATE loops. Because they are stupid. 99.9999% of the time they do nothing but eating performance.

Share this post


Link to post
Share on other sites

How about mouseButtonDown event? Something like (pseudo code)

(call BIS_fnc_displayMission) displayAddEventHandler ["mouseButtonDown", {
	[] spawn {
		private _timeout = time;
		waitUntil {count (currentCommand (gunner (vehicle player))) > 0 || _timeout - time > 1};
		if (_timeout - time > 1) exitWith {hint "TOOK TOO LONG"};
		if (currentCommand (gunner (vehicle player)) == "FIRE AT POSITION") then {
			hint format ["POS %1", screenToWorld getMousePosition];
			THE_TARGET_POS = screenToWorld getMousePosition;
		};
	};
}]

:shrug:

  • Like 1

Share this post


Link to post
Share on other sites

I would like to get the coordinates of an artillery commanded to fire at a certain position. Usually, you open the map, select artillery units, opening the command menu. Then you mousewheel scroll through the menu until you got the needed round and number of rounds to be fired. All good, when mouse button is used for selecting the menu points. But what when the player uses 'space'? Will make some loop then :(. Let's see what I come up with. Many thanks for your suggestion, h-

Share this post


Link to post
Share on other sites

To account for space or any other keyboard key you could use keyDown event in addition to the mouse event.
This of course requires some checks to be performed so that things won't trigger several times, overlap etc. but sounds it might be doable, maybe.

Share this post


Link to post
Share on other sites
7 hours ago, Nicoman35 said:

I would like to get the coordinates of an artillery commanded to fire at a certain position. Usually, you open the map, select artillery units, opening the command menu. Then you mousewheel scroll through the menu until you got the needed round and number of rounds to be fired. All good, when mouse button is used for selecting the menu points. But what when the player uses 'space'? Will make some loop then :(. Let's see what I come up with. Many thanks for your suggestion, h-

 

The artillery can be fired from unit's player (fire artillery menu) or via support system (BI modules).

As far as you are using BI modules, these scripts display a marker on map. That's not the case for direct command on subordinate unit.

You can grab the marker's position by:
 

addMissionEventHandler ["MarkerCreated", {
  params ["_marker"];
  _marker spawn {
    params ["_marker"];
    sleep 0.1;
    if (markerType _marker isEqualTo "mil_destroy" && "(ETA: " in markerText _marker) then {
      ARTTARGETPOS = AGLToASL markerpos _marker
    }
  };
}];

Check with your mods. Marker type can be different, as well as marker text.

The sleep seems to be mandatory because this MEH fires as soon as a marker is created so markerType and markerText can return ""  if not yet set.

  • Like 1

Share this post


Link to post
Share on other sites

Hey pierremgi, just tested your code:

addMissionEventHandler ["MarkerCreated", {
  params ["_marker"];
  _marker spawn {
    params ["_marker"];
    sleep 0.1;
	diag_log formatText ["%1%2%3", time, "s  _marker: ", _marker];
    if (markerType _marker isEqualTo "mil_destroy" && "(ETA: " in markerText _marker) then {
      ARTTARGETPOS = AGLToASL markerpos _marker;
	  diag_log formatText ["%1%2%3", time, "s  ARTTARGETPOS: ", ARTTARGETPOS];
    }
  };
}];

 

Inserted some diag_log for checks. I observed it works when I manually place some markers on the map opened with 'M', but it does not work when I open the artillery computer and click on the artillery computer map. Do you have an idea, how to get it working on the artillery computer map?

Share this post


Link to post
Share on other sites
8 hours ago, Nicoman35 said:

 

Inserted some diag_log for checks. I observed it works when I manually place some markers on the map opened with 'M', but it does not work when I open the artillery computer and click on the artillery computer map. Do you have an idea, how to get it working on the artillery computer map?

 

You need to add an EH when clicking on map of artillery computer:

 

[] spawn {
  disableSerialization;   
  private "_displ";
  while {true} do {     
    waitUntil {_displ = ({ if !(isNull (_x displayCtrl 510)) exitWith {_x}; displayNull } forEach allDisplays) displayCtrl 510; !isNull _displ};   
    systemChat "Artillery computer opened";
    _eh = (findDisplay -1 displayCtrl 500) ctrlAddEventHandler ["mouseButtonDown","
      systemChat str ((_this select 0) ctrlMapScreenToWorld [_this select 2,_this select 3])
    "];
    waitUntil {isNull _displ};
    (findDisplay -1 displayCtrl 500) ctrlRemoveEventHandler ["mouseButtonDown",_eh];
    systemChat "Artillery computer closed";   
  };
};

 

  • Like 1

Share this post


Link to post
Share on other sites

😀 Oh yes. Just what I needed. Many thanks pierremgi.

 

 

Wish I had become a programmer sometimes.

Share this post


Link to post
Share on other sites

One last question. Is it somehow possible to get the vehicle, from which the control #500 was opened? Imagine a rare case when player sits in an artillery unit, but is in control over a mk 45 ship cannon.

I ask because I would like to save the coordinates as a variable on the vehicle the artillery computer was opened on.

Share this post


Link to post
Share on other sites

vehicle player setVariable ["whatYouWant",((_this select 0) ctrlMapScreenToWorld [_this select 2,_this select 3])};

 

or perhaps cameraOn instead of vehicle player. I don't have time to to test that.

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

×