What is the best way to detect air fighter?

What is the best way to detect air fighter?

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

Moderator: Moderators

Post Reply
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

What is the best way to detect air fighter?

Post by dizekat »

Hello,

I'm making simple widget that will remove all commands from air units leaving factory, except for fighters. (i dont want anything else on patrol anyway... brawlers on patrol are pretty useless, radar planes on patrol lag the game a LOT (i'd say 20 radars = 200 fighters), bombers on patrol are lulz, etc)
I'm using factory kickstart widget as starting point, so everything is there.
I only need to do something like
if ud.canFly and its a fighter then Spring.GiveOrderToUnit(id,CMD.STOP,{},{}) end

What is the best way to tell if it is fighter?
Should i check all weapons and see if it can shot air? (like defencerange widget does) Or theres better way?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: What is the best way to detect air fighter?

Post by lurker »

Looks like you can literally check if ud.type == "Fighter"
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

lurker wrote:Looks like you can literally check if ud.type == "Fighter"
Thanks! Very nice.
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

done, doesnt work well though.
Using
if ud.canFly and not (ud.type == "Fighter") then
Spring.GiveOrderToUnit(unitID,CMD.STOP,{},{})
end
In BA 6.21 it doesnt stop:
all scouts, radars, and sonars
fighters
liche

I'll try to add check that it has weapons, and that weapons fire by themselves rather than have to be set with attack order (how to check for that). Also gonna check if theres some isscout or whatever
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: What is the best way to detect air fighter?

Post by lurker »

Oh. I thought you wanted to know if units were fighters, not if they were fighters.
There is no such thing as a scout unit in the context of the engine.
If you want a custom profile, then yeah, you'll have to make it yourself. I think making sure that it has a fighter type and at least one weapon can attack air units should work. Then you exclude scouts and divebombers.
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

Well, now, i'm doing that:

--- liche: workaround for BA bug
if ud.canFly and (ud.weaponCount==0 or (not (ud.type == "Fighter")) or (ud.humanName=="Liche")) then
Spring.GiveOrderToUnit(unitID,CMD.STOP,{},{})
end
Works in BA 6.21 at least, feel free to test with your fav mod and make compatible.

I dont want to check weapons just because in BA liche's type is "fighter".

Link:
http://dmytry.no-ip.org/unit_only_fighters_patrol.lua
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: What is the best way to detect air fighter?

Post by lurker »

The liche's type is fighter because it is a dive bomber. No, it's not truely a 'fighter', but it's not a bomber that flies overhead releasing bombs either, and it moves as fighters do. It's not a bug.
If you want to be compatible with other mods, you should check if it has any weapons that can shoot air. That will take care of the liche as well as the Evolution dive bombers, and possibly others. But it's not a big deal to make people edit in the names of dive bombers.
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

hmm, I may add weapon check later on. The problem is, Liche does some (very tiny) damage to air units, and fighter does some damage to ground, so it has to compare damages etc.
Is there a quick way to see if weapon is aimed and fired automatically? that should exclude all bombers in most mods.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: What is the best way to detect air fighter?

Post by lurker »

Not really. You can put the CA bombers at least on fire at will.
But you're thinking the wrong way. It's not whether it can damage planes, it's whether it will attack planes. The liche has onlytargetcategory1=NOTAIR; and most mods will have the same NOTAIR category.
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

ahh, right. Need to dump out weapondefs then and see.
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

well i checked weapon defs.
In the WeaponDefs for liche's weapon, i have onlyTargetCategories
i dumped it out like this

Code: Select all

	
local wd = WeaponDefs[ weapon.weaponDef ]
	for name,param in wd:pairs() do
		Spring.Echo("wd:",name,param)
	end
	categories=wd.onlyTargetCategories
	if categories then
		for name,value in pairs(categories) do
			Spring.Echo("wdtc:",name,value)
		end
	end
and got

Code: Select all

wdtc:, antiflame, true
wdtc:, vtol, true
wdtc:, notland, true
wdtc:, fort, true
wdtc:, special, true
wdtc:, notair, true
wdtc:, kbot, true
wdtc:, antiemg, true
wdtc:, commander, true
wdtc:, jam, true
wdtc:, tport, true
wdtc:, constr, true
wdtc:, strategic, true
wdtc:, kamikaze, true
wdtc:, minelayer, true
wdtc:, hover, true
wdtc:, noweapon, true
wdtc:, plant, true
wdtc:, ship, true
wdtc:, antilaser, true
wdtc:, phib, true
wdtc:, mine, true
wdtc:, notstructure, true
wdtc:, tank, true
wdtc:, mobile, true
wdtc:, underwater, true
wdtc:, antigator, true
wdtc:, notship, true
wdtc:, all, true
wdtc:, notsub, true
wdtc:, weapon, true
I'm checking for ud.noAutoFire now too, to exclude stuff at least in mods where bombers don't fire at will.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: What is the best way to detect air fighter?

Post by KDR_11k »

lurker wrote:Not really. You can put the CA bombers at least on fire at will.
But you're thinking the wrong way. It's not whether it can damage planes, it's whether it will attack planes. The liche has onlytargetcategory1=NOTAIR; and most mods will have the same NOTAIR category.
I use GROUND...

EDIT: How about checking if the unit is part of its own target categories?
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: What is the best way to detect air fighter?

Post by dizekat »

the stuff i'm getting for liche's weapon's onlyTargetCategories isnt useful at all, everything in it is true.

BTW i updated the widget. Would be good to get people to use this widget, it is really helpful for reducing lag.
The only problem so far is that it removes orders of air conses, thus conflicting with factory guard widget. However, air conses have such crappy nanopower for their cost and buildtime (in BA at least), that factory guard widget for airlab is IMO really not worth it, for me its better when air constructors go idle and show up on idlebuilders list, so i see when them become avaliable and can use them to make nanos.
Post Reply

Return to “Lua Scripts”