//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//x x
//x O Dragonblood Creations' Jump System x
//x _ - /Y- Version 2.0 x
//x - / \ © Waldbaer@Dragonblood Creations, January 7th, 2007 x
//x- x
//x Check www.dragonblood-creations.de for the latest update! x
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
//___________________________________________________________________________
//|You have to give credits, if you use anything of this system for your |
//|map, either whole functions or only parts of them. You are allowed to |
//|change this system, if you still give credits to Dragonblood Creations. |
//|If you think that changes by you are so useful in a way that they should |
//|be implemented in the official version for everybody's use, send an |
//|e-mail to |
//|[email protected] |
//|and write us your changes in it, as well as a description of what their |
//|exact effect is. If we decide to implement them really, you will of |
//|course also be credited. |
//|_________________________________________________________________________|
//Constant Functions for easy editing of basic preferences
//--------------------------------------------------------
constant function DCJS_LoopFrequence takes nothing returns real
return 0.03 //This is the time period in seconds between the position corrections of the unit
endfunction
constant function DCJS_Jumpers takes nothing returns group
return udg_DCJS_Jumpers //You can change this variable's name here if you want it to have another name
endfunction
constant function PathChecker takes nothing returns integer
return 'uske' //The preset unit for pathchecking is the undead skeleton. If you want to use another ground unit, replace 'uske' with its rawcode
endfunction
//Used Secondary Functions of the system
//--------------------------------------
constant function DCJS_FlyTrick takes nothing returns integer
return 'Amrf'
endfunction
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2U takes integer i returns unit
return i
return null
endfunction
function IsLocPathable takes location target returns boolean
local unit u = CreateUnitAtLoc( Player(13), PathChecker(), target, 0 )
local real x = GetUnitX( u ) - GetLocationX( target )
local real y = GetUnitY( u ) - GetLocationY( target )
if x < 1 and x > -1 and y < 1 and y > -1 then
call RemoveUnit(u)
set u = null
return true
endif
call RemoveUnit(u)
set u = null
return false
endfunction
function GetNearestPathableLoc takes location source returns location
local unit u = CreateUnitAtLoc( Player(13), PathChecker(), source, 0 )
local location pathable = GetUnitLoc( u )
call RemoveUnit(u)
set u = null
return pathable
endfunction
//Main Functions of the system
//----------------------------
function DCJS_Jump takes unit u, location target, real height, real ttime returns nothing
local location uPos = GetUnitLoc(u)
local real startz = GetLocationZ( uPos )
local real x
local real y
local real angle
local integer number = GetStoredInteger( udg_DCJS_GC, "Units", "Count" )
local integer i = number * 9
if GetUnitFlyHeight(u) > 0 then
set startz = startz + GetUnitFlyHeight(u)
endif
set x = GetLocationX( target )
set y = GetLocationY( target )
call SetUnitPathing( u, false )
call UnitAddAbility( u, DCJS_FlyTrick() )
call UnitRemoveAbility( u, DCJS_FlyTrick() )
set angle = Atan2( y - GetUnitY(u), x - GetUnitX(u))
//Save all needed variables in GameCache and the data array and add unit to the Jumpers group
set udg_DCJS_Data[i] = GetLocationX( target )
set udg_DCJS_Data[i+1] = GetLocationY( target )
set udg_DCJS_Data[i+2] = angle
set udg_DCJS_Data[i+3] = startz
set udg_DCJS_Data[i+4] = (GetLocationZ( target ) - startz) / ttime
set udg_DCJS_Data[i+5] = DistanceBetweenPoints( uPos, target ) / ttime * DCJS_LoopFrequence()
set udg_DCJS_Data[i+6] = 0
set udg_DCJS_Data[i+7] = ttime
set udg_DCJS_Data[i+8] = height
call StoreInteger( udg_DCJS_GC, I2S(H2I(u)), "Number", number )
call StoreInteger( udg_DCJS_GC, I2S(number), "Unit", H2I(u) )
call StoreInteger( udg_DCJS_GC, "Units", "Count", number + 1 )
call GroupAddUnit( DCJS_Jumpers(), u )
call RemoveLocation( uPos )
set uPos = null
endfunction
function DCJS_JumpSpeed takes unit u, location target, real height, real speed returns nothing
local location uPos = GetUnitLoc(u)
local real startz = GetLocationZ( uPos )
local real x
local real y
local real angle
local real ttime = DistanceBetweenPoints( uPos, target ) / speed
local integer number = GetStoredInteger( udg_DCJS_GC, "Units", "Count" )
local integer i = number * 9
if GetUnitFlyHeight(u) > 0 then
set startz = startz + GetUnitFlyHeight(u)
endif
set x = GetLocationX( target )
set y = GetLocationY( target )
call SetUnitPathing( u, false )
call UnitAddAbility( u, DCJS_FlyTrick() )
call UnitRemoveAbility( u, DCJS_FlyTrick() )
set angle = Atan2( y - GetUnitY(u), x - GetUnitX(u))
//Save all needed variables in GameCache and the data array and add unit to the Jumpers group
set udg_DCJS_Data[i] = GetLocationX( target )
set udg_DCJS_Data[i+1] = GetLocationY( target )
set udg_DCJS_Data[i+2] = angle
set udg_DCJS_Data[i+3] = startz
set udg_DCJS_Data[i+4] = (GetLocationZ( target ) - startz) / ttime
set udg_DCJS_Data[i+5] = speed * DCJS_LoopFrequence()
set udg_DCJS_Data[i+6] = 0
set udg_DCJS_Data[i+7] = ttime
set udg_DCJS_Data[i+8] = height
call StoreInteger( udg_DCJS_GC, I2S(H2I(u)), "Number", number )
call StoreInteger( udg_DCJS_GC, I2S(number), "Unit", H2I(u) )
call StoreInteger( udg_DCJS_GC, "Units", "Count", number + 1 )
call GroupAddUnit( DCJS_Jumpers(), u )
call RemoveLocation( uPos )
set uPos = null
endfunction
function DCJS_EndJump takes unit u, boolean StopHeightChange returns nothing
local string s = I2S(H2I(u))
local unit last
local integer count
local integer number = GetStoredInteger( udg_DCJS_GC, s, "Number" )
local integer i = 0
if StopHeightChange then
call GroupRemoveUnit( DCJS_Jumpers(), u )
set count = GetStoredInteger( udg_DCJS_GC, "Units", "Count" ) - 1
set last = I2U( GetStoredInteger( udg_DCJS_GC, I2S(count), "Unit" ) )
call FlushStoredInteger( udg_DCJS_GC, I2S(count), "Unit" )
call StoreInteger( udg_DCJS_GC, I2S(H2I(last)), "Number", number )
call StoreInteger( udg_DCJS_GC, "Units", "Count", count )
set number = number * 9
set count = count * 9
loop
set udg_DCJS_Data[number + i] = udg_DCJS_Data[count + i]
set i = i + 1
exitwhen i == 9
endloop
call FlushStoredInteger( udg_DCJS_GC, s, "Number" )
call SetUnitPathing( u, true )
else
set udg_DCJS_Data[ number * 9 + 5 ] = 0
endif
set last = null
endfunction
function DCJS_Bounce takes unit u, location newtarget returns nothing
local real time
local real ttime
local real rise
local location uPos = GetUnitLoc(u)
local integer i = GetStoredInteger( udg_DCJS_GC, I2S(H2I(u)), "Number" ) * 9
set time = udg_DCJS_Data[i+6]
set ttime = udg_DCJS_Data[i+7]
set rise = ( GetLocationZ( newtarget ) - GetLocationZ( uPos ) ) / ( ttime - time )
set udg_DCJS_Data[i+2] = Atan2(GetLocationY(newtarget) - GetUnitY(u), GetLocationX(newtarget) - GetUnitX(u))
set udg_DCJS_Data[i+5] = DistanceBetweenPoints( uPos, newtarget ) / ( ttime - time ) * DCJS_LoopFrequence()
set udg_DCJS_Data[i+3] = GetLocationZ( uPos ) - time * rise
set udg_DCJS_Data[i+4] = rise
set udg_DCJS_Data[i] = GetLocationX( newtarget )
set udg_DCJS_Data[i+1] = GetLocationY( newtarget )
call RemoveLocation( uPos )
set uPos = null
endfunction
function DCJS_LoopEnum takes nothing returns nothing
local unit u = GetEnumUnit()
local real x
local real y
local real time
local real ttime
local real height
local real angle
local real rise
local real startz
local real movedistance
local real flyheight
local location nextposition
local integer number = GetStoredInteger( udg_DCJS_GC, I2S(H2I(u)), "Number" )
local integer i = number * 9
local integer count
local unit last
set time = udg_DCJS_Data[i+6] + DCJS_LoopFrequence()
set ttime = udg_DCJS_Data[i+7]
set movedistance = udg_DCJS_Data[i+5]
if time < ttime then
//Jumper is still going up
set height = udg_DCJS_Data[i+8]
set startz = udg_DCJS_Data[i+3]
set rise = udg_DCJS_Data[i+4]
set angle = udg_DCJS_Data[i+2]
set x = GetUnitX(u) + movedistance * Cos( angle )
set y = GetUnitY(u) + movedistance * Sin( angle )
set nextposition = Location( x, y )
set flyheight = height - height / ttime / ttime * 4 * ( time - ttime/2 ) * ( time - ttime/2 ) + time * rise + startz - GetLocationZ( nextposition )
call SetUnitFlyHeight(u, flyheight, 0 )
call SetUnitPosition( u, x, y )
set udg_DCJS_Data[i+6] = time
else
if movedistance > 0 then
//Move unit to target position
set x = udg_DCJS_Data[i]
set y = udg_DCJS_Data[i+1]
call SetUnitPosition( u, x, y )
endif
call SetUnitFlyHeight(u, 0, 0 )
//End jump and reset values
call GroupRemoveUnit( DCJS_Jumpers(), u )
set count = GetStoredInteger( udg_DCJS_GC, "Units", "Count" ) - 1
set last = I2U( GetStoredInteger( udg_DCJS_GC, I2S(count), "Unit" ) )
call FlushStoredInteger( udg_DCJS_GC, I2S(count), "Unit" )
call StoreInteger( udg_DCJS_GC, I2S(H2I(last)), "Number", number )
call StoreInteger( udg_DCJS_GC, "Units", "Count", count )
set i = 0
set number = number * 9
set count = count * 9
loop
set udg_DCJS_Data[number + i] = udg_DCJS_Data[count + i]
set i = i + 1
exitwhen i == 9
endloop
call FlushStoredInteger( udg_DCJS_GC, I2S(H2I(u)), "Number" )
call SetUnitPathing( u, true )
set nextposition = null
endif
set u = null
set last = null
call RemoveLocation( nextposition )
set nextposition = null
endfunction
function DCJS_Loop takes nothing returns nothing
call ForGroup(DCJS_Jumpers(), function DCJS_LoopEnum )
endfunction
function Init_DCJumpSystem takes nothing returns nothing
set udg_DCJS_Loop = CreateTrigger( )
call TriggerRegisterTimerEvent( udg_DCJS_Loop, DCJS_LoopFrequence(), true )
call TriggerAddAction( udg_DCJS_Loop, function DCJS_Loop )
set udg_DCJS_GC = InitGameCache( "jumpsystem.w3v" )
call FlushGameCache( udg_DCJS_GC )
call SaveGameCache( udg_DCJS_GC )
set udg_DCJS_GC = InitGameCache( "jumpsystem.w3v" )
call StoreInteger( udg_DCJS_GC, "Units", "Count", 0 )
endfunction
Name | Type | is_array | initial_value |
DCJS_Data | real | Yes | |
DCJS_GC | gamecache | No | |
DCJS_Jumpers | group | No | |
DCJS_Loop | trigger | No | |
NextTrigger | timer | No | |
Point | location | No | |
RunningTrigger | trigger | No |