[JASS] Problem with event

Status
Not open for further replies.
If you know what trigger to fire, just use TriggerExecute() after dropping. You can also just use something like this:
JASS:
function UnitRemoveItemEx takes unit whichUnit, item whichItem returns nothing
   //do actions/execute trigger/whatever you want
   //this detects when you use the UnitRemoveItem() function
   //[internally it just does a function replacement though]
endfunction

hook UnitRemoveItem UnitRemoveItemEx
 
Last edited:
If you know what trigger to fire, just use TriggerExecute() after dropping. You can also just use something like this:
JASS:
function UnitRemoveItemEx takes unit whichUnit, item whichItem returns nothing
   //do actions/execute trigger/whatever you want
   //this detects when you use the UnitRemoveItem() function
   //[internally it just does a function replacement though]
endfunction

hook UnitRemoveItem

Would you mind going over your syntax used here? I'm unfamiliar with some vJass syntax.
 
Sorry, I've updated it lol. I forgot to hook to the function.

Basically, "hook" is used as something to detect when an action is called in a trigger, for example:
JASS:
hook DestroyEffect DestroyEffectRevised

That would "hook" the DestroyEffect function, and redirect it to the DestroyEffectRevised function. (However, DestroyEffect's() actions will still be executed)

When you redirect it, the function must take the same parameters.
JASS:
function DestroyEffectRevised takes effect whichEffect returns nothing
    //do actions here
endfunction

hook DestroyEffect DestroyEffectRevised

Now once the function is called, it will redirect to the revised function and do the actions within. Now internally, this doesn't detect when a function is called. Instead, it goes through the map and replaces all DestroyEffect's with DestroyEffectRevised, and adds the native to be executed to the hook function. Yes, many people can do this easily themselves, but it is very time consuming if you have a large map. Here is some sort of practical use I've found from it:
JASS:
library RecycleChecking
    //this is freehand, but basically this is useful for detecting when a unit is recycled and when it isn't
    //useful for spells to check if your recycling is working (assuming you use the ShowUnit()) method of recycling
    globals
        private integer count = 0
        private integer removeCount = 0
    endglobals
    
    function CreateUnitEx takes player id, integer uid, real x, real y, real face returns unit
        set count = count+1
        call BJDebugMsg("A unit was created! Count: "+I2S(count))
    endfunction 
    function RemoveUnitEx takes unit u returns nothing
        set removeCount = removeCount+1
        set count = count-1
        call BJDebugMsg("A unit was removed! Count: "+I2S(count))
        call BJDebugMsg("Remove Count: "+I2S(removeCount))
    endfunction

    function ShowUnitEx takes unit u, boolean show returns nothing
        if show then
            set count = count+1
            call BJDebugMsg("A unit was shown! Count: "+I2S(count))
        else
            set count = count-1
            call BJDebugMsg("A unit was hidden! Count: "+I2S(count))
        endif    
    endfunction

    hook ShowUnit ShowUnitEx
    hook CreateUnit CreateUnitEx //I would hook the other functions for creating units, but I don't use those
    hook RemoveUnit RemoveUnitEx
endlibrary

Something like that. Of course, it is just freehand and is useful only for testing, but hooks are pretty powerful and definitely useful in some cases.
 
Status
Not open for further replies.
Back
Top