Different range for different target categories?
Moderator: Moderators
Different range for different target categories?
Is it possible? A weapon that is long-ranged vs unit X but short-ranged vs unit Y? Without swapping weapons around and dealing with all the bugs associated with that?
Re: Different range for different target categories?
Not possible and dunno
-
- Posts: 1398
- Joined: 17 Sep 2008, 04:36
Re: Different range for different target categories?
By weapon swapping do you mean giving it 2 different weapons identical in everything except range and target catergories? You could use the script to block the other weapon when one is firing, but I suppose the potential bugs come from what happens when it tries to retarget.
Re: Different range for different target categories?
as i understand that is the way he does not want to use for whatever reason.By weapon swapping do you mean giving it 2 different weapons identical in everything except range and target catergories?
I did something similiar:
rocketlauncher, vs vehicles it "locks on" and is tracking but not vs infantry targets. It consists of 2 weapons and when one is fired, the other is blocked until reload is finished.
Seems to work okayish.
Maybe try like this:
1) figure out what unitID the unit is targeting:
gadget:AllowWeaponTarget or in unitscript targetWeight
2) see what category that unit belongs into
3) adjust weapon range accordingly
or
3b) get distance to target and make it retarget
It basically comes down to the question "How can I control what target is picked by a weapon/unit?"
When I tried similiar things it never really worked right eg:
http://answers.springlobby.info/questio ... rgetweight
My feeling is that such things are possible but I do not really understand how the targeting and callins work. Or maybe bugs.
Re: Different range for different target categories?
Hmm... correct me if I'm wrong, but when a Spring unit decides to "attack" something, how does it choose which range to fire at? That is, if I have a long-ranged antiA weapon and a short-ranged antiB weapon, will it intelligently pursue units properly when patrolling/fighting? That is, if I see an "A", will I be dumb and try to move into my primary (short-ranged) weapon range? I know Spring's logic is generally "get close to unit until you can hit it, then fire and stop advancing on it" or is there any more intelligent consideration of firing range or "primary" vs "secondary" weapons?
Maybe the two-weapon / jamming approach would work, but it would be tricky to switch around which weapon was "active" if they tried to choose different targets (but Knorke's thing might have the same problem). Is it possible to read the Target Priority calculated value that the engine is using internally to determine which one to go with?
edit: googles reveal there is a CLuaUnitScript::TargetWeight that you can use to read the target weigh for a given weapon/unit combo, so yes, the latter could work.
Dual weapon setup might be the way to go for something like this. Duly noted for the day I get off my duff and code something.
Maybe the two-weapon / jamming approach would work, but it would be tricky to switch around which weapon was "active" if they tried to choose different targets (but Knorke's thing might have the same problem). Is it possible to read the Target Priority calculated value that the engine is using internally to determine which one to go with?
edit: googles reveal there is a CLuaUnitScript::TargetWeight that you can use to read the target weigh for a given weapon/unit combo, so yes, the latter could work.
Dual weapon setup might be the way to go for something like this. Duly noted for the day I get off my duff and code something.
- Pressure Line
- Posts: 2283
- Joined: 21 May 2007, 02:09
Re: Different range for different target categories?
No. Spring gets the unit to move into range of Weapon1. 'Best' way would be to do something like knorke suggested.is there any more intelligent consideration of firing range or "primary" vs "secondary" weapons?
Code: Select all
function gadget:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defaultPriority)
attackerUnitDefID = Spring.GetUnitDefID(attackerID)
targetUnitDefID = Spring.GetUnitDefID(targetID)
if UnitDefs[attackerUnitDefID].name = "footank"
if UnitDefs[targetDefID].name = "infantry"
Spring.SetUnitWeaponState(attackerID, 1, "range", 128)
else
Spring.SetUnitWeaponState(attackerID, 1, "range", 512)
end
end
return true, defaultPriority
end
PS: don't use that code verbatim, it will only cause fail and lulz.
I have a few other gadgets that I want to write, and with this weekend being a 3 day weekend I might be able to quickly whack something out :)
- Pressure Line
- Posts: 2283
- Joined: 21 May 2007, 02:09
Re: Different range for different target categories?
Bump for new info in previous post.
Re: Different range for different target categories?
i had played around a bit:
problem is, if a there is a "far-range" target in far range then the unit can only shot at it after is has previously shot a "far-range" target at close range.
AllowWeaponTarget is only called when the target is in range but if the weapons range is not "extended" yet, it will not be called.
So the range will not e extended and so on.
One way to get around that would be with using 2 weapons:
weapon 0: fake weapon (invisible)
weapon 1: real weapon
(SetUnitWeaponState starts counting with 0)
weapon 0 would be a bit like a targeting laser/painter..
and then add something like
On the good side is, it seems not abuseable:
I thought it might be possible to target a "far-category" target and at last moment change target to a "near-category" target to cheat but that seems not possible.
Anyway thats just quick note i thought might be helpful
Code: Select all
function gadget:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defaultPriority)
Spring.Echo ("attackerID=".. attackerID .." " .. "targetID=" .. targetID)
attackerUnitDefID = Spring.GetUnitDefID(attackerID)
targetUnitDefID = Spring.GetUnitDefID(targetID)
if UnitDefs[attackerUnitDefID].name == "tptank" then
if UnitDefs[targetUnitDefID].name == "tpdude" then
Spring.Echo ("aiming at a dude")
Spring.SetUnitWeaponState(attackerID, 0, "range", 2000)
else
Spring.Echo ("aiming at something else")
Spring.SetUnitWeaponState(attackerID, 0, "range", 400)
end
end
return true, defaultPriority
end
AllowWeaponTarget is only called when the target is in range but if the weapons range is not "extended" yet, it will not be called.
So the range will not e extended and so on.
One way to get around that would be with using 2 weapons:
weapon 0: fake weapon (invisible)
weapon 1: real weapon
(SetUnitWeaponState starts counting with 0)
weapon 0 would be a bit like a targeting laser/painter..
and then add something like
Code: Select all
function gadget:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defaultPriority)
if attackerWeaponNum == 0 then
...
blabla adjust range of weapon 1
I thought it might be possible to target a "far-category" target and at last moment change target to a "near-category" target to cheat but that seems not possible.
Anyway thats just quick note i thought might be helpful
Re: Different range for different target categories?
PL, don't hammer something out on account of me... I was just hammering out an idea for a project in my head and wanted to know feasibility.
- Pressure Line
- Posts: 2283
- Joined: 21 May 2007, 02:09
Re: Different range for different target categories?
I wanna do it for shits and giggles
i did write a gadget to add a ui button to select a range for a unit, but yeah, easiest to use a fake weapon1 imo.
i did write a gadget to add a ui button to select a range for a unit, but yeah, easiest to use a fake weapon1 imo.