Page 1 of 1

Widget::UnitDestroyed

Posted: 31 Mar 2012, 21:29
by Anarchid
So, upon losing yet another game in ZK, and finding myself with some spare time, i got to thinking that a widget that counted my own and confirmed enemy casualties and displayed their cost in metal would be a nice and useful idea.

However, i can't seem to get enemy losses - even those within my los - detected by the widget. Does widget::UnitDestroyed fire only on owned units in unsynced context?

If so - can anyone point me to how i could detect any confirmed kills from unsynced?

Re: Widget::UnitDestroyed

Posted: 31 Mar 2012, 21:39
by Jools
I think you can get some information by looking at the UnitLeftLos and UnitLeftRadar callins. Don't remember how it worked.

Re: Widget::UnitDestroyed

Posted: 01 Apr 2012, 06:07
by CarRepairer
What if I made a game where there were no corpses, units disappear when they die, and they can cloak. If widget:unitdestroyed worked on enemy units, a widget could help you cheat in my game.

Re: Widget::UnitDestroyed

Posted: 01 Apr 2012, 10:59
by Anarchid
I would gladly accept the limitation to confirmed kills only. So in that theoretical game, the widget would have been somewhat useless anyway, and even the player themselves wouldn't be able to determine, was unit killed or just cloaked and ran away.

Similarly, i'm completely ok if units killed outside LOS (such as glaives set on fire by a pyro) are not counted.

Going to try the left-los thing, see if it gives anything useful...

Re: Widget::UnitDestroyed

Posted: 01 Apr 2012, 12:57
by Niobium

Code: Select all

local inLos = {}

function widget:UnitEnteredLos(uID)
    inLos[uID] = true
end

function widget:UnitLeftLos(uID)
    inLos[uID] = nil
end

function widget:GameFrame(n)
    for uID, _ in pairs(inLos) do
        if not Spring.GetUnitDefID(uID) then
            Spring.Echo(uID .. ' has died !')
            inLos[uID] = nil
        end
    end
end

Re: Widget::UnitDestroyed

Posted: 01 Apr 2012, 13:59
by Anarchid
Niobium ^^ <3

Re: Widget::UnitDestroyed

Posted: 13 Apr 2012, 12:40
by Jools
Niobium wrote: function widget:GameFrame(n)
for uID, _ in pairs(inLos) do
if not Spring.GetUnitDefID(uID) then
Spring.Echo(uID .. ' has died or morphed !')
inLos[uID] = nil
end
end
end[/code]
Corrected that. Unit has either died or morphed. Morphed units receive new uID:s.

Re: Widget::UnitDestroyed

Posted: 13 Apr 2012, 17:37
by Niobium
Jools wrote:Corrected that. Unit has either died or morphed. Morphed units receive new uID:s.
Morph == Destroyed and at the same time a completely new unit is spawned at the same position with the old commands, giving the appearance of just one unit changing types.

Re: Widget::UnitDestroyed

Posted: 13 Apr 2012, 19:14
by Jools
Yes, that's technically what happens, but not what most users would consider as a confirmed kill.

Spring also counts built dragons teeth as killed units, but we don't have to copy everything spring does -- at least when it makes no sense.

Re: Widget::UnitDestroyed

Posted: 05 Oct 2013, 12:35
by jamerlan
I just wanted to say: Niobium is such a cool guy! Just used that trick in my widget