Jump to content

Trigger in ME for AI


hog_driver111th
 Share

Recommended Posts

Does anyone know of a way to put in triggers for the gunners or someone in the helo to call out enemy vehicles? I'm guessing it'd take quite a bit of work to get something like that implemented into mission... I'm just thinking about how we're basically flying alone in the Huey with 3 dummies.

A-10C - FC3 - CA - L-39 - UH1 - P-51 - Hawk - BS2 - F-86 - Gazelle - F-5E - AV8B - F/A-18C

i5-4590 - GTX 1060 - Oculus CV1 - TM:Warthog

[sIGPIC]http://forums.eagle.ru/signaturepics/sigpic9979_1.gif[/sIGPIC]

Link to comment
Share on other sites

Hi,

 

Interesting problem - here's my solution....

 

You'll need to know a bit about lua to understand it.

 

Add two triggers.

 

1) MISSION START - DO SCRIPT FILE (MistV1_1.lua) (library from Grimes/Speed)

2) ONCE - DO SCRIPT FILE(SpotEnemy.lua)

 

The code for SpotEnemy.lua is here

 

badGuys = mist.makeUnitTable({'[red][vehicle]'})
function spot()
local playerPos = Unit.getByName('Player'):getPosition().p
for index=1,table.getn(badGuys) do
 local pos=Unit.getByName(badGuys[index]):getPosition().p
 local dist2=(playerPos.x-pos.x)^2 + (playerPos.y-pos.y)^2 + (playerPos.z-pos.z)^2
 if dist2 < (4000*4000) then
  local bearing = math.atan2( pos.z-playerPos.z,pos.x-playerPos.x) 
  bearing = mist.utils.toDegree(bearing)
  if bearing < 0 then
    bearing = 360 + bearing
  end
  bearing = math.floor((bearing/5)+0.5)*5
  if(dist2<0) then
   dist2=1
  end
  trigger.action.outText("Contact bearing "..bearing.." for "..(math.floor((100.0 * (math.sqrt(dist2)/1000.0) * 0.53995))/100.0).."nm",5)
  break
 end
end
mist.scheduleFunction(spot,{},timer.getTime() + 10)
end
spot()

 

This will basically set up simple schedule function that will display 'Contact bearing XXXX for YYYYY' every 10 seconds as long as there are enemy vehicles within a 4Km radius of your helicopter. The script assumes you are flying as a unit called 'Player'. It's crude but should give you an idea of what's possible. Also, it only reports the first unit it finds.

 

I've attached a sample mission demonstrating it.

Cheers,

Stacker.

SpotEnemy.miz

i7-4790K@4.7GHz : EVGA 1070 SC : 16GB Corsair Vengence Pro : 2xEVO 840 SSD : EVGA 850W PSU : CORSAIR H100i Cooler : ASUS Z97-AR MB : CORSAIR OBSIDIAN 750D FULL TOWER

Link to comment
Share on other sites

I may use this script. I've had an issue with "the player" being able to see infantry on the ground in one of my missions. Now I just have to do some reading how to use scripts. :)

 

Yeah, feel free. It's definitely worth reading up about scripting. I only started looking into it a week ago so there's still lots to learn.

 

BTW - the sharp eyed will notice the bug. :doh: The following

  if dist2<0 then

 

should be

 if dist2<=0 then

 

Sqrt() functions really don't like 0 values :)

i7-4790K@4.7GHz : EVGA 1070 SC : 16GB Corsair Vengence Pro : 2xEVO 840 SSD : EVGA 850W PSU : CORSAIR H100i Cooler : ASUS Z97-AR MB : CORSAIR OBSIDIAN 750D FULL TOWER

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...