Right, so I have a missile tank. It also has a laser for extra defense. its missiles only fire when its deployed and it dont move when deployed. So far so good, as that all works.
Here's the problem though. When its not deployed (and cant fire missiles) it wont move to attack with its laser (with its shorter range) as the missles (which cant fire) are in range and it seems to think thats enough.
So I thought, hay I'll swap the weapons around so the laser is the primary, as it wont be able to move into range with the laser anyway when its deployed it wont matter.
However this had an advers side effect in that it won't shoot the missiles now unless you aim only within the range of the laser. It's like its waiting for the laser to be in range befor it cheacks the secondary weapon.
So basicly, I'm wondering is there a way to switch a weapon off properly (IE ignore it compleatly) instead of just blocking it in script, or does anyone know of any work arounds?
Stupid weapon range issues
Moderator: Moderators
Re: Stupid weapon range issues
I think primary weapon is always used for the move-into-range behavior.
Maybe changing weapon range via script and Spring.SetUnitWeaponState might work but not sure if it works at all?
workaround:
The deployable gun could be an invisible fake unit that gets created on deploying and deleted on undeploying. The invisible fake unit talks to the real unit and tells it how to animate the turret etc.
Maybe changing weapon range via script and Spring.SetUnitWeaponState might work but not sure if it works at all?
workaround:
The deployable gun could be an invisible fake unit that gets created on deploying and deleted on undeploying. The invisible fake unit talks to the real unit and tells it how to animate the turret etc.
Re: Stupid weapon range issues
Workaround sounds like a lot of work for somthing so trivial...
Im thinking maybe swap the unit when deployed with a differn't unit, but then again, that seems stupid seeing as how I cant think of a reason why the engin would want to limit the range of all weapons to that of the lowest range weapon (effectivly what its done). Feels like a rather stupid bug in the engin that we should have to work around. I fact I'm kinda surpirsed no ones noticed it before... there must be similar units...
Im thinking maybe swap the unit when deployed with a differn't unit, but then again, that seems stupid seeing as how I cant think of a reason why the engin would want to limit the range of all weapons to that of the lowest range weapon (effectivly what its done). Feels like a rather stupid bug in the engin that we should have to work around. I fact I'm kinda surpirsed no ones noticed it before... there must be similar units...
Re: Stupid weapon range issues
unit switch is probably your cleanest bet man
Re: Stupid weapon range issues
Bothers... OK anyone point me to some example code
and I'll give it a go (I see this one little thing taking more than 1 lunch break to fix... dam it all. How does everyone else seem to get so much done...)

Re: Stupid weapon range issues
Probably can cannibalize the morph gadget..
Re: Stupid weapon range issues
In the second case, did you test the missiles attacking ground or against enemy units? I suspect they will still properly target enemies even if they won't attack ground.
I might consider doing unit swapping directly in the LUS for something like this if its the only way
I might consider doing unit swapping directly in the LUS for something like this if its the only way
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Stupid weapon range issues
if he is doing lus he can also adjust the range. so maybe doing a longer range but still block the laser might help? or a 0 range for the missiles being mobile?
- Deadnight Warrior
- Posts: 183
- Joined: 08 Jun 2009, 17:59
Re: Stupid weapon range issues
In a proof-of-concept game I made I used
Long story short, I check which turret I enabled on a chasis and adjust weapon[0] to the range of the chosen weapon, or set it to 1 if I attached radar turret instead. Variable sensors ranges from 1 to 1.25 and allows for extended range of a turret (option when building a unit with long-range targeting sesors), factory turrets range from 0 to 3 (4 for radar) and enable one of the predefined weapons in a unitDef.
I do this in gadget:UnitFromFactory and not in LUS
Code: Select all
if factory_buttons[factories[UnitDefs[factDefID].name]].turret_cmdDesc.params[curFactory.turret+2]:find("Radar",1,true) then
Spring.SetUnitSensorRadius(unitID, "radar", Spring.GetUnitSensorRadius(unitID, "radar") * sensors)
Spring.SetUnitWeaponState(unitID, 0, "range", 1)
else
Spring.SetUnitWeaponState(unitID, curFactory.turret, "range", Spring.GetUnitWeaponState(unitID, curFactory.turret, "range") * sensors)
Spring.SetUnitWeaponState(unitID, 0, "range", Spring.GetUnitWeaponState(unitID, curFactory.turret, "range"))
end
I do this in gadget:UnitFromFactory and not in LUS