• 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.

[Trigger] Riposte/ Counter Attack,

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
While creating a Parry + Counter attack type ability (haven't seen any besides retaliation types in wc3 btw) I didn't think about that I couldn't use unit handle as index so I made a global unit group and thought I'd just save and then load a boolean in the unit group loop instead. For some reason it doesn't work though.

  • Riposte init
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set u = Riposter 0000 <gen>
      • Custom script: call SaveBoolean(udg_hash, GetHandleId(udg_u), 0, true)
  • Riposte 1
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Custom script: local unit udg_u = GetTriggerUnit()
      • Custom script: local unit udg_a = GetAttacker()
      • Custom script: local player udg_p = GetTriggerPlayer()
      • Custom script: local integer udg_id_u = GetHandleId(udg_u)
      • Custom script: local integer udg_id_a = GetHandleId(udg_a)
      • -------- attacked unit has Riptose ability --------
      • Custom script: if LoadBoolean(udg_hash, udg_id_u, 0) then
      • -------- have Riptose ability --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (a is in riposte_unitGroup) Not equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in riposte_unitGroup) Equal to 0
            • Then - Actions
              • Unit - Create 1 Being Attacked (Riposte Dummy Unit) for p at (Center of (Playable map area)) facing Default building facing degrees
              • Custom script: call SaveUnitHandle(udg_hash, udg_id_u, 1, GetLastCreatedUnit())
            • Else - Actions
          • Unit Group - Add a to riposte_unitGroup
          • Custom script: call SaveBoolean(udg_hash, udg_id_u, udg_id_a, true)
          • Unit - Add Riposte Target (Buff Placer) to a
        • Else - Actions
      • Custom script: else
      • -------- does not have Riptose ability --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (a is in riposte_unitGroup) Equal to True
        • Then - Actions
          • Unit Group - Remove a from riposte_unitGroup
        • Else - Actions
      • Custom script: endif
  • Riposte 2
    • Events
      • Game - damageEventTrigger becomes Equal to 1.00
    • Conditions
    • Actions
      • Custom script: local unit udg_u = udg_target
      • Custom script: local unit udg_a = udg_source
      • Custom script: local integer udg_id_u = GetHandleId(udg_u)
      • Custom script: local integer udg_id_a = GetHandleId(udg_a)
      • Custom script: local player udg_p = GetOwningPlayer(udg_u)
      • Custom script: if LoadBoolean(udg_hash, udg_id_u, 0) then
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • damageType Equal to PHYSICAL
        • Then - Actions
          • Unit Group - Remove a from riposte_unitGroup
          • Custom script: call SaveBoolean(udg_hash, udg_id_u, udg_id_a, false)
          • Unit - Remove Riposte Target (Buff Placer) from a
          • Unit - Remove Riposte Target (Slow Aura) buff from a
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in riposte_unitGroup) Equal to 0
            • Then - Actions
              • Custom script: call RemoveUnit(LoadUnitHandle(udg_hash, udg_id_u, 1))
            • Else - Actions
        • Else - Actions
      • Custom script: else
      • Custom script: endif
  • Riposte 3
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Riposte (retaliate)
    • Actions
      • Custom script: local player udg_p = GetTriggerPlayer()
      • Custom script: local unit udg_u = GetTriggerUnit()
      • Custom script: local unit udg_a
      • Custom script: local integer udg_id_u = GetHandleId(udg_u)
      • Custom script: local integer udg_id_a
      • Game - Display to (All players) the text: start
      • Unit Group - Pick every unit in riposte_unitGroup and do (Actions)
        • Loop - Actions
          • Custom script: set udg_a = GetEnumUnit()
          • Custom script: set udg_id_a = GetHandleId(udg_a)
          • Custom script: call DisplayTextToForce( GetPlayersAll(), ( GetUnitName(udg_a) + GetUnitName(udg_u) ))
          • Custom script: if LoadBoolean(udg_hash, udg_id_u, udg_id_a) then
          • Game - Display to (All players) the text: true
          • Unit - Cause u to damage a, dealing 150.00 damage of attack type Spells and damage type Normal
          • Custom script: else
          • Custom script: endif
 

Deleted member 219079

D

Deleted member 219079

Hashtables are slower than variable arrays, use arrays always when possible.

But that's not major as you don't have loop trigger here :)

You shouldn't declare locals on GUI that much, avoid it when possible.

For example, Unit Group - Pick every unit in xxx and do (Actions) will call another function, which has no acces to your current locals.

So try to make as few locals as possible on GUI :)

Edit: Example;
  • My Trigger
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: local unit udg_u = GetTriggerUnit()
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Custom script: call BJDebugMsg(GetUnitName(udg_u))
Converts to -->
JASS:
function Trig_My_Trigger_Func003A takes nothing returns nothing
    call BJDebugMsg(GetUnitName(udg_u))
endfunction

function Trig_My_Trigger_Actions takes nothing returns nothing
    local unit udg_u = GetTriggerUnit()
    call ForGroupBJ( GetUnitsInRectAll(GetPlayableMapRect()), function Trig_My_Trigger_Func003A )
endfunction

//===========================================================================
function InitTrig_My_Trigger takes nothing returns nothing
    set gg_trg_My_Trigger = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_My_Trigger, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_My_Trigger, function Trig_My_Trigger_Actions )
endfunction
 
Level 12
Joined
Nov 3, 2013
Messages
989
yeah, that fixed it. I don't really know how hashtable work but with save/load it sounds like it would be faster to me, I mean instead of going through all the indexes one by one it looks like it just take the two integers provided and get straight to the point. But maybe function calls are that much slower or smth?
 

Deleted member 219079

D

Deleted member 219079

It's all right to use hashtables and they're way more flexible than variable arrays :)

Variable arrays use no function calls to work, so they're the fastest.
 

Deleted member 219079

D

Deleted member 219079

Ofc not, but check the example I posted.
 
Status
Not open for further replies.
Top