UnitDestroyed is called when construction is canceled?

UnitDestroyed is called when construction is canceled?

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

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

UnitDestroyed is called when construction is canceled?

Post by smoth »

Um so why? or am I doin it rong?

I cannot use the attackerid param to detect it, because if the attacker dies before the projectile hits from what I understand the attackerid will be nil

so is there a call that is ONLY called when a unit dies? or is there a way I can better use this command?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: UnitDestroyed is called when construction is canceled?

Post by FLOZi »

Have you tried using Spring.GetUnitHealth to get the buildprogress? I'm not sure whether it will work or not but it's worth a try.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: UnitDestroyed is called when construction is canceled?

Post by knorke »

for my logging thing i use UnitDamaged

Code: Select all

function widget:UnitDamaged (unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam) 
if (Spring.GetGameSeconds() < 1) then 
	return --for some reason units "die" in the first moments of gameplay when startunits spawn in some mods
	end
	
if (Spring.GetUnitHealth (unitID) > 0 ) then 
	return 
	end
--unit actually died here--
...
...
didnt notice it getting called for decaying nano frames.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: UnitDestroyed is called when construction is canceled?

Post by smoth »

I will try it out..

for now I have to sleep, thanks guys.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: UnitDestroyed is called when construction is canceled?

Post by smoth »

that seems to have worked. thanks guys
Post Reply

Return to “Lua Scripts”