• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] why do this bugg?

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
i had some strange buggs to night when i did caster shard rain and then Blinky my timer on shard rain did stop(to run exe) :/ dunno why when i used ABC instead of CSData no bugg(may just been luck) and when i used CreateTimer() instead of NewTimer() in blinky i didnt find any buggs

any1 know why?

EDIT: this fucks up all the timers on the map

JASS:
scope Blinky initializer Init

globals
    private constant integer Abil_id = 'A00D'
    private constant integer Stun_id = 'A00C'
    private constant string SFX = "Abilities\\Spells\\Undead\\FreezingBreath\\FreezingBreathTargetArt.mdl"
endglobals

private struct Data
unit c
unit t

real x
real y
real face
real wait

integer lvl

timer time
    
    static method create takes nothing returns Data
        local Data d = Data.allocate()
        local unit dum
        
        set d.c = GetTriggerUnit()
        set d.t = GetSpellTargetUnit()
        set d.x = GetUnitX(d.t)
        set d.y = GetUnitY(d.t)
        set d.lvl = GetUnitAbilityLevel(d.c,Abil_id)
        set d.time = NewTimer()
        set d.face = GetUnitFacing(d.t)-180
        set dum = CreateUnit(GetOwningPlayer(d.c),Dum_id,d.x,d.y,0.)
        
        call UnitAddAbility(dum,Stun_id)
        call SetUnitAbilityLevel(dum,Stun_id,d.lvl)
        call IssueTargetOrder(dum,"thunderbolt",d.t)
        call UnitApplyTimedLife(dum,'BTLF',2.)
        call SetUnitTimeScale(d.t,0)
        call SetUnitFacingTimed(d.c,Atan2(d.y-GetUnitY(d.c),d.x-GetUnitX(d.c))*3.14169/180,0.)
        call IssueTargetOrder(d.c,"attack",d.t)
        call SetUnitX(d.c,d.x+100*Cos(d.face*3.14169/180))
        call SetUnitY(d.c,d.y+100*Sin(d.face*3.14169/180))
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\CloudOfFog\\CloudOfFog",d.x,d.y))
        
        set dum = null
    
        return d
    endmethod    
    
    method onDestroy takes nothing returns nothing
        call SetUnitTimeScale(.t,1.)
        call ReleaseTimer(.time)
    endmethod
    
endstruct

private function PreLoad takes nothing returns nothing
    local unit dum = CreateUnit(Player(15),Dum_id,0.,0.,0.)
    call UnitAddAbility(dum,Stun_id)
    call RemoveUnit(dum)
    set dum = null
    call Preload(SFX)
endfunction

private function SetTime takes integer lvl returns real
        local real r 
        
        if lvl < 6 then
            set r = 1+(0.25*lvl)
        elseif lvl == 6 then
            set r = 2.5
        elseif lvl == 7 then
            set r = 3
        endif
        
        return r
endfunction

private function end takes nothing returns nothing
    local Data d = GetCSData(GetExpiredTimer())
        
    call d.destroy()
endfunction

private function Action takes nothing returns nothing
    local Data d = Data.create()
    
    set d.wait = SetTime(d.lvl)
        
    call SetCSData(d.time,d)
    call TimerStart(d.time,d.wait,false,function end)
endfunction
    
private function Conds takes nothing returns boolean
    return GetSpellAbilityId()==Abil_id
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 TriggerAddAction(t,function Action)
    call TriggerAddCondition(t,Filter(function Conds))
    call PreLoad()
    
    set t = null
endfunction
    
endscope

JASS:
library ShardRain initializer Init needs CSSafety,CSData

globals
    private constant integer Abil_id = 'A00B' //! RawCode for The Shard
    private constant integer NumberOfShards = 12 //! Number of Shards, too little shards wont keep units in
    private constant integer Dum_id = 'e004' //! RawCode for the Shards
    private constant integer Block_id = 'e003' //! RawCode of the unit that Block
    private constant string SFX = "Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl" //! SFX when the shards Explode
    private constant real Aoe = 250 //!to big wont keep units in (250 Aoe need 12 shards to block good use that as forumal or something :P )
    private constant real DmgPerLvl = 150.
    private constant real Delay = 3. //!time before shards explode
endglobals

private function SetupDmg takes integer lvl returns real
    return lvl*DmgPerLvl
endfunction
//!=============================================================================!\\  
//!=================================Setup Ends==================================!\\
//!=============================================================================!\\
private struct Data
unit c
unit array shard[NumberOfShards]
unit array block[NumberOfShards]

integer Nr

real x
real y
real aoe
real incrangle
real dmg

lightning array lit[NumberOfShards]

timer t

    static method create takes nothing returns Data
        local Data dat = Data.allocate()
        
        set dat.t = NewTimer()
        
        return dat
    endmethod
    
    method onDestroy takes nothing returns nothing
        local integer a = 0    
        loop
            exitwhen a == .Nr
            set a = a + 1
            call DestroyLightning(.lit[a])
        endloop
        call ReleaseTimer(.t)
    endmethod
endstruct

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

private function filter takes nothing returns boolean
    local Data dat = GetCSData(GetExpiredTimer())
    local unit f = GetFilterUnit()
    local boolean ok = GetWidgetLife(f) > .405 and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and not IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) and IsUnitEnemy(f,GetOwningPlayer(dat.c))
    set f = null
    return ok
endfunction
        
private function exe takes nothing returns nothing
    local Data dat = GetCSData(GetExpiredTimer())
    local integer a = 0
    local unit d
    local group g = NewGroup()
    local real x
    local real y

    loop
        exitwhen a == dat.Nr
        set a = a + 1
        set x = GetUnitX(dat.shard[a])
        set y = GetUnitY(dat.shard[a])
        call SetUnitTimeScale(dat.shard[a],1.)
        call KillUnit(dat.shard[a])
        call KillUnit(dat.block[a])
        call DestroyEffect(AddSpecialEffect(SFX,x,y))
    endloop
    call GroupEnumUnitsInRange(g,dat.x,dat.y,250,Filter(function 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)
    endloop
    
    call dat.destroy()
        
    call ReleaseGroup(g)
    set g = null
endfunction

private function stop takes nothing returns nothing
    local Data dat = GetCSData(GetExpiredTimer())
    local integer a = 0
    local integer f = 0
    local real sx
    local real sy
    local real angle = 0.
    
    loop
        exitwhen a == dat.Nr
        set a = a + 1
        set f = a + 1
        set sx = dat.x+dat.aoe*Cos(angle*3.14159/180)
        set sy = dat.y+dat.aoe*Sin(angle*3.14159/180)
        set dat.block[a] = CreateUnit(GetOwningPlayer(dat.c),Block_id,sx,sy,0.)
        call SetUnitX(dat.block[a],sx)
        call SetUnitY(dat.block[a],sy)
        call SetUnitTimeScale(dat.shard[a],0)
        set angle = angle + dat.incrangle
        if f > dat.Nr then
            set f = 1
        endif
        set dat.lit[a] = AddLightningEx("DRAM",true,GetUnitX(dat.shard[a]),GetUnitY(dat.shard[a]),50,GetUnitX(dat.shard[f]),GetUnitY(dat.shard[f]),50)
    endloop
    
    call PauseTimer(dat.t)
    call TimerStart(dat.t,Delay,false,function exe)
endfunction

private function Actions takes nothing returns nothing
    local Data dat = Data.create()
    local location loc = GetSpellTargetLoc()
    local real tx = GetLocationX(loc)
    local real ty = GetLocationY(loc)
    local real angle = 0.
    local integer a = 0
    local real sx
    local real sy
    
    set dat.c = GetTriggerUnit()
    set dat.x = tx
    set dat.y = ty
    set dat.aoe = Aoe
    set dat.Nr = NumberOfShards
    set dat.incrangle = 360/NumberOfShards
    set dat.dmg = SetupDmg(GetUnitAbilityLevel(dat.c,Abil_id))
    
    loop
        exitwhen a == dat.Nr
        set a = a + 1
        set sx = tx+dat.aoe*Cos(angle*3.14159/180)
        set sy = ty+dat.aoe*Sin(angle*3.14159/180)
        set dat.shard[a] = CreateUnit(GetOwningPlayer(dat.c),Dum_id,sx,sy,Atan2(sy-ty,sx-tx)*57.27589)
        call SetUnitX(dat.shard[a],sx)
        call SetUnitY(dat.shard[a],sy) 
        set angle = angle + dat.incrangle
    endloop
    
    call SetCSData(dat.t,dat)
    call TimerStart(dat.t,.75,false,function stop)
    call RemoveLocation(loc)
    set loc = null
endfunction

private function conds takes nothing returns boolean
    return GetSpellAbilityId()==Abil_id
endfunction

public 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 TriggerAddAction(t,function Actions)
    call TriggerAddCondition(t,Filter(function conds))
    call preload()
    
    set t = null
endfunction

endlibrary
 
Last edited:
Status
Not open for further replies.
Top