Jump to content

How to use Unit.getRadar()?


L39Tom

Recommended Posts

Hi,

I want to know if a unit has detected a plane and found that function:

boolean, Object Unit.getRadar(Class Self )

 

example: unitRadar,target=Unit.getByName(red):getRadar()

 

1st val gets true, if the unit has a search radar.

The 2nd val returns the object that has been detected, right?

 

How can I get the name of the detected object("target")?

Link to comment
Share on other sites

I haven't tested it, but I'm guessing this would work:

 

unitRadar,target = Unit.getByName("[color="Red"]ME PILOT name of the unit using the radar[/color]"):getRadar()

target:getName() [color="Blue"]-- Should return a string containing the name of the unit being painted[/color]

[color="Blue"]-- It can be used in messages:[/color]

trigger.action.outText("Name of the unit being painted = "..target:getName(),10) 

[color="blue"]-- In logic checks (probably what you're after):[/color]

if target:getName() == "[color="Red"]ME PILOT name of the unit you're interested in[/color]" then

do stuff

end


[color="blue"]-- etc.[/color]


Edited by Hardcard
Link to comment
Share on other sites

As I wanted to know when a plane gets detected by radar from a sam site, I hope the function getRadar() could bring me further.

With your help Hardcard I find something interesting.

 

1.The boolean "unitRadar" is getting true just for search radar units.

2.In the case of a S300-site just the launcher-units gives you the "target", but just before it fires a missile.

 

Is there an other function fits better.

(In a mission I want to fire a flag when a player flies to high an gets detected by radar)

 

PS: Try it with "isTargetDetected" aswell, but that function stays true in line of sight and radar detection after once gets true.

Link to comment
Share on other sites

Ok, so you're only interested in triggering a flag when a client flies over a certain altitude and gets detected... right?

 

What would be the altitude threshold?

 

Also, can you provide more details on detection conditions?

 

Do you want the flag to be triggered when the client gets detected by ANY radar or only when it gets detected by certain specific radar units?


Edited by Hardcard
Link to comment
Share on other sites

Ok, so you're only interested in triggering a flag when a client flies over a certain altitude and gets detected... right?

The client/player should stay as low as possible to avoid the radar and should use the terrain to stay undetected. If getting detected a red flight should start.

 

This is not done with checking MSL-AGL, so I wanted to combine radar detection (search radar sites - radar picture) and some visual detection (red units - Line of sight and distance).

To get LOS and distance is no problem, but I have still no clue to get that radar detection.

Link to comment
Share on other sites

Here's a way of getting the unit's altitude from ground (required fields marked in red, don't remove the quotation marks):

 

 

local Target = Unit.getByName("Unit/PILOT name of the client in ME")

 

local Target_Position = Target:getPosition()

 

local Ground_Elevation_MSL = land.getHeight( { x = Target_Position.p.x, y = Target_Position.p.z } )

 

local Target_Altitude_Ground = ( Target_Position.p.y - Ground_Elevation_MSL ) -- This will return the client's altitude from ground in meters

 

 

-- If you want to get the value in feet, use this (keep in mind that the DCS scripting engine works in meters, though):

 

local Target_Altitude_Ground_Feet = Target_Altitude_Ground * 3.281

 

 

-- If you want to, you can also round the altitude values (it isn't required for logic checks, but comes in handy when you need to include the values in text messages):

 

local Target_Altitude_Ground_Rounded = math.floor( Target_Altitude_Ground + 0.5 ) -- This will return the client's altitude from ground in meters (rounded)

 

local Target_Altitude_Ground_Feet_Rounded = math.floor( Target_Altitude_Ground_Feet + 0.5 ) -- This will return the client's altitude from ground in feet (rounded)

 

 

 

-- In any case, you can then use the client's altitude from ground in logic checks:

 

if Target_Altitude_Ground > altitude from ground threshold in meters then

 

do stuff

 

end

 

 

 

 

As for radar detection, let me think about it.


Edited by Hardcard
Link to comment
Share on other sites

  • Recently Browsing   0 members

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