- Joined
- Dec 16, 2007
- Messages
- 252
Meat hook spell by emijl3r.
I dont use JASS but I used his spell in my map and I'm trying to make the meat hook retract if it hits a destructible.
But it doesn't work.
The code:
I dont use JASS but I used his spell in my map and I'm trying to make the meat hook retract if it hits a destructible.
But it doesn't work.
The code:
JASS:
scope MeatHook
globals
private constant integer MH_ID = 'A00F' //Raw code of the Meat Hook ability
private constant integer Hook_Part_ID = 'u001' //Raw code of the Hook Part unit
private constant real Range_Base_Value = 1800 //Formula for hook range = level * Max_Range_Increment + Range_Base_Value
private constant real Max_Range_Increment = 200 //(See above)
private constant real Max_Range = 3000 //A limit for the range of the hook - it will NOT go above this range. Don't want a limit? Then set this value to something... big.
private constant real Dmg_Base = 100 //Formula for hook damage = level * Dmg_Base
private constant real Speed = 40 //The distance between 2 Hook_Part_ID units/how fast the hook goes
private constant real AoE = 115 //How close a target needs to be to be snagged (remember this adds to the total range of the hook)
private constant string Eyecandy = "Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodFootman.mdl" //SFX created on target
endglobals
private struct dat
unit u = GetTriggerUnit()
unit array D[400]
real ang
integer lvl
real rng = Speed
real OX
real OY
integer i
unit p
endstruct
private function Cond takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true and IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING) != true and GetWidgetLife(GetFilterUnit()) > 0.405 and GetFilterUnit() != bj_ghoul[3442]
endfunction
globals
boolean DestructableInRange = false
endglobals
function IsADestructableInRangeEnum takes nothing returns nothing
set DestructableInRange = true
endfunction
function IsADestructableInRange takes real x, real y, real radius returns boolean
local location o = Location(x, y)
set DestructableInRange = false
call EnumDestructablesInCircleBJ(radius, o, function IsADestructableInRangeEnum)
call RemoveLocation(o)
set o = null
return DestructableInRange
endfunction
private function Uncreate takes nothing returns boolean
local dat d = TT_GetData()
local real PX = d.OX + d.rng * Cos(d.ang)
local real PY = d.OY + d.rng * Sin(d.ang)
set d.rng = d.rng - Speed
call RemoveUnit(d.D[d.i])
set d.i = d.i - 1
call SetUnitX(d.p, PX)
call SetUnitY(d.p, PY)
if d.i == 0 then
call SetUnitPathing(d.p, true)
call PauseUnit(d.p, false)
set d.p = null
set d.u = null
call d.destroy()
return true
endif
return false
endfunction
private function Create takes nothing returns boolean
local dat d = TT_GetData()
local real PX = d.OX + d.rng * Cos(d.ang)
local real PY = d.OY + d.rng * Sin(d.ang)
local real r = d.lvl * Max_Range_Increment + Range_Base_Value
local group g
set d.rng = d.rng + Speed
if d.rng < r and d.rng < Max_Range and d.p == null and not(IsADestructableInRange(PX,PY,115.00)) then
set g = CreateGroup()
set bj_ghoul[3442] = d.u
call GroupEnumUnitsInRange(g, PX, PY, AoE, Condition(function Cond))
set d.p = FirstOfGroup(g)
if d.p != null then
call UnitDamageTarget(d.u, d.p, d.lvl * Dmg_Base, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
call DestroyEffect(AddSpecialEffectTarget(Eyecandy, d.p, "origin"))
call SetUnitPathing(d.p, false)
call PauseUnit(d.p, true)
call SetUnitX(d.p, PX)
call SetUnitY(d.p, PY)
endif
set d.D[d.i] = CreateUnit(GetOwningPlayer(d.u), Hook_Part_ID, PX, PY, d.ang * bj_RADTODEG)
set d.i = d.i + 1
call DestroyGroup(g)
set g = null
else
set d.rng = d.rng - Speed
call TT_Start(function Uncreate, d)
return true
endif
return false
endfunction
private function Cast takes nothing returns nothing
local dat d = dat.create()
local location l = GetSpellTargetLoc()
set d.ang = Atan2(GetLocationY(l)-GetUnitY(d.u), GetLocationX(l)-GetUnitX(d.u))
set d.lvl = GetUnitAbilityLevel(d.u, MH_ID)
set d.OX = GetUnitX(d.u)
set d.OY = GetUnitY(d.u)
set d.i = 1
call TT_Start(function Create, d)
call RemoveLocation(l)
set l = null
endfunction
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == MH_ID
endfunction
function InitTrig_Meat_Hook takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(t, Condition( function Conditions ) )
call TriggerAddAction( t, function Cast )
set t = null
endfunction
endscope
Last edited: