• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Dummy Unit - Submission

Status
Not open for further replies.
Level 7
Joined
Apr 17, 2017
Messages
316
Updated:
JASS:
library DummyUnit initializer init
   
   globals
       private hashtable h = InitHashtable()
       private constant real VELOCITY = 1050
       private constant real TIMER_INTERVAL = 0.03
       private constant integer ABIL_ID = 'A000'
       private constant integer DUMMY_UNIT_ID = 'e000'
       private constant integer SHOCKWAVE_ID = 'e001'
       private constant integer TAUREN_ID = 'Otch'
       private constant real Dmg = 100.
   endglobals
   
   scope Part1
   
       public function cast takes nothing returns nothing
           local unit tauren = LoadUnitHandle(h, 0, 0)
           local unit dummy = LoadUnitHandle(h, GetHandleId(tauren), 1)
           
           call IssuePointOrder(dummy, "shockwave", GetUnitX(tauren), GetUnitY(tauren))
           set dummy = null
           set tauren = null
       endfunction
   endscope
   
   scope Part2
   
       public function cast takes nothing returns nothing
           local unit tauren = LoadUnitHandle(h, 0, 0)
           local unit dummy = LoadUnitHandle(h, GetHandleId(tauren), 1)
           local integer i = 1
           local real x
           local real y
           local real x2
           local real y2
           local real dist = 50.
           local real ang
           
           set x = GetUnitX(tauren)
           set y = GetUnitY(tauren)
           call SetUnitX(dummy, x)
           call SetUnitY(dummy, y)
           loop
               exitwhen i > 8
               set ang = ((i*45)*bj_DEGTORAD)
               set x2 = x+dist*Cos(ang)
               set y2 = y+dist*Sin(ang)
               call IssuePointOrder(dummy, "shockwave", x2, y2)
               set i = i + 1
           endloop
           set tauren = null
           set dummy = null
       endfunction
   endscope
   
   scope Part3
   
       private function onloop takes nothing returns nothing
           local timer t = GetExpiredTimer()
           local integer handleid = GetHandleId(t)
           local unit dummy = LoadUnitHandle(h, handleid, 1)
           local real x2 = LoadReal(h, handleid, 2)
           local real y2 = LoadReal(h, handleid, 3)
           local real dx = LoadReal(h, handleid, 4)
           local real dy = LoadReal(h, handleid, 5)
           local real x = LoadReal(h, handleid, 6)
           local real y = LoadReal(h, handleid, 7)
           local real dist
           
            set dist = SquareRoot(((x2-x)*(x2-x))+((y2-y)*(y2-y)))
            set x = x+dx
            set y = y+dy
            call SaveReal(h, handleid, 6, x)
            call SaveReal(h, handleid, 7, y)
            call SetUnitX(dummy, x)
            call SetUnitY(dummy, y)
               if dist < 50.00 then
                   call RemoveUnit(dummy)
                   call PauseTimer(t)
                   call DestroyTimer(t)
                endif
           set dummy = null
           set t = null
       endfunction
       
       public function cast takes nothing returns nothing
           local unit tauren = LoadUnitHandle(h, 0, 0)
           local unit dummy
           local integer i = 1
           local real dist = 50.
           local real ang
           local real x = GetUnitX(tauren)
           local real y = GetUnitY(tauren)
           local real x2
           local real y2
           local real x3
           local real y3
           local real dx
           local real dy
           local real vx
           local real vy
           local integer handleid
           local timer t
           
           loop
               exitwhen i > 8
               set t = CreateTimer()
               set handleid = GetHandleId(t)
               set ang = ((45*i)*bj_DEGTORAD)
               set x2 = x+dist*Cos(ang)
               set y2 = y+dist*Sin(ang)
               set dummy = CreateUnit(Player(0),SHOCKWAVE_ID, x2, y2, ang*bj_RADTODEG)
               call SaveUnitHandle(h, handleid, 1, dummy)
               set x3 = x+1000*Cos(ang)
               set y3 = y+1000*Sin(ang)
               call SaveReal(h, handleid, 2, x3)
               call SaveReal(h, handleid, 3, y3)
               set vx = VELOCITY*Cos(ang)
               set vy = VELOCITY*Sin(ang)
               set dx = vx*TIMER_INTERVAL
               set dy = vy*TIMER_INTERVAL
               call SaveReal(h, handleid, 4, dx)
               call SaveReal(h, handleid, 5, dy)
               call SaveReal(h, handleid, 6, GetUnitX(dummy))
               call SaveReal(h, handleid, 7, GetUnitY(dummy))
               call TimerStart(t, TIMER_INTERVAL, true, function onloop)
               set i = i+1
           endloop
           set dummy = null
           set tauren = null
           set t = null
       endfunction
   endscope
   
   scope Part4
   
       
       private function onloop takes nothing returns nothing
           local timer t = GetExpiredTimer()
           local integer handleid = GetHandleId(t)
           local unit dummy = LoadUnitHandle(h, handleid, 1)
           local real x2 = LoadReal(h, handleid, 2)
           local real y2 = LoadReal(h, handleid, 3)
           local real dx = LoadReal(h, handleid, 4)
           local real dy = LoadReal(h, handleid, 5)
           local real x = LoadReal(h, handleid, 6)
           local real y = LoadReal(h, handleid, 7)
           local group g = LoadGroupHandle(h, handleid, 8)
           local group g2 = LoadGroupHandle(h, handleid, 9)
           local real dist
           local unit target
           local unit tauren = LoadUnitHandle(h, 0, 0)
           
            set dist = SquareRoot(((x2-x)*(x2-x))+((y2-y)*(y2-y)))
            set x = x+dx
            set y = y+dy
            call SaveReal(h, handleid, 6, x)
            call SaveReal(h, handleid, 7, y)
            call SetUnitX(dummy, x)
            call SetUnitY(dummy, y)
           call GroupEnumUnitsInRange(g, x, y, 125, null)
           loop
               set target = FirstOfGroup(g)
               exitwhen target == null
               if not IsUnitInGroup(target, g2) then
                   if IsUnitEnemy(target, GetOwningPlayer(tauren)) then
                       call GroupAddUnit(g2, target)
                       call UnitDamageTarget(tauren, target, Dmg, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, null)
                   endif
               endif
               call GroupRemoveUnit(g, target)
           endloop
           call SaveGroupHandle(h, handleid, 9, g2)
               if dist < 50.00 then
                   call RemoveUnit(dummy)
                   call GroupClear(g2)
                   call PauseTimer(t)
                   call DestroyTimer(t)
                   call DestroyGroup(g)
                   call DestroyGroup(g2)
                endif
           set dummy = null
           set tauren = null
           set target = null
           set g2 = null
           set g = null
           set t = null
       endfunction
   
       public function cast takes nothing returns nothing
           local unit tauren = LoadUnitHandle(h, 0, 0)
           local unit dummy
           local integer i = 1
           local real dist = 50.
           local real ang
           local real x = GetUnitX(tauren)
           local real y = GetUnitY(tauren)
           local real x2
           local real y2
           local real x3
           local real y3
           local real dx
           local real dy
           local real vx
           local real vy
           local integer handleid
           local timer t
           local group g
           local group g2
           
           loop
               exitwhen i > 8
               set t = CreateTimer()
               set handleid = GetHandleId(t)
               set g = CreateGroup()
               call SaveGroupHandle(h, handleid, 8, g)
               set g2 = CreateGroup()
               call SaveGroupHandle(h, handleid, 9, g2)
               set ang = ((45*i)*bj_DEGTORAD)
               set x2 = x+dist*Cos(ang)
               set y2 = y+dist*Sin(ang)
               set dummy = CreateUnit(Player(0),SHOCKWAVE_ID, x2, y2, ang*bj_RADTODEG)
               call SaveUnitHandle(h, handleid, 1, dummy)
               set x3 = x+1000*Cos(ang)
               set y3 = y+1000*Sin(ang)
               call SaveReal(h, handleid, 2, x3)
               call SaveReal(h, handleid, 3, y3)
               set vx = VELOCITY*Cos(ang)
               set vy = VELOCITY*Sin(ang)
               set dx = vx*TIMER_INTERVAL
               set dy = vy*TIMER_INTERVAL
               call SaveReal(h, handleid, 4, dx)
               call SaveReal(h, handleid, 5, dy)
               call SaveReal(h, handleid, 6, GetUnitX(dummy))
               call SaveReal(h, handleid, 7, GetUnitY(dummy))
               call TimerStart(t, TIMER_INTERVAL, true, function onloop)
               set i = i+1
           endloop
           set dummy = null
           set tauren = null
           set t = null
           set g = null
           set g2 = null
       endfunction
   endscope
       
   private function init takes nothing returns nothing
       local trigger tr = CreateTrigger()
       local unit dummy
       local unit tauren
       
       set tauren = CreateUnit(Player(0), TAUREN_ID, 0, 0, 0)
       call SaveUnitHandle(h, 0, 0, tauren)
       set dummy = CreateUnit(Player(0), DUMMY_UNIT_ID, 0, 0, 0)
       call UnitAddAbility(dummy, ABIL_ID)
       call SaveUnitHandle(h, GetHandleId(tauren), 1, dummy)
       call TriggerRegisterPlayerEvent(tr, Player(0), EVENT_PLAYER_END_CINEMATIC)
       call TriggerAddAction(tr, function Part1_cast)
       set dummy = null
       set tauren = null
       set tr = null
   endfunction
endlibrary
 

Attachments

  • Dummy Unit-Submission.w3x
    21.9 KB · Views: 69
Last edited:
How to test different parts? I could only test part 1.

I guess "part1" is "scope 1". It makes no sense to store and to load a unit like this with hashtable, using two constant keys [0][0] ... just use a global then.

Casting shockwaves from part 1 mission isn't casting from tauren's position.

Haven't looked into the rest. Please make an update post at updates.
 
Last edited:
Status
Not open for further replies.
Top