unit only targetable by one weapon

unit only targetable by one weapon

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

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

unit only targetable by one weapon

Post by knorke »

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?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: unit only targetable by one weapon

Post by Argh »

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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: unit only targetable by one weapon

Post by zwzsg »

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.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: unit only targetable by one weapon

Post by Pxtl »

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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: unit only targetable by one weapon

Post by knorke »

Use Spring.SetUnitNeutral on those objects
was my first idea but i cant do that as i still want miners to attack the minerals on their own.

so there surely is no tag to do this?
dont want to do lots of stuff if it can be done simpler.
Iirc, weapondefs_post.lua allows you to run a script that executes against every weapon def before the game starts.
good. any mod that uses it?
Don't use the engine attack. Use a custom action,
maybe no way around.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: unit only targetable by one weapon

Post by FLOZi »

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.
This is how I'd do it too.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: unit only targetable by one weapon

Post by Pxtl »

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?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: unit only targetable by one weapon

Post by FLOZi »

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."
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: unit only targetable by one weapon

Post by Argh »

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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: unit only targetable by one weapon

Post by zwzsg »

was my first idea but i cant do that as i still want miners to attack the minerals on their own.
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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: unit only targetable by one weapon

Post by FLOZi »

There's a UnitIdle callin too, zwzsg.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: unit only targetable by one weapon

Post by zwzsg »

such as ordering the Unit to approach the minerals
Spring.SetUnitMoveGoal(MinerId,x,y,z,range)
call animations, etc.
Spring.CallCOBScript(MinerId,"StartMining",0,MineralId)
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.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: unit only targetable by one weapon

Post by KDR_11k »

There's a reason I usually have OnlyTargetCategory=TARGET on everything.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: unit only targetable by one weapon

Post by Google_Frog »

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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: unit only targetable by one weapon

Post by knorke »

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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: unit only targetable by one weapon

Post by knorke »

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 :shock:

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? :shock:

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)
but none had any effect but did not give errors either.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: unit only targetable by one weapon

Post by Pxtl »

Hmm.... if the weapons are defined in the unit lua files, maybe they're accessible through Unitdefs_Post.lua?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: unit only targetable by one weapon

Post by knorke »

sounds almost too easy :)
Post Reply

Return to “Lua Scripts”