Yet Another Wanna Be MeatHook

RaiJin

New Member
Reaction score
40
JASS:
scope MeatHook initializer MeatHookInit


globals
    private constant integer SPELL_ID   =   'A000'
    private constant integer DUMMY_ID   =   'h001'
    private constant integer MAXHOOKS   =   30
    private constant real    INTERVAL   =   0.03
    private constant real    DISTANCE   =   30.00
    private constant real    COLLISION  =   60.00
endglobals

private struct hook
    unit hooker
    unit snagger
    unit array hooks [30]
    group snaggroup
    location s
    location h
    real offset
    real angle
    real distance
    integer hookline
    boolean snagged
    static hook k
    method Clear takes nothing returns nothing
    call DestroyGroup(.snaggroup)
    call RemoveLocation(.s)
    call RemoveLocation(.h)
    set .snagged=false
    set .offset = 0.00
    set .hookline = 0
    endmethod
endstruct

private function MConditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function MeatHookCondition takes nothing returns boolean
    local hook h = hook.k
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitAliveBJ(GetFilterUnit()) and GetFilterUnit() != h.hooker
endfunction

private function retract takes nothing returns nothing
    local hook h = hook.k
    local location oo
    if h.snagged == true then
        set h.offset = h.offset - DISTANCE
        set oo = PolarProjectionBJ(h.h, h.offset, h.angle)
        call RemoveUnit(h.hooks[h.hookline])
        set h.hookline = h.hookline - 1
        call SetUnitPositionLoc(h.snagger, oo)
        call RemoveLocation(oo)
        set oo=null
        
        if h.hookline <= 0 then
        call PauseTimer(GetExpiredTimer())
        else
        endif
    else
    endif
endfunction

private function TimerActions takes nothing returns nothing
    local hook h = hook.k
    local location o
    set h.offset = h.offset + DISTANCE
    set h.hookline = h.hookline + 1
    set o=PolarProjectionBJ(h.h, h.offset, h.angle)
    set h.distance = DistanceBetweenPoints(o, h.s)
    set h.snaggroup = GetUnitsInRangeOfLocMatching(COLLISION, o, Condition(function MeatHookCondition))
    set h.snagger = GroupPickRandomUnit(h.snaggroup)
    call DestroyGroup(h.snaggroup)
    if h.snagged == false then
        if h.snagger == null then
            set h.hooks[h.hookline] = CreateUnitAtLoc(GetOwningPlayer(h.hooker), DUMMY_ID, o, h.angle)
        elseif h.distance <= COLLISION then
            call PauseTimer(GetExpiredTimer())
            set h.snagged = true
        endif
    else
    endif
endfunction

private function MActions takes nothing returns nothing
    local hook h = hook.create()
    local timer t = CreateTimer()
    local timer t2 = CreateTimer()
    set h.hooker = GetTriggerUnit()
    set h.s = GetSpellTargetLoc()
    set h.h = GetUnitLoc(h.hooker)
    set h.angle = AngleBetweenPoints(h.h, h.s)
    call TimerStart(t, INTERVAL, true, function TimerActions)
    call TimerStart(t2, INTERVAL, true, function retract)
endfunction

//===========================================================================
public function MeatHookInit takes nothing returns nothing
    local trigger Meathook = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Meathook, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Meathook, Condition( function MConditions ) )
    call TriggerAddAction( Meathook, function MActions )
endfunction

endscope


mkay so basically he doesn't create any hooks at all o_O nothing even happens. I really dont know why... the last time i tried this it worked O_O

why im not using x and y's ? because im still trying to learn how to use them xD AND HUGE THANKS TO PEOPLE that took there time to tell me how to use x and y's THANKS!!!<3:thup::):D:D:D:D:D:D
 

Tom Jones

N/A
Reaction score
437
Your not passing the struct from one function to another. Locals go out of scope when a thread ends.
 

RaiJin

New Member
Reaction score
40
JASS:
scope MeatHook initializer MeatHookInit


globals
    private constant integer SPELL_ID   =   &#039;A000&#039;
    private constant integer DUMMY_ID   =   &#039;h001&#039;
    private constant integer MAXHOOKS   =   30
    private constant real    INTERVAL   =   0.03
    private constant real    DISTANCE   =   30.00
    private constant real    COLLISION  =   100.00
endglobals

private struct hook
    unit hooker
    unit snagger
    unit array hooks [MAXHOOKS]
    group snaggroup
    location s
    real cos
    real sin
    real x
    real y
    real x2
    real y2
    real newx
    real newy
    real offset
    real angle
    real distance
    integer hookline
    boolean snagged
    static hook k
    method Clear takes nothing returns nothing
    call DestroyGroup(.snaggroup)
    call RemoveLocation(.s)
    set .snagged=false
    set .offset = 0.00
    set .hookline = 0
    endmethod
endstruct

private function MConditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function MeatHookCondition takes nothing returns boolean
    local hook h = hook.k
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitAliveBJ(GetFilterUnit())
endfunction

private function retract takes nothing returns nothing
    local hook h = hook.k
    local real minx
    local real miny
    local real sx
    local real sy
    local timer t3 = GetExpiredTimer()
    set sx = GetUnitX(h.snagger)
    set sy = GetUnitY(h.snagger)
    if h.snagged == true then
        call RemoveUnit(h.hooks[h.hookline])
        set h.hookline = h.hookline - 1
        set h.newx = sx - h.offset * h.cos
        set h.newy = sy - h.offset * h.sin
        call SetUnitX(h.snagger, h.newx)
        call SetUnitY(h.snagger, h.newy)
        if h.hookline == 0 then
        call PauseTimer(GetExpiredTimer())
        set t3 = null
        call h.Clear()
        else
        endif
    else
    endif
endfunction

private function TimerActions takes nothing returns nothing
    local hook h = hook.k
    local real newx
    local real newy
    local real xx
    local real yy
    local timer tim = GetExpiredTimer()
    set h.hookline = h.hookline + 1
    set h.offset = h.offset + DISTANCE
    set h.newx = h.x + h.offset * h.cos
    set h.newy = h.y + h.offset * h.sin
    set xx = h.x2 - h.newx
    set yy = h.y2 - h.newy
    set h.distance = SquareRoot((xx * xx) + (yy * yy))
    set h.snaggroup = CreateGroup()
    call GroupEnumUnitsInRange(h.snaggroup, h.newx, h.newy, COLLISION, Condition(function MeatHookCondition))
    set h.snagger = GroupPickRandomUnit(h.snaggroup)
    if h.snagged == false then
        if h.snagged == null then
            set h.hooks[h.hookline] = CreateUnit(GetOwningPlayer(h.hooker), DUMMY_ID, h.newx, h.newy, h.sin)
            call SetUnitFacingTimed(h.hooks[h.hookline], h.angle * bj_RADTODEG,0)
        else
            set h.snagged = true
            call PauseTimer(GetExpiredTimer())
            set tim = null
            return
        endif
        if h.distance &lt;= COLLISION then
            set h.snagged = true
            call PauseTimer(GetExpiredTimer())
            set tim = null
        else
        endif
    else
    endif
endfunction

private function MActions takes nothing returns nothing
    local hook h = hook.create()
    local timer t = CreateTimer()
    local timer t2 = CreateTimer()
    local real tx
    local real ty
    local location unitloc
    local location sl
    set hook.k = h
    set h.hooker = GetTriggerUnit()
    set unitloc = GetUnitLoc(h.hooker)
    set sl = GetSpellTargetLoc()
    set h.x = GetUnitX(h.hooker)
    set h.y = GetUnitY(h.hooker)
    set h.x2 = GetLocationX(sl)
    set h.y2 = GetLocationY(sl)
    set tx = h.x2 - h.x
    set ty = h.y2 - h.y
    set h.angle = Atan2(ty, tx)
    set h.cos = Cos(h.angle)
    set h.sin = Sin(h.angle)
    set h.s = PolarProjectionBJ(unitloc, 1000.00, h.sin)
    call RemoveLocation(unitloc)
    call RemoveLocation(sl)
    set sl=null
    set unitloc=null
    call TimerStart(t, INTERVAL, true, function TimerActions)
    call TimerStart(t2, INTERVAL, true, function retract)
endfunction

//===========================================================================
public function MeatHookInit takes nothing returns nothing
    local trigger Meathook = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Meathook, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Meathook, Condition( function MConditions ) )
    call TriggerAddAction( Meathook, function MActions )
endfunction

endscope


EDIT: Problem is ... unit doesn't retract properly.. what i mean is that he just disappears whenever hes snagged. 2nd Problem is the hooks take like 1 second to turn to the proper angle.. and u can fully see them turning which is kinda lame..
 

saw792

Is known to say things. That is all.
Reaction score
280
Change the turning rate in the dummy unit's object editor entry, or just set them to be facing h.angle * bj_RADTODEG when you create them.
 

RaiJin

New Member
Reaction score
40
OMG damit im so shit when it comes to object editor xD sorry bear with me please T_T

Last question :) How do i do like X and Y offset but going backwards?

as you can see in my trigger the hook goes foward.. i want it to retract the same path. so what would the formula be?

SO this would be offset going foward..

JASS:
    set h.newx = h.x + h.offset * h.cos
set h.newy = h.y + h.offset * h.sin


JASS:
    set h.newx = h.x - h.offset * h.cos
set h.newy = h.y - h.offset * h.sin


would that be correct?
 

saw792

Is known to say things. That is all.
Reaction score
280
Either that, or reverse the angle. The way you suggested would be easier though.
 

RaiJin

New Member
Reaction score
40
shit i got it lol xD it came to me as soon as i turned off my computer for the night lol
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top