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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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