• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] function works inside trigger but not outside

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
hi peps, i'v runned in to some probs again :/ well its the H2I function,
when i have inside the trigger it work but when i move it to a trigger/mapheader it wont work (undefined function H2I)

well heres ma spell

p.s i think its becoz the library but i want it in a library:P


JASS:
library LightningVoid initializer Init needs CSSafety,CSData
//!=============================================================================!\\
//! LightningVoid by Ciebron.                                                   !\\
//! Give Credits is you use this in your map                                    !\\
//! --------------------------------------------------------------------------- !\\
//! Summons Orbs around the caster that spin into the caster, when              !\\
//! they have reached the caster the will move out in a spiral                  !\\
//! draging units with them                                                     !\\
//! --------------------------------------------------------------------------- !\\
//! Requires:                                                                   !\\
//! ¯¯¯¯¯¯¯¯¯                                                                   !\\
//! - Object Editor - A hero                                                    !\\
//! - Object Editor - The NoNameYet ability                                     !\\
//! - Object Editor - The Orb Dummy Units                                       !\\
//! - Trigger Editor - This Trigger                                             !\\
//! - Trigger Editor - CSData - by Vexorian                                     !\\
//! - Trigger Editor - CSSaftey - by Vexorian                                   !\\
//!   ([url]http://www.wc3campaigns.net/showthread.php?t=80534[/url])                      !\\
//! --------------------------------------------------------------------------- !\\
//!=============================================================================!\\
//!=================================Setup Starts================================!\\
//!=============================================================================!\\
globals                                                                 
    private constant integer Abil_id = 'A004' //! Ability RawCode                                
    private constant integer Dum_id = 'h002' //! Dummy Unit RawCode
    private constant integer NumberOfOrbs = 6 //! Number of shards that will spawn (duh :P)
    private real distance = 500. //! Aoe
    private real time = 2. //!half the time in and half the time out
    
    private group LightningVoid = CreateGroup()
    private Table activeTable  

endglobals

constant function SetDmg takes integer lvl returns real
    return lvl*75.
endfunction
//!=============================================================================!\\  
//!=================================Setup Ends==================================!\\
//!=============================================================================!\\
private function H2I takes handle h returns integer  //can move this!! argh
    return h
    return 0
endfunction


private struct Data
unit c
unit array dum[NumberOfOrbs]

real angle = 0
real dist
real movedist
real time
real incrangle
real Maxdist
real x
real y
real dmg

group g

integer Nr = NumberOfOrbs

player play

trigger trig = CreateTrigger()

timer t

    static method create takes nothing returns Data
        local Data dat = Data.allocate()
        local integer a = 0
        local real angle = 0
        
        set dat.c = GetTriggerUnit()
        set dat.incrangle = 360/dat.Nr
        set dat.time = time/2
        set dat.Maxdist = distance
        set dat.movedist = (dat.Maxdist/dat.time)/(1./.035)
        set dat.x = GetUnitX(dat.c)
        set dat.y = GetUnitY(dat.c)
        set dat.dmg = SetDmg(GetUnitAbilityLevel(dat.c,Abil_id))
        set dat.play = GetOwningPlayer(dat.c)
        set dat.t = NewTimer()
        set dat.g = NewGroup()
        
        loop
            exitwhen a == dat.Nr
            set dat.dum[a] = CreateUnit(dat.play,Dum_id,dat.x+dat.Maxdist*Cos(angle*3.14159/180),dat.y+dat.Maxdist*Sin(angle*3.14159/180),0.)
            set a = a + 1
            set angle = angle + dat.incrangle
        endloop
    
        call SetCSData(dat.t,integer(dat))
        call TimerStart(dat.t,.035,true,function Data.In)
        
        set activeTable[H2I(dat.c)] = dat
        call GroupAddUnit(LightningVoid,dat.c)
        
        return dat
    endmethod
    
    static method In takes nothing returns nothing
        local Data dat = GetCSData(GetExpiredTimer())
        local integer a = 0
        local real angle = 0
    
        set dat.dist = dat.dist - dat.movedist
        set dat.angle = dat.angle + 10
        set angle = dat.angle
    
        if dat.dist > 0 then
            loop
                exitwhen a == dat.Nr
                call SetUnitX(dat.dum[a],dat.x+dat.dist*Cos(angle*3.14159/180))
                call SetUnitY(dat.dum[a],dat.y+dat.dist*Sin(angle*3.14159/180))
                set a = a + 1
                set angle = angle + dat.incrangle
            endloop
        else
            call PauseTimer(dat.t)
            call TimerStart(dat.t,.035,true,function Data.out)
        endif
    endmethod
    
        
    static method out takes nothing returns nothing
        local Data dat = GetCSData(GetExpiredTimer())
        local integer a = 0
        local real angle = 0
        local group g 
        local unit d
        local real anglee
        local real x
        local real y
    
        set dat.dist = dat.dist + dat.movedist
        set dat.angle = dat.angle + 10
        set angle = dat.angle
    
    
        if dat.dist < dat.Maxdist then
            set g = NewGroup()
            call GroupEnumUnitsInRange(g,dat.x,dat.y,dat.dist,Filter(function Data.filter))
        
            loop
                set d = FirstOfGroup(g)
                exitwhen d == null
                call GroupRemoveUnit(g,d)
                call UnitDamageTarget(dat.c,d,dat.dmg,false,false,ATTACK_TYPE_MAGIC,null,null)
                call GroupAddUnit(dat.g,d)
            endloop
        
            call GroupAddGroup(dat.g,g)
        
            loop
                set d = FirstOfGroup(g)
                exitwhen d == null
                call GroupRemoveUnit(g,d)
                set anglee = Atan2(GetUnitY(d)-dat.y,GetUnitX(d)-dat.x)*57.27589+(10)
                set x = dat.x+dat.dist*Cos(anglee*3.14159/180)
                set y = dat.y+dat.dist*Sin(anglee*3.14159/180)
                if MinX < x and MaxX > x then
                    call SetUnitX(d,x)
                endif
                if MinY < y and MaxY > y then
                    call SetUnitY(d,y)
                endif
            endloop
        
            loop
                exitwhen a == dat.Nr
                call SetUnitX(dat.dum[a],dat.x+dat.dist*Cos(angle*3.14159/180))
                call SetUnitY(dat.dum[a],dat.y+dat.dist*Sin(angle*3.14159/180))
                set a = a + 1
                set angle = angle + dat.incrangle
            endloop
        call ReleaseGroup(g)
        endif
    
        set g = null
    endmethod
    
    static method filter takes nothing returns boolean
        local Data dat = GetCSData(GetExpiredTimer())
        local unit f = GetFilterUnit()
        local boolean ok = GetWidgetLife(f) > .405 and IsUnitEnemy(f,dat.play) and not IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and not IsUnitInGroup(f,dat.g)
        set f = null
        return ok
    endmethod
    
    method onDestroy takes nothing returns nothing
        local integer a = 0
        loop
            exitwhen a == .Nr
            call KillUnit(.dum[a])
            set a = a + 1
        endloop
        call activeTable.flush( H2I(.c)) 
        call GroupRemoveUnit(LightningVoid,.c)
        call ReleaseTimer(.t)
        call DestroyTrigger(.trig)
        call ReleaseGroup(.g)
    endmethod
endstruct

private function preload takes nothing returns nothing
    call RemoveUnit(CreateUnit(Player(15),Dum_id,0.,0.,0.))
endfunction

private function onEnd takes nothing returns boolean
    local Data dat
    local unit u = GetTriggerUnit()
    
    if IsUnitInGroup(u,LightningVoid) then
        set dat = activeTable[H2I(u)]
        call dat.destroy()
    endif
    
    set u = null
    return false
endfunction

private function conds takes nothing returns boolean
    local Data d
    
    if GetSpellAbilityId()==Abil_id then
        set d = Data.create()
    endif
    
    return false
endfunction

private function Init takes nothing returns nothing
    local trigger t =CreateTrigger()
    local integer index = 0
    
    loop
        call TriggerRegisterPlayerUnitEvent(t,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition(t,Condition( function conds ) )

    set t = CreateTrigger()
    set index = 0
    
    loop
        call TriggerRegisterPlayerUnitEvent(t,Player(index),EVENT_PLAYER_UNIT_SPELL_ENDCAST,null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition(t,Condition(function onEnd))
    
    set activeTable = Table.create()
    call preload()
endfunction


endlibrary
 
Last edited:
ohh that worked :D +
reputation.gif


Edit: must spread first :/
 
Status
Not open for further replies.
Back
Top