Abilities Events

Troll-Brain

You can change this now in User CP.
I've made this because SpellStruct is truly overkilled for my needs and anyway as SpellEvent don't do all the stuff i want.
Here these lack of features :

- In SpellStruct when the ENDCAST event fire you have to figure yourself it the spell was successfully casted or interrupted before the end.
- We can't get the responses events for spells which are not registered and i don't see why ...
- We can't safely use a spell which doesn't interrupt orders and have a cast time, like windwalk if you edit the cast time.
Else the systems could bug because an unit can have more than one spell active.
- The use of Table is overkilled in SpellEvent
- The user can't define himself when the spell is ended, can be done with a simple boolean in mine and SpellEvent.
Mostly because it's really spell dependant but for triggered spell it's also handy.

JASS:
library AbilitiesEvents requires AutoIndex,UnitListModule

globals
    private keyword init
    private keyword s_spell
    private hashtable HashT
endglobals

private function interface FunctionInterface takes nothing returns nothing

globals
    s_spell Spell = 0
    key SPELL_CHANNEL
    key SPELL_CAST
    key SPELL_EFFECT
    key SPELL_FINISH // if the unit had succesfully finished the spell
    key SPELL_ENDCAST // if the unit abort the spell before the end
endglobals

private struct s_spell
    
    integer abilityId = 0
    unit castingUnit = null
    unit targetUnit = null
    item targetItem = null
    destructable targetDestructable = null
    real targetX = 0.
    real targetY = 0.
    boolean isTargetPoint = false
    boolean isTargetUnit = false
    boolean isTargetItem = false
    boolean isTargetDestructable = false
    boolean isNoTarget = false
    integer targetUnitTypeId = 0
    integer targetDestructableTypeId = 0
    integer targetItemTypeId = 0
    boolean isEnded = false
    
    implement UnitList
    
    private static integer Index
    private static timer Tim
    private thistype S
    private static FunctionInterface func
    
    private static method create takes nothing returns thistype
        local thistype this = .allocate()
        
        set .castingUnit = GetSpellAbilityUnit()
        set .targetUnit = GetSpellTargetUnit()
        set .abilityId = GetSpellAbilityId()
        
        if .targetUnit != null then
            set .isTargetUnit = true
            set .targetUnitTypeId = GetUnitTypeId(.targetUnit)
            set .targetX = GetUnitX(.targetUnit)
            set .targetY = GetUnitY(.targetUnit)
            
        else
            set .targetDestructable = GetSpellTargetDestructable()
                
            if .targetDestructable != null then
                set .isTargetDestructable = true
                set .targetDestructableTypeId = GetDestructableTypeId(.targetDestructable)
                set .targetX = GetDestructableX(.targetDestructable)
                set .targetY = GetDestructableY(.targetDestructable)
            else
                set .targetItem = GetSpellTargetItem()
                
                if .targetItem != null then
                    set .isTargetItem = true
                    set .targetItemTypeId = GetItemTypeId(.targetItem)
                    set .targetX = GetItemX(.targetItem)
                    set .targetY = GetItemY(.targetItem)
                else
                    set .isNoTarget = true
                    set .targetX = GetSpellTargetX()
                    set .targetY = GetSpellTargetY()
                endif
                
            endif
            
        endif

        call .unitListAdd(.castingUnit)
        return this
    endmethod
    
    private method onDestroy takes nothing returns nothing
        call .unitListRemove()
    endmethod
    
    private static method DestroyInstances takes nothing returns nothing
        loop
        exitwhen .Index == 0
            set .Index = .Index-1
            call thistype(.Index).S.destroy()
        endloop
    endmethod
    
    private static method OnChannel takes nothing returns boolean
        set Spell = thistype.create()
        //! runtextmacro t_FindSpellFunctionInterface("SPELL_CHANNEL")
        return false
    endmethod
    
    private static method OnEndCast takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        set thistype(.Index).S = Spell
        set .Index = .Index+1
        call TimerStart(.Tim,0.,false,function thistype.DestroyInstances)
        //! runtextmacro t_FindSpellFunctionInterface("SPELL_ENDCAST")
        return false
    endmethod
    
    private static method OnCast takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        //! runtextmacro t_FindSpellFunctionInterface("SPELL_CAST")
        return false
    endmethod

    private static method OnEffect takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        //! runtextmacro t_FindSpellFunctionInterface("SPELL_EFFECT")
        return false
    endmethod

    private static method OnFinish takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        set Spell.isEnded = true
        //! runtextmacro t_FindSpellFunctionInterface("SPELL_FINISH")
        return false
    endmethod
    
    implement init

endstruct

function RegisterSpellEvent takes integer whichEvent, integer whichSpell, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,whichEvent,whichSpell,integer(whichFunc))
endfunction

private module init
    static method onInit takes nothing returns nothing
        local trigger trig
        //! runtextmacro t_CreateSpellsTriggers("OnChannel","EVENT_PLAYER_UNIT_SPELL_CHANNEL")
        //! runtextmacro t_CreateSpellsTriggers("OnCast","EVENT_PLAYER_UNIT_SPELL_CAST")
        //! runtextmacro t_CreateSpellsTriggers("OnEffect","EVENT_PLAYER_UNIT_SPELL_EFFECT")
        //! runtextmacro t_CreateSpellsTriggers("OnFinish","EVENT_PLAYER_UNIT_SPELL_FINISH")
        //! runtextmacro t_CreateSpellsTriggers("OnEndCast","EVENT_PLAYER_UNIT_SPELL_ENDCAST")
        set .Tim = CreateTimer()
        set HashT = InitHashtable()
    endmethod
endmodule

//! textmacro t_FindWhichSpell
    set Spell = s_spell.unitFirst(GetSpellAbilityUnit())
    loop
    exitwhen Spell.abilityId == GetSpellAbilityId()
        set Spell = Spell.unitNext
    endloop
//! endtextmacro

//! textmacro t_CreateSpellsTriggers takes NAME , EVENT
    set trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig,$EVENT$)
    call TriggerAddCondition(trig,function thistype.$NAME$)
//! endtextmacro

//! textmacro t_FindSpellFunctionInterface takes EVENT
    set .func = FunctionInterface(LoadInteger(HashT,$EVENT$,Spell.abilityId))
    if .func != 0 then
        call .func.execute()
    endif
    return false
//! endtextmacro

endlibrary


PS :

Here AutoIndex and UnitListModule
 

Jesus4Lyf

