- Joined
- Dec 12, 2008
- Messages
- 7,385
The documentation has a brief explanation as to why I made this.
Code
Demo
And I posted a test-map.
Code
JASS:
/*************************************
*
* FlyHeight
* v2.0.0.0
* By Magtheridon96
*
* - Warcraft III movement types are pretty
* bugged. It would be much better to write
* them from scratch. This system allows
* you to create flying units with changeable
* heights.
*
* All units must have Movement Type Foot.
*
* Requires:
* ---------
*
* - UnitIndexer by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
* - Table by Bribe
* - hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
* - AutoFly by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/snippet-autofly-unitindexer-version-195563/
*
* API:
* ----
*
* - struct FlyHeight extends array
*
* - static method operator [] takes unit u returns thistype
* - Returns an instance of the struct given a unit
*
* - static method setDefault takes integer unitType, real flyHeight returns nothing
* - When a unit of a certain type enters the map, his height will be set
* to a default value input by the user using this function.
*
* - method operator height takes nothing returns real
* - Returns the height of a unit
*
* - method operator height= takes real newHeight returns nothing
* - Sets the height of a unit
*
*************************************/
library FlyHeight requires UnitIndexer, Table, AutoFly
private module Init
private static method onInit takes nothing returns nothing
set default = Table.create()
endmethod
endmodule
struct FlyHeight extends array
private static real array height_p
private static Table default
method operator height takes nothing returns real
return height_p[this]
endmethod
static method setDefault takes integer unitType, real defaultHeight returns nothing
set default.real[unitType] = defaultHeight
endmethod
private static method haveDefault takes integer unitType returns boolean
return default.real.has(unitType)
endmethod
private method index takes nothing returns nothing
local integer unitType = GetUnitTypeId(this.unit)
if haveDefault(unitType) then
set height_p[this] = default.real[unitType]
call SetUnitFlyHeight(this.unit, height_p[this], 0)
endif
endmethod
implement UnitIndexStruct
method operator height= takes real newHeight returns nothing
if height_p[this] != newHeight then
set height_p[this] = newHeight
call SetUnitFlyHeight(this.unit, newHeight, 0)
endif
endmethod
implement Init
endstruct
endlibrary
Demo
JASS:
struct Demo extends array
private static method onInit takes nothing returns nothing
local unit peasant
local unit hawk
call FlyHeight.setDefault('hpea', 200)
call FlyHeight.setDefault('hdhw', 150)
set peasant = CreateUnit(Player(0), 'hpea', -256, 0, 270)
set hawk = CreateUnit(Player(0), 'hdhw', 256, 0, 270)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[peasant].height, 5, 1))
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[hawk].height, 5, 1))
call TriggerSleepAction(5)
set FlyHeight[peasant].height = 900
set FlyHeight[hawk].height = 2
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[peasant].height, 5, 1))
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, R2SW(FlyHeight[hawk].height, 5, 1))
set peasant = null
set hawk = null
endmethod
endstruct
And I posted a test-map.
Attachments
Last edited: