unit only targetable by one weapon
Moderator: Moderators
unit only targetable by one weapon
i want a unit only targetable by one weapon.
ie i do not want tanks on roam try to shot at my gaiea "mineral" units.
alot of onlytargetcategory could be used, putting it in every weapon def.
is there an easier way?
like a tag for the unit onlytargetedby=
or maybe a lua that set target categories at gamestart?
ie i do not want tanks on roam try to shot at my gaiea "mineral" units.
alot of onlytargetcategory could be used, putting it in every weapon def.
is there an easier way?
like a tag for the unit onlytargetedby=
or maybe a lua that set target categories at gamestart?
Re: unit only targetable by one weapon
Use Spring.SetUnitNeutral on those objects, and they won't be targeted unless the user deliberately orders an attack.
Then to polish it, intercept cmd.ATTACK and either cancel the order (in the case of the tanks) or change the order to something more appropriate, such as a synthetic command (cmd.GATHER, for example) that triggers the behavior you want.
For an example of a Gadget dealing with this sort of issue, see AutoHack in the P.U.R.E. source.
Then to polish it, intercept cmd.ATTACK and either cancel the order (in the case of the tanks) or change the order to something more appropriate, such as a synthetic command (cmd.GATHER, for example) that triggers the behavior you want.
For an example of a Gadget dealing with this sort of issue, see AutoHack in the P.U.R.E. source.
Re: unit only targetable by one weapon
Don't use the engine attack. Use a custom action, and if you need it to be auto issued, a couple more line of Lua to auto-issue it.
While you may manage making the player's tanks not engage the minerals with those onlytargetcategory tags, that's only the tip of the iceberg of the issues you'll have if minerals are considered hostile units.
While you may manage making the player's tanks not engage the minerals with those onlytargetcategory tags, that's only the tip of the iceberg of the issues you'll have if minerals are considered hostile units.
Re: unit only targetable by one weapon
Alternately, if you want to block attacking the neutral units altogether, you could use onlytargetcategory like you said.
Iirc, weapondefs_post.lua allows you to run a script that executes against every weapon def before the game starts. So you could write a script that modifies the onlytargetcategory of every weapon in weapondefs_post.lua
Iirc, weapondefs_post.lua allows you to run a script that executes against every weapon def before the game starts. So you could write a script that modifies the onlytargetcategory of every weapon in weapondefs_post.lua
Re: unit only targetable by one weapon
was my first idea but i cant do that as i still want miners to attack the minerals on their own.Use Spring.SetUnitNeutral on those objects
so there surely is no tag to do this?
dont want to do lots of stuff if it can be done simpler.
good. any mod that uses it?Iirc, weapondefs_post.lua allows you to run a script that executes against every weapon def before the game starts.
maybe no way around.Don't use the engine attack. Use a custom action,
Re: unit only targetable by one weapon
This is how I'd do it too.zwzsg wrote:Don't use the engine attack. Use a custom action, and if you need it to be auto issued, a couple more line of Lua to auto-issue it.
While you may manage making the player's tanks not engage the minerals with those onlytargetcategory tags, that's only the tip of the iceberg of the issues you'll have if minerals are considered hostile units.
Re: unit only targetable by one weapon
I'm gonna go ahead and guess that CA uses it, because CA uses *everything*. However, I've never seen or used it myself - I've only used the unit counterpart, unitdefs_post.lua.
I can see why he wants to use *attack* - after all, who wouldn't want to be able to keep the patrol and fight behaviors for these things? Can you get that with a custom action? Alternatley, could the "Reclaim" behavior be overridden for harvesting?
I can see why he wants to use *attack* - after all, who wouldn't want to be able to keep the patrol and fight behaviors for these things? Can you get that with a custom action? Alternatley, could the "Reclaim" behavior be overridden for harvesting?
Re: unit only targetable by one weapon
S44's is here:
http://spring1944.svn.sourceforge.net/v ... threv=3081
But I'm concurring with zwzsg's assessment that "that's only the tip of the iceberg of the issues you'll have if minerals are considered hostile units."
http://spring1944.svn.sourceforge.net/v ... threv=3081
But I'm concurring with zwzsg's assessment that "that's only the tip of the iceberg of the issues you'll have if minerals are considered hostile units."
Re: unit only targetable by one weapon
I guess what I am assuming is that eventually he won't be using an actual attack to do "mining".
Anyhow, all these approaches can work, it just depends on what you want in terms of final behavior.
If you want people to be able to deliberately destroy minerals, but not unless they manually give the order, then SetUnitNeutral, and then a Gadget can give an explicit cmd.ATTACK to your miners, but to nothing else.
Honestly, I agree with the custom command thing for this, but that gets you into some additional complications, such as ordering the Unit to approach the minerals, call animations, etc. It may be better to get it all running in a basic way and then come back to that problem.
Anyhow, all these approaches can work, it just depends on what you want in terms of final behavior.
If you want people to be able to deliberately destroy minerals, but not unless they manually give the order, then SetUnitNeutral, and then a Gadget can give an explicit cmd.ATTACK to your miners, but to nothing else.
Honestly, I agree with the custom command thing for this, but that gets you into some additional complications, such as ordering the Unit to approach the minerals, call animations, etc. It may be better to get it all running in a basic way and then come back to that problem.
Re: unit only targetable by one weapon
More lua, but not that complicated. In GameFrame, but not every frame to save CPU, for all miners units, if idle (that's the hard part!), look for all mineral in range, if one mineral nearby and good looking issue the custom command. Fallback transform custom command into attack command.was my first idea but i cant do that as i still want miners to attack the minerals on their own.
Re: unit only targetable by one weapon
There's a UnitIdle callin too, zwzsg.
Re: unit only targetable by one weapon
Spring.SetUnitMoveGoal(MinerId,x,y,z,range)such as ordering the Unit to approach the minerals
Spring.CallCOBScript(MinerId,"StartMining",0,MineralId)call animations, etc.
0 being the number of argument returned by the COB function, and MineralId the argument passed to the cob function. Maybe instead of MineralId you'll want to pass a x,y,z or maybe a heading, pitch, or maybe nothing. Cob can then use a new callin, StartMining(target_id)
Heck, if you want you can even use a return argument to implement something like the cob saying "I don't want that mineral" or "I'm busy aiming".
As a first step, I suggest using an attack command, and have some extra gadget/widget to issue attack command on nearby neutral minerals.
As a second step, a custom command that fallback on attack.
As a last step, a custom command calling custom COB animation.
Re: unit only targetable by one weapon
There's a reason I usually have OnlyTargetCategory=TARGET on everything.
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: unit only targetable by one weapon
Just use onlyTargetCatergories for everything. The current implementation of target categories allows you to define any combination of units that can and cannot be targeted. You don't need more functions to do exactly the same thing and cause confusion.
To make a unit not targetable by all but one unit create a category for it and don't tell most of the units to target it.
This is extremely simple to do for lua unit defs with a batch editor such as SpringModEdit.
To make a unit not targetable by all but one unit create a category for it and don't tell most of the units to target it.
This is extremely simple to do for lua unit defs with a batch editor such as SpringModEdit.
Re: unit only targetable by one weapon
thanks for all the hints, for now i will use targetcategorys and then as following
zwzsg wrote:As a first step, I suggest using an attack command, and have some extra gadget/widget to issue attack command on nearby neutral minerals.
As a second step, a custom command that fallback on attack.
As a last step, a custom command calling custom COB animation.
Re: unit only targetable by one weapon
so i tried to copy from the s44 code FLOZi posted.
putting this:
http://pastebin.ca/1967866
in a gadget prints a list of all weapons into infolog.txt but does not change any settings.
so i put it into gamedata\weapondefs_post.lua
and it only prints the weapons defined in weapons\Unit_Explosions.lua
It also removes all weapons from the units without any error message from spring
I believe it is because CT has most weapons defined directly in the unit.lua's and the gagdet does not print those.
and of course not change either.
I changed the for-loop a bit ( http://pastebin.ca/1967867 ) but that makes no difference.
Mighty strange?
Also I tried to change various unit parameters with all kind of varitions of
but none had any effect but did not give errors either.
putting this:
http://pastebin.ca/1967866
in a gadget prints a list of all weapons into infolog.txt but does not change any settings.
so i put it into gamedata\weapondefs_post.lua
and it only prints the weapons defined in weapons\Unit_Explosions.lua
It also removes all weapons from the units without any error message from spring

I believe it is because CT has most weapons defined directly in the unit.lua's and the gagdet does not print those.
and of course not change either.
I changed the for-loop a bit ( http://pastebin.ca/1967867 ) but that makes no difference.
Mighty strange?

Also I tried to change various unit parameters with all kind of varitions of
Code: Select all
function gadget:UnitFinished(unitID, unitDefID, teamID)
Spring.SetUnitResourcing (unitID, "metal",0)
Re: unit only targetable by one weapon
Hmm.... if the weapons are defined in the unit lua files, maybe they're accessible through Unitdefs_Post.lua?
Re: unit only targetable by one weapon
sounds almost too easy :)