Good Idea™
I made this script because SpellStruct is truly overkilled for my needs
Alright, for all the crap we might like to hang on SpellStruct (because it's big), can I just note that it's actually really rather clean, quick, and efficient?

Anyway,
JASS:
        if Spell.abilityId == GetSpellAbilityId() then
            exitwhen true
        endif

-->
JASS:
exitwhen Spell.abilityId==GetSpellAbilityId()

I don't know why you're using unit list. Actually, I don't know what this is supposed to do. The more I look at it the more I think it's inefficient, and doesn't do enough. For example, how does this handle ability id hashing to load what is supposed to fire for an ability? If it doesn't what's the point of having this at all...? :confused:
 

Troll-Brain

You can change this now in User CP.
I don't find it ugly but meh it seems it will be a personnal code anyway.

Alright, for all the crap we might like to hang on SpellStruct (because it's big), can I just note that it's actually really rather clean, quick, and efficient?
But i still don't need most of the things, and you won't manage ENDCAST and FINISH events like i suggested, so it's a no no.

Anyway,
JASS:
        if Spell.abilityId == GetSpellAbilityId() then
            exitwhen true
        endif

-->
JASS:
exitwhen Spell.abilityId==GetSpellAbilityId()
Yes, i can and will do that.

I don't know why you're using unit list. Actually, I don't know what this is supposed to do. The more I look at it the more I think it's inefficient, and doesn't do enough. For example, how does this handle ability id hashing to load what is supposed to fire for an ability? If it doesn't what's the point of having this at all...? :confused:
An unit can have several spells launched at the same time, if the unit have spells that doesn't interrupt orders and have a cast time like windwalk (if you edit it).

Also for particular abilities, like i've said, it's not implemented yet i will bump when it will be done.
 

Troll-Brain

You can change this now in User CP.
Done.

Comments :

- Most of the things included the interface are the same as Anitarf's code, excepts the RegisterSpellEvent function, and how i handle particular spells.
- Why i don't set members readonly ? Because it's handy if you want to change them for triggered spells.
- If for some reason the target no longer exists when the spell event fire we can still have his TypeId.
- There is a boolean isEnded to know if the spell was successfully casted, the user can set it to true himself, because it's really spell dependant, most of spells are successfully casted when the SPELL_EFFECT event fire.
- There is no known bugs, even if you have two spells with the same order on a same unit, it should work (this case is silly though), you're able to use spells which doesn't interrupt orders with a cast time, like WindWalk (if you edit the casting time)
- You can get the caster,the target and so one for each spell and not only for particular registered ones.

EDIT : Lulz , epic fail with TriggerRegisterSpellEvent, i'm fixing it by using function interfaces instead.
EDIT 2 : Done.
 

Troll-Brain

You can change this now in User CP.
Well, because of the 255 limit of hashtable it's not a good habit to post a library which use his own hashtable instead of Table.
But since it's a personal script it doesn't matter that much, i just won't use more than 255 hashtables :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    I have a GIF though
  • tom_mai78101 tom_mai78101:
    In the GIF, I've configured it so the lower the "Main Value" is, the better. I had to compress it pretty far down though.
  • tom_mai78101 tom_mai78101:
    And this is the thread with the video that shows the wall clip. https://tasvideos.org/Forum/Topics/23453
    +2
  • tom_mai78101 tom_mai78101:
    Hmm, about the Headline News, I noticed threads are being moved into the subforum (Health News, Environmental News, etc.). When that happens, the TH Forum Home page loses the articles, and instead would show old articles posted 1 or 2 weeks ago.
  • tom_mai78101 tom_mai78101:
    What do we do with the Home page?
  • Ghan Ghan:
    I added those forums to the filter for that widget.
    +1
  • tom_mai78101 tom_mai78101:
    Oh nice. They're back. Thanks.
  • tom_mai78101 tom_mai78101:
    Now I think it makes more sense for me to put news in their own subforums, without worry.
  • The Helper The Helper:
    Awesome Ghan thanks! I was purposely not moving the first 15 news articles in Headline news to the different subforums but I guess I don't have to do that now?
  • tom_mai78101 tom_mai78101:
    Question: Is there a way to remove thread redirects? It creates a copy of the moved thread and takes up space, and I am leaning towards wanting to remove them in the Headline News. But if they have an expiration date, I guess I'm fine with it.
  • The Helper The Helper:
    If you move a thread please leave a permanent redirect. You can delete any redirects after 6 months. The redirects are left to help Search Engines find the moved content.
  • tom_mai78101 tom_mai78101:
    What if you move the permanent redirect, not the thread?
  • The Helper The Helper:
    I think that works but I have not messed with it. You can delete redirects though if you have to that will not delete the original thread
  • The Helper The Helper:
    if a redirect ends up in the same forum as the post it goes to though I think the redirect drops or fails or something but they are not bugged out and when you are working on an indirect the original post is safe.
  • The Helper The Helper:
    Happy Early Friday :)
    +1
  • V-SNES V-SNES:
    Happy Friday :)
  • tom_mai78101 tom_mai78101:
    Fun Friday for me
  • tom_mai78101 tom_mai78101:
    Happy Fun Friday to all.
    +2
  • The Helper The Helper:
    Happy Sunday everyone!!!
  • V-SNES V-SNES:
    Happy Sunday!!!
    +1
  • jonas jonas:
    Happy monday :p
  • jonas jonas:
    Everyone hates mondays?
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • jonas jonas:
    Happy belated tuesday

    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