Jump to content

Recommended Posts

Posted (edited)

I realized I don't know how to determine if airborn unit/group is a player/client controlled or AI. Anybody knows that?

 

Thanks!

Edited by sea2sky

i5-9600K@4.8GHz 32Gb DDR4 rtx5070ti Quest Pro Warthog on Virpil base

Posted

Sorry, I meant - how to figure that using lua scripting.

i5-9600K@4.8GHz 32Gb DDR4 rtx5070ti Quest Pro Warthog on Virpil base

Posted

Use something like:

if Unit.getPlayerName(unit name being checked) == nil

 

 

if the above is true then it's AI. Note that "unit name being checked" is the actual unit name of the unit you are trying to figure out whether it is AI or human.

  • Like 1
Posted (edited)
Use something like:

if Unit.getPlayerName(unit name being checked) == nil

 

Close. But the Unit.getPlayerName argument must be a unit, not a string (name).

 

So you're gonna need to obtain the unit first (if you haven't already), then invoke "getPlayerName" for this unit. If this function returns a string, it is a player. If not, it's AI.

 

-- obtain unit by name
local unit = Unit.getByName(nameOfUnit)

-- check if the unit has a "player name"
if unit:getPlayerName() then

 -- it's a player

else

 -- it's AI

end

 

Or if you prefer oneliners:

if Unit.getByName(nameOfUnit):getPlayerName() then
 -- it's a player
end

 

http://wiki.hoggit.us/view/DCS_func_getByName

http://wiki.hoggit.us/view/DCS_func_getPlayerName

Edited by gromit190
Posted

Yep you are right. Sorry I haven't had time to look at lua for quite a while so I am forgetting stuff.

 

 

 

 

Close. But the Unit.getPlayerName argument must be a unit, not a string (name).

 

So you're gonna need to obtain the unit first (if you haven't already), then invoke "getPlayerName" for this unit. If this function returns a string, it is a player. If not, it's AI.

 

-- obtain unit by name
local unit = Unit.getByName(nameOfUnit)

-- check if the unit has a "player name"
if unit:getPlayerName() then

 -- it's a player

else

 -- it's AI

end

Or if you prefer oneliners:

if Unit.getByName(nameOfUnit):getPlayerName() then
 -- it's a player
end

http://wiki.hoggit.us/view/DCS_func_getByName

http://wiki.hoggit.us/view/DCS_func_getPlayerName

  • Recently Browsing   0 members

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