Zwiebelchen
Hosted Project GR
- Joined
- Sep 17, 2009
- Messages
- 7,234
This snippet works just like
It does so by using the HeroicUnit exploit found by Lean and applying a neat chaos morph trick on top of it to set the base armor of a unit.
It will then apply leveling tomes to set the level of the unit (the HeroicUnit exploit allows that) and use attack tomes to set the damage.
There are three requirements for the units created, though:
- The base attack damage of the unit in the object editor must be 0 (attack dice and dice sides doesn't matter)
- The base armor of the unit in the object editor must be 0
- The unit must have the hero inventory ability (AInv)
One important thing to know, though:
But you can always keep track of the unit levels via a simple table.
The main purpose of this snippet is to create creeps of any level without requiring a bulk of object data. You can use SetUnitMaxState snippet to adjust the life and mana values of created units.
CreateUnit()
, but also allows setting the unit level, base (= "white") armor and base (= "white") attack.CreateUnitWithProperties(player, rawcode, x, y, facing, attack, armor, level)
It does so by using the HeroicUnit exploit found by Lean and applying a neat chaos morph trick on top of it to set the base armor of a unit.
It will then apply leveling tomes to set the level of the unit (the HeroicUnit exploit allows that) and use attack tomes to set the damage.
There are three requirements for the units created, though:
- The base attack damage of the unit in the object editor must be 0 (attack dice and dice sides doesn't matter)
- The base armor of the unit in the object editor must be 0
- The unit must have the hero inventory ability (AInv)
One important thing to know, though:
GetUnitLevel
and GetHeroLevel
will not return the correct value for units created with this snippet. The former will return the level defined in the object editor and the latter will always return 0.But you can always keep track of the unit levels via a simple table.
JASS:
library UnitWithProperties uses HeroicUnit
//Please enter 3 unused rawcodes abilities and two unused item rawcodes below:
//! runtextmacro CreatePropertyObjects("A001", "A002", "A003", "I001", "I002")
//Now save & restart the editor, then search for the "PropertyMorph" ability and replace the unit field with an empty unit
//(the editor won't allow entering no unit, but you can copy and paste "empty" data from the raise dead ability level 2 field)
//! textmacro CreatePropertyObjects takes ABIL, ARMOR, ATTACK, ITEM, LEVELS
//! external ObjectMerger w3a Sca1 $ABIL$ anam "PropertyMorph" achd 0 areq ""
//! external ObjectMerger w3a AId1 $ARMOR$ aite 0 alev 99 Idef 1 1 anam "PropertyArmorBonus"
//! external ObjectMerger w3a AIaa $ATTACK$ Iaa1 "1" anam "PropertyAttackBonus"
//! external ObjectMerger w3t tkno $ITEM$ iabi $ATTACK$ ipow 0 iuse 0 iper 0 unam "ProperyAttackTome"
//! external ObjectMerger w3t tkno $LEVELS$ ipow 0 iuse 0 iper 0 unam "ProperyLevelTome"
globals
private hashtable TimerHash = InitHashtable()
private constant real DELAY = 0.5 //Adjusts the delay needed for the morph ability to finish
private constant integer ABIL_ID = '$ABIL$' //Morph ability with empty unit field to convert green armor stat
private constant integer ARMOR_ID = '$ARMOR$' //Armor bonus ability
private constant integer ATTACK_ID = '$ATTACK$' //Attack bonus ability
private constant integer ITEM_ID = '$ITEM$' //Attack bonus tome
private constant integer LEVELS_ID = '$LEVELS$' //Level bonus tome
endglobals
//! endtextmacro
private function callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(TimerHash, GetHandleId(t), 0)
local item it
local integer attack = LoadInteger(TimerHash, GetHandleId(t), 1)
call UnitRemoveAbility(u, ARMOR_ID)
set it = CreateItem(ITEM_ID,0,0)
call UnitAddItem(u, it)
loop
exitwhen attack <= 0
call UnitUseItem(u, it)
set attack = attack - 1
endloop
call UnitRemoveItem(u, it)
call RemoveItem(it)
call FlushChildHashtable(TimerHash, GetHandleId(t))
call DestroyTimer(t)
set t = null
set u = null
set it = null
endfunction
function CreateUnitWithProperties takes player id, integer unitid, real x, real y, real face, integer attack, integer armor, integer level returns unit
local integer i = 0
local unit u = CreateUnit(id, unitid, x, y, face)
local item it = CreateItem(LEVELS_ID,0,0)
local timer t = CreateTimer()
call UnitMakeHeroic(u)
call UnitAddItem(u, it)
loop
exitwhen i >= level-1
call UnitUseItem(u, it)
set i = i + 1
endloop
call UnitRemoveItem(u, it)
call RemoveItem(it)
if armor > 0 then
call UnitAddAbility(u, ARMOR_ID)
call SetUnitAbilityLevel(u, ARMOR_ID, armor)
endif
call UnitAddAbility(u, ABIL_ID)
call TimerStart(t, DELAY, false, function callback)
call SaveUnitHandle(TimerHash, GetHandleId(t), 0, u)
call SaveInteger(TimerHash, GetHandleId(t), 1, attack+1)
set t = null
return u
endfunction
endlibrary
The main purpose of this snippet is to create creeps of any level without requiring a bulk of object data. You can use SetUnitMaxState snippet to adjust the life and mana values of created units.
Last edited: