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

Spell Request

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
Make a new trigger.
Event: A unit is issued an order with no target
Conditions: (Issued order) equal to (Order(defend))
Actions:
- Set TempBoolean = false
- Set TempUnit = Triggering Unit
- Set TempLocation = Position of TempUnit
- Custom Script: "set bj_wantDestroyGroup = true"
- Pick every unit in ... range of TempLocation
---- If
------- unit is alive and unittype is equal to ...
---- Then
------- Set TempBoolean = true
- If
---- TempBoolean is equal to false
- Then
---- Custom Script: "call IssueImmediateOrderDelayed(udg_TempUnit, "stop", 0)"
---- Set TempForce = (Player Group(Owner of TempUnit))
---- Cinematic - Clear the screen of text messages for TempForce
---- Game - Display to TempForce the text: "No ... unit is near."
---- Custom Script: "call DestroyForce(udg_TempForce)"
- Custom Script: "call RemoveLocation(udg_TempLocation)"

To make this work, you need my Delayed Order Snippet:
JASS:
globals
    hashtable udg_DelayedOrder_Hashtable        = InitHashtable()
    integer udg_DelayedOrder_TypeTarget         = 1
    integer udg_DelayedOrder_TypePointTarget    = 2
    integer udg_DelayedOrder_TypeTrain          = 3
    integer udg_DelayedOrder_TypeNoTarget       = 4
endglobals





library delayedorder
    function IssueOrderCallback takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer id = GetHandleId(t)
        local unit whichUnit = LoadUnitHandle(udg_DelayedOrder_Hashtable, id, 0)
        local integer orderType = LoadInteger(udg_DelayedOrder_Hashtable, id, 1)
        local string order = LoadStr(udg_DelayedOrder_Hashtable, id, 2)
        local widget targetWidget
        local location targetLocation
        local integer unitTypeId
        
        if orderType == udg_DelayedOrder_TypeTarget then
            set targetWidget = LoadWidgetHandle(udg_DelayedOrder_Hashtable, id, 3)
            call IssueTargetOrder(whichUnit, order, targetWidget)
            set targetWidget = null
        elseif orderType == udg_DelayedOrder_TypePointTarget then
            set targetLocation = LoadLocationHandle(udg_DelayedOrder_Hashtable, id, 3)
            call IssuePointOrder(whichUnit, order, GetLocationX(targetLocation), GetLocationY(targetLocation))
            call RemoveLocation(targetLocation)
            set targetLocation = null
        elseif orderType == udg_DelayedOrder_TypeTrain then
            set unitTypeId = LoadInteger(udg_DelayedOrder_Hashtable, id, 3)
            call IssueImmediateOrderById(whichUnit, unitTypeId)
        elseif orderType == udg_DelayedOrder_TypeNoTarget then
            call IssueImmediateOrder(whichUnit, order)
        endif
        
        call FlushChildHashtable(udg_DelayedOrder_Hashtable, id)
        call DestroyTimer(t)
        set t = null
        set whichUnit = null
    endfunction
    function IssueTargetOrderDelayed takes unit whichUnit, string order, widget targetWidget, real delay returns nothing
        local timer t = CreateTimer()
        local integer id = GetHandleId(t)
        
        call TimerStart(t, delay, false, function IssueOrderCallback)
        call SaveUnitHandle(udg_DelayedOrder_Hashtable, id, 0, whichUnit)
        call SaveInteger(udg_DelayedOrder_Hashtable, id, 1, udg_DelayedOrder_TypeTarget)
        call SaveStr(udg_DelayedOrder_Hashtable, id, 2, order)
        call SaveWidgetHandle(udg_DelayedOrder_Hashtable, id, 3, targetWidget)
        
        set t = null
    endfunction
    function IssuePointOrderDelayed takes unit whichUnit, string order, location targetLocation, real delay returns nothing
        local timer t = CreateTimer()
        local integer id = GetHandleId(t)
        
        call TimerStart(t, delay, false, function IssueOrderCallback)
        call SaveUnitHandle(udg_DelayedOrder_Hashtable, id, 0, whichUnit)
        call SaveInteger(udg_DelayedOrder_Hashtable, id, 1, udg_DelayedOrder_TypePointTarget)
        call SaveStr(udg_DelayedOrder_Hashtable, id, 2, order)
        call SaveLocationHandle(udg_DelayedOrder_Hashtable, id, 3, targetLocation)
        
        set t = null
    endfunction
    function IssueTrainOrderDelayed takes unit whichUnit, integer unitTypeId, real delay returns nothing
        local timer t = CreateTimer()
        local integer id = GetHandleId(t)
        
        call TimerStart(t, delay, false, function IssueOrderCallback)
        call SaveUnitHandle(udg_DelayedOrder_Hashtable, id, 0, whichUnit)
        call SaveInteger(udg_DelayedOrder_Hashtable, id, 1, udg_DelayedOrder_TypeNoTarget)
        call SaveInteger(udg_DelayedOrder_Hashtable, id, 3, unitTypeId)
        
        set t = null
    endfunction
    function IssueImmediateOrderDelayed takes unit whichUnit, string order, real delay returns nothing
        local timer t = CreateTimer()
        local integer id = GetHandleId(t)
        
        call TimerStart(t, delay, false, function IssueOrderCallback)
        call SaveUnitHandle(udg_DelayedOrder_Hashtable, id, 0, whichUnit)
        call SaveInteger(udg_DelayedOrder_Hashtable, id, 1, udg_DelayedOrder_TypeNoTarget)
        call SaveStr(udg_DelayedOrder_Hashtable, id, 2, order)
        
        set t = null
    endfunction
endlibrary

If you dont have JNGP, then remove the library and endlibrary tags and place the code in the header file.
Also make the global variables in the variable list.
If you do have JNGP, which I highly recommend, you can just make a trigger, Edit -> Convert to custom text, and place this code into it.

However, this only prevents them from activating spells.
For toggleable spells, like defend, you can activate it and then run away from the tower.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
There is actually another problem with Defend on this matter... it is instant cast so it cannot be interrupted I guess.

But here is a map where the defend and flare can only be cast if an Allied Guard Tower is nearby.
 

Attachments

  • Restrict Defend.w3x
    20.2 KB · Views: 52
Status
Not open for further replies.
Top