• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Code goes wrong

Status
Not open for further replies.
JASS:
//**********************************************************************************************
//*
//*
//*        Jump In Place
//*
//*
//**********************************************************************************************
//*
//*    Allows unit to jump in place
//*
//**********************************************************************************************
//*
//*    Variables:
//*    
//*    JP_N        ( Integer Array )
//*    JP_P        ( Integer Array )
//*    JP_RC       ( Integer Array )
//*    JP_IC       ( Integer       )
//*    JP_Count    ( Integer       )
//*    JP_U        ( Unit    Array )
//*    JP_StackedZ ( Real    Array )
//*    JP_Duration ( Real    Array )
//*    JP_Current  ( Real    Array )
//*    JP_Height   ( Real    Array )
//*    JP_Timer    ( Timer         )
//*
//*
//**********************************************************************************************

//Looping time value
constant function JumpTimeout takes nothing returns real
    return 0.03125000
endfunction

//Tool for getting parabola height
function GetArc takes real z,real d,real t returns real
    return 4*z*t*(d - t) / (d * d)
endfunction

function DestroyJump takes integer id returns nothing
    // Running On Drop Event
                
    set udg_JumpEventOnDropUnit = udg_JP_U[id]
    set udg_JumpEventOnDrop = 0
    set udg_JumpEventOnDrop = 1
    set udg_JumpEventOnDrop = 0
            
    set udg_JP_N[udg_JP_P[id]] = udg_JP_N[id]
    set udg_JP_P[udg_JP_N[id]] = udg_JP_P[id]
    set udg_JP_RC[id] = udg_JP_RC[0]
    set udg_JP_RC[0] = id
    // Nulling
    set udg_JP_Count = udg_JP_Count - 1
    
    if 0 == udg_JP_Count then

        call PauseTimer(udg_JP_Timer)

    endif

    call SetUnitPropWindow(udg_JP_U[id],GetUnitDefaultPropWindow(udg_JP_U[id]))
    set udg_JP_U[id] = null
    set udg_JP_StackedZ[id] = 0
    set udg_JP_Duration[id] = 0
    set udg_JP_Current[id] = 0
    set udg_JP_Height[id] = 0

endfunction

function JP_Periodic takes nothing returns nothing
    
    local integer id = udg_JP_N[0]
    local real z = 0

    loop
        exitwhen 0 == id
        
        if null != udg_JP_U[id] then
            // Running Periodic Event
        
            set udg_JumpEventOnLoopUnit = udg_JP_U[id]
            set udg_JumpEventOnLoop = 0
            set udg_JumpEventOnLoop = 1
            set udg_JumpEventOnLoop = 0

            set udg_JP_Current[id] = udg_JP_Current[id] + JumpTimeout()
            
            set z = udg_JP_StackedZ[id] + GetArc(udg_JP_Height[id],udg_JP_Duration[id],udg_JP_Current[id])

            if  z <= GetUnitDefaultFlyHeight(udg_JP_U[id]) + 1 then            
                call DestroyJump(id)
            else
                call SetUnitFlyHeight(udg_JP_U[id],z,0)
            endif
        endif
        set id = udg_JP_N[id]
     
     endloop
        
endfunction

function CreateJump takes unit u , real z , real duration returns nothing
    
    local integer i2 = udg_JP_N[0]
    local integer i = 0
    loop
        exitwhen 0 == i2
        if u == udg_JP_U[i2] then
            set i = i2
        endif
        set i2 = udg_JP_N[i2]
    endloop

    if 0 == i then
        
        set i = udg_JP_RC[0]
        if 0 == i then
            set udg_JP_IC = udg_JP_IC + 1
            set i = udg_JP_IC
        else
            set udg_JP_RC[0] = udg_JP_RC[i]
        endif
        
        set udg_JP_N[i] = 0 
        set udg_JP_P[i] = 0
        set udg_JP_N[udg_JP_P[0]] = i
        set udg_JP_P[0] = i
        
        set udg_JP_Count = udg_JP_Count + 1
        if 1 == udg_JP_Count then
            call TimerStart(udg_JP_Timer,JumpTimeout(),true,function JP_Periodic)
        endif

        if UnitAddAbility(u,'Amrf') and UnitRemoveAbility(u,'Amrf') then
        endif

    endif

    call SetUnitPropWindow(u,0)
    
    set udg_JP_U[i] = u
    set udg_JP_StackedZ[i] = GetUnitFlyHeight(u)
    set udg_JP_Duration[i] = duration
    set udg_JP_Current[i] = 0
    set udg_JP_Height[i] = z

endfunction

I cant find what's wrong in the code,but when a unit begans to stack its height in the second time , it stucks in the air. it drops again when it the jump is stacked again.

Here is the test map:
 

Attachments

  • JumpInPlace v1.0.w3x
    19.8 KB · Views: 30
Status
Not open for further replies.
Top