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.
  • The Helper The Helper:
    Friday Yay!
  • mgarcia mgarcia:
    did you guys catch Carl's interview? https://www.youtube.com/watch?v=kuHiMXABkGs
  • mgarcia mgarcia:
    he's the one that informed me about the DVD's working!
  • mgarcia mgarcia:
    he also mentioned the progress on the controllers!
  • The Helper The Helper:
    I did actually it was cool to see the NUON mention
  • The Helper The Helper:
    https://discord.com/channels/985377399338332202/985377399950696481 you can still use this chat too we are two fisted now :)
  • thewrongvine thewrongvine:
    costs me $80 to fill gas tank sad face
  • Ghan Ghan:
    Oof
  • The Helper The Helper:
    Yeah that gas is some expensive stuff :)
  • The Helper The Helper:
    ghan does not have to worry about it he has a tesla and I have a small tank so it does not cost me usually more than 50
  • The Helper The Helper:
    fyi Ghan we are getting an error trying to access stats or world editor tutorials Error 526 Ray ID: 72128c6bf99f6707 • 2022-06-26 02:35:15 UTCInvalid SSL certificate
  • Ghan Ghan:
    An artifact of switching to Cloudflare... the Let's Encrypt certs can't autorenew through Cloudflare.
  • Ghan Ghan:
    I got the forum updated before things expired but there were some other casualties.
  • Ghan Ghan:
    Everything should be fixed now....
  • The Helper The Helper:
    Thank you Ghan!
  • The Helper The Helper:
    Happy Monday!
  • The Helper The Helper:
    new NUON forum mod cubanral!
    +1
  • The Helper The Helper:
  • tom_mai78101 tom_mai78101:
    Started learning how to make tools-assisted speedruns, so I'm lately busy.
  • tom_mai78101 tom_mai78101:
    Here's my current project.
    +3
  • O Old Mountain Shadow:
    that was pretty good!
  • jonas jonas:
    really cool! I saw the game before but always thought it's just a half as good double dragon. Now I realize it actually has a lot of depth!
  • The Helper The Helper:
    I just saw a bunch of running and jumping past all the enemies look like it was scripted as he said I guess I should have watched the whole thing. I only got a couple of minutes in. You should post that video in the forum Tom
  • Darthfett Darthfett:
    "Hi in the chat!"
    +1
  • tom_mai78101 tom_mai78101:
    Currently busy with making the run even better, so I'll post that new one once I'm done. Right now, I had to modify the emulator itself, the tools that makes this video, and some RAM address disassembling / reverse-engineering to get the right values, and such.
    +1

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top