Abilities Events

Troll-Brain

You can change this now in User CP.
Reaction score
85
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™
Reaction score
397
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.
Reaction score
85
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.
Reaction score
85
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.
Reaction score
85
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.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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