Help with UnitDefs Weapons

Help with UnitDefs Weapons

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Help with UnitDefs Weapons

Post by very_bad_soldier »

Hi all,

I'm trying to figure out if a unit is able to shoot at air or if it does not. For this reason I tried to read the units' onlyTargets-category "notair" to do that.
So I hoped the boolean value would be different for example for the armanni and for the armflak.

Below is the code I use:

Code: Select all

local udef = UnitDefs[Spring.GetUnitDefID(unitID)]
local targetCat = udef.weapons[1].onlyTargets;

local tcat = "true"
if ( targetCat["notair"] == false ) then
  tcat = "false"
end
	    
Spring.Echo( udef.humanName .. " NotAir: " .. tcat )
The problem is that in both cases (armanni and armfalk) the value is true and I expected them to be different since the flak shoots at air while the anni does not.
Could anyone tell me plz what I am doing wrong? Many thanks in advance...
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Post by jK »

There are multiple ways to define if an unit should only attacks air. Also there is a lot of anti air that attacks primarily air, but can still attack ground (see XTA,CA,...).

But if you only want to find units that do the first, you have first to check their UnitDef as you do and if you don't find it there you have to check its WeaponDefs. So you can set a toAirWeapon in the weapon's tdf. Btw there isn't a toAirWeapon tag in the WeaponDef, instead it writes into the onlyTarget category (the one in the WeaponDef!).
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

toAirWeapon also prevents the unit from shooting at ground. It uses the VTOL category, BTW.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

What about games that don't use the VTOL category, then?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Post by jK »

with the new luaDefs (svn) you will be able to create your own tags like toGround, toWater, toUnderwater, toAir etc. and you will be able to map them to your own categories.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Then you're fucked.
tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Post by tombom »

KDR_11k wrote:Then you're fucked.
I prefer this answer.
Post Reply

Return to “Lua Scripts”