//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//x x
//x O Dragonblood Creations' Jump System x
//x _ - /Y- Version 2.01 x
//x - / \ © Waldbaer@Dragonblood Creations, December 22nd, 2007 x
//x- x
//x Check www.dragonblood-creations.com 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. |
//|Special thanks go to Doomhammer.
//|_________________________________________________________________________|
//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
constant function DCJS_DataArrayCount takes nothing returns integer
return 9 //The number of variables saved in the Data-Array for each unit. If you edit the system itself and want to add anything, this may make your edits easier.
endfunction
//Used Secondary Functions of the system
//--------------------------------------
constant function DCJS_FlyTrick takes nothing returns integer
return 'Amrf'
endfunction
function DCJS_H2I takes handle h returns integer
return h
return 0
endfunction
function DCJS_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 = GetLocationX( target )
local real y = GetLocationY( target )
local real m = (GetLocationZ( target ) - startz) / ttime
local integer number = GetStoredInteger( udg_DCJS_GC, "Units", "Count" )
local integer i = number * DCJS_DataArrayCount()
local real zcorrect1 = SquareRoot(4 * height / ttime / ttime)
local real zcorrect2
local real zcorrect3
if GetUnitFlyHeight(u) > 0 then
set startz = startz + GetUnitFlyHeight(u)
endif
set zcorrect2 = zcorrect1 * ttime / -2 - m / 2 / zcorrect1
set zcorrect3 = zcorrect2 * zcorrect2 + startz
call SetUnitPathing( u, false )
call UnitAddAbility( u, DCJS_FlyTrick() )
call UnitRemoveAbility( u, DCJS_FlyTrick() )
//Save all needed variables in GameCache and the data array and add unit to the Jumpers group
set udg_DCJS_Data[i] = x
set udg_DCJS_Data[i+1] = y
set udg_DCJS_Data[i+2] = (x - GetLocationX(uPos)) / ttime * DCJS_LoopFrequence()
set udg_DCJS_Data[i+3] = (y - GetLocationY(uPos)) / ttime * DCJS_LoopFrequence()
set udg_DCJS_Data[i+4] = zcorrect1
set udg_DCJS_Data[i+5] = zcorrect2
set udg_DCJS_Data[i+6] = zcorrect3
set udg_DCJS_Data[i+7] = 0
set udg_DCJS_Data[i+8] = ttime
call StoreInteger( udg_DCJS_GC, I2S(DCJS_H2I(u)), "Number", number )
call StoreInteger( udg_DCJS_GC, I2S(number), "Unit", DCJS_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)
call DCJS_Jump( u, target, height, DistanceBetweenPoints( uPos, target ) / speed )
call RemoveLocation( uPos )
set uPos = null
endfunction
function DCJS_Bounce takes unit u, location newtarget returns nothing
local location uPos = GetUnitLoc(u)
local integer i
local real ttime
local real dtime
local real rise
local real zcorrect1
//only do anything if the unit is actually jumping
if IsUnitInGroup( u, udg_DCJS_Jumpers ) then
set i = GetStoredInteger( udg_DCJS_GC, I2S(DCJS_H2I(u)), "Number" ) * DCJS_DataArrayCount()
set ttime = udg_DCJS_Data[i+8]
set dtime = ttime - udg_DCJS_Data[i+7]
set rise = ( GetLocationZ( newtarget ) - GetLocationZ( uPos ) ) / dtime
set zcorrect1 = udg_DCJS_Data[i+4]
set udg_DCJS_Data[i] = GetLocationX( newtarget )
set udg_DCJS_Data[i+1] = GetLocationY( newtarget )
set udg_DCJS_Data[i+2] = (udg_DCJS_Data[i] - GetLocationX(uPos)) / dtime * DCJS_LoopFrequence()
set udg_DCJS_Data[i+3] = (udg_DCJS_Data[i+1] - GetLocationY(uPos)) / dtime * DCJS_LoopFrequence()
set udg_DCJS_Data[i+5] = zcorrect1 * ttime / -2 - rise / 2 / zcorrect1
set udg_DCJS_Data[i+6] = udg_DCJS_Data[i+5] * udg_DCJS_Data[i+5] + GetLocationZ( uPos ) - rise * udg_DCJS_Data[i+7]
endif
call RemoveLocation( uPos )
set uPos = null
endfunction
function DCJS_EndJump takes unit u, boolean StopHeightChange returns nothing
local string s = I2S(DCJS_H2I(u))
local unit last
local integer count
local integer number = GetStoredInteger( udg_DCJS_GC, s, "Number" )
local integer i = 0
//only do anything if the unit is actually jumping
if IsUnitInGroup( u, udg_DCJS_Jumpers ) then
if StopHeightChange then
call GroupRemoveUnit( DCJS_Jumpers(), u )
set count = GetStoredInteger( udg_DCJS_GC, "Units", "Count" ) - 1
set last = DCJS_I2U( GetStoredInteger( udg_DCJS_GC, I2S(count), "Unit" ) )
call FlushStoredInteger( udg_DCJS_GC, I2S(count), "Unit" )
call StoreInteger( udg_DCJS_GC, I2S(DCJS_H2I(last)), "Number", number )
call StoreInteger( udg_DCJS_GC, "Units", "Count", count )
set number = number * DCJS_DataArrayCount()
set count = count * DCJS_DataArrayCount()
loop
set udg_DCJS_Data[number + i] = udg_DCJS_Data[count + i]
set i = i + 1
exitwhen i == DCJS_DataArrayCount()
endloop
call FlushStoredInteger( udg_DCJS_GC, s, "Number" )
call SetUnitPathing( u, true )
else
set udg_DCJS_Data[ number * DCJS_DataArrayCount() + 2 ] = 0
set udg_DCJS_Data[ number * DCJS_DataArrayCount() + 3 ] = 0
endif
endif
set last = null
endfunction
function DCJS_LoopEnum takes nothing returns nothing
local unit u = GetEnumUnit()
local integer number = GetStoredInteger( udg_DCJS_GC, I2S(DCJS_H2I(u)), "Number" )
local integer i = number * DCJS_DataArrayCount()
local real x = GetUnitX(u) + udg_DCJS_Data[i+2]
local real y = GetUnitY(u) + udg_DCJS_Data[i+3]
local location nextposition = Location(x, y)
local real z = GetLocationZ(nextposition)
local real zcorrect1 = udg_DCJS_Data[i+4]
local real zcorrect2 = udg_DCJS_Data[i+5]
local real zcorrect3 = udg_DCJS_Data[i+6]
local real time = udg_DCJS_Data[i+7] + DCJS_LoopFrequence()
local real ttime = udg_DCJS_Data[i+8]
local real flyheight
local real tmp = zcorrect1 * time + zcorrect2
local integer count
local unit last
if time < ttime then
//Jumper is still in air
set flyheight = -tmp * tmp + zcorrect3 - z
call SetUnitFlyHeight(u, flyheight, 0 )
call SetUnitPosition( u, x, y )
set udg_DCJS_Data[i+7] = time
else
if RAbsBJ(udg_DCJS_Data[i+2]) + RAbsBJ(udg_DCJS_Data[i+3]) > 0 then
//Move unit to target position
call SetUnitPosition( u, udg_DCJS_Data[i], udg_DCJS_Data[i+1] )
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 = DCJS_I2U( GetStoredInteger( udg_DCJS_GC, I2S(count), "Unit" ) )
call FlushStoredInteger( udg_DCJS_GC, I2S(count), "Unit" )
call StoreInteger( udg_DCJS_GC, I2S(DCJS_H2I(last)), "Number", number )
call StoreInteger( udg_DCJS_GC, "Units", "Count", count )
set i = 0
set number = number * DCJS_DataArrayCount()
set count = count * DCJS_DataArrayCount()
loop
set udg_DCJS_Data[number + i] = udg_DCJS_Data[count + i]
set i = i + 1
exitwhen i == DCJS_DataArrayCount()
endloop
call FlushStoredInteger( udg_DCJS_GC, I2S(DCJS_H2I(u)), "Number" )
call SetUnitPathing( u, true )
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 |
AvailableSpawns | integer | Yes | |
Beast_Master | integer | No | |
CameraLock | real | Yes | |
Cameras | camerasetup | Yes | |
ComputerAction | boolean | Yes | |
ComputerActionTime | real | Yes | |
ComputerCurrentPlayer | player | No | |
ComputerCurrentUnit | unit | No | |
ComputerNearestDistance | real | No | |
ComputerNearestUnit | unit | No | |
ComputerSkillDistance | real | No | |
ComputerSkillMult | real | Yes | |
ComputerSkillTimeBias | real | No | |
Configurer | player | No | |
CurrentSpawn | integer | No | |
DCJS_Data | real | Yes | |
DCJS_GC | gamecache | No | |
DCJS_Jumpers | group | No | |
DCJS_Loop | trigger | No | |
DialogButtonAdvanced | button | No | |
DialogButtonExpert | button | No | |
DialogButtonNightmare | button | No | |
DialogButtonNoob | button | No | |
DialogCompSkill | dialog | No | |
Entries | rect | Yes | |
Leaderboard | leaderboard | No | |
Messages | string | Yes | |
Occupied | boolean | No | |
PlayerIsPlaying | boolean | Yes | |
PlayerNames | string | Yes | |
PlayerType | unitcode | Yes | |
Point | location | No | |
RedPingChx | boolean | No | false |
Regions | rect | Yes | |
Scores | integer | Yes | |
SpawningPlayer | player | No | |
Spawns | rect | Yes | |
TempBool | boolean | No | |
Timer | timer | No | |
Timer_Set | dialog | No | |
TimerMins | button | Yes | |
TotalMessages | integer | No | |
TotalPlayerTypes | integer | No | |
TotalSpawns | integer | No | |
Units | unit | Yes | |
UseableSpawnCount | integer | No | |
WinningScore | integer | No |
function Trig_Combine_Items_Conditions takes nothing returns boolean
if ( not ( GetItemCharges(GetManipulatedItem()) > 0 ) ) then
return false
endif
return true
endfunction
function Trig_Combine_Items_Actions takes nothing returns nothing
local integer ITEMCOUNT
local integer ITEMLOOP
local integer CHARGES
local integer MAXIMUM
local item NEWITEM
local unit OURUNIT
set MAXIMUM = 15
set ITEMCOUNT = 0
set ITEMLOOP = 0
set CHARGES = 0
set NEWITEM = GetManipulatedItem()
set OURUNIT = GetManipulatingUnit()
loop
exitwhen ITEMLOOP > 6
if ((GetItemTypeId(NEWITEM)) == (GetItemTypeId(UnitItemInSlotBJ(OURUNIT, ITEMLOOP)))) then
if ((GetItemCharges(UnitItemInSlotBJ(OURUNIT, ITEMLOOP)) + GetItemCharges(NEWITEM)) <= MAXIMUM) then
if not ( (UnitItemInSlotBJ(OURUNIT, ITEMLOOP)) == (NEWITEM)) then
set CHARGES = (GetItemCharges(UnitItemInSlotBJ(OURUNIT, ITEMLOOP))) + GetItemCharges(NEWITEM)
call SetItemCharges( UnitItemInSlotBJ(OURUNIT, ITEMLOOP), CHARGES )
call RemoveItem( NEWITEM )
set ITEMLOOP=7
endif
endif
endif
if ( ITEMLOOP < 7 ) then
set ITEMLOOP = ITEMLOOP + 1
endif
endloop
endfunction
//===========================================================================
function InitTrig_Combine_Items takes nothing returns nothing
set gg_trg_Combine_Items = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Combine_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Combine_Items, Condition( function Trig_Combine_Items_Conditions ) )
call TriggerAddAction( gg_trg_Combine_Items, function Trig_Combine_Items_Actions )
endfunction