• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to revive a unit (not a hero)

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

I found this tutorial on reviving units (creeps in this case).

http://world-editor-tutorials.thehelper.net/cat_usersubmit.php?view=55581

But it uses a rather hacky method--it doesn't revive the unit but rather create a brand new.

I want to simply revive the same unit--the unit handle has to be the same.

Is there a native that revives a unit? Use search in the jass manual did not turn up anything :[ (used "unit" and "revive" as searches with ctrl + f). Resssurection spell revives a unit and presumably keeps the handle (because they are the same unit instances). So why can't I find a native that does what Ressurection does.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
The unit would have to not die.

Detect when a unit would take lethal damage, prevent it and store the unit (hide, make invulnerable) until it's needed again. For the death animation, just create and kill and SFX using the same model as the unit.

The only other spell I can think of besides Resurrection would be the Tauren Spirit Walker's revive spell.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Alright I think I did what you suggested.

I made this quick trigger. But one problem, if "whosyourdaddy" is on, the trigger doesn't fire. Hope that is expected behavior, though.

JASS:
	static method deathMain takes nothing returns boolean
		local unit u = GetTriggerUnit()
		local real damage = GetEventDamage()
		if damage >= GetUnitState(u, UNIT_STATE_LIFE) then
			call SetUnitLifePercentBJ(u, 100.0)
		endif
		return false
	endmethod
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
IIRC, there's no script native to do the same thing as resurrection, you'd have to use the resurrection spell to do that, as even unit recycling systems use the same method to recycle units (I remember moyackx doing something like that).
 
Alright I think I did what you suggested.

I made this quick trigger. But one problem, if "whosyourdaddy" is on, the trigger doesn't fire. Hope that is expected behavior, though.

JASS:
	static method deathMain takes nothing returns boolean
		local unit u = GetTriggerUnit()
		local real damage = GetEventDamage()
		if damage >= GetUnitState(u, UNIT_STATE_LIFE) then
			call SetUnitLifePercentBJ(u, 100.0)
		endif
		return false
	endmethod

With the script I gave you on the other topic of yours (lever), whosyoudaddy fires the trigger just fine.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Ah I see, that condition you gave is a lot smarter. Changed it to that, thank you again.

Edit: Hmm well I changed the condition to this

JASS:
if (GetUnitState(u, UNIT_STATE_LIFE) - GetEventDamage()) < 0.405 then

But with "whosyourdaddy" on, Archimonde kills the unit permanently--it still does not fire the trigger. Otherwise works the same AFAIK.
 
Ah I see, that condition you gave is a lot smarter. Changed it to that, thank you again.

Edit: Hmm well I changed the condition to this

JASS:
if (GetUnitState(u, UNIT_STATE_LIFE) - GetEventDamage()) < 0.405 then

But with "whosyourdaddy" on, Archimonde kills the unit permanently--it still does not fire the trigger. Otherwise works the same AFAIK.

From benchmark tests, WidgetLife is optimal, as it is slightly faster. However, I adapted it to the code and I still don't get issues with whosyourdaddy. What event do you have? Hopefully you do have an event, otherwise GetEventDamage returns 0.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Here's the full code for context. Might be my mistake is in there.

JASS:
	static method deathMain takes nothing returns boolean
		local unit u = GetTriggerUnit()
		local Lever l = handleTable[GetHandleId(u)]
		local integer pid = GetPlayerId(GetOwningPlayer(GetEventDamageSource()))
		if (GetUnitState(u, UNIT_STATE_LIFE) - GetEventDamage()) < 0.405 then
			call SetUnitLifePercentBJ(u, 100.0)
			if l.state == true then //on event
				call SetUnitAnimation(u, "death")
				set l.state = false
				if l.onEvent != 0 then
					call l.onEvent.do(pid)
				endif
			else //off event
				call SetUnitAnimation(u, "stand")
				set l.state = true
				if l.offEvent != 0 then
					call l.offEvent.do(pid)
				endif
				call PlaySoundOnUnitBJ(gg_snd_Lever, 100.0, u)
			endif
		endif
		set u = null
		return false
	endmethod
	
	method setup takes nothing returns nothing
		local trigger t = CreateTrigger()
		call TriggerAddCondition(t, Condition(function Lever.deathMain))
		call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_DAMAGED)
		set t = null
	endmethod
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
You have to prevent the unit from dying, setting the lever's life to 100% won't work since it's maximum life is still less than the damage it receives. Try adding an ability that increases maximum health to the lever before it receives the damage and remove it after it receives it.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Ah I see now. It does more damage than its maximum. That won't ever happen in a real game, but I guess it would be a case that it doesn't handle.
 
Status
Not open for further replies.
Top