Widget::UnitDestroyed

Widget::UnitDestroyed

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

Moderator: Moderators

Post Reply
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Widget::UnitDestroyed

Post 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?
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Widget::UnitDestroyed

Post by Jools »

I think you can get some information by looking at the UnitLeftLos and UnitLeftRadar callins. Don't remember how it worked.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Widget::UnitDestroyed

Post 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.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Widget::UnitDestroyed

Post 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...
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Widget::UnitDestroyed

Post 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
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Widget::UnitDestroyed

Post by Anarchid »

Niobium ^^ <3
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Widget::UnitDestroyed

Post 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.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Widget::UnitDestroyed

Post 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.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Widget::UnitDestroyed

Post 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.
User avatar
jamerlan
Balanced Annihilation Developer
Posts: 683
Joined: 20 Oct 2009, 13:04

Re: Widget::UnitDestroyed

Post by jamerlan »

I just wanted to say: Niobium is such a cool guy! Just used that trick in my widget
Post Reply

Return to “Lua Scripts”