• 🏆 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.
JASS:
library UnitSpawn initializer Init
    globals
        unit Chief
        hashtable h = InitHashtable()
        unit Unit1
        real Real1
        private boolexpr filter
    endglobals
    private function Damage takes nothing returns boolean
        local unit u = GetFilterUnit()
        if IsUnitEnemy(u, GetOwningPlayer(Unit1)) and GetUnitState(u, UNIT_STATE_LIFE) > 0 then
            call UnitDamageTarget(Unit1, u, Real1, true, true, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        endif
        return false
    endfunction
    private function Periodic takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer i = GetHandleId(t)
        local integer ii = LoadInteger(h, i, 0)
        local real spd = LoadReal(h, i, ii + 2)
        local real aoe = LoadReal(h, i, ii + 5)
        local integer dst = LoadInteger(h, i, ii + 4)
        local integer l = 0
        local real x
        local real y
        local real a
        local unit u
        local group g
        set Unit1 = LoadUnitHandle(h, i, ii + 1)
        set Real1 = LoadReal(h, i, ii + 3)
        set dst = dst - 1
        if dst > 0 then
            call SaveInteger(h, i, ii + 4, dst)
            loop
                exitwhen l == ii
                set l = l + 1
                set u = LoadUnitHandle(h, i, l)
                set a = GetUnitFacing(u) * bj_DEGTORAD
                set x = GetUnitX(u) + spd * Cos(a)
                set y = GetUnitY(u) + spd * Sin(a)
                call SetUnitX(u, x)
                call SetUnitY(u, y)
                set g = CreateGroup()
                call GroupEnumUnitsInRange(g, x, y, aoe, filter)
                call DestroyGroup(g)
            endloop
        else
            loop
                exitwhen l == ii
                set l = l + 1
                call RemoveUnit(LoadUnitHandle(h, i, l))
            endloop
            call DestroyTimer(t)
            call FlushChildHashtable(h, i)
        endif
        set t = null
        set u = null
        set g = null
    endfunction
    function Shock takes unit u, integer wavs returns nothing
        local timer t = CreateTimer()
        local integer i = GetHandleId(t)
        local integer ii = wavs
        local real a = 360 / ii
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local player p = GetOwningPlayer(u)
        call SaveInteger(h, i, 0, ii)
        call SaveUnitHandle(h, i, ii + 1, u)
        call SaveReal(h, i, ii + 2, 31.25)//speed
        call SaveReal(h, i, ii + 3, 3.125)//damage
        call SaveInteger(h, i, ii + 4, 32)//distance
        call SaveReal(h, i, ii + 5, 192)//aoe
        loop
            exitwhen ii == 0
            call SaveUnitHandle(h, i, ii, CreateUnit(p, 'h000', x, y, a * ii))
            set ii = ii - 1
        endloop
        call TimerStart(t, .03125, true, function Periodic)
        set t = null
    endfunction
    private function Esc takes nothing returns boolean
        call Shock(Chief, 8)
        return false
    endfunction
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        set filter = Condition(function Damage)
        call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddCondition(t, function Esc)
        set Chief = CreateUnit(Player(0), 'Otch', 0, 0, 0)
    endfunction
endlibrary


//Code indented using The_Witcher's Script Language Aligner
//Download the newest version and report bugs at www.hiveworkshop.com
 

Attachments

  • Dummy Unit.w3x
    15.6 KB · Views: 53
Last edited:
The map code is not indented. I would recommand to get used to indenting code yourself.

Using arbitary literals like "32" for distance is confusing in code, it makes things hard to follow.

The "GetUnitState(u, UNIT_STATE_LIFE) > 0" is not the best way to check if a unit is dead, try to improve it.

Groups don't need to be destoyed/re-created always, you can reuse one global group, as optimization.

Instead of working with generic globals and filter func, you might as well use just your locals, and work with a FoG loop.

The part with dummy casting is required, too.
 
Status
Not open for further replies.
Top