• 🏆 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] My friend detect damage system :\

Status
Not open for further replies.
Level 6
Joined
Jan 27, 2007
Messages
208
Hi, 1.24 patch seems make my friend system wont work at all :/
I dont know JASS, so i just use his system without understand a thing about this system, but i think i know, this system wont work in 1.24 patch.

Here it is

JASS:
// ===========================
function H2I takes handle h returns integer
    return h
    return 0
endfunction

// ===========================
function LocalVars takes nothing returns gamecache
    return udg_LocalVars
endfunction

function SetHandleHandle takes handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
    endif
endfunction

function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleGroup takes handle subject, string name returns group
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleWidget takes handle subject, string name returns widget
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction

// ===========================

And this

JASS:
function AnyUnitTakesDamage takes nothing returns nothing
    call DisableTrigger(GetTriggeringTrigger())
    call ConditionalTriggerExecute( gg_trg_Damage_Register )
    call EnableTrigger(GetTriggeringTrigger())
endfunction

// part 1
function AddDamageTriggers takes nothing returns nothing
    local trigger takedamage = CreateTrigger()
    call TriggerRegisterUnitEvent(takedamage,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
    call SetHandleHandle(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
    call SetHandleHandle(GetTriggerUnit(),"TakeDamageTrigger",takedamage)
endfunction

// part 2
function RemoveDamageTriggers takes nothing returns nothing
    local trigger me = GetHandleTrigger(GetTriggerUnit(),"TakeDamageTrigger")
    // delete action and trigger
    call TriggerRemoveAction(me,GetHandleTriggerAction(me,"action"))
    call DestroyTrigger(me)
    call FlushHandleLocals(me)
    set me = null
endfunction

// part 3
function InitTrig_Detect_Damage_Events takes nothing returns nothing
    local trigger entermap = CreateTrigger()
    local group startingunits = CreateGroup()
    local unit u
    local trigger takedamage
    local trigger upondeath = CreateTrigger()
    call GroupEnumUnitsInRect(startingunits,bj_mapInitialPlayableArea,null)
    loop
        set u = FirstOfGroup(startingunits)
        exitwhen u == null
        set takedamage = CreateTrigger()
        call TriggerRegisterUnitEvent(takedamage,u,EVENT_UNIT_DAMAGED)
        call SetHandleHandle(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
        call SetHandleHandle(u,"TakeDamageTrigger",takedamage)
        call GroupRemoveUnit(startingunits,u)
    endloop
    set takedamage = null

    // unit enters the map/revives
    call TriggerRegisterAnyUnitEventBJ(entermap ,EVENT_PLAYER_HERO_REVIVE_FINISH)
    call TriggerRegisterEnterRectSimple(entermap, bj_mapInitialPlayableArea)
    call TriggerAddAction(entermap,function AddDamageTriggers)

    // unit dies
    call TriggerRegisterAnyUnitEventBJ(upondeath,EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction(upondeath,function RemoveDamageTriggers)
endfunction

Well, i will appreciate any kind of helps from you guys. Thanks
 
Replace the first bit (HandleVars) with this:
JASS:
/*******************************************************************************************
 Faux Handle Vars
 ----------------
    Do not use these functions for new stuff, it is just not the right thing to do...

    The intention of Faux Handle Vars is to be a patch fix for a map's migration to
  patch 1.24 This library might not cover all uses of handle vars, some of them are just
  impossible with the new rules set in patches 1.23b and 1.24, but they should work for
  most of the cases....

    All of them but the SetHandle*** ones are inline friendly. I follow the interface
  in official Kattana's handle vars from wc3jass.com, if your handle vars functions
  look different, then you were not using handle vars but another thing...

*******************************************************************************************/

//==========================================================================================
library HandleVars initializer init

 globals
    private hashtable ht
 endglobals
 
    // too bad the Handle vars' old functionality forces me to make these things
    // inline-unfriendly
    function SetHandleHandle takes agent subject,  string label, agent value returns nothing
        if(value==null) then
            call RemoveSavedHandle( ht, GetHandleId(subject), StringHash(label))
        else
            call SaveAgentHandle( ht, GetHandleId(subject), StringHash(label), value)
        endif
    endfunction

    function SetHandleInt takes agent subject, string label, integer value returns nothing
        if value==0 then
            call RemoveSavedInteger(ht, GetHandleId(subject), StringHash(label))
        else
            call SaveInteger(ht, GetHandleId(subject), StringHash(label), value)
        endif        
    endfunction

    function SetHandleBoolean takes agent subject, string label, boolean value returns nothing
        if (value == false) then
            call RemoveSavedBoolean(ht, GetHandleId(subject), StringHash(label))
        else
            call SaveBoolean(ht, GetHandleId(subject), StringHash(label), value)
        endif
    endfunction

    function SetHandleReal takes agent subject, string label, real value returns nothing
        if (value == 0.0) then
            call RemoveSavedReal(ht, GetHandleId(subject), StringHash(label))
        else
            call SaveReal(ht, GetHandleId(subject), StringHash(label), value)
        endif
    endfunction

    function SetHandleString takes agent subject, string label, string value returns nothing
        if ((value=="") or (value==null)) then
            call RemoveSavedString(ht, GetHandleId(subject), StringHash(label)) 
        else
            call SaveStr(ht, GetHandleId(subject), StringHash(label), value) //yay for blizz' consistent naming scheme...
        endif
    endfunction

    function GetHandleHandle takes agent subject, string label returns agent
        debug call BJDebugMsg("[debug] What the heck? Why would you call HandleHandle I guess this was caused by a search and replace mistake")
        return null
    endfunction

    // these are inline friendly, ok, maybe they aren't because jasshelper does not recognize
    // GetHandleId as non-state changing. But they will be once I fix jasshelper...

    function GetHandleInt takes agent subject, string label returns integer
        return LoadInteger(ht, GetHandleId(subject), StringHash(label))
    endfunction

    function GetHandleBoolean takes agent subject, string label returns boolean
        return LoadBoolean(ht, GetHandleId(subject), StringHash(label))
    endfunction

    function GetHandleString takes agent subject, string label returns string
        return LoadStr(ht, GetHandleId(subject), StringHash(label))
    endfunction

    function GetHandleReal takes agent subject, string label returns real
        return LoadReal(ht, GetHandleId(subject), StringHash(label))
    endfunction

    // got bored so I now use a textmacro...
    //! textmacro FAUX_HANDLE_VARS_GetHandleHandle takes NAME, TYPE
         function SetHandle$NAME$ takes agent subject,  string label, $TYPE$ value returns nothing
             if(value==null) then
                call RemoveSavedHandle( ht, GetHandleId(subject), StringHash(label))
             else
                call Save$NAME$Handle( ht, GetHandleId(subject), StringHash(label), value)
             endif
         endfunction

         function GetHandle$NAME$ takes agent subject, string label returns $TYPE$
             return Load$NAME$Handle( ht, GetHandleId(subject), StringHash(label))
         endfunction
    //! endtextmacro
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Player","player")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Widget","widget")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Destructable","destructable")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Item","item")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Unit","unit")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Ability","ability")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Timer","timer")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Trigger","trigger")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerCondition","triggercondition")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerAction","triggeraction")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerEvent","event")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Force","force")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Group","group")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Location","location")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Rect","rect")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("BooleanExpr","boolexpr")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Sound","sound")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Effect","effect")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("UnitPool","unitpool")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("ItemPool","itempool")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Quest","quest")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("QuestItem","questitem")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("DefeatCondition","defeatcondition")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TimerDialog","timerdialog")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Leaderboard","leaderboard")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Multiboard","multiboard")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("MultiboardItem","multiboarditem")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Trackable","trackable")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Dialog","dialog")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Button","button")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TextTag","texttag")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Lightning","lightning")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Image","image")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Ubersplat","ubersplat")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Region","region")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("FogState","fogstate")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("FogModifier","fogmodifier")
    //! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Hashtable","hashtable")


    function FlushHandleVars takes agent subject returns nothing
        call FlushChildHashtable(ht, GetHandleId(subject))
    endfunction
    function FlushHandleLocals takes agent subject returns nothing
        call FlushHandleVars(subject)
    endfunction


    private function init takes nothing returns nothing
        set ht=InitHashtable()
    endfunction

endlibrary

Make sure you are using JassNewGenPack for vJass!
 
Level 6
Joined
Jan 27, 2007
Messages
208
Sorry, i bump this thread again, because my friend system still not working :/

@Element of Water
Got this error message when i paste your JASS.

ERrorAgain.jpg
 
Level 11
Joined
May 16, 2007
Messages
288
Ugh, the problem is that the handle vars system you were using is ultra-outdated (no joke) and may cause many nasty bugs if used incorrectly, most ppl prefer alternatives nowadays.

Well, after reading the code, I have no idea why it isn't working, may be Blizzard's crappy way of removing the return bug that screwed up the code, or maybe something else (I never actually used that system).

If your friend (the one you got the system from), or someone else who is used to making stuff with handle vars can't fix the problem, I suggest using this system by Rising_Dusk (http://www.wc3c.net/showthread.php?t=100618) it does basically the same thing, but is more efficient and way less buggy. Replace the second trigger (the damage detection system one) with the system in Dusk's map.
 
Status
Not open for further replies.
Top