• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Problem with EVENT_PLAYER_UNIT_ATTACKED

Status
Not open for further replies.
Level 3
Joined
Sep 14, 2007
Messages
43
my problem is that whenever the attacking unit is even starting to attack (without ever finishing the move) the trigger is launched.
Here is my trigger, if you find any bugs or know a way around my problem please help me:

JASS:
function EC_t_Actions takes nothing returns nothing
local unit u = GetHandleUnit(GetTriggeringTrigger(),"u")
local unit dummy
local unit a = GetAttacker() 
local unit attacked = GetTriggerUnit()
local integer level
if(a == u) then
set dummy = CreateUnit(GetOwningPlayer(u),'h014',GetUnitX(u),GetUnitY(u),1)
set level = GetUnitAbilityLevel(u,'A04C')
call UnitAddAbility(dummy,'A04E')
call SetUnitAbilityLevel(dummy,'A04E',level)
call IssueTargetOrder(dummy, "forkedlightning", attacked)
endif
set u = null
set a = null
call RemoveUnit(dummy)
set dummy = null
set attacked = null
endfunction

function Trig_Electric_Charge_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A04C' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Electric_Charge_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local trigger EC = CreateTrigger()
local integer level = GetUnitAbilityLevel(u,'A04C')
if(GetUnitTypeId(u) == 'N02G') then
call TriggerRegisterAnyUnitEventBJ( EC, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddAction(EC, function EC_t_Actions)
call SetHandleHandle(EC,"u",u)
call TriggerSleepAction(20.3)
endif
call DestroyTrigger(EC)
set u = null
endfunction

//===========================================================================
function InitTrig_Electric_Charge takes nothing returns nothing
    set gg_trg_Electric_Charge = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Electric_Charge, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Electric_Charge, Condition( function Trig_Electric_Charge_Conditions ) )
    call TriggerAddAction( gg_trg_Electric_Charge, function Trig_Electric_Charge_Actions )
endfunction
 
Before reading your code: you've hit one of the biggest problems in attack detection. Its (nigh) impossible to accurately detect when a unit finishes an attack. That event fires when a unit starts an attack. There are many (not perfect) solutions to that problem, search around.
 
It is possible to get the moment a unit gets actually hurt by another by using
JASS:
call TriggerRegisterUnitEvent( YourTrigger, UnitThatIsAttacked, EVENT_UNIT_DAMAGED )
Here you can already see the problem with this event: You'll have to add the event for every unit, that may be attacked, but we are lucky that this is not a big problem in JASS. :wink:

PS: indent your code, that makes it much easier to read, especially for others who do not yet know your script!
 
Just add a condition and the problem is gone, isn't it?
At least it works, even if not very economic.

Another possibility would be to use the
JASS:
call TriggerRegisterAnyUnitEventBJ( EC, EVENT_PLAYER_UNIT_ATTACKED )
and use a timer that makes it wait the required time, but that's so difficult to script until it runs as it should, that I doubt that it is worth the effort.
By the way, this will fire every time unit gets attacked, what is not much less often than the event that a unit gets damage.
How would you combine these events?
 
A quick question, is it possible to get the damaging unit with the EVENT_UNIT_DAMAGED event? If its possible then I would be very happy. (Also if it is possible, whats the function that returns the damaging unit?)

Edit: Changed it to the event I meant to say.
 
Last edited:
Ok since I was so tired I wrote about the wrong event, I meant to say EVENT_UNIT_DAMAGED. Unfortunitly the GetAttacker() doesn't seem to work for EVENT_UNIT_DAMAGED. Though thats what I was looking for. Its a shame it doesn't work. Does anyone know anything that will return the damaging unit?
 
Status
Not open for further replies.
Back
Top