• 🏆 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!

Creating a Unit that acts like a Tower (Pseudo-Building)

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,567
Alright, so I'm trying to create a Unit with these properties (it's basically a Guard Tower with special behaviors):

1) It cannot move normally BUT it can be moved with triggers using SetUnitX/Y.
2) It cannot turn.
3) It cannot attack but it can acquire targets. I use a custom missile system to make my own attacks.

I've managed to get everything working besides the Turning, here's my code so far:
Lua:
    Tower = CreateUnit(Player(0), FourCC("h001"), 0, 0, 270)
    SetUnitTurnSpeed(Tower, 0) --Supposed to prevent turning but it doesn't really work
    SetUnitPropWindow(Tower, 0) --Prevents moving, works fine


This is to prevent the player from issuing orders to their Tower. I realize this will apply to ALL units but I'll change that in the future.
Lua:
    local trig = CreateTrigger()
    TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    TriggerAddAction( trig, function ()
        local o = GetIssuedOrderId()
        if o == String2OrderIdBJ("move") or o == String2OrderIdBJ("smart") then
            local u = GetTriggerUnit()
            IssueImmediateOrder(u, "stop")
        end
    end)


The Tower attacks using a custom missile system that I made. I take advantage of the Acquire Target Event since this runs at the exact moment that my Unit finds an eligible target within it's range. This means that my Tower has an Attack enabled since you cannot acquire targets without one, but I interrupt this attack so that it never happens. Instead, my custom missile system kicks in and mimics the behavior of Warcraft 3's attack-projectile system.
Lua:
    local trig = CreateTrigger()
    TriggerRegisterUnitEvent(trig, Tower, EVENT_UNIT_ACQUIRED_TARGET)
    TriggerAddAction( trig, function ()
        local u = GetTriggerUnit()
        local t = GetEventTargetUnit()
        local model = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
        local effect = function ()
            UnitDamageTarget(u, t, 250, false, true, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, nil)
        end

        Missile_Create_Unit(u, t, 900, 200, 30, model, effect) --This launches a missile at the enemy unit

        --Interrupt the attack, disarm the tower, and stun it
        IssueImmediateOrder(u, "stop")
        UnitAddAbility(u, FourCC("A000")) --Disarm (Cargo Hold)
        BlzPauseUnitEx(u, true)

        --This timer acts as the Attack Cooldown
        local timer = CreateTimer()
        TimerStart(timer, 1.00, false, function ()
            --Resume normal behavior
            BlzPauseUnitEx(u, false)
            UnitRemoveAbility(u, FourCC("A000"))
            IssueImmediateOrder(u, "stop")

            PauseTimer(timer)
            DestroyTimer(timer)
        end)

    end)

So everything works properly except for the turning. Despite setting it's turn speed to 0 the Unit is still turning, just very slowly, and not always. It's very odd how it behaves. The Unit won't turn at all for a good 5-6 seconds as it properly attacks and changes targets. But then all of a sudden it will start turning at an extremely slow rate, then randomly snap back to normal. I'm not sure what the deal is there...

Any ideas on how I can prevent it from Turning entirely while also retaining it's ability to:
1) Have an Attack (it just needs to be able to Acquire Targets)
2) Have Movement (SetUnitX/Y doesn't work if you disable Movement)

Or an alternate approach I could use?

Edit:
At the moment I have prevented the Tower from turning using all of the above plus running this after the tower acquires a target:
Lua:
SetUnitFacingTimed(unit, 270, 1.00)
 
Last edited:
Status
Not open for further replies.
Top