SetUnitFlyHeight

tuantai120

Cool Member
Reaction score
1
please have a look at my code , specially the code SetUnitFlyHeight after d.time > 4 , i want to when d.time >4 then SetUnitFlyeHeight of p and d.dummy to 0 , but it's doesn't work , please help me fix that bug :((
JASS:
scope sphere initializer Init

globals
    private constant integer SID = 'A000'
    private constant integer DID = 'h000'
    private constant integer Fly = 'Amrf'
    private constant string SFX = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
    private constant real Height = 500
    private constant real Period = 0.04
    private constant real SPHERE_HEIGHT = 500
    private constant real SPHERE_FLY_SPEED = 200
    private constant real SPHERE_FALL_SPEED = 2500
    private constant real TARGET_MAX_HEIGHT = 400
    private constant real TARGET_MIN_HEIGHT = 350
    private constant real TARGET_FLY_SPEED = 150
    private constant real TARGET_FALL_SPEED = 2300
    private integer TEMPINT
endglobals

private function SphereC takes nothing returns boolean
    return GetSpellAbilityId() == SID
endfunction

private struct sp
    unit c
    unit dummy
    real time
    integer tick
    group g
endstruct

private function SphereF takes nothing returns boolean
    local sp d = TEMPINT
    local unit f = GetFilterUnit()
    local boolean ok = false
    if IsUnitEnemy(f,GetOwningPlayer(d.c)) == true then
        if IsUnitType(f,UNIT_TYPE_STRUCTURE) == false then
            if IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) == false then
                if IsUnitInGroup(f,d.g) == false then
                    set ok = true
                endif
            endif
        endif
    endif
    set f = null
    return ok
endfunction

private function SphereT takes nothing returns nothing
    local timer ti = GetExpiredTimer()
    local sp d = GetTimerData(ti)
    local real x = GetUnitX(d.dummy)
    local real y = GetUnitY(d.dummy)
    local real px
    local real py
    local unit p
    local group g = CreateGroup()
    set TEMPINT = d
    call UnitAddAbility(d.dummy,Fly)
    call SetUnitFlyHeight(d.dummy,SPHERE_HEIGHT,SPHERE_FLY_SPEED)
    call GroupEnumUnitsInRange(g,x,y,400,function SphereF)
    set d.time = d.time + Period
    loop
        set p = FirstOfGroup(g)
        exitwhen p == null
        call GroupRemoveUnit(g,p)
        call GroupAddUnit(d.g,p)
        set px = GetUnitX(p)
        set py = GetUnitY(p)
        call UnitAddAbility(p,Fly)
        call PauseUnit(p,true)
        call SetUnitFlyHeight(p,GetRandomReal(TARGET_MAX_HEIGHT,TARGET_MIN_HEIGHT),TARGET_FLY_SPEED)
        if d.time >= 4 then
            set d.tick = d.tick + 1
            call SetUnitFlyHeight(p,GetUnitDefaultFlyHeight(p),TARGET_FALL_SPEED)
            call SetUnitFlyHeight(d.dummy,GetUnitDefaultFlyHeight(d.dummy),SPHERE_FALL_SPEED)
            if d.tick >=10 then
                call UnitRemoveAbility(d.dummy,Fly)
                call UnitRemoveAbility(p,Fly)
                call KillUnit(d.dummy)
                call DestroyEffect(AddSpecialEffect(SFX,px,py))
                call PauseUnit(p,false)
                call DestroyGroup(d.g)
                call ReleaseTimer(ti)
                call d.destroy()
            endif
        endif
    endloop
    call DestroyGroup(g)
    set p = null
endfunction

private function SphereA takes nothing returns nothing
    local sp d = sp.create()
    local timer ti = NewTimer()
    local unit c = GetTriggerUnit()
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    local unit dummy = CreateUnit(GetOwningPlayer(c),DID,x,y,0)
    local real time = 0
    call SetTimerData(ti,d)
    set d.c = c
    set d.dummy = dummy
    set d.time = time
    set d.tick = 0
    set d.g = CreateGroup()
    call TimerStart(ti,Period,true,function SphereT)
    call BJDebugMsg("done")
    set c = null
    set dummy = null
endfunction

private function Init takes nothing returns nothing
    local trigger ts = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(ts,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(ts,Condition(function SphereC))
    call TriggerAddAction(ts,function SphereA)
endfunction

endscope
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
private function SphereF takes nothing returns boolean
    local sp d = TEMPINT
    local unit f = GetFilterUnit()
    local boolean ok = false
    if IsUnitEnemy(f,GetOwningPlayer(d.c)) == true then
        if IsUnitType(f,UNIT_TYPE_STRUCTURE) == false then
            if IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) == false then
                if IsUnitInGroup(f,d.g) == false then
                    set ok = true
                endif
            endif
        endif
    endif
    set f = null
    return ok
endfunction


>>

JASS:
private function SphereF takes nothing returns boolean
    local sp d = TEMPINT
    local unit f = GetFilterUnit()
    local boolean ok = false
    if IsUnitEnemy(f,GetOwningPlayer(d.c)) and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and not IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitInGroup(f,d.g) then
        set ok = true
    endif
    set f = null
    return ok
endfunction



PS: i think get default height will set the unit height to default one... = no effect, correct me if i'm wrong

EDIT:
PS²: you can add crow form to an unit and remove with no delay, you still can change unit Z
 

tuantai120

Cool Member
Reaction score
1
PS: i think get default height will set the unit height to default one... = no effect, correct me if i'm wrong

.... , if you're right so the dummy will be killed at least but it won't be killed @@

EDIT:
PS²: you can add crow form to an unit and remove with no delay, you still can change unit Z

ok , thanks
 

Laiev

Hey Listen!!
Reaction score
188
try to change this

[ljass]call SetTimerData(ti,d)[/ljass]

after/before you start the timer, but after set the variables
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
scope sphere initializer Init

globals
    private constant integer SID = 'A000'
    private constant integer DID = 'h000'
    private constant integer Fly = 'Amrf'
    private constant string SFX = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
    private constant real Height = 500
    private constant real Period = 0.04
    private constant real SPHERE_HEIGHT = 500
    private constant real SPHERE_FLY_SPEED = 200
    private constant real SPHERE_FALL_SPEED = 2500
    private constant real TARGET_MAX_HEIGHT = 400
    private constant real TARGET_MIN_HEIGHT = 350
    private constant real TARGET_FLY_SPEED = 150
    private constant real TARGET_FALL_SPEED = 2300
endglobals

private function SphereC takes nothing returns boolean
    return GetSpellAbilityId() == SID
endfunction

private struct sp
    unit c
    unit dummy
    real time
    integer tick
    group g
    timer ti
endstruct

private function SphereF takes unit f, unit c, group g returns boolean
    return IsUnitEnemy(f,GetOwningPlayer(c)) and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and not IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitInGroup(f,g)
endfunction

private function SphereT takes nothing returns nothing
    local sp d = GetTimerData(GetExpiredTimer())
    local real x = GetUnitX(d.dummy)
    local real y = GetUnitY(d.dummy)
    local real px
    local real py
    local unit p
    local group g = CreateGroup()
    
    call UnitAddAbility(d.dummy,Fly)
    call UnitRemoveAbility(d.dummy,Fly)
    call SetUnitFlyHeight(d.dummy,SPHERE_HEIGHT,SPHERE_FLY_SPEED)
    call GroupEnumUnitsInRange(g, x, y, 400, null)
    
    set d.time = d.time + Period
    
    loop
        set p = FirstOfGroup(g)        
        exitwhen p == null
        
        if not SphereF (p, d.c, d.g) then
        
            call GroupRemoveUnit(g,p)
            call GroupAddUnit(d.g,p)
        
            set px = GetUnitX(p)
            set py = GetUnitY(p)
        
            call UnitAddAbility(p,Fly)
            call UnitRemoveAbility(p,Fly)
            call PauseUnit(p,true)
            call SetUnitFlyHeight(p,GetRandomReal(TARGET_MAX_HEIGHT,TARGET_MIN_HEIGHT),TARGET_FLY_SPEED)
        
            if d.time >= 4 then
                set d.tick = d.tick + 1
                
                call SetUnitFlyHeight(p,GetUnitDefaultFlyHeight(p),TARGET_FALL_SPEED)
                call SetUnitFlyHeight(d.dummy,GetUnitDefaultFlyHeight(d.dummy),SPHERE_FALL_SPEED)
                
                if d.tick >=10 then
                
                    call KillUnit(d.dummy)
                    call DestroyEffect(AddSpecialEffect(SFX,px,py))
                    call PauseUnit(p,false)
                    call DestroyGroup(d.g)
                    call ReleaseTimer(d.ti)
                    call d.destroy()

                endif

            endif

        endif

        call GroupRemoveUnit(d,p)

    endloop
    
    call DestroyGroup(g)
    set p = null
    set g = null
endfunction

private function SphereA takes nothing returns nothing
    local sp d = sp.create()
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    
    set d.c = GetTriggerUnit()
    set d.ti = NewTimer()
    set d.dummy = CreateUnit(GetOwningPlayer(d.c),DID,x,y,0)
    set d.time = 0
    set d.tick = 0
    set d.g = CreateGroup()
    
    call SetTimerData(d.ti,d)
    call TimerStart(d.ti, Period, true, function SphereT)
    call BJDebugMsg("done")
endfunction

private function Init takes nothing returns nothing
    local trigger ts = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(ts,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(ts,Condition(function SphereC))
    call TriggerAddAction(ts,function SphereA)
endfunction

endscope


try this

EDIT: forget to fix the ti in release timer :p
EDIT²: forget to null variable p -.-
 

tuantai120

Cool Member
Reaction score
1
i fixed it :)
anyway , thanks for you help :)
JASS:
scope sphere initializer Init

globals
    private constant integer SID = 'A000'
    private constant integer DID = 'h000'
    private constant string SFX = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
    private constant real Height = 500
    private constant real Period = 0.04
    private constant real SPHERE_HEIGHT = 600
    private constant real SPHERE_FLY_SPEED = 200
    private constant real SPHERE_FALL_SPEED = 2500
    private constant real TARGET_MAX_HEIGHT = 450
    private constant real TARGET_MIN_HEIGHT = 0
    private constant real TARGET_FLY_SPEED = 150
    private constant real TARGET_FALL_SPEED = 2300
    private integer TEMPINT
endglobals

private function SphereC takes nothing returns boolean
    return GetSpellAbilityId() == SID
endfunction

private struct sp
    unit c
    unit dummy
    
    real height
    
    integer tick
    integer mtick
    integer time
    integer lvl
    
    boolean up
    
    group g
endstruct

private function SphereF takes nothing returns boolean
    local sp d = TEMPINT
    local unit f = GetFilterUnit()
    local boolean ok = false
    
    if IsUnitEnemy(f,GetOwningPlayer(d.c)) and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and not IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitInGroup(f,d.g) then
        set ok = true
    endif
    
    set f = null
    return ok
endfunction

private function SphereU takes nothing returns nothing
    local sp d = TEMPINT
    local unit e = GetEnumUnit()
    
    if d.up then
        //call SetUnitZ( e, TARGET_MAX_HEIGHT * Sin( ( 90 / d.mtick ) * d.tick * bj_DEGTORAD ) )
        call SetUnitZ( e, GetUnitFlyHeight( e ) + ( TARGET_MAX_HEIGHT / d.mtick ) )
    else
        //call SetUnitZ( e, (TARGET_MIN_HEIGHT + 10) * Sin( ( 90 / d.mtick ) * d.tick * bj_DEGTORAD ) )
        call SetUnitZ( e, GetUnitFlyHeight( e ) - ( TARGET_MAX_HEIGHT / d.mtick ) )
    endif

    set e = null
endfunction

private function SphereD takes nothing returns nothing
    local sp d = TEMPINT
    local unit e = GetEnumUnit()
    
    call SetUnitZ( e, GetUnitDefaultFlyHeight( e ) )
    call UnitDamageTarget( d.c, e, 500. * d.lvl, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null )
    call DestroyEffect( AddSpecialEffect( SFX, GetUnitX( e ), GetUnitY( e ) ) )

    set e = null
endfunction

private function SphereT takes nothing returns nothing
    local timer ti = GetExpiredTimer()
    local sp d = GetTimerData( ti )    

    local unit p
    
    local group g = CreateGroup()

    //call SetUnitZ( d.dummy, d.height * Sin( ( 90 / d.mtick ) * d.tick * bj_DEGTORAD ) )
    
    set TEMPINT = d
    call GroupEnumUnitsInRange( g, GetUnitX( d.dummy ), GetUnitY( d.dummy ), 400, function SphereF )
    loop
        set p = FirstOfGroup( g )
        exitwhen p == null
        
        call GroupRemoveUnit( g, p )
        call GroupAddUnit( d.g, p )

        call PauseUnit( p, true )
 
        set p = null
    endloop
    call DestroyGroup(g)
    set g = null
        
    set TEMPINT = d
    call ForGroup( d.g, function SphereU )
    
    if d.up then
        call SetUnitZ( d.dummy, GetUnitFlyHeight( d.dummy ) + d.height )

        set d.tick = d.tick + 1
        
        if d.tick > 100 then
            set d.tick = 25
            set d.mtick = 25
            set d.up = false
            set d.height = SPHERE_HEIGHT / d.mtick
        endif
        
    else
        call SetUnitZ( d.dummy, GetUnitFlyHeight( d.dummy ) - d.height )

        set d.tick = d.tick - 1
        
        if d.tick < 1 then
            set TEMPINT = d
            call ForGroup( d.g, function SphereD )
            
            call KillUnit( d.dummy )
            call DestroyGroup( d.g )
            call ReleaseTimer( ti )
            call d.destroy()
        endif
        
    endif
    
endfunction

private function SphereA takes nothing returns nothing
    local sp d = sp.create()
    local timer ti = NewTimer()

    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()

    set d.c = GetTriggerUnit()
    set d.dummy = CreateUnit( GetOwningPlayer( d.c ), DID, x, y, 0 )
        
    set d.tick = 1
    set d.mtick = 100
    set d.height = SPHERE_HEIGHT / d.mtick

    set d.lvl = GetUnitAbilityLevel( d.c, SID )
    
    set d.up = true
    
    set d.g = CreateGroup()
    
    call SetTimerData( ti, d )
    call TimerStart( ti, Period, true, function SphereT )
    
endfunction

private function Init takes nothing returns nothing
    local trigger ts = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(ts,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(ts,Condition(function SphereC))
    call TriggerAddAction(ts,function SphereA)
endfunction

endscope
 
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