System help...

XeNiM666

I lurk for pizza
Reaction score
138
I'm no JASS master but I made a small cast time system that I use it for every spell on my heroes only and some items. I was wondering how to get the instance of a struct without copy/pasting this on every spell I have, maybe similar to KT2's KT_GetData()...

Code:
JASS:
scope CT initializer onInit

    private struct Cast
        unit caster
        real time
        real t = 0.00
        integer order
        
        unit bar
        
        static method Update takes nothing returns boolean
            local Cast c = KT_GetData()
            
            set c.t = c.t + 0.01
            call SetUnitAnimationByIndex( c.bar, R2I( ( c.t / c.time ) * 20 ) + 1 )
            if c.t >= c.time or GetUnitCurrentOrder( c.caster ) != c.order then
                // call function here
                call c.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        method onDestroy takes nothing returns nothing
            call UnitApplyTimedLife( .bar, 'BTLF', 0.25 )
            call FadeUnit( .bar, 255.00, 0.00, 0.25 ) //custom function
            call IssueImmediateOrder( .caster, "stop" )
            set .caster = null
        endmethod
        
    endstruct

    public function Apply takes unit caster, real time, string order returns Cast
        local Cast c = Cast.create()
        
        set c.caster = caster
        set c.time = time
        set c.order = OrderId( order )
        
        set c.bar = CreateUnit( GetOwningPlayer( c.caster ), 'h00P', GetUnitX( c.caster ), GetUnitY( c.caster ), 270.00 ) // Hatebreeder's w/e Bars-modeled unit
        call SetUnitAnimationByIndex( c.bar, 0 )

        call KT_Add( function Cast.Update, c, 0.01 )
                
        return c
    endfunction

endscope


I want to be able to do something like this but don't know how.
JASS:
struct Spell
    unit caster
    unit target
    
    static method After 
        local Spell s = Cast.GetData()
        call KillUnit( s.target )
        call something( s.caster )
    endmethod
    
endstruct

function Test1
    local Spell s = Spell.create()
    set s.caster = GetTriggerUnit()
    set s.target = GetSpellTargetUnit()
    call CT_Apply( s.caster, 2.00, "holybolt", function Spell.After )
endfunction


Any suggestions? Also, is it fast/efficient?
TIA :)
 

XeNiM666

I lurk for pizza
Reaction score
138
ok, i read it in the jass manual and have 1 question..
how do i determine which are function interfaces and which are not?
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
interface myFunc
    function //....................
endinterface

struct myStruct extends myFunc

endstruct


If I remember right..

Edit: PS: You should do all with struct (at your code posted before...)
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Attach the data to the casting unit via a hash table or a unit indexing attachment.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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