- Joined
- Oct 16, 2008
- Messages
- 10,454
Well, a simple Jump in Place library
JASS:
/*
Jump in Place version 1.02
by Adiktuz
Basically, this library handles jumping in place, but mainly for usage with the
impale system
It also allows the user to specify actions to be done after the jump is done
You're also allowed to choose what to do when a unit that is currently jumping
is re-jumped again by modifying the value of the jumptype parameter
You can use either:
JUMP_TYPE_STACK - stack each instance of jump for the unit
JUMP_TYPE_HEIGHT_STACK - stack only the jump height
JUMP_TYPE_RESET - stops the existing jump and resets unit height before doing the jump
JUMP_TYPE_NO_OVERWRITE - don't allow stacking
Disclaimer: Mixing these jump types might look weird...
Please take note that if you registered a StopEvent for the spell, and set the jumps to stack or reset,
the event will only run once when the unit hits the ground
How to Use:
call JumpInPlace.fire(unit flyUnit, unit causeUnit, real duration, real maxheight, integer abil, integer jumptype)
unit flyUnit -> unit that will jump
unit causeUnit -> the unit that caused the jump
real duration -> duration of jump
real maxheight -> maxheight of jump
integer abil -> rawcode of the ability that caused the jump
integer jumptype -> jump type
How to set action for when the unit returns to it's original height:
call JumpInPlace.registerStopEvent(integer abil, code action)
integer abil => the rawcode of the spell in which you want to add the action
use 0 if it won't be tied to any ability
code action => the function which will be run
You can also register global stop and start actions
call JumpInPlace.registerGlobalEndEvent(code action)
-> fires for any jump that finishes
call JumpInPlace.registerGlobalStartEvent(code action)
-> fires for any jump that starts
But before using them, make sure to set their correspoding variables to true on the globals block below
Variables you can use for the Event handlers
JumpInPlace.tmpFlyUnit => unit that triggered the event (the jumping unit)
JumpInPlace.tmpCauseUnit => the unit that caused the FlyUnit to jump
*/
library JumpInPlace requires T32, Table
globals
//Do you have an auto-fly library (like Magtheridon96's or Nestharus')?
private boolean AUTO_FLY = false
private constant integer FLY_ID = 'Amrf'
//Set to true if you're gonna use the global start event handler
private constant boolean USE_GLOBAL_START = false
//Set to true if you're gonna use the global end event handler
private constant boolean USE_GLOBAL_END = false
//Do not touch
constant integer JUMP_TYPE_STACK = 1
constant integer JUMP_TYPE_HEIGHT_STACK = 2
constant integer JUMP_TYPE_RESET = 3
constant integer JUMP_TYPE_NO_OVERWRITE = 4
endglobals
private module init
static method onInit takes nothing returns nothing
set FlyTable = Table.create()
set EventTable = Table.create()
static if USE_GLOBAL_START then
set globalStart = CreateTrigger()
endif
static if USE_GLOBAL_END then
set globalEnd = CreateTrigger()
endif
endmethod
endmodule
struct JumpInPlace extends array
private static integer instanceCount = 0
private static thistype recycle = 0
private thistype recycleNext
static Table FlyTable
static Table EventTable
static trigger globalEnd
static trigger globalStart
static unit tmpFlyUnit
static unit tmpCauseUnit
unit flyUnit
unit causeUnit
real maxheight
real hps
real height
real dfh
boolean up
integer abil
static method registerStopEvent takes integer abil, code toDo returns nothing
if not EventTable.handle.has(abil) then
set EventTable.trigger[abil] = CreateTrigger()
endif
call TriggerAddCondition(EventTable.trigger[abil], Filter(toDo))
endmethod
static method registerGlobalStartEvent takes code toDo returns nothing
call TriggerAddCondition(globalStart,Filter(toDo))
endmethod
static method registerGlobalEndEvent takes code toDo returns nothing
call TriggerAddCondition(globalEnd,Filter(toDo))
endmethod
method stop takes nothing returns nothing
call SetUnitFlyHeight(this.flyUnit, this.dfh, 0.0)
call this.stopPeriodic()
set thistype.tmpFlyUnit = this.flyUnit
set thistype.tmpCauseUnit = this.causeUnit
if EventTable.handle.has(this.abil) then
call TriggerEvaluate(EventTable.trigger[this.abil])
endif
static if USE_GLOBAL_END then
call TriggerEvaluate(globalEnd)
endif
set FlyTable[GetHandleId(this.flyUnit)] = 0
set recycleNext = recycle
set recycle = this
endmethod
method periodic takes nothing returns nothing
if this.up then
set this.height = this.height + hps
if this.height >= this.maxheight then
set this.up = false
endif
call SetUnitFlyHeight(this.flyUnit, this.height, 0.0)
else
set this.height = this.height - hps
call SetUnitFlyHeight(this.flyUnit, this.height, 0.0)
if this.height <= this.dfh then
set this.up = true
call this.stop()
endif
endif
endmethod
implement T32x
static method fire takes unit flyUnit, unit causeUnit, real duration, real maxheight, integer abil, integer jumptype returns nothing
local thistype this
local integer id = GetHandleId(flyUnit)
if FlyTable[id] == 0 or jumptype == 1 then
if (recycle == 0) then
set instanceCount = instanceCount + 1
set this = instanceCount
else
set this = recycle
set recycle = recycle.recycleNext
endif
set FlyTable[id] = this
static if not AUTO_FLY then
if UnitAddAbility(flyUnit, FLY_ID) and UnitRemoveAbility(flyUnit, FLY_ID) then
endif
endif
set this.abil = abil
set this.causeUnit = causeUnit
set this.flyUnit = flyUnit
set this.dfh = GetUnitDefaultFlyHeight(flyUnit)
set this.maxheight = maxheight + dfh
set this.hps = (maxheight*2/duration)*T32_PERIOD
set this.height = dfh
set this.up = true
call this.startPeriodic()
else
set this = FlyTable[id]
if jumptype == 2 then
static if not AUTO_FLY then
if UnitAddAbility(flyUnit, FLY_ID) and UnitRemoveAbility(flyUnit, FLY_ID) then
endif
endif
set this.abil = abil
set this.causeUnit = causeUnit
set this.maxheight = this.maxheight + maxheight
set this.hps = ((this.maxheight*2 - this.height)/duration)*T32_PERIOD
set this.up = true
elseif jumptype == 3 then
static if not AUTO_FLY then
if UnitAddAbility(flyUnit, FLY_ID) and UnitRemoveAbility(flyUnit, FLY_ID) then
endif
endif
set this.causeUnit = causeUnit
set this.abil = abil
call SetUnitFlyHeight(this.flyUnit, dfh, 0.0)
set this.maxheight = maxheight + dfh
set this.hps = (maxheight*2/duration)*T32_PERIOD
set this.height = dfh
set this.up = true
elseif jumptype == 4 then
return
endif
endif
set thistype.tmpFlyUnit = this.flyUnit
set thistype.tmpCauseUnit = this.causeUnit
static if USE_GLOBAL_START then
call TriggerEvaluate(globalStart)
endif
endmethod
implement init
endstruct
endlibrary
Last edited: