• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS]Simple Hero Revival [v1.1d] -PLAIN JASS VERS

  • Like
Reactions: Mainy and hell gate
I got asked to make my Simple Hero Revival System Link into plain JASS for those who don't want JNGP, so I made one.

Have no requirements.

HOW TO IMPORT:

1. Copy the JASS script into your map header.

2. Copy the create variables trigger or create them yourself in the variable editor

3. Save the map, open it up, delete the create variables trigger.

4. You are good to go!

CRITCAL ERROR HAS BEEN FIXED, IF YOU USED EARLIER VERSIONS PLEASE CHANGE TO THE NEWER

In version 1.1d I fixed another naughty bug so please use 1.1d or later.

JASS:
function SHRS_Revive takes nothing returns nothing
    local integer id = GetHandleId(GetExpiredTimer()) //just for simpleness and no indexing
    //recycle the timer
    set udg_SHRS_Timers[udg_SHRS_N] = GetExpiredTimer()
    set udg_SHRS_N = udg_SHRS_N + 1
    //revive
    call ReviveHero(LoadUnitHandle(udg_SHRS_Hashtable, id, 1), LoadReal(udg_SHRS_Hashtable, id, 2), LoadReal(udg_SHRS_Hashtable, id, 3), LoadBoolean(udg_SHRS_Hashtable, id, 4))
    //flush the child keys of the id
    call FlushChildHashtable(udg_SHRS_Hashtable, id)
endfunction

function HeroRevive takes unit hero, real time, real x, real y, boolean eff returns nothing
    local timer t
    local integer id
    //the if below is just to protect the users from making mistakes
    if IsUnitType(hero, UNIT_TYPE_HERO) and IsUnitType(hero, UNIT_TYPE_DEAD) and GetUnitTypeId(hero) != 0 then
        // Simple timer recycling
        if (udg_SHRS_N == 0) then
            set t = CreateTimer()
        else
            set udg_SHRS_N = udg_SHRS_N - 1
            set t = udg_SHRS_Timers[udg_SHRS_N]
        endif
        set id = GetHandleId(t)
        // store unit
        call SaveUnitHandle(udg_SHRS_Hashtable, id, 1, hero)
        // store x coordinate
        call SaveReal(udg_SHRS_Hashtable, id, 2, x)
        // store y coordinate
        call SaveReal(udg_SHRS_Hashtable, id, 3, y)
        // store the boolean
        call SaveBoolean(udg_SHRS_Hashtable, id, 4, eff)
        // fire the timer
        call TimerStart(t, time, false, function SHRS_Revive)
        set t = null
    debug else
        // just a simple error message for those who don't understand the words dead and hero
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "SHRS Error - The unit is either not dead or is not a hero")
    endif
endfunction

// A location-wrapper for the above function
function HeroReviveLoc takes unit hero, real time, location loc, boolean eff returns nothing
    call HeroRevive(hero, time, GetLocationX(loc), GetLocationY(loc), eff)
endfunction

and the gui example and variable creator trigger


  • SHRS Variables create
    • Events
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set SHRS_Hashtable = (Last created hashtable)
      • Set SHRS_N = 0
      • Set SHRS_Timers[0] = (Last started timer)
  • 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 SHRS_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!)




v1.0 released

v1.1 fixed the death bug (checked the reverse thanks to hell gate), also fixed the final flush of parent key, now it stores the instances in the hashtable in case someone would use the timer recycle for other systems

v1.1b critical error mistake fixed, people using earlier version have to switch to the newer, parent key flush removed

v1.1c updated to Bribe's suggestion

v1.1d updated again with Bribe's suggestion and fixed another naughty bug



Credit me if used!

Special thanks goes to The_Reborn_Devil for showing his example of simple timer recycling.

Enjoy

Keywords:
baassee, simple, hero, revival, jass, gui, friendly, no, jngp, or, vjass
Contents

Simple Hero Revival v1.1d [JASS] (Map)

Reviews
11:24, 28th Feb 2011 Bribe: A simple utility which could prove useful for GUI users.

Moderator

M

Moderator

11:24, 28th Feb 2011
Bribe:

A simple utility which could prove useful for GUI users.
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
Level 22
Joined
Nov 14, 2008
Messages
3,256
I think the documentation is sufficient, all you need to know is basically in the GUI example or the two functions, the one who starts it up and the finish. I didn't want to explain the little timer recycler :p

I'll gladly explain anything you want to know! Just ask.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Looking at it further, the whole thing could use a nice optimization and bug correction, a bit of an API change because there is no reason to prefix HeroRevive and HeroReviveLoc as those are the functions, after all. If you prefix them, you may as well call it SHRS_ReviveHero and SHRS_ReviveHeroLoc.

JASS:
function SHRS_Revive takes nothing returns nothing
    local integer id = GetHandleId(GetExpiredTimer()) //just for simpleness and no indexing
    //recycle the timer
    set udg_SHRS_Timers[udg_SHRS_N] = GetExpiredTimer()
    set udg_SHRS_N = udg_SHRS_N + 1
    //revive
    call ReviveHero(LoadUnitHandle(udg_SHRS_Hashtable, id, 1), LoadReal(udg_SHRS_Hashtable, id, 2), LoadReal(udg_SHRS_Hashtable, id, 3), LoadBoolean(udg_SHRS_Hashtable, id, 4))
    //flush the child keys of the id
    call FlushChildHashtable(udg_SHRS_Hashtable, id)
endfunction

function HeroRevive takes unit hero, real time, real x, real y, boolean eff returns nothing
    local timer t
    local integer id
    //the if below is just to protect the users from making mistakes
    if IsUnitType(hero, UNIT_TYPE_HERO) and IsUnitType(hero, UNIT_TYPE_DEAD) and GetUnitTypeId(hero) != 0 then
        // Simple timer recycling
        if (udg_SHRS_N == 0) then
            set t = CreateTimer()
        else
            set udg_SHRS_N = udg_SHRS_N - 1
            set t = udg_SHRS_Timers[udg_SHRS_N]
        endif
        set id = GetHandleId(t)
        // store unit
        call SaveUnitHandle(udg_SHRS_Hashtable, id, 1, hero)
        // store x coordinate
        call SaveReal(udg_SHRS_Hashtable, id, 2, x)
        // store y coordinate
        call SaveReal(udg_SHRS_Hashtable, id, 3, y)
        // store the boolean
        call SaveBoolean(udg_SHRS_Hashtable, id, 4, eff)
        // fire the timer
        call TimerStart(t, time, false, function SHRS_Revive)
        set t = null
    debug else
        // just a simple error message for those who don't understand the words dead and hero
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "SHRS Error - The unit is either not dead or is not a hero")
    endif
endfunction

// A location-wrapper for the above function
function HeroReviveLoc takes unit hero, real time, location loc, boolean eff returns nothing
    call SHRS_HeroRevive(hero, time, GetLocationX(loc), GetLocationY(loc), eff)
endfunction
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
http://en.wikipedia.org/wiki/Duplicate_code

That, and it's harder to maintain different copies of the same thing. Imagine if you copied it five or six times over with minimal differences, then suddenly you need to fix a syntax error and you have to change all five or six. Just have one common function with as simple parameters as it gets, to handle all the dirty work.

For a GUI user, that one function call doesn't mean anything anyway. GUI users almost never care about BJ's, spamming the same "GetOwningPlayer(GetTriggerUnit())" over and over again. And if they did, they are probably on their way to JASS anyway.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
I just advise updating the triggers on this site as they still point to the old variable names, and:

Set SHRS_N = 0
Set SHRS_Timers[0] = (Last started timer)

Both are unnecessary. SHRS_Timers[0] does not need to be initialized as the script automatically does that, and SHRS_N is automatically set in GUI's InitGlobals function to 0.
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
The trigger might be enabled yes, I have to check.

EDIT:

What do you mean with disable them in the trigger itself? You cannot disable variables or?

Anyway the best option would be to have a second trigger where those are created due to that the hashtable is created in the first create trigger.
 
Top