function Real_SafeX takes real xx returns real
local real r=GetRectMinX(bj_mapInitialPlayableArea)+50
if(xx<r)then
return r
endif
set r=GetRectMaxX(bj_mapInitialPlayableArea)-50
if(xx>r)then
return r
endif
return xx
endfunction
function Real_SafeY takes real yy returns real
local real r=GetRectMinY(bj_mapInitialPlayableArea)+50
if(yy<r)then
return r
endif
set r=GetRectMaxY(bj_mapInitialPlayableArea)-50
if(yy>r)then
return r
endif
return yy
endfunction
function Unit_CreateDummy takes player id,integer unitid,real x,real y,real facing returns unit
set udg_j_spellCaster=CreateUnit(id,unitid,x,y,facing)
return udg_j_spellCaster
endfunction
function Unit_CreateDummySingle takes player p,integer unitid,real x,real y,real facing,integer abilid,integer level,string order,unit target,real interval,real height returns unit
if (x!=0) then
set x=Real_SafeX(x)
endif
if (y!=0) then
set y=Real_SafeY(y)
endif
set udg_j_spellCaster=Unit_CreateDummy(p,unitid,x,y,facing)
call UnitAddAbility(udg_j_spellCaster,abilid)
call SetUnitAbilityLevel(udg_j_spellCaster,abilid,level)
call IssueTargetOrderById(udg_j_spellCaster,OrderId(order),target)
call UnitAddAbility(udg_j_spellCaster,'Aloc')
call SetUnitPathing(udg_j_spellCaster,false)
call SetUnitFlyHeight(udg_j_spellCaster,height,0)
call UnitApplyTimedLife(udg_j_spellCaster,'BTLF',interval)
return udg_j_spellCaster
endfunction
//Ahh Necessary evil!!!
function Unit_DummyPreloadAbility takes player whichPlayer,integer unitid,integer abilid returns nothing
set udg_j_spellCaster=Unit_CreateDummySingle(whichPlayer,unitid,0,0,0,abilid,0,"",null,0,0)
//If you set up UnitApplyTimedLife the greater value of 0 for example Unit_CreateDummySingle(whichPlayer,unitid,0,0,0,abilid,0,"",null,1,0)
call UnitRemoveAbility(udg_j_spellCaster,abilid)
//then these last two functions do not need
call KillUnit(udg_j_spellCaster)
call RemoveUnit(udg_j_spellCaster)
endfunction