Snippet DetectRevivingStructure

Troll-Brain

You can change this now in User CP.
Reaction score
85
Because i love making useless things that don't exist in the trigger editor, and because also someone "need" it, i decided to create the GetRevivingStructure(), the building which ressurect the hero.

Here is the code :

This library have a removal detection, the "system" itself can't have any leak.

Librairies needed :

Table , TimerUtils (used by RemovalDetection)

JASS:
// *************************************************************
// *   DetectRevivingStructure with a Removal Detection -- Version 2.0
// *                        by Troll-Brain
// *************************************************************
// *
// *    CREDITS:
// *        - Vexorian (JassHelper)
// *        - PitzerMike (JassNewGenPack)
// *        - Pipedream (Grimoire)
// *        - Anitarf (v 2.0)
// *
// *    WHAT THIS LIBRARY DOES:
// *        - When an hero is ressurected with a building or why not an other unit wicth can ressurect heroes like an altar,
// *          there is not Get to know witch unit did that. This library let to know that. Ofc it works for all revive events.
// *  
// *    REQUIRES:
// *        - The Jass New Gen Pack
// *        - Table : <a href="http://www.wc3campaigns.net/showthread.php?t=101246" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://www.wc3campaigns.net/showthread.php?t=101246</a>
// *        - TimerUtils : <a href="http://www.wc3campaigns.net/showthread.php?t=101322" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://www.wc3campaigns.net/showthread.php?t=101322</a>
// *        - RemovalDetection : <a href="http://www.wc3campaigns.net/showthread.php?t=102588" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://www.wc3campaigns.net/showthread.php?t=102588</a>
// *
// *    HOW TO USE:
// *        - check the examples
// *
// *        - If you plan to ressurect heroes with a trigger action you must use the functions ReviveHeroAlt or ReviveHeroLocAlt
// *          witch work exactly as the natives ones, ReviveHero and ReviveHeroLoc.
// *          Or you can also use the functions InitTriggeringRessurect and EndTriggeringRessurect like in the gui example.
// *          You have also to care about the GetRevivingStructure usage (if you use TriggerSleepAction or PolledWait), use a local and
// *          set it to GetRevivingStructure before any wait.
// *
// *    CHANGELOG:
// *        - v 2.0 * Edited the code, because it did leaks, now require the library RemovalDetection and so TimerUtils as well.
// *                * Adding Table to avoid using one more game cache.
// *                * Renamed library and functions to follow jass conventions
// *
// *        - v 1.0 Initial Release
// *************************************************************

library DetectRevivingStructure initializer init uses RemovalDetection , Table

globals
    private HandleTable Ht
    private boolean IsATriggerAction= false
endglobals

private struct s_data
    unit revivingstructure
    unit hero
    
    static method create takes unit u returns s_data
        local s_data s = s_data.allocate()
        
        set Ht<u> = s
        set s.hero = u
        return s
    endmethod
    
    method onDestroy takes nothing returns nothing
        call Ht.flush(.hero)
        set .revivingstructure = null
        set .hero = null
    endmethod
    
endstruct

globals
    private s_data S_data = 0
endglobals

public function IsUnitHero takes unit u returns boolean
    return IsHeroUnitId(GetUnitTypeId(u))
endfunction

private function Conditions takes nothing returns boolean
    local unit u = GetOrderTargetUnit()
    
    if GetIssuedOrderId()&gt;=852027 and GetIssuedOrderId()&lt;=852038 and IsUnitHero(u) and IsUnitType(u,UNIT_TYPE_DEAD) then
        set S_data = Ht<u>
        
        if S_data == 0 then
            set S_data= s_data.create(u)
        endif
        set S_data.revivingstructure=GetOrderedUnit()
        
    endif
    
    set u=null
    return false
    
endfunction

private function DestroyData takes nothing returns boolean
    
    if IsUnitHero(GetScopingUnit()) then
        set S_data = Ht[GetScopingUnit()]
        call S_data.destroy()
    endif
    return false
endfunction

function GetRevivingStructure takes nothing returns unit
    local eventid evd = GetTriggerEventId()
    
    if evd==EVENT_PLAYER_HERO_REVIVE_START or evd==EVENT_PLAYER_HERO_REVIVE_CANCEL or evd==EVENT_PLAYER_HERO_REVIVE_FINISH or evd==EVENT_UNIT_HERO_REVIVE_START or evd==EVENT_UNIT_HERO_REVIVE_CANCEL or evd==EVENT_UNIT_HERO_REVIVE_FINISH then
    
        if IsATriggerAction then
            set evd = null
            return null
        else
            set evd = null
            set S_data = Ht[GetRevivingUnit()]
            return S_data.revivingstructure
        endif
        
    else
        debug call BJDebugMsg(&quot;You tried to use GetRevivingStructure() with a wrong event, use an EVENT_PLAYER/UNIT_HERO_REVIVE&quot;)
    endif
    
    set evd = null
    return null
endfunction

function ReviveHeroAlt takes unit whichHero, real x, real y, boolean doEyecandy returns boolean
    local boolean b=false
    set IsATriggerAction=true
    set b=ReviveHero(whichHero,x,y,doEyecandy)
    set IsATriggerAction=false
    return b
endfunction

function ReviveHeroLocAlt takes unit whichHero, location loc , boolean doEyecandy returns boolean
    local boolean b=false
    set IsATriggerAction=true
    set b=ReviveHeroLoc(whichHero,loc,doEyecandy)
    set IsATriggerAction=false
    return b
endfunction

function InitTriggeringRessurect takes nothing returns nothing
    set IsATriggerAction=true 
endfunction

function EndTriggeringRessurect takes nothing returns nothing
    set IsATriggerAction=false
endfunction

public function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    
    set Ht = HandleTable.create()
    
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
    call TriggerAddCondition(trig,Condition(function Conditions))
    
    set trig = CreateTrigger()
    call TriggerRegisterOutOfScopeEvent(trig)
    call TriggerAddCondition(trig,Condition(function DestroyData))
    
    set trig = null
endfunction

endlibrary</u></u>


For some reasons if the requirement of the library RemovalDetection is too mutch i have made this one :

Librairies needed :

Table

Since there is not a removal detection, the "system" itself can leak, but only if some heroes are removed during the game.
If you care about it i have made a custom function RemoveHero.
Even if you don't use this function the "system" will be fail only if you try to ressurect with a building more than 8190 different heroes.

JASS:
// *************************************************************
// *                   DetectRevivingStructure -- Version 2.0
// *                          WITHOUT removal detection
// *                              by Troll-Brain
// *************************************************************
// *
// *    CREDITS:
// *        - Vexorian (JassHelper)
// *        - PitzerMike (JassNewGenPack)
// *        - Pipedream (Grimoire)
// *        - Anitarf (v 2.0)
// *
// *    WHAT THIS LIBRARY DOES:
// *        - When an hero is ressurected with a building or why not an other unit witch can ressurect heroes like an altar,
// *          there is no Get to know witch unit did that. This library let to know that. Ofc it works for all revive events.
// *  
// *    REQUIRES:
// *        - The Jass New Gen Pack
// *        - Table : <a href="http://www.wc3campaigns.net/showthread.php?t=101246" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://www.wc3campaigns.net/showthread.php?t=101246</a>
// *
// *    HOW TO USE:
// *        - check the examples
// *
// *        - If you plan to ressurect heroes with a trigger action you must use the functions ReviveHeroAlt or ReviveHeroLocAlt
// *          which work exactly as the natives ones, ReviveHero and ReviveHeroLoc.
// *          Or you can also use the functions InitTriggeringRessurect and EndTriggeringRessurect like in the gui example.
// *          You have also to care about the GetRevivingStructure usage (if you use TriggerSleepAction or PolledWait), use a local and
// *          set it to GetRevivingStructure before any wait.
// *
// *        - CAREFULL !!!
// *          In this library i don&#039;t use the removal detection that can be too much in some maps.
// *          If you already use the library RemovalDetection don&#039;t use this one. It can&#039;t leak, if the heroes in the map are not removed.
// *          But it will leak if heroes are removed without the function RemoveHero.
// *          Also if the hereoes are removed without this function, it will fail if you try to ressurect with a building more than 8190 different heroes during the game.
// *
// *    CHANGELOG:
// *        - v 2.0 * Edited the code, because it did leaks, now require the library RemovalDetection and so TimerUtils as well.
// *                * Adding Table to avoid using one more game cache.
// *                * Renamed library and functions to follow jass conventions
// *
// *        - v 1.0 Initial Release
// *************************************************************

library DetectRevivingStructure initializer init uses Table

globals
    private HandleTable Ht
    private boolean IsATriggerAction= false
endglobals

private struct s_data
    unit revivingstructure
    unit hero
    
    static method create takes unit u returns s_data
        local s_data s = s_data.allocate()
        
        set Ht<u> = s
        set s.hero = u
        return s
    endmethod
    
    method onDestroy takes nothing returns nothing
        call Ht.flush(.hero)
        set .revivingstructure = null
        set .hero = null
    endmethod
    
endstruct

globals
    private s_data S_data = 0
endglobals

public function IsUnitHero takes unit u returns boolean
    return IsHeroUnitId(GetUnitTypeId(u))
endfunction

private function Conditions takes nothing returns boolean
    local unit u = GetOrderTargetUnit()
    
    if GetIssuedOrderId()&gt;=852027 and GetIssuedOrderId()&lt;=852038 and IsUnitHero(u) and IsUnitType(u,UNIT_TYPE_DEAD) then
        set S_data = Ht<u>
        
        if S_data == 0 then
            set S_data= s_data.create(u)
        endif
        set S_data.revivingstructure=GetOrderedUnit()
        
    endif
    
    set u=null
    return false
    
endfunction

function GetRevivingStructure takes nothing returns unit
    local eventid evd = GetTriggerEventId()
    
    if evd==EVENT_PLAYER_HERO_REVIVE_START or evd==EVENT_PLAYER_HERO_REVIVE_CANCEL or evd==EVENT_PLAYER_HERO_REVIVE_FINISH or evd==EVENT_UNIT_HERO_REVIVE_START or evd==EVENT_UNIT_HERO_REVIVE_CANCEL or evd==EVENT_UNIT_HERO_REVIVE_FINISH then
    
        if IsATriggerAction then
            set evd = null
            return null
        else
            set evd = null
            set S_data = Ht[GetRevivingUnit()]
            return S_data.revivingstructure
        endif
        
    else
        debug call BJDebugMsg(&quot;You tried to use GetRevivingStructure() with a wrong event, use an EVENT_UNIT/PLAYER_HERO_REVIVE_&quot;)
    endif
    
    set evd = null
    return null
endfunction

function ReviveHeroAlt takes unit whichHero, real x, real y, boolean doEyecandy returns boolean
    local boolean b=false
    set IsATriggerAction=true
    set b=ReviveHero(whichHero,x,y,doEyecandy)
    set IsATriggerAction=false
    return b
endfunction

function ReviveHeroLocAlt takes unit whichHero, location loc , boolean doEyecandy returns boolean
    local boolean b=false
    set IsATriggerAction=true
    set b=ReviveHeroLoc(whichHero,loc,doEyecandy)
    set IsATriggerAction=false
    return b
endfunction

function RemoveHero takes unit witchHero returns nothing
    if witchHero == null then
        debug call BJDebugMsg(&quot;function RemoveHero : the witchHero argument is null&quot;)
        return
    elseif not IsUnitHero(witchHero) then
        debug call BJDebugMsg(&quot;function RemoveHero : the witchHero argument is not an hero&quot;)
        return
    endif
    set S_data = Ht[witchHero]
    if S_data != 0 then
        call S_data.destroy()
    endif
    call RemoveUnit(witchHero)
endfunction

function InitTriggeringRessurect takes nothing returns nothing
    set IsATriggerAction=true 
endfunction

function EndTriggeringRessurect takes nothing returns nothing
    set IsATriggerAction=false
endfunction

public function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    
    set Ht = HandleTable.create()
    
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
    call TriggerAddCondition(trig,Condition(function Conditions))
    
    set trig = null
    
endfunction

endlibrary</u></u>


In the attached map, there are examples of usage.

Critics of code are welcome.
 

Attachments

  • DetectRevivingStructure.w3x
    36.7 KB · Views: 217

Romek

Super Moderator
Reaction score
964
Something minor caught my eye:
JASS:
 // ...
    else
        debug call BJDebugMsg//...
   endif

Should be:
JASS:
//...
   debug else
        debug call BJDebugMsg//...
   endif


This seems quite useful, and I'm surprised it hasn't got many comments already.
I'll look over it in more detail later.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
If this will be approved, i will "fix" the else.
And add new feature(s), like know since let knowing how much time the hero is actually resurrecting.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Usually it goes the opposite way :p .
You fix/add stuff first then it gets approved.

At the snippet itself;
This could be useful for some people indeed ;) .
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I can see it for like RPG's or something maybe.
A building revives and players need to be warned or something.

EDIT: And I'm pretty sure this needs more feedback/comments to get approved.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Last bump ever.
If you want approve it but something is wrong with this for you, tell me what.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top