Please note mods: this is not specifically a Jass question, hence the reason I posted in WE forum.. This is a question of "GUI or Jass is better?"
I note that Replace Unit uses coordinates. It is however a BJ.
Is it ok to use Replace unit, or should I make my own that cleans units/items/other leaks or just does a simple hide/remove/create/new unit with life/abilitys/mana/items creation?
Something I made that does a similar effect to replace. It wouldnt take much to do hiding:
I note that Replace Unit uses coordinates. It is however a BJ.
Is it ok to use Replace unit, or should I make my own that cleans units/items/other leaks or just does a simple hide/remove/create/new unit with life/abilitys/mana/items creation?
Code:
Unit - Replace (Triggering unit) with a chaos test 2 using The old unit's relative life and mana
JASS:
function ReplaceUnitBJ takes unit whichUnit, integer newUnitId, integer unitStateMethod returns unit
local unit oldUnit = whichUnit
local unit newUnit
local boolean wasHidden
local integer index
local item indexItem
local real oldRatio
// If we have bogus data, don't attempt the replace.
if (oldUnit == null) then
set bj_lastReplacedUnit = oldUnit
return oldUnit
endif
// Hide the original unit.
set wasHidden = IsUnitHidden(oldUnit)
call ShowUnit(oldUnit, false)
// Create the replacement unit.
if (newUnitId == 039;ugol039;) then
set newUnit = CreateBlightedGoldmine(GetOwningPlayer(oldUnit), GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
else
set newUnit = CreateUnit(GetOwningPlayer(oldUnit), newUnitId, GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
endif
// Set the unit's life and mana according to the requested method.
if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
// Set the replacement's current/max life ratio to that of the old unit.
// If both units have mana, do the same for mana.
if (GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE) > 0) then
set oldRatio = GetUnitState(oldUnit, UNIT_STATE_LIFE) / GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE)
call SetUnitState(newUnit, UNIT_STATE_LIFE, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
endif
if (GetUnitState(oldUnit, UNIT_STATE_MAX_MANA) > 0) and (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
set oldRatio = GetUnitState(oldUnit, UNIT_STATE_MANA) / GetUnitState(oldUnit, UNIT_STATE_MAX_MANA)
call SetUnitState(newUnit, UNIT_STATE_MANA, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
endif
elseif (unitStateMethod == bj_UNIT_STATE_METHOD_ABSOLUTE) then
// Set the replacement's current life to that of the old unit.
// If the new unit has mana, do the same for mana.
call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(oldUnit, UNIT_STATE_LIFE))
if (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(oldUnit, UNIT_STATE_MANA))
endif
elseif (unitStateMethod == bj_UNIT_STATE_METHOD_DEFAULTS) then
// The newly created unit should already have default life and mana.
elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
// Use max life and mana.
call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
else
// Unrecognized unit state method - ignore the request.
endif
// Mirror properties of the old unit onto the new unit.
//call PauseUnit(newUnit, IsUnitPaused(oldUnit))
call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))
// If both the old and new units are heroes, handle their hero info.
if (IsUnitType(oldUnit, UNIT_TYPE_HERO) and IsUnitType(newUnit, UNIT_TYPE_HERO)) then
call SetHeroXP(newUnit, GetHeroXP(oldUnit), false)
set index = 0
loop
set indexItem = UnitItemInSlot(oldUnit, index)
if (indexItem != null) then
call UnitRemoveItem(oldUnit, indexItem)
call UnitAddItem(newUnit, indexItem)
endif
set index = index + 1
exitwhen index >= bj_MAX_INVENTORY
endloop
endif
// Remove or kill the original unit. It is sometimes unsafe to remove
// hidden units, so kill the original unit if it was previously hidden.
if wasHidden then
call KillUnit(oldUnit)
call RemoveUnit(oldUnit)
else
call RemoveUnit(oldUnit)
endif
set bj_lastReplacedUnit = newUnit
return newUnit
endfunction
Something I made that does a similar effect to replace. It wouldnt take much to do hiding:
JASS:
function Trig_CreateProximityMineJass2_Actions takes nothing returns nothing
local unit Caster = GetTriggerUnit()
local real CasterX = GetUnitX(Caster)
local real CasterY = GetUnitY(Caster)
local real CasterFace = GetUnitFacing(Caster)
local unit Mine
local unit Explosion
set Mine = CreateUnit(GetOwningPlayer(Caster), MineID(), CasterX, CasterY, bj_UNIT_FACING)
call UnitApplyTimedLife(Mine ,039;BTLF039;, MineFuse())
call TriggerSleepAction(MineFuse())
set Explosion = CreateUnit(GetOwningPlayer(Caster),039;h00Q039;,GetUnitX(Mine),GetUnitY(Mine),bj_UNIT_FACING)
call UnitDamagePoint(Mine, 0, MineBlastRadius(), GetUnitX(Mine), GetUnitY(Mine), MineDamage(), true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call UnitApplyTimedLife(Explosion, 039;BTLF039;, 2)
set Caster = null
set Mine = null
set Explosion = null
endfunction