HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Meat Hook Spell

03-02-2007, 10:25 AM#1
Fulla
one of the admins/mods on thehelper, posted a meathook spell, unfortunetly it was in handles, so I tried to convert it to tables which I use.

I got it semi working, except the actual 'hook' itself doesnt get destroyed.
I cant figure it out.

Collapse JASS:
//RAWCODE FUNCTIONS

constant function HookUnit takes nothing returns integer
    return 'u006'
endfunction

constant function HookDistance_Limit takes nothing returns real
    return 1000.00 //maximum range of hook
endfunction

constant function HookRange takes nothing returns real
    return 75.00 //distance between chain and hooked unit
endfunction

constant function HookDistances takes nothing returns real
    return 25.00 //distance between two chains of the hook
endfunction

//********************
//CONDITION FUNCTIONS

function HookFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), TempPlayer) and GetWidgetLife(GetFilterUnit())>0.00 and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)==false
endfunction

function Trig_Meathook_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A0DE'
endfunction

//*****************
//ACTION FUNCTIONS

function HookGrab takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local string s = GetAttachmentTable(t)
    local unit prev = GetTableUnit(s, "prev")
    local unit cast = GetTableUnit(s, "cast")
    local unit hook = GetTableUnit(s, "hook")
    local real dist = GetTableReal(s, "dist")
    local unit targ = GetTableUnit(s, "targ")
    local real angle = GetTableReal(s, "angle")
    local real PolarX = GetUnitX(cast) + dist * Cos(angle)
    local real PolarY = GetUnitY(cast) + dist * Sin(angle)

    call SetTableObject(s, "hook", prev)
    //call FlushHandleLocals(hook) 
    call RemoveUnit(hook)
    set hook = null
    
    call SetUnitPosition(targ, PolarX, PolarY)
    
    if dist<=10.00 then
        //call FlushHandleLocals(t)
        call PauseTimer(t)
        call DestroyTimer(t)
    else  
    call SetTableReal(s, "dist", dist-HookDistances())
    endif
    
    set targ = null
    set cast = null
    set hook = null  
endfunction

function MeatHookCreate takes nothing returns nothing
local timer t = GetExpiredTimer()
local string s = GetAttachmentTable(t)
local unit prev = GetTableUnit(s, "prev")
local unit cast = GetTableUnit(s, "cast")
local real angle = GetTableReal(s, "angle")   
local real dist = GetTableReal(s, "dist") 
local real PolarX = GetUnitX(cast) + dist * Cos(angle)
local real PolarY = GetUnitY(cast) + dist * Sin(angle)
local unit hook = CreateUnit(GetOwningPlayer(cast), HookUnit(), PolarX, PolarY, bj_RADTODEG*angle)
local group aux = CreateGroup()
local timer trix// = CreateTimer()
local string srix// = GetAttachmentTable(trix)
local real count = 0
local unit targ = null
local real newdist = dist + HookDistances()

//call SetTableObject(srix, "prev", prev)
set TempPlayer = GetOwningPlayer(cast)
call GroupEnumUnitsInRange(aux, PolarX, PolarY, HookRange(), Condition(function HookFilter))
set count = CountUnitsInGroup(aux)
if count>0 then
    set targ = GroupPickRandomUnit(aux)
endif

if count>0 or dist>=HookDistance_Limit() then
    call PauseTimer(t)
    call DestroyTimer(t)
    //call FlushHandleLocals(t)
    set trix = CreateTimer()
    set srix = GetAttachmentTable(trix)
    call SetTableObject(srix, "cast", cast)
    call SetTableObject(srix, "targ", targ)
    call SetTableReal(srix, "dist", dist)
    call SetTableObject(srix, "hook", hook)
    call SetTableReal(srix, "angle", angle)
    call TimerStart(trix, 0.01, true, function HookGrab)  
else
    call SetTableReal(s, "dist", newdist)
    call SetTableObject(s, "prev", hook)
endif
call DestroyGroup(aux)
set hook = null
set prev = null
set targ = null
set aux = null
set cast = null    
endfunction

function Trig_Meathook_Actions takes nothing returns nothing

local unit cast = GetTriggerUnit()
local real X = GetLocationX(GetSpellTargetLoc())
local real Y = GetLocationY(GetSpellTargetLoc())
local timer t = CreateTimer()
local string s = GetAttachmentTable(t)
local real angle = Atan2(Y-GetUnitY(cast),X-GetUnitX(cast))

call SetTableObject(s, "cast", cast)
call SetTableObject(s, "prev", null)
call SetTableReal(s, "angle", angle)
call SetTableReal(s, "dist", 0.25)
call TimerStart(t, 0.01, true, function MeatHookCreate)

call RemoveLocation(GetSpellTargetLoc())
set cast = null
endfunction

//===========================================================================
function InitTrig_Meathook takes nothing returns nothing
    set gg_trg_Meathook = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Meathook, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Meathook, Condition( function Trig_Meathook_Conditions ) )
    call TriggerAddAction( gg_trg_Meathook, function Trig_Meathook_Actions )
endfunction

thx for anyhelp.
03-02-2007, 10:31 AM#2
Toink
Don't see anything wrong here.

Try to convert each trigger into JASS, then cnp each function in order in a new trigger. Then slowly work your way up and try to understand how it works.
03-02-2007, 11:35 AM#3
Fulla
hmm it already is in jass?

Yea I went over it several times thou, I semi understand how hes done it, but not sure how hes intended to destroy the chain/hooks 1by1 when it returns to the caster.
03-02-2007, 12:03 PM#4
Szythe
Why not just make the hook units an array, and create them in order (1, 2, 3...) and have an integer variable with the total number of hooks. Then when it hits a unit go backward through the array (44, 43, 42...) and remove them that way. Sorry if this doesn't apply, or is just stupid. I didn't have the time to read through your code at all.
03-03-2007, 08:52 AM#5
Brash
i made a gui one for my map.. let me know if you need.. i dont know jass so can't help you with that code there.
03-03-2007, 09:19 AM#6
Toink
In the meat hook create, you store the hook in an array, so that when someone's grabbed you can destroy them.

EDIT: You also set the hook = null twice in the Hook Grab function, waste of lines.
03-03-2007, 10:55 AM#7
Fulla
thx for help guys, I managed to fix it now thou:D