- Joined
- Dec 12, 2008
- Messages
- 7,385
This is an API used for managing units.
It can increase efficiency by storing constant unit data too.
I didn't provide "Get" functions in the API because that would actually decrease efficiency =o
It requires AIDS and AutoFly
If you want, I'll create a UnitIndexer-based version of this.... On second thought, nevermind 0.o
The final product would be:
Give credits if used
It can increase efficiency by storing constant unit data too.
I didn't provide "Get" functions in the API because that would actually decrease efficiency =o
JASS:
library Unit requires AIDS, AutoFly // v1.2.0.0 by Magtheridon96
private module Init
private static method onInit takes nothing returns nothing
call AIDS_RegisterOnEnter(Condition(function thistype.run))
call AIDS_RegisterOnDeallocate(Condition(function thistype.clear))
endmethod
endmodule
struct Unit
unit whichUnit
string unitName
integer handleId
integer foodMade
integer foodUsed
race unitRace
real defaultRange
real defaultMoveSpeed
real defaultZ
real defaultTurnSpeed
static integer array index
static method operator [] takes unit u returns thistype
return index[GetUnitId(u)]
endmethod
method operator hp= takes real new returns nothing
call SetWidgetLife(this.whichUnit,new)
endmethod
method operator hpAdd= takes real new returns nothing
call SetWidgetLife(this.whichUnit,GetWidgetLife(this.whichUnit)+new)
endmethod
method operator hpSub= takes real new returns nothing
call SetWidgetLife(this.whichUnit,GetWidgetLife(this.whichUnit)-new)
endmethod
method operator mana= takes real new returns nothing
call SetUnitState(this.whichUnit,UNIT_STATE_MANA,new)
endmethod
method operator manaAdd= takes real new returns nothing
call SetUnitState(this.whichUnit,UNIT_STATE_MANA,GetUnitState(this.whichUnit,UNIT_STATE_MANA)+new)
endmethod
method operator manaSub= takes real new returns nothing
call SetUnitState(this.whichUnit,UNIT_STATE_MANA,GetUnitState(this.whichUnit,UNIT_STATE_MANA)-new)
endmethod
method operator moveSpeed= takes real new returns nothing
call SetUnitMoveSpeed(this.whichUnit,new)
endmethod
method operator moveSpeedAdd= takes real new returns nothing
call SetUnitMoveSpeed(this.whichUnit,GetUnitMoveSpeed(this.whichUnit)+new)
endmethod
method operator moveSpeedSub= takes real new returns nothing
call SetUnitMoveSpeed(this.whichUnit,GetUnitMoveSpeed(this.whichUnit)-new)
endmethod
method operator angle= takes real new returns nothing
call SetUnitFacing(this.whichUnit,new)
endmethod
method operator x= takes real new returns nothing
call SetUnitX(this.whichUnit,new)
endmethod
method operator y= takes real new returns nothing
call SetUnitY(this.whichUnit,new)
endmethod
method operator z= takes real new returns nothing
call SetUnitFlyHeight(this.whichUnit,new,0)
endmethod
method operator range= takes real new returns nothing
call SetUnitAcquireRange(this.whichUnit,new)
endmethod
method operator rangeAdd= takes real new returns nothing
call SetUnitAcquireRange(this.whichUnit,GetUnitAcquireRange(this.whichUnit)+new)
endmethod
method operator rangeSub= takes real new returns nothing
call SetUnitAcquireRange(this.whichUnit,GetUnitAcquireRange(this.whichUnit)-new)
endmethod
method operator order= takes integer new returns nothing
call IssueImmediateOrderById(this.whichUnit,new)
endmethod
method operator turnSpeed= takes real new returns nothing
call SetUnitTurnSpeed(this.whichUnit,new)
endmethod
method operator turnSpeedAdd= takes real new returns nothing
call SetUnitTurnSpeed(this.whichUnit,GetUnitTurnSpeed(this.whichUnit)+new)
endmethod
method operator turnSpeedSub= takes real new returns nothing
call SetUnitTurnSpeed(this.whichUnit,GetUnitTurnSpeed(this.whichUnit)-new)
endmethod
method operator pathing= takes boolean new returns nothing
call SetUnitPathing(this.whichUnit,new)
endmethod
method operator size= takes real new returns nothing
call SetUnitScale(this.whichUnit,new,new,new)
endmethod
method operator invulnerable= takes boolean new returns nothing
call SetUnitInvulnerable(this.whichUnit,new)
endmethod
method operator animation= takes string new returns nothing
call SetUnitAnimation(this.whichUnit,new)
endmethod
method operator animationIndex= takes integer new returns nothing
call SetUnitAnimationByIndex(this.whichUnit,new)
endmethod
method operator blendtime= takes real new returns nothing
call SetUnitBlendTime(this.whichUnit,new)
endmethod
method operator creepGuard= takes boolean new returns nothing
call SetUnitCreepGuard(this.whichUnit,new)
endmethod
method operator exploded= takes boolean new returns nothing
call SetUnitExploded(this.whichUnit,new)
endmethod
method operator color= takes playercolor new returns nothing
call SetUnitColor(this.whichUnit,new)
endmethod
method operator useFood= takes boolean new returns nothing
call SetUnitUseFood(this.whichUnit,new)
endmethod
method operator owner= takes player new returns nothing
call SetUnitOwner(this.whichUnit,new,true)
endmethod
method operator propWindow= takes real new returns nothing
call SetUnitPropWindow(this.whichUnit,new)
endmethod
method operator typeSlots= takes integer new returns nothing
call SetUnitTypeSlots(this.whichUnit,new)
endmethod
method operator timeScale= takes real new returns nothing
call SetUnitTimeScale(this.whichUnit,new)
endmethod
method operator level= takes integer new returns nothing
call SetHeroLevel(this.whichUnit,new,false)
endmethod
method operator levelAdd= takes integer new returns nothing
call SetHeroLevel(this.whichUnit,GetUnitLevel(this.whichUnit)+new,false)
endmethod
method operator levelSub= takes integer new returns nothing
call SetHeroLevel(this.whichUnit,GetUnitLevel(this.whichUnit)-new,false)
endmethod
method operator agility= takes integer new returns nothing
call SetHeroAgi(this.whichUnit,new,true)
endmethod
method operator agilityAdd= takes integer new returns nothing
call SetHeroAgi(this.whichUnit,GetHeroAgi(this.whichUnit,false)+new,true)
endmethod
method operator agilitySub= takes integer new returns nothing
call SetHeroAgi(this.whichUnit,GetHeroAgi(this.whichUnit,false)-new,true)
endmethod
method operator intelligence= takes integer new returns nothing
call SetHeroInt(this.whichUnit,new,true)
endmethod
method operator intelligenceAdd= takes integer new returns nothing
call SetHeroInt(this.whichUnit,GetHeroInt(this.whichUnit,false)+new,true)
endmethod
method operator intelligenceSub= takes integer new returns nothing
call SetHeroInt(this.whichUnit,GetHeroInt(this.whichUnit,false)-new,true)
endmethod
method operator strength= takes integer new returns nothing
call SetHeroStr(this.whichUnit,new,true)
endmethod
method operator strengthAdd= takes integer new returns nothing
call SetHeroStr(this.whichUnit,GetHeroStr(this.whichUnit,false)+new,true)
endmethod
method operator strengthSub= takes integer new returns nothing
call SetHeroStr(this.whichUnit,GetHeroStr(this.whichUnit,false)-new,true)
endmethod
method operator xp= takes integer new returns nothing
call SetHeroXP(this.whichUnit,new,false)
endmethod
method operator xpAdd= takes integer new returns nothing
call SetHeroXP(this.whichUnit,GetHeroXP(this.whichUnit)+new,false)
endmethod
method operator xpSub= takes integer new returns nothing
call SetHeroXP(this.whichUnit,GetHeroXP(this.whichUnit)-new,false)
endmethod
static method run takes nothing returns boolean
local thistype this = thistype.allocate()
set this.whichUnit = GetTriggerUnit()
set this.handleId = GetHandleId(this.whichUnit)
set this.unitName = GetUnitName(this.whichUnit)
set this.foodMade = GetUnitFoodMade(this.whichUnit)
set this.foodUsed = GetUnitFoodUsed(this.whichUnit)
set this.unitRace = GetUnitRace(this.whichUnit)
set this.defaultZ = GetUnitDefaultFlyHeight(this.whichUnit)
set this.defaultRange = GetUnitDefaultAcquireRange(this.whichUnit)
set this.defaultMoveSpeed = GetUnitDefaultMoveSpeed(this.whichUnit)
set this.defaultTurnSpeed = GetUnitDefaultTurnSpeed(this.whichUnit)
set thistype.index[GetUnitId(this.whichUnit)]=this
return false
endmethod
method destroy takes nothing returns nothing
set this.whichUnit = null
set this.unitRace = null
call this.deallocate()
endmethod
static method clear takes nothing returns boolean
call Unit[GetTriggerUnit()].destroy()
return false
endmethod
implement Init
endstruct
endlibrary
It requires AIDS and AutoFly
If you want, I'll create a UnitIndexer-based version of this.... On second thought, nevermind 0.o
The final product would be:
JASS:
function bla takes nothing returns nothing
local unit u = GetTriggerUnit()
set Unit[u].hp = 2423
set Unit[u].maxMana = 2325
set Unit[u].angle = 90
set Unit[u].z = 100
set Unit[u].x = 34
set Unit[u].y = 24
set Unit[u].hpAdd = 23 // Adds 23 hp
set Unit[u].manaAdd = 24 // Adds 24 mana
set Unit[u].moveSpeedSub = 4 // Decreases by 4
endfunction
Give credits if used
Last edited: