AllowWeaponTarget

AllowWeaponTarget

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

Moderator: Moderators

Post Reply
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

AllowWeaponTarget

Post by Pressure Line »

How the hell does this work?

Code: Select all

function gadget:AllowWeaponTarget(aID, tID, aWN, aWDID, dP)
	local tDID = Spring.GetUnitDefID(tID)
	if UnitDefs[tDID].name == "resourcepoint" then
		Spring.Echo(foo)
		return false, 0
	end
	Spring.Echo("bar")
	return false, 0
	--return true, dP
end
does nothing, the echos print out fine, but otherwise does nothing.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: AllowWeaponTarget

Post by Google_Frog »

I have a gadget unit_dont_fire_at_radar that implements units which cannot be fired at. It also takes some LUS.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: AllowWeaponTarget

Post by gajop »

I don't think that function works in the way we think it does, and I'm not sure on what the intended effect was.
http://springrts.com/mantis/view.php?id=3219
That got closed early, and it would perhaps be better if we discussed it here after all, it might be explained in more detail, and it seems I'm not the only one having trouble grasping it.

What is the point of that function if not to prevent units targeting other units? How else can we prevent specific units from firing at each other?
PS: I'm returning false for all calls of AllowWeaponTarget, and I was returning true for all calls of AllowWeaponTargetCheck, which I assumed would allow calling of AllowWeaponTarget.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: AllowWeaponTarget

Post by Pressure Line »

kloot wrote:you don't seem to understand what returning false from AllowWeaponTarget does and does not do...
since there are no references to the callin in the changelog (other than the fixes in more recent versions) and the Wiki only mentions that the return value is expected to be "targetAllowed, targetPriority"

What this says to me is that:
a) if I 'return false,number' that weapon will completely ignore that target as a possible target
b)if I 'return true,priority' i can use some sort of logic to adjust the default priority value to make a unit prefer to attack certain target unitdefs (or whatever) first (something like a hypothetical 'preferredtargetcategory'), or conversely prefer to shoot anything other than a certain target first (iow badtargetcategory)

since there does not appear to be anything written down (changelog,wiki,source comments) anywhere other than the mantis comment, there is no way for us to know what it does or how to use it.
kloot wrote:IT DOES:

* block a specific target from being considered during a weapon's periodic auto-targeting sweep
great!
kloot wrote:IT DOES NOT:

* prevent a weapon from auto-generating a target for itself (that's the job of the AllowWeaponTargetCheck callin / commandfire WeaponDef key / unit states other than fire-at-will), unless false is always returned for all targets
And if it is returning false for all targets? As far as I could tell units would gleefully shoot at anything in range even if the entire gadget consisted of GetInfo and:

Code: Select all

function gadget:AllowWeaponTarget(attID, tarID, attWepNum, attWePDefID, defPri)
     return false,0
end
kloot wrote:* prevent a unit from returning fire at its last attacker (that's what the hold-fire unit state is for)

* prevent a unit's command "AI" from picking a target when the unit is idle (which is again controlled by a unit's fire- and movestate)
Imo it should be up to the game maker/gadget writer to impliment this properly, I don't think it's the engine's job to protect us from bad game design. (I could easily add a gadget to BA that randomly explodes metalmakers as nuclear explosions :twisted:. Possible? Yes. A good idea? Probably not. But nothing is stopping me from doing it.)

Examples:
1) Use AllowWeapontarget to impliment a minimum range. Minimum range is minimum range, it doesn't matter what the potential target is doing, I'm too close, so I cant shoot at it.

2) Game F has a unit that when given a custom command by the user becomes invulnerable, I dont want units wasting time shooting something that can't be hurt anyway, they should ignore it, or run away (or whatever, it's up to me to code behaviours for this)

3) Game U has massive radar wobble, I don't want my sharpshooter units shooting at things unless its in los *even if the radar blip is shooting at the sharpshooter* because it's a waste of time/metal/energy/whatever because the chance of the shots actually hitting is miniscule. Again, it should be up to me as the game dev to write in behaviours to manage this.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: AllowWeaponTarget

Post by Google_Frog »

Here is my gadget which uses allowWeaponTarget. It implements '3' but there is a function canShootAtUnit which could be adapted for anything. It requires LUS (or a lot of painful cob stuff).

http://code.google.com/p/zero-k/source/ ... _radar.lua

Example script http://code.google.com/p/zero-k/source/ ... msnipe.lua
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: AllowWeaponTarget

Post by Pressure Line »

The point is it shouldn't be painful. You should just be able to hit the "Don't shoot at radar blips" button in your gadget and the unit should just not shoot at radar blips.

Then you can just add functionality in the gadget to let it shoot at its last attacker if it is set to return fire/fire at will (easy), and/or move to a position it can see the unit from (a bit tricker) but imo it should all be able to be done gadget-side.
Post Reply

Return to “Lua Scripts”