Condition of "at war" or "at peace"

Condition of "at war" or "at peace"

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

Moderator: Moderators

Post Reply
otyugh
Posts: 43
Joined: 26 Oct 2014, 18:31

Condition of "at war" or "at peace"

Post by otyugh »

Hey, still another naive question that might be trivial.

I try to raise an alert when any unit of the player (me) is dealing damage ton another unit that is not the player's property (friendly fire or ctrl+d on my own units, shouldn't be taken into account).

I don't find out, widget:UnitDamaged seem to only report damages on the player and not anybody else -unitTeam is everytime == Spring.GetMyTeamID()-.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Condition of "at war" or "at peace"

Post by Jools »

Hmmm, I'm not sure I understood correctly: you want to have a report when any of your own units is shooting at a not-allied unit. Correct?

Widgets only have information of what happens within your line of sight. That means you can have a report when your peewee shoots at enemy peewee, but not when your bertha hits enemy base.

Yes, when you have LoS on enemy it goes like this:

Code: Select all

widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, projectileID, attackerID, attackerDefID, attackerTeam)
check when attackerTeam equals your own team, and attackerID will be your UnitID that deals damage.
otyugh
Posts: 43
Joined: 26 Oct 2014, 18:31

Re: Condition of "at war" or "at peace"

Post by otyugh »

That my actual whole problem.
Consider the following :

Code: Select all

function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, projectileID, attackerID, attackerDefID, attackerTeam)
	if(attackerTeam==nil) then
		attackerTeam='?'
	end
	Spring.Echo("attacker :"..attackerTeam.." victim:"..unitTeam)
end
What I get in a melee pewee fight early on is a bunch of
"attacker ? victim 0"
, 0 being my teamID. Oddly I was getting better results using "UnitLastAttacker" on unitID.


Basically damage are only perceived from my point of view, so a pewee can fire on foreign ressources building directly without any chance to trigger UnitDamaged.


I was wondering if there was a way to work around this. But the functions around projectiles does not seem not to cover this, althought I'm not 100% sure.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Condition of "at war" or "at peace"

Post by Silentwings »

LuaUI is only able to see things from your own point of view, to work around that you need help from a gadget.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Condition of "at war" or "at peace"

Post by Jools »

otyugh wrote:That my actual whole problem.
Consider the following :

Code: Select all

function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, projectileID, attackerID, attackerDefID, attackerTeam)
	if(attackerTeam==nil) then
		attackerTeam='?'
	end
	Spring.Echo("attacker :"..attackerTeam.." victim:"..unitTeam)
end
What I get in a melee pewee fight early on is a bunch of
"attacker ? victim 0"
, 0 being my teamID. Oddly I was getting better results using "UnitLastAttacker" on unitID.


Basically damage are only perceived from my point of view, so a pewee can fire on foreign ressources building directly without any chance to trigger UnitDamaged.


I was wondering if there was a way to work around this. But the functions around projectiles does not seem not to cover this, althought I'm not 100% sure.
Try with this code:

Code: Select all

function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, projectileID, attackerID, attackerDefID, attackerTeam)
	if attackerTeam and  weaponDefID > 0 then
		Spring.Echo("attacker :"..attackerTeam.." victim:"..unitTeam)
	end	
end
That will filter out a bunch of cases with indirect damage, such as unit damaged by debris, collateral damage, fire, water, fall damage, etc etc.

But the point is as silentwings says, it cannot catch all cases when your unit damages enemy, because in the game, this information is not present. Even with a gadget you cannot catch the case when a kamikaze unit blows itself up and kills enemy stuff.

But it will work as a way of telling when your units are in peace or in a firefight. But those 'empty' values you get are when the the enemy is damaged by other means than a direct hit by the peewees gun.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Condition of "at war" or "at peace"

Post by FLOZi »

But the point is as silentwings says, it cannot catch all cases when your unit damages enemy, because in the game, this information is not present. Even with a gadget you cannot catch the case when a kamikaze unit blows itself up and kills enemy stuff.
Depends if you are using engine kamikaze... in MCL I identify mechs that meltdown in a catastrophic over heating which result in damaging enemy units as the "attacker".
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Condition of "at war" or "at peace"

Post by Jools »

FLOZi wrote:
But the point is as silentwings says, it cannot catch all cases when your unit damages enemy, because in the game, this information is not present. Even with a gadget you cannot catch the case when a kamikaze unit blows itself up and kills enemy stuff.
Depends if you are using engine kamikaze... in MCL I identify mechs that meltdown in a catastrophic over heating which result in damaging enemy units as the "attacker".
Yes, you can do it 'manually' but the information is not present in that callin.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Condition of "at war" or "at peace"

Post by FLOZi »

It is if you set the kamikaze unit as the owner of the explosion
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Condition of "at war" or "at peace"

Post by Google_Frog »

I am fairly sure that widget:UnitDamaged is only called for units which you own (technically, ones with your allyTeamID). You are going to need some ingenious method of collecting the information you want (periodically check seen unit health?) or help from a gadget.

In ZK we're opening up some information which would make sense for a team to see. Here is a gadget that sends enemy deaths that occur within LOS https://github.com/ZeroK-RTS/Zero-K/blo ... events.lua
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Condition of "at war" or "at peace"

Post by Jools »

Google_Frog wrote:I am fairly sure that widget:UnitDamaged is only called for units which you own (technically, ones with your allyTeamID). You are going to need some ingenious method of collecting the information you want (periodically check seen unit health?) or help from a gadget.
I'm not sure but I think it's called for every unit that you can see, i.e also enemy units. But it should be tested, I'm too tired now to test.

At least the widget that plays self destruction sounds: everybody visible can hear that sound. I guess I assumed it works the same way.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Condition of "at war" or "at peace"

Post by gajop »

If not, it definitely should be like that. Polling which GF mentioned might cause performance issues if you're worried about that. It's also rather ugly.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Condition of "at war" or "at peace"

Post by Google_Frog »

Is there anything wrong with the gadget I linked? I was not involved in its implementation and would like to know whether it is a good method for giving widgets more information.

If the ZK gadget is a good implementation then I disagree with this:
If not, it definitely should be like that. Polling which GF mentioned might cause performance issues if you're worried about that. It's also rather ugly.
A game might need to hide whether a unit was destroyed or just left LOS. For example a unit could have an ability which makes it look like it self-destructed but actually it teleported or went invisible. If the game implemented widget:UnitDestroyed for enemy units then it would be able to decide when to send the event. Spring is already quite bad at information warfare games so I would not want to make it worse.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Condition of "at war" or "at peace"

Post by gajop »

A game might need to hide whether a unit was destroyed or just left LOS
Maybe there can be a single callin for those cases if not already? I'm against polling to mimic events (I've written some and they can be slow and non-trivial to write).
otyugh
Posts: 43
Joined: 26 Oct 2014, 18:31

Re: Condition of "at war" or "at peace"

Post by otyugh »

Jools wrote:
Google_Frog wrote:I am fairly sure that widget:UnitDamaged is only called for units which you own (technically, ones with your allyTeamID). You are going to need some ingenious method of collecting the information you want (periodically check seen unit health?) or help from a gadget.
I'm not sure but I think it's called for every unit that you can see, i.e also enemy units. But it should be tested, I'm too tired now to test.
At least in BA, I wasn't able to get any teamID from UnitDamaged that wasn't mine of wholes games.

And is true in fact, we can always guess someone is dead by the sounds. So it's not that much of a hidden stuff. :p
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Condition of "at war" or "at peace"

Post by Google_Frog »

gajop wrote:
A game might need to hide whether a unit was destroyed or just left LOS
Maybe there can be a single callin for those cases if not already? I'm against polling to mimic events (I've written some and they can be slow and non-trivial to write).
I am not advocating polling. I am saying that if a game wants widgets to see events such as these it should send those events from a gadget. It is easier to add a callin to a particular game than to block one if the callin gives away too much information.
Post Reply

Return to “Lua Scripts”