Shooter side

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

Shooter side

Post by nukkxx5058 »

Hi, when a civilian/neutral unit is destroyed (trigger= unit destroyed) I want to create an Action to negatively impact the shooter's side score. I know how to get info about the triggering unit (ie the destroyed civilian unit in my example) with ScenEditUnitX() but how do I get the same unit wrapper for the shooter so that I can determine the side of the shooter and apply the penalty ?
Thx
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Shooter side

Post by KnightHawk75 »

Since there is no UnitY for Unit-Destroyed, you may have to track it by grabbing UnitY on Unit-Damaged trigger > XX (such as 99), where UnitY does exist and you can pull the side from that munition unit which in vast majority of cases should be the side you need. I suppose you might run into some edge cases if multiple sides munitions are impacting at exactly the same time for the final blow for a unit, but that should be pretty rare i think. Other edges would be a munition damaging a ship unit to something like 96%, sets it ablaze and flooding and it sinks a few minutes later, then there is less of a direct correlation between last munition impact and the actual destruction, unless you are independently tracking last impacts for units one cares about, and firing off a check on destruction for who last hit it (can be done).


User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: Shooter side

Post by nukkxx5058 »

Ok. I found the way. I didn't realise that this was dependent on the side I'm switched on. Problem solved.

*EDIT: oops I thought I found the way but won't work ... :-(
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: Shooter side

Post by nukkxx5058 »

ORIGINAL: KnightHawk75

Since there is no UnitY for Unit-Destroyed, you may have to track it by grabbing UnitY on Unit-Damaged trigger > XX (such as 99), where UnitY does exist and you can pull the side from that munition unit which in vast majority of cases should be the side you need. I suppose you might run into some edge cases if multiple sides munitions are impacting at exactly the same time for the final blow for a unit, but that should be pretty rare i think. Other edges would be a munition damaging a ship unit to something like 96%, sets it ablaze and flooding and it sinks a few minutes later, then there is less of a direct correlation between last munition impact and the actual destruction, unless you are independently tracking last impacts for units one cares about, and firing off a check on destruction for who last hit it (can be done).



Thanks. Will require some thinking ...
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: Shooter side

Post by nukkxx5058 »

ORIGINAL: KnightHawk75

Since there is no UnitY for Unit-Destroyed, you may have to track it by grabbing UnitY on Unit-Damaged trigger > XX (such as 99), where UnitY does exist and you can pull the side from that munition unit which in vast majority of cases should be the side you need. I suppose you might run into some edge cases if multiple sides munitions are impacting at exactly the same time for the final blow for a unit, but that should be pretty rare i think. Other edges would be a munition damaging a ship unit to something like 96%, sets it ablaze and flooding and it sinks a few minutes later, then there is less of a direct correlation between last munition impact and the actual destruction, unless you are independently tracking last impacts for units one cares about, and firing off a check on destruction for who last hit it (can be done).



So you are right, this seems to be the solution ! Took me a while to figure out because I'm a total beginner with events and lua. I haven't had it work yet but I think I will. But I already can get the shooter's side with your method. In fact, I wanted to give a huge penalty for destroying a civilian unit but just causing damage (e.g. > 5%) to a civilian unit should be enough to get the penalty (i.e. shooting at it without necessarly killing it).

Brilliant ! Thanks
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: Shooter side

Post by nukkxx5058 »

So I think it works. Hope there's no bug ...
But I didn't have to use the "unit damaged" trigger
Attachments
PBEMFirstscen6.zip
(74.33 KiB) Downloaded 24 times
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
musurca
Posts: 168
Joined: Wed Jul 15, 2020 10:06 pm
Contact:

RE: Shooter side

Post by musurca »

Since there is no UnitY for Unit-Destroyed,

They actually changed this sometime earlier this year, and now there is a reliable UnitY, which returns the weapon that killed the unit (and includes things like unguided projectiles not usually tracked as units). I make use of it in the PBEM mod to track kills for the off-turn.

On a Unit-Destroyed trigger, you should be able to do something like this in a script:

local killed = ScenEdit_UnitX()
local killer = ScenEdit_UnitY()
if killer then
if killer.unit then
print("Killed by "..killer.unit.side)
end
end
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Shooter side

Post by KnightHawk75 »

ORIGINAL: musurca
Since there is no UnitY for Unit-Destroyed,

They actually changed this sometime earlier this year, and now there is a reliable UnitY, which returns the weapon that killed the unit (and includes things like unguided projectiles not usually tracked as units). I make use of it in the PBEM mod to track kills for the off-turn.

On a Unit-Destroyed trigger, you should be able to do something like this in a script:

local killed = ScenEdit_UnitX()
local killer = ScenEdit_UnitY()
if killer then
if killer.unit then
print("Killed by "..killer.unit.side)
end
end

Interesting cause I tried tested UnitY before posting that in 1147.32 (non-pro) on a Destroyed unit and it came up nil on Unit-Destroyed in my test (and showed the weapon on Unit-Damaged), I'll try it some more (maybe I fubar'd something in my test- are there cases where it can still be nil? like delayed sinkings etc?), if so it's a great change and thank you for alerting me, as it's by far the simple and easy answer.

User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: Shooter side

Post by nukkxx5058 »

ORIGINAL: musurca
Since there is no UnitY for Unit-Destroyed,

They actually changed this sometime earlier this year, and now there is a reliable UnitY, which returns the weapon that killed the unit (and includes things like unguided projectiles not usually tracked as units). I make use of it in the PBEM mod to track kills for the off-turn.

On a Unit-Destroyed trigger, you should be able to do something like this in a script:

local killed = ScenEdit_UnitX()
local killer = ScenEdit_UnitY()
if killer then
if killer.unit then
print("Killed by "..killer.unit.side)
end
end

Ok, this is why I didn't have to use the damaged unit trigger ! unitY worked in my code (see save above). I defacto used the same code as proposed by musurca. Good to know !
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Shooter side

Post by KnightHawk75 »

Just fyi UnitY is always nil for certain surface ships when destroyed. (Testing with with a 'Light Amphibious Warship' or old 11m RHIB)
Does seem to works for:
Aircraft (all i tried)
Buoy's (hmm.. guess it has to do with subtype?)
Subs (couple of subs units I tried)
Land facilities (cars, and other typical structures)

I'll post this as a bug in tech support later today.

User avatar
nukkxx5058
Posts: 3141
Joined: Thu Feb 03, 2005 2:57 pm
Location: France

RE: Shooter side

Post by nukkxx5058 »

ORIGINAL: KnightHawk75

Just fyi UnitY is always nil for certain surface ships when destroyed. (Testing with with a 'Light Amphibious Warship' or old 11m RHIB)
Does seem to works for:
Aircraft (all i tried)
Buoy's (hmm.. guess it has to do with subtype?)
Subs (couple of subs units I tried)
Land facilities (cars, and other typical structures)

I'll post this as a bug in tech support later today.


Good to know, thanks.
Winner of the first edition of the Command: Modern Operations COMPLEX PBEM Tournament (IKE) (April 2022) :-)
musurca
Posts: 168
Joined: Wed Jul 15, 2020 10:06 pm
Contact:

RE: Shooter side

Post by musurca »

Just fyi UnitY is always nil for certain surface ships when destroyed. (Testing with with a 'Light Amphibious Warship' or old 11m RHIB)

Interesting! I would imagine that this is probably a reversion. If not, perhaps it's related to the gap in time between when a ship is last damaged and when it sinks? Regardless, the weapon which got the last 'whack' in should still probably be the destroying weapon for the sake of simplicity. I might also vote for an weapon coded as 'FIRE' or 'FLOOD' with the killer's side, in the same way that unguided projectiles are handled for other units.

Here's the original thread from when I first reported it, if it's helpful as a reference when you log it again: https://www.matrixgames.com/forums/tm.a ... =&#4959907
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Shooter side

Post by KnightHawk75 »

Interesting! I would imagine that this is probably a reversion. If not, perhaps it's related to the gap in time between when a ship is last damaged and when it sinks?

I thought that, but the thing is in the cases I was testing the RHIB and the LAW were destroyed instantly (or nearly so), I would think it would keep a record of last impacting munition for those cases just like others, the buoy that worked actually seemed to be delayed the most when getting destroyed more than the others. I gotta play around more with targeting all different surface ships with different subtypes and if that munition used plays a part (I was using agm-158c and some 109i-j's..basically all guided munitions), see what's common among ones I can find that fail\don't fail. Then work up a good sample for TS from all I find for a TS post, today got away from me a bit, maybe tomorrow.

Thank you for the link to the post first bringing this up.





User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Shooter side

Post by michaelm75au »

Funny. I thought I had 'exposed' the last weapon hit in the unit wrapper, but looks like it was a 'thought' and not a done deal. [:D]
It is recorded as part of the unit damage, so it would make sense to add it to table that comes out of 'unit.damage'.
Michael
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Shooter side

Post by michaelm75au »

ORIGINAL: nukkxx5058

ORIGINAL: KnightHawk75

Just fyi UnitY is always nil for certain surface ships when destroyed. (Testing with with a 'Light Amphibious Warship' or old 11m RHIB)
Does seem to works for:
Aircraft (all i tried)
Buoy's (hmm.. guess it has to do with subtype?)
Subs (couple of subs units I tried)
Land facilities (cars, and other typical structures)

I'll post this as a bug in tech support later today.


Good to know, thanks.

The recorded weapon is a hit. Blast or such damage doesn't get recorded from memory.
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Shooter side

Post by KnightHawk75 »

The recorded weapon is a hit.
So then it's actually up in the air if UnitY will be populated (non-nil) on any given unit-destroyed? or Did you just mean the population is always the last known 'hit', vs say blast damage/fire/flooding etc that might have actually pushed something over the edge to destruction?
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Shooter side

Post by michaelm75au »

From memory, this was put in to track the actual weapon hits sometime back but not the damage that might be sustained by blast/frag from a near miss. That blast/frag could result in the eventual destruction of the unit BUT it wasn't destroyed by an actual weapon hit.

I'll have to look at this to refresh my aging memory on what it is actually.
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Shooter side

Post by KnightHawk75 »

Filed in Tech Support, I think I found some issues, and yes some of it revolves around impact vs 'hit but missed + blastdmg', but it's weird in that the problem doesn't happen universally, just 'mostly'. lol

See the details here:
https://www.matrixgames.com/forums/tm.asp?m=5104622

That said I'm not going to be relying on UnitY() data when ships are involved and it's damage OR destroyed, even if not-nil for the time being, as the data can be varying degrees of bad I've found.
Post Reply

Return to “Lua Legion”