TheLegend
New Member
- Reaction score
- 10
im having some problems with a jump system im making, well that is, only one problem. When the system starts the unit does change heights and it does move with the key system but the height gets set to 0 each 3rd run and it kinda bounces the unit
JASS:
library jumpenhanced initializer jumpinit uses OZSYS
globals
private boolean array LEFT_PRESSED //Monitors if the Left key is pressed
private boolean array RIGHT_PRESSED //Monitors if the Right key is pressed
private boolean array UP_PRESSED //Monitors if the Up key is pressed
private boolean array DOWN_PRESSED //Monitors if the Down key is pressed
private integer totaldata = 0 //The total ammount of jumping units
private real array xadjust //Loc x offset for moving the unit
private group jumpers = CreateGroup() //Units jumping
private real array yadjust //Loc y offset for moving the unit
endglobals
private struct storeddata
unit u //the unit jumping
location startloc //the units start location
integer playerid //id of the units owner
real maxheight //the jumps max height
real nowheight //the jumps height now
real newflyheight //fly height that has to be set to simulate flight
location currentloc //current location of the unit
integer reachedmax //+8 if not -8 if it did, will adjust the height
endstruct
globals
private storeddata array D //jump data array
endglobals
//These functions set the offsets for moving the unit by pressing keys
//--------------------------------------------------------------------
private function ARROW_LEFT takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
if LEFT_PRESSED<i> then
set LEFT_PRESSED<i> = false
set xadjust<i> = xadjust<i> + 8
else
set LEFT_PRESSED<i> = true
set xadjust<i> = xadjust<i> - 8
endif
endfunction
private function ARROW_RIGHT takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
if RIGHT_PRESSED<i> then
set RIGHT_PRESSED<i> = false
set xadjust<i> = xadjust<i> - 8
else
set RIGHT_PRESSED<i> = true
set xadjust<i> = xadjust<i> + 8
endif
endfunction
private function ARROW_UP takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
if UP_PRESSED<i> then
set UP_PRESSED<i> = false
set yadjust<i> = yadjust<i> - 8
else
set UP_PRESSED<i> = true
set yadjust<i> = yadjust<i> + 8
endif
endfunction
private function ARROW_DOWN takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
if DOWN_PRESSED<i> then
set DOWN_PRESSED<i> = false
set yadjust<i> = yadjust<i> + 8
else
set DOWN_PRESSED<i> = true
set yadjust<i> = yadjust<i> - 8
endif
endfunction
//--------------------------------------------------------------------
private function destroyD takes integer id returns nothing
local storeddata data = D[id]
call SetUnitPathing(data.u, true )
set data.u = null
set data.reachedmax = 0
set data.playerid = 0
set data.maxheight = 0
set data.nowheight = 0
set data.newflyheight = 0
set data.startloc = null
set data.currentloc = null
// The loop will correct the array, that is it
//will remove the gap created by the deleted data
loop
set D[id] = D[id + 1]
set id = id + 1
exitwhen id == totaldata
endloop
call data.destroy()
set totaldata = totaldata - 1
endfunction
//This function will identificate the data which is connected to the unit
private function identify takes unit u returns integer
local integer unitid = 0
loop
set unitid = unitid + 1
exitwhen unitid == totaldata
endloop
return unitid
endfunction
private function unitadjust takes nothing returns nothing
local integer id = identify(GetEnumUnit()) //Locate the data for the unit
local location newloc
set D[id].currentloc = GetUnitLoc(D[id].u) //Set the units location now
if D[id].nowheight > D[id].maxheight then //Checks if the unit reached max
set D[id].reachedmax = -8
endif
set D[id].nowheight = D[id].nowheight + D[id].reachedmax //adjust the current height of the unit
set D[id].newflyheight = D[id].nowheight - GetLocationZ(D[id].currentloc) //sets the flight height
if D[id].newflyheight < 1 then
set D[id].newflyheight = 1
endif
call SetUnitFlyHeight(D[id].u,D[id].newflyheight,0)
// this will move the unit to the adjsuted loc
if xadjust[D[id].playerid] != 0 or yadjust[D[id].playerid] != 0 then
//call IssueImmediateOrder(D[id].u,"stop")
set newloc = Location(GetLocationX(D[id].currentloc) + xadjust[D[id].playerid],GetLocationY(D[id].currentloc) + yadjust[D[id].playerid])
//call IssuePointOrderLoc(D[id].u,"move",D[id].currentloc)
call SetUnitPositionLoc(D[id].u, newloc)
call SetUnitFacing(D[id].u, AngleBetweenPoints(D[id].currentloc, newloc))
endif
call RemoveLocation(newloc)
if 2*D[id].newflyheight + GetUnitPointValue(D[id].u) - OZSYS_GetMinimumZ(D[id].currentloc,false,16,true)< 0 then
call GroupRemoveUnit(jumpers,D[id].u)
call destroyD(id)
endif
endfunction
public function jump takes unit u, real jumpheight returns nothing
local storeddata data = storeddata.create()
if IsUnitInGroup(u,jumpers) == false then
call SetUnitPathing(u, false )
call UnitAddAbility(u, 039;Amrf039;)
call UnitRemoveAbility(u, 039;Amrf039;)
call GroupAddUnit(jumpers,u)
set totaldata = totaldata + 1
set data.u = u
set data.playerid = GetPlayerId(GetOwningPlayer(u))
call SetCameraTargetController(u, 0, 0, false)
set data.startloc = GetUnitLoc(u)
set data.currentloc = GetUnitLoc(u)
set data.reachedmax = 8
set data.maxheight = GetLocationZ(data.startloc) + GetUnitFlyHeight(u) + jumpheight
set D[totaldata] = data
endif
endfunction
private function jumpadjust takes nothing returns nothing
call ForGroup(jumpers,function unitadjust)
endfunction
private function jumpinit takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
local trigger t4 = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerEvent(t1, Player(i), EVENT_PLAYER_ARROW_LEFT_DOWN)
call TriggerRegisterPlayerEvent(t1, Player(i), EVENT_PLAYER_ARROW_LEFT_UP)
call TriggerRegisterPlayerEvent(t2, Player(i), EVENT_PLAYER_ARROW_RIGHT_DOWN)
call TriggerRegisterPlayerEvent(t2, Player(i), EVENT_PLAYER_ARROW_RIGHT_UP)
call TriggerRegisterPlayerEvent(t3, Player(i), EVENT_PLAYER_ARROW_UP_DOWN)
call TriggerRegisterPlayerEvent(t3, Player(i), EVENT_PLAYER_ARROW_UP_UP)
call TriggerRegisterPlayerEvent(t4, Player(i), EVENT_PLAYER_ARROW_DOWN_DOWN)
call TriggerRegisterPlayerEvent(t4, Player(i), EVENT_PLAYER_ARROW_DOWN_UP)
set LEFT_PRESSED<i> = false
set RIGHT_PRESSED<i> = false
set UP_PRESSED<i> = false
set DOWN_PRESSED<i> = false
set xadjust<i> = 0
set yadjust<i> = 0
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
call TriggerAddAction(t1,function ARROW_LEFT)
call TriggerAddAction(t2,function ARROW_RIGHT)
call TriggerAddAction(t3,function ARROW_UP)
call TriggerAddAction(t4,function ARROW_DOWN)
call TriggerRegisterTimerEvent(t,0.03,true)
call TriggerAddAction(t,function jumpadjust)
set i = 0
set t1 = null
set t2 = null
set t3 = null
set t4 = null
endfunction
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>