[vJASS]Simple Hero Revival[v1.2] -GUI Friendly-

This bundle is marked as approved. It works and satisfies the submission rules.
Alright I made a plain search for keyword "revive" and this came up Link to search

No I couldn't find any hero revival that was like call function takes hero, time, where and effect and it will revive after. I've seen loads of other system before the purge with waits and polled wait. It wont be effective enough and it is inaccurate too.

So I made this simple system. You just need one simple function call for each hero. Remember that this is probably most useful where you controll one hero at the time as when the unit is revived it will be selected and the camera will pan to the hero over a time you can select.

Contains a formula functions so you can just put the "takes real time" to 0 and let the function to the time stuff. Also have a simple filter function that will protect the users from themselves.

THIS IS GUI FRIENDLY, I HAVE A GREAT EXAMPLE HOW TO USE THIS IN GUI AND IT IS VERY EASY. IF YOU ENCOUNTER ANY PROBLEMS PLEASE REPLY TO THIS THREAD OR PM/VM ME FOR HELP.

NO THIS SYSTEM DOES NOT DISPLAY A TIMER DIALOG YOU HAVE TO CREATE ONE ON YOUR OWN.

Enjoy the system.

*Requirements*
TimerUtils by Vexorian

*HOW TO IMPORT*

1. Copy the library code or the trigger into your map.

2. If you dont have TimerUtils, copy that too.

3. You're good to go! Gui Users can copy my example

Credits goes to Vexorian for JASSHelper and TimerUtils.

Please credit if used,

Enjoy!

~baassee

JASS:
library HeroRevival requires TimerUtils
//*******************************************************************************************************************************
//
// This is just a simple hero revival
//      by baassee
//      Credits is appreciated
//          and please credit Bribe too for his brilliant remake.
//
//         *Requires:
//              TimerUtils by Vexorian
//              A vJass Compiler
//
//
//      Credits flies out to:
//              Axarion for showing me his scope
//              Hell Gate and Deaod for their Health Reserve system, taught me alot
//              Vexorian for TimerUtils, JassHelper and vJass
//              Bribe for recoding the system.
//
//  How to use:
//      This library provides you with these functions
//          function HeroRevive takes unit hero, real time, real x, real y, boolean eff
//          function HeroReviveLoc takes unit hero, real time, location loc, boolean eff
//
//          The unit hero is obviously the hero you are going to revive.
//          The real time is the time you want to revive your hero.
//              ps. you can set this to 0 and use the GetTime func to make your formula.
//          The real x states which x coordinate where you are going to revive your hero.
//          The real y states which y coordinate where you are going to revive your hero.
//          The location loc is for those who don't know to use coordinates.
//          The boolean eff is for show or not show rebirth effect.
//
//      Example 1:
//          call HeroRevive(GetTriggerUnit(), 30., 0., 0., true)
//
//      If you use this with an event "A Unit Dies" then it will
//          Revive the dying unit, revive it after 30 seconds at coord (0,0) showing revival effect
//
//      Example 2:
//          call HeroRevive(GetTriggerUnit(), 0., GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), false)
//
//      If you use this as said above it will
//          Revive the dying unit, it will USE the formula function so you better customize it there.
//          It will revive where it died and will not show revival effect.
//
//      Example 3:
//          call HeroReviveLoc(GetTriggerUnit(), 0., udg_TempLoc, true)
//
//      If you use this as said above with a location for all GUI users it will
//          Revive the dying unit, it will USE the formula function so you better customize it there.
//          It will revive the unit at a location you've set
//          Just remember to remove the location afterwards!
//
//      End of Documentation
//
//***************************************************************************************************************************
//
//      SETUP
//
//
globals
//
//*************GUI USERS LOOK BELOW HERE****************************
//
//      This variable is where you can set how fast the camera should pan to the revived unit.
//      As this usally is set to a low value, lower the greater the size is, you can set it
//      to 0. if you want to, then it will be panned instantly.
//
    private constant real PANCAM        = 0.6
    
endglobals
    
    private function GetAdjustedTime takes real time, unit hero returns real
        
        return time + 0. * GetHeroLevel(hero)
        
        //if you want something extra or you can set the time to 0
        //and use this for a formula instead
        //I call this function for the formula func in the documentation
    endfunction
    
    
    private function FilterHero takes unit u returns boolean
        
        return IsUnitType(u, UNIT_TYPE_HERO) and IsUnitType(u, UNIT_TYPE_DEAD)
        
        //just check if the unit is a hero
        //and to check if the unit is already dead (thanks to axarion for this one)
        //you can edit the filter if you want
    endfunction
                
//      END SETUP
//******************************************************************************************************************************
//

globals
//
//      To make sure that the users wont run several instances with the same unit
//
    private group NOSTACK   = CreateGroup()
    
endglobals
    

    private struct data extends array
        static integer i = 0
        static integer array r
        
        unit    hero
        real    x
        real    y
        boolean eff
    endstruct
    
    
    private function finish takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local data dat = GetTimerData(t)
        call ReleaseTimer(t)    //recycle timer
        set t = null
        
        call ReviveHero(dat.hero, dat.x, dat.y, dat.eff)    //revive hero
        call GroupRemoveUnit(NOSTACK, dat.hero)
        
        if GetLocalPlayer() == GetOwningPlayer(dat.hero) then
            call PanCameraToTimed(dat.x, dat.y, PANCAM)
            call ClearSelection()
            call SelectUnit(dat.hero, true)
        endif
        set data.r[0] = data.r[data.r[0]]
        set data.r[data.r[0]] = dat
    endfunction
    
    
    function HeroRevive takes unit hero, real time, real x, real y, boolean eff returns nothing
        local data dat
        local timer t
        
        if FilterHero(hero) and not IsUnitInGroup(hero, NOSTACK) then
            if 0 == data.r[0] then
                set data.i = data.i + 1
                set dat = data.i
            else
                set dat = data.r[0]
                set data.r[0] = data.r[data.r[0]]
            endif

            set t = NewTimer()
                
            set dat.hero = hero
            set dat.x = x
            set dat.y = y
            set dat.eff = eff
            
            call GroupAddUnit(NOSTACK, hero)
            call SetTimerData(t, dat)
            call TimerStart(t, GetAdjustedTime(time, hero), false, function finish)
            set t = null
        debug else
            debug call BJDebugMsg("HeroRevival Error: The unit is either alive or isn't a hero unit or is already in the system, please check your trigger calls.")
        endif
    endfunction
    
    
    function HeroReviveLoc takes unit hero, real time, location loc, boolean eff returns nothing
        call HeroRevive(hero, time, GetLocationX(loc), GetLocationY(loc), eff)
    endfunction
    
    
endlibrary

GUI SAMPLE

  • Test GUI FRIENDLY
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • -------- This is the unit that will be Revived by the system --------
      • -------- set it to whatever unit you want to --------
      • -------- that you want the system to revive after set time --------
      • Set TempUnit = (Triggering unit)
      • -------- Here we get the location, where the unit will be revived at --------
      • -------- as we will use the "loc" function --------
      • -------- also more friendly for GUI users --------
      • Set TempLoc = (Position of TempUnit)
      • -------- This variable shouldn't be necessary but just for an example --------
      • -------- and to help GUI coders --------
      • -------- This value below will represent the revival time of the hero --------
      • Set TempReal = 7.00
      • -------- This variable below will tell the system that it should --------
      • -------- Show revival animations (birth animation) --------
      • -------- Set it to true and it will show, set it to false and it wont --------
      • Set TempEff = True
      • -------- That was it --------
      • -------- Now I will call the function below --------
      • -------- And it will start reviving the unit --------
      • Custom script: call HeroReviveLoc(udg_TempUnit, udg_TempReal, udg_TempLoc, udg_TempEff)
      • -------- Clear the point leak --------
      • Custom script: call RemoveLocation(udg_TempLoc)
      • -------- Just to show in-game that the unit will be revived soon. --------
      • Game - Display to (All players) the text: ((Proper name of (Triggering unit)) + will be revived in 7 seconds!)
PS:

I've put this as coded in vJASS and GUI as it can be easily used in GUI


v1.0 released

v1.1 Bribes fix and others

v1.1b thanks to hell gate for noticing that the system made a reverse call of checking, also added another death check and changed the message

v1.2 Made the struct extended.
Custom allocation and deallocation.
Removed healthcheck.
GetAdjustedTime function now takes the unit hero instead of the herolevel to increase the possibilities with the time amount.
Fixed a few nulling errors.


v1.2 Now the system is lighter than ever before. And faster. Enjoy.

Keywords:
simple, hero, revival, revive, vjass, gui, friendly, baassee
Contents

Simple Hero Revival v1.2 (Map)

Reviews
17:48, 18th Sep 2010 busterkomo: The script is short, but it works well for something like this. I don't see any major problems with this, and it definitely could be useful.

Moderator

M

Moderator

17:48, 18th Sep 2010
busterkomo: The script is short, but it works well for something like this. I don't see any major problems with this, and it definitely could be useful.
 
Level 18
Joined
Feb 25, 2009
Messages
2,006
The only thing I don't agree is the time for camera-pan.. it should be instant no matter what, otherwise user can move it faster than the pan itself, which makes it unneeded.

Also I think the message should be "Your hero will be revived in X seconds", and it should be only displayed to the local player.

All tho, it's good but a bit simple, eh, will give it a 4/5.
 
Last edited:
Level 21
Joined
Nov 14, 2008
Messages
3,256
Short nice and effective. I'm no vJass expert; but I can't see any flaws.
Put the code in HIDDEN tags.. :p

+rep, vote for approval & 5/5 (As it's the best Revive System on the hive.. ;))

Well I put the GUI stuff in hidden now, the JASS tag is actually a JASS/HIDDEN tag as you can see :D

Thanks alot! :)

The only thing I don't agree is the time for camera-pan.. it should be instant no matter what, otherwise user can move it faster than the pan itself, which makes it unneeded.

Also I think the message should be "Your hero will be revived in X seconds", and it should be only displayed to the local player.

All tho, it's good but a bit simple, eh, will give it a 4/5.

The users can change the pan time in the vJASS global declaration. Made it stick out alot so it would be noticeable :p Yeah ofc you can make it instant, it's up to you :D

The message is only for demonstration, isn't really meant to be there :p

Thanks alot! It's meant to be simple :D

Pretty nice and simple. Nothing really wrong pops out at me. ;D

How come you don't want to support timer dialogs?

I guess it's as simple as it can be, though I will make a new one with another method so you can get values of the unit, timer etc.

I dislike to make it timerdialogs. Some want it to display for all players, some want it only to display for the local player, some even dont want it and then they get mad :p So I made it this way. It's quite easy to make your own dialog ofc but it will require another timer (if you arent a JASSER so you can just change the library).
 
Level 9
Joined
Aug 27, 2009
Messages
473
I dislike to make it timerdialogs. Some want it to display for all players, some want it only to display for the local player, some even dont want it and then they get mad :p So I made it this way. It's quite easy to make your own dialog ofc but it will require another timer (if you arent a JASSER so you can just change the library).

I think you should add this;
- A configuration to have Timerwindow / not
- Show to local? (TRUE) Show to all? (FALSE)

The above is the 2 configureable variables added in the config area.. With just 2 variables you can do that; You could also do it with just 1 variable, with intengers.. (0: No Timer Window | 1: Timer Window for Local player | 2: Timer Window for ALL Players)..

This should be a easy add.. ;)

EDIT: I'm not sure if I should say Variable or Local.. I'm to used with PHP now.. ;P
 
Level 38
Joined
Sep 26, 2009
Messages
8,456
Some changes and optimizations I recommend:

HeroReviveCoord changed to HeroRevive. HeroReviveLoc remains the same.

Get rid of the timer-member of the struct as well as the time-member of the struct. They occupy array space needlessly.

You don't need == true or == false.

instead of (bool == true), do (bool) (parenthesis optional)

instead of (bool == false), do (not bool).

The changes I recommend are applied in the code below:

JASS:
library HeroRevival requires TimerUtils
//*******************************************************************************************************************************
//
// This is just a simple hero revival
//      by baassee
//      Credits are appreciated
//
//         *Requires:
//              TimerUtils by Vexorian
//              A vJass Compiler
//
//
//      Credits flies out to:
//              Axarion for showing me his scope
//              Hell Gate and Deaod for their Health Reserve system, taught me alot
//              Vexorian for TimerUtils, JassHelper and vJass
//
//  How to use:
//      This library provides you with these functions
//          function HeroRevive takes unit hero, real time, real x, real y, boolean eff
//          function HeroReviveLoc takes unit hero, real time, location loc, boolean eff
//
//          The unit hero is obviously the hero you are going to revive.
//          The real time is the time you want to revive your hero.
//              ps. you can set this to 0 and use the GetTime func to make your formula.
//          The real x states which x coordinate where you are going to revive your hero.
//          The real y states which y coordinate where you are going to revive your hero.
//          The location loc is for those who don't know to use coordinates.
//          The boolean eff is for show or not show rebirth effect.
//
//      Example 1:
//          call HeroRevive(GetTriggerUnit(), 30., 0., 0., true)
//          
//      If you use this with an event "A Unit Dies" then it will
//          Revive the dying unit, revive it after 30 seconds at coord (0,0) showing revival effect
//
//      Example 2:
//          call HeroRevive(GetTriggerUnit(), 0., GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), false)
//          
//      If you use this as said above it will
//          Revive the dying unit, it will USE the formula function so you better customize it there.
//          It will revive where it died and will not show revival effect.
//
//      Example 3:
//          call HeroReviveLoc(GetTriggerUnit(), 0., udg_TempLoc, true)
//          
//      If you use this as said above with a location for all GUI users it will
//          Revive the dying unit, it will USE the formula function so you better customize it there.
//          It will revive the unit at a location you've set
//          Just remember to remove the location afterwards!
//
//      End of Documentation
//
//***************************************************************************************************************************
//
//      SETUP
//
//
globals
//
//*************GUI USERS LOOK BELOW HERE****************************
//
//      This variable is where you can set how fast the camera should pan to the revived unit.
//      As this usally is set to a low value, lower the greater the size is, you can set it
//      to 0. if you want to, then it will be panned instantly.
//
    private constant real PANCAM        = 0.6
    
endglobals
    
    private function GetAdjustedTime takes real time, integer herolvl returns real
        
        return time + 0. * herolvl
        
        //if you want something extra or you can set the time to 0
        //and use this for a formula instead
        //I call this function for the formula func in the documentation
    endfunction
    
    
    private function FilterHero takes unit u returns boolean
        
        return IsUnitType(u, UNIT_TYPE_HERO)
        
        //just check if the unit is a hero
        //you can edit the filter if you want
    endfunction
                
//      END SETUP
//******************************************************************************************************************************
// 

globals
//
//      To make sure that the users wont run several instances with the same unit
//
    private group NOSTACK   = CreateGroup()
    
endglobals
    

    private struct data
        unit    hero
        real    x
        real    y
        boolean eff
    endstruct
    
    
    private function finish takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local data dat = data(GetTimerData(t))
        call ReleaseTimer(t)                                //recycle timer
    
        call ReviveHero(dat.hero, dat.x, dat.y, dat.eff)    //revive hero
        call GroupRemoveUnit(NOSTACK, dat.hero)
        
        if GetLocalPlayer() == GetOwningPlayer(dat.hero) then
            call PanCameraToTimed(dat.x, dat.y, PANCAM)
            call ClearSelection()
            call SelectUnit(dat.hero, true)
        endif
        call dat.destroy()
    endfunction
    
    
    function HeroRevive takes unit hero, real time, real x, real y, boolean eff returns nothing
        local data dat
        local timer t
        
        if FilterHero(hero) and not IsUnitInGroup(hero, NOSTACK) then
            set dat = data.create()
            set t = NewTimer()
            
            set dat.hero = hero
            set dat.x = x
            set dat.y = y
            set dat.eff = eff
            
            call GroupAddUnit(NOSTACK, hero)
            call SetTimerData(t, dat)
            call TimerStart(t, GetAdjustedTime(time, GetHeroLevel(hero)), false, function finish)
            
        debug else
            debug call BJDebugMsg("HeroRevival Error: The unit you want to revive is not a hero or was already set to revive")
        endif
    endfunction
    
    
    function HeroReviveLoc takes unit hero, real time, location loc, boolean eff returns nothing
        call HeroRevive(hero, time, GetLocationX(loc), GetLocationY(loc), eff)
    endfunction
    
    
endlibrary
 
Level 12
Joined
Nov 23, 2008
Messages
512
ehhm did you regionized that it doesn't work?
you just get the error message (HeroRevival Error: The unit is either dead or isn't a hero unit or is already in the system, please check your trigger calls.)

Edit: i think it's because
return IsUnitType(u, UNIT_TYPE_HERO) and GetWidgetLife(u) > 0.405

it should be GetWidgetLife(u) < 0.405 if you want to know if the hero is dead

Edit2: yes it works now (you have to change the if a bit now)
 
Top