Sgqvur
FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
- Reaction score
- 62
BlinkBJ is a jass version of the Warden's ability Blink. BlinkBJ tries to mimic as much as possible the behavior of Blink. In a zealous attempt to make it as close as possible to the original it also "inherits" a flaw. The flaw is that Blink doesn't check if the target position is in the playable map area, BlinkBJ doesn't do either but it can easily be added =).
BlinkBJ requires SimError
BlinkBJ requires SimError
Code:
Credits to Vexorian, DioD, Cohadar and Alexander244.
http://www.wc3c.net/showthread.php?t=96955
globals
sound SimError_Sound = null
real SIMERROR_DEFAULT_DURATION = 2.00
endglobals
function SimError takes player p, string msg, real duration returns nothing
if (GetLocalPlayer() == p) then
call ClearTextMessages()
call DisplayTimedTextToPlayer(p, 0.51, 0.96, duration, "|cffffcc00\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + msg + "|r")
call StartSound(SimError_Sound)
endif
endfunction
function InitTrig_SimError takes nothing returns nothing
set SimError_Sound = CreateSoundFromLabel("InterfaceError", false, false, false, 10, 10)
endfunction
Code:
globals
constant integer BLINKBJ_RAWCODE = 'ABBJ'
constant string BLINKBJ_DEFAULT_EFFECT_CASTER_LOCATION = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
constant string BLINKBJ_DEFAULT_EFFECT_TARGET_POINT_LOCATION = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl"
constant integer BLINKBJ_ERROR_TERRAIN_IS_MASKED = 10
constant string BLINKBJ_ERROR_TERRAIN_IS_MASKED_MESSAGE = "Must explore there first."
constant integer BLINKBJ_ERROR_WITHIN_MINIMUM_RANGE = 20
constant string BLINKBJ_ERROR_WITHIN_MINIMUM_RANGE_MESSAGE = "Target is inside minimum range."
constant integer BLINKBJ_ERROR_INVALID_TARGET_POINT = 30
constant string BLINKBJ_ERROR_INVALID_TARGET_POINT_MESSAGE = "Unable to target there."
constant integer BLINKBJ_ERROR_CASTER_DISABLED_MOVEMENT = 40
constant string BLINKBJ_ERROR_CASTER_DISABLED_MOVEMENT_MESSAGE = "Caster movement has been disabled."
constant integer BLINKBJ_SUCCESS = 1
endglobals
//function UnitResetAbilityCooldown takes unit u, integer abilityid returns nothing
// local integer level = GetUnitAbilityLevel(u, abilityid)
// call UnitRemoveAbility(u, abilityid)
// call UnitAddAbility(u, abilityid)
// call SetUnitAbilityLevel(u, abilityid, level)
//endfunction
function BlinkBJClearSideEffects takes unit u returns nothing
call IssueImmediateOrder(u, "stop")
call TriggerSleepAction(0.0)
call SetUnitAnimation(u, "stand")
endfunction
function BlinkBJ takes string effect_caster_loc, string effect_target_point_loc, real min_range, real max_travel_range, unit hero_nakamura, real target_pointx, real target_pointy, string hotkey returns integer
local player hero_owner = GetOwningPlayer(hero_nakamura)
local real casterx = GetUnitX(hero_nakamura)
local real castery = GetUnitY(hero_nakamura)
local real dx
local real dy
local real range
local real angle
local real blinkendx
local real blinkendy
local boolean hero_is_invul
if IsMaskedToPlayer(target_pointx, target_pointy, hero_owner) then
call BlinkBJClearSideEffects(hero_nakamura)
call ForceUIKey(hotkey)
call SimError(hero_owner, BLINKBJ_ERROR_TERRAIN_IS_MASKED_MESSAGE, SIMERROR_DEFAULT_DURATION)
return BLINKBJ_ERROR_TERRAIN_IS_MASKED
endif
set dx = target_pointx - casterx
set dy = target_pointy - castery
set range = SquareRoot(dx * dx + dy * dy)
set angle = Atan2(dy, dx)
if range < min_range then
call BlinkBJClearSideEffects(hero_nakamura)
call ForceUIKey(hotkey)
call SimError(hero_owner, BLINKBJ_ERROR_WITHIN_MINIMUM_RANGE_MESSAGE, SIMERROR_DEFAULT_DURATION)
return BLINKBJ_ERROR_WITHIN_MINIMUM_RANGE
elseif range >= max_travel_range then
set dx = casterx + max_travel_range * Cos(angle)
set dy = castery + max_travel_range * Sin(angle)
else
set dx = casterx + range * Cos(angle)
set dy = castery + range * Sin(angle)
endif
set blinkendx = dx
set blinkendy = dy
if IsMaskedToPlayer(blinkendx, blinkendy, hero_owner) then
call BlinkBJClearSideEffects(hero_nakamura)
call ForceUIKey(hotkey)
call SimError(hero_owner, BLINKBJ_ERROR_INVALID_TARGET_POINT_MESSAGE, SIMERROR_DEFAULT_DURATION)
return BLINKBJ_ERROR_INVALID_TARGET_POINT
endif
// ensnare, roots etc.
if GetUnitMoveSpeed(hero_nakamura) <= 0.0 then
call BlinkBJClearSideEffects(hero_nakamura)
call ForceUIKey(hotkey)
call SimError(hero_owner, BLINKBJ_ERROR_CASTER_DISABLED_MOVEMENT_MESSAGE, SIMERROR_DEFAULT_DURATION)
return BLINKBJ_ERROR_CASTER_DISABLED_MOVEMENT
endif
call DestroyEffect(AddSpecialEffect(effect_caster_loc, casterx, castery))
call SetUnitX(hero_nakamura, blinkendx)
call SetUnitY(hero_nakamura, blinkendy)
call DestroyEffect(AddSpecialEffect(effect_target_point_loc, GetUnitX(hero_nakamura), GetUnitY(hero_nakamura)))
set hero_is_invul = (GetUnitAbilityLevel(hero_nakamura, 'Avul') >= 1)
if not hero_is_invul then
// Add spell ivul to avoid projectiles(storm bolt, death coil etc.)
call UnitAddAbility(hero_nakamura, 'Avul')
endif
// keep the ivul for some fraction of second
// why 0.4? felt like a nice magic number what can I say it's my favorite number 4 div by 10 =)
call TriggerSleepAction(0.4)
if not hero_is_invul then
// remove invul from hero to prevent imba
call UnitRemoveAbility(hero_nakamura, 'Avul')
endif
return BLINKBJ_SUCCESS
endfunction
function BlinkBJ_Action takes nothing returns nothing
local unit caster = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(caster, BLINKBJ_RAWCODE)
local real min_range = 200
local real max_travel_range = (1000 + ((level - 1) * 75)) * 0.75 // 3/4
// http://world-editor-tutorials.thehelper.net/formula.php
// 50 / 10 / 10
//local real mana_cost = 20 * level * level - 100 * level + 130
local location loc = GetSpellTargetLoc()
local real target_pointx = GetLocationX(loc)
local real target_pointy = GetLocationY(loc)
call BlinkBJ(BLINKBJ_DEFAULT_EFFECT_CASTER_LOCATION, BLINKBJ_DEFAULT_EFFECT_TARGET_POINT_LOCATION, min_range, max_travel_range, caster, target_pointx, target_pointy, "B")
call RemoveLocation(loc)
set loc = null
endfunction
//===========================================================================
function BlinkBJ_Condition takes nothing returns boolean
return GetSpellAbilityId() == BLINKBJ_RAWCODE
endfunction
function InitTrig_BlinkBJ takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t, Condition(function BlinkBJ_Condition))
call TriggerAddAction(t, function BlinkBJ_Action)
endfunction