• 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.

[vJASS] One at a time SetUnitFlyHeight

Status
Not open for further replies.
Level 10
Joined
May 27, 2009
Messages
495
I'm currently making some sort of little library
unfortunately.. i can't make it work the way it should be..

What i want is.. make the SetUnitFlyHeight (in this case, SetUnitFlyHeightEx) take effect only one at a time per unit
meaning, only one call at a time will work(for a specific unit) and later calls will be ignored.. then if the first call has ended accept queued or those calls that was initiated during the first call of the function

here's my code o.o

JASS:
    function FlyUnit takes unit u returns integer
        if UnitAddAbility(u,'Arav') then
            call UnitRemoveAbility(u,'Arav')
        endif
        call SaveInteger(ht,GetHandleId(u),0,LoadInteger(ht,GetHandleId(u),0)+1)
        return LoadInteger(ht,GetHandleId(u),0)
    endfunction
    
    function SetUnitFlyHeightEx takes unit u, real height, boolean b, integer index returns nothing
        local integer int = LoadInteger(ht,GetHandleId(u),0)
        if index == 1 then
            call SetUnitFlyHeight(u,height,0)
        endif
        if not b then
            call SaveInteger(ht,GetHandleId(u),0,int-1)
        endif
    endfunction

it's pretty simeple.. but my problem here is that yeah only one call per unit will work.. but queued calls are being ignored
well i guess due to the fact that int-1 doesn't have enough checks i guess
 
Level 10
Joined
May 27, 2009
Messages
495
ok i'll write a code

JASS:
struct Demo
	unit caster
	integer flyIndex
	real wait
	real height

	private method periodic takes nothing returns nothing
		set this.wait = this.wait + 0.03
		if this.wait < 3 then
			set this.height = this.height + 5
			call SetUnitFlyHeightEx(this.caster,this.height,true,this.flyIndex) //if true.. the unit is still flying with the said index
		else
			call SetUnitFlyHeightEx(this.caster,GetUnitDefaultFlyHeight(this.caster),false,this.flyIndex) //it's false, so his fly moments ends
			call this.stopPeriodic()
			call this.destroy()
		endif
	endmethod
	implement T32x
	static method start takes nothing returns nothing
		local thistype this = thistype.allocate()
		set this.caster = GetTriggerUnit()

		set this.flyIndex = FlyUnit(this.caster)
		//well call the onloop method, timer tools, t32, timerutils whatever
		call this.startPeriodic() //just think the onloop method is looping
	endmethod
endstruct

just wrote it head on
 
If you just want to have the last call take effect... but I personally believe it will look bad, I mean the unit's height will get reset everytime the system is used...

JASS:
private module init
    static method onInit takes nothing returns nothing
        set thistype.DemoTable = Table.create()
     endmethod
endmodule

struct Demo
    unit caster
    real wait
    real height
    static Table DemoTable
 
    private method periodic takes nothing returns nothing
        set this.wait = this.wait + 0.03
        if this.wait < 3 then
            set this.height = this.height + 5
            call SetUnitFlyHeight(this.caster,this.height,0)
        else
            call SetUnitFlyHeight(this.caster,GetUnitDefaultFlyHeight(this.caster),0)
            set DemoTable[GetHandleId(this.caster)] = 0
            call this.stopPeriodic()
            call this.destroy()
        endif
    endmethod
    implement T32x
    static method start takes nothing returns nothing
        local integer id = GetHandleId(GetTriggerUnit())
        local thistype this = DemoTable[id]
        if this == 0 then
            set this = .allocate() 
            set this.caster = GetTriggerUnit()
            if UnitAddAbility(u,'Arav') then
                call UnitRemoveAbility(u,'Arav')
            endif
            set DemoTable[id] = this
            this.height = GetUnitDefaultFlyHeight(this.caster) //so that he starts flying at his current height
        else
            this.wait = 0.0
            this.height = GetUnitDefaultFlyHeight(this.caster)
        endif
        //well call the onloop method, timer tools, t32, timerutils whatever
        call this.startPeriodic() //just think the onloop method is looping
    endmethod

    implement init
endstruct
 
Level 10
Joined
May 27, 2009
Messages
495
last calls can be bypassed i think

but the first call really looks weird on my map.. when the first call ended the jump session (or any jump) the second call will run (this time the counter should already be in mid-air) which in fact looks weird... it jumps out of nowhere D:

i guess i might remove this line on start:
this.height = GetUnitDefaultFlyHeight(this.caster)
so it wouldn't look that weird.. lol

but it gave me an idea.. hope it will work
 
Status
Not open for further replies.
Top