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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top