HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Detecting when a unit is about to attack?

05-07-2003, 10:44 PM#1
LunarCrisis
In a map I'm making, i'm trying to make it so whenever a unit is about to attack, he casts shockwave instead. I have a trigger that checks whenever he's ordered to attack, but that doesn't trigger when he attacks automatically, or even when you attack by right clicking. How can I set up a trigger that runs whenever a unit attacks another?
05-07-2003, 11:04 PM#2
Guest
I think its
Events
A unit owned by [Player#] is [attacked]

Actions
Order [attacking unit] to [stop]
Order [attacking unit] to [shockwave] [position of [attacked unit]]
05-07-2003, 11:12 PM#3
LunarCrisis
wouldn't that only fire after the unit actually attacks?
05-07-2003, 11:49 PM#4
Mr.Safety
Technically yes. But it'll work. The attack takes about .4 seconds to execute. One he 'attacks' no damage is dealt until the animation is performed. This trigger will catch the unit the moment the attack is started.

My guess is it'll start the attack animation and then immediatly stop. So your units will probably be jumpy when they attack with this trigger. Thats just a guess. But it should work. They shouldn't actually attack.
05-08-2003, 12:11 AM#5
dataangel
Dunno why your order trig isn't working when you attack click, but the reason right clicking doesn't work is because a right click is a different order called "smart"

Also, you can just make the projectile the shockwave model in the unit editor if you just want their attacks to look like that. (keep in mind it won't go through multiple units, have cooldown, or cost mana like a normal shockwave)
05-08-2003, 12:15 AM#6
LunarCrisis
yarg..... i cant delete this double post
05-08-2003, 12:22 AM#7
LunarCrisis
after trying that trigger, the guy stands there trying to cast shockwave, but he never finishes.... he stands still, the shockwave box is lit up like hes using it, but he never actually does it

ps. to dataangel... the reason im using shockwave is for it to go thru a bunch of units. incase noone can guess, im trying to make a lurker unit :)..... this means that the trigger has to be able to fire for every lurker on the map
05-08-2003, 02:32 AM#8
MarSara
Here try this trigger, with this the unit wont appear "jumpy".

I haven't really tested this fully, yet, but it should work. You may need to add a trigger on initlization to set all the arrays to NULL, and the Integer to 0.

This trigger won't affect any units created by triggers or any preplaced units. (just change the Event down at the bottom of the trigger if you need it to affect summons, structures, etc...) Hope this works for you.

Code:
//=============================================
// Trigger:       unit - a unit owned by player x aquires a target
// Script Author: Mar_Sara[LoC]
// Info:          Workaround for the missing event...
// Required Variables:
//     - TrigDeath - Trigger Array
//     - TrigAquireTarg - Trigger Array
//     - TrigIndex - Integer
//=============================================
function Trig_AquireTarget_Conditions takes nothing returns boolean
    // Perform any test on target here

    // You can make the Attacking Unit only do something
    // if  the target is of a certain type, has a
    // certain health value, is a hero, etc...
    return true
endfunction

function Trig_AquireTarget_Actions takes nothing returns nothing
    // Add Actions for when unit aquires target here

    // This function executes BEFORE the attacking unit
    // actually attacks.  It runs once you either click
    // on the target, a unit comes within its aqusition
    // range, or you order it to attack.  This will also
    // run if the unit is ordered to attack by triggers.

    // Order the unit to use a spell on the target,
    // tell him to stop, or you could even heal him
endfunction

function Trig_Death_Actions takes nothing returns nothing

    // This function removes any unneeded triggers created
    // via the main trigger, then left-shifts the entire
    // array, allowing more triggers to be created.
    // DO NOT edit this function

    local integer i
    local integer j
    local trigger ThisTrigger

    set ThisTrigger = GetTriggeringTrigger()

    // Find Current Trigger
    set i = 0
    loop
        exitwhen udg_TrigDeath[i] = ThisTrigger
        set i = i + 1
    endloop

    // Delete unneeded Triggers
    call DestroyTrigger( udg_TrigDeath[i] )
    call DestroyTrigger( udg_TrigAquireTarg[i] )

    // Shift Triggers Right of [i] Left 1
    set j = i
    loop
        exitwhen j > udg_TrigIndex
        set udg_TrigDeath[j] = udg_TrigDeath[j+1]
        set udg_TrigAquireTarg[j] = udg_TrigAquireTarg[j+1]
        set j = j + 1
    endloop

    set udg_TrigIndex = udg_TrigIndex - 1

endfunction

function Trig_DisallowAttack_Conditions takes nothing returns boolean
    // Perform any tests on the triggering unit here

    // You can limit the effects for specific types
    // of units, or even units trained from specific 
    // structures/races.

    // if you need to limit it to specific players,
    // change the EVENTS at the bottom to only include
    // the players wanted.

    return true
endfunction

function Trig_DisallowAttack_Actions takes nothing returns nothing

    // This is the main function, it creates all the 
    // triggers used. (DO NOT change any thing here)

    // Depending of the EVENT change to:
    // Structure - GetConstructedStructure()
    // Unit - GetTrainedUnit()
    // Summon - GetSummonedUnit()
    // Rescued Unit - GetRescuer()
    local unit theUnit = GetTrainedUnit()

    // Create Aquire Target Trigger
    set udg_TrigAquireTarg[udg_TrigIndex] = CreateTrigger( )
    call TriggerRegisterUnitEvent( udg_TrigAquireTarg[udg_TrigIndex], theUnit, EVENT_UNIT_ACQUIRED_TARGET )
    call TriggerAddCondition( udg_TrigAquireTarg[udg_TrigIndex], Condition( function Trig_AquireTarget_Conditions ) )
    call TriggerAddAction( udg_TrigAquireTarg[udg_TrigIndex], function Trig_AquireTarget_Actions )

    // Create trigger to remove excess triggers
    set udg_TrigDeath[udg_TrigIndex] = CreateTrigger( )
    call TriggerRegisterUnitEvent( udg_TrigDeath[udg_TrigIndex], theUnit, EVENT_UNIT_DEATH )
    call TriggerAddAction( udg_TrigDeath[udg_TrigIndex], function Trig_Death_Actions )

    set udg_TrigIndex = udg_TrigIndex + 1
endfunction

//===========================================================================
function InitTrig_DisallowAttack takes nothing returns nothing
    set gg_trg_DisallowAttack = CreateTrigger(  )
    //======EVENTS========//
    // Copy this line for all required players. (Also edit the EVENT_PLAYER_UNIT_TRAIN_FINISH for the approate type)
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_DisallowAttack, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH)
    //======CONDITIONS====// (DO NOT edit this line)
    call TriggerAddCondition( gg_trg_DisallowAttack, Condition( function Trig_DisallowAttack_Conditions ) )
    //======ACTIONS=======// (DO NOT edit this line)
    call TriggerAddAction( gg_trg_DisallowAttack, function Trig_DisallowAttack_Actions )
endfunction

EDIT: here's the code with more comments and a major bug was fixed.
05-08-2003, 02:57 AM#9
Guest
Whoa, thats a big trigger. The guy prolly isnt casting shockwave because he keeps trying to attack, so each time the shockwave order is renewed. Try that with a TC, just keep pushing the hotkey and clicking. If you do it fast enough he wont do it.

Try puting a 10 second cooldown for attack.
05-08-2003, 10:57 AM#10
LunarCrisis
whoa sweet marsara! im not too smooth with custom trigger text, so id love it if u could slide a few more comment lines in there so i can tell exactly what its doing.

thx in advance :)