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

Entering/Leaving Combat

Status
Not open for further replies.
Level 10
Joined
Nov 3, 2009
Messages
687
Hello,

Have one question, is it possible to make entering/leaving combat system? (Like world of warcraft.. you enter combat then you cant do some spells or eat only when out of combat) if it possible then how?

Thank you!

~Spoontoobig :ogre_hurrhurr:
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
It's actually very easy to create.

It could be as simple as this:

Detect when unit takes damage, add unit to "in combat group". Create some sort of timer for the unit, and when it expires, check if there are enemies close by. If there are, you can refresh the timer with some value. Each time the unit takes damage, the timer is refreshed.

I can create it if I can solve one other problem first.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Try this. It affects heroes only. Heroes can't cast spells while in combat.

When you take damage or an enemy is close to you, you are in combat.

You can configure the "in combat" duration and range.


  • InCombat Init
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set InCombatHash = (Last created hashtable)
      • -------- ------------------------------------------------------------ --------
      • -------- When a unit takes damage, this is how long it will stay in combat after that --------
      • -------- ------------------------------------------------------------ --------
      • Set InCombatDmgDur = 8
      • -------- ------------------------------------------------------------ --------
      • -------- If any enemy is closer than this, you the unit is in combat --------
      • -------- ------------------------------------------------------------ --------
      • Set InCombatEnemyDist = 600.00
      • -------- ------------------------------------------------------------ --------
      • -------- When an enemy is detected to be nearby, this is how long the unit will stay in combat --------
      • -------- ------------------------------------------------------------ --------
      • Set InCombatEnemyDur = 4
      • -------- ------------------------------------------------------------ --------
      • -------- When an enemy is detected to be nearby, this is how long the unit will stay in combat --------
      • -------- ------------------------------------------------------------ --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to NotInCombat
          • Trigger - Add to InCombatAdd 1 <gen> the event (Unit - (Picked unit) Takes damage)
  • InCombat Cast
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • ((Triggering unit) is in InCombatGroup) Equal to True
    • Actions
      • Unit - Order (Triggering unit) to Stop
      • Game - Display to (Player group((Owner of (Triggering unit)))) the text: ((|cffffcc00 + Can't cast the spell. The unit is in combat. ) + |r)
  • InCombatAdd 1
    • Events
    • Conditions
    • Actions
      • Set u1 = (Triggering unit)
      • Set u2 = (Damage source)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (u1 is in InCombatGroup) Equal to False
        • Then - Actions
          • Unit Group - Remove u1 from NotInCombat
          • Unit Group - Add u1 to InCombatGroup
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (u2 is A Hero) Equal to True
          • (u2 is in InCombatGroup) Equal to False
        • Then - Actions
          • Unit Group - Remove u2 from NotInCombat
          • Unit Group - Add u2 to InCombatGroup
        • Else - Actions
      • Custom script: call SaveInteger( udg_InCombatHash , GetHandleId(udg_u1) , StringHash("timer") , udg_InCombatDmgDur )
      • Custom script: call SaveInteger( udg_InCombatHash , GetHandleId(udg_u2) , StringHash("timer") , udg_InCombatDmgDur )
  • InCombat Loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in InCombatGroup and do (Actions)
        • Loop - Actions
          • Set u1 = (Picked unit)
          • Custom script: set udg_i1 = GetHandleId(udg_u1)
          • Custom script: set udg_i2 = LoadInteger( udg_InCombatHash , udg_i1 , StringHash("timer") )
          • Set i2 = (i2 - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • i2 Greater than 0
            • Then - Actions
              • Custom script: call SaveInteger( udg_InCombatHash , udg_i1 , StringHash("timer") , udg_i2 )
            • Else - Actions
              • Unit Group - Add u1 to NotInCombat
              • Unit Group - Remove u1 from InCombatGroup
          • Game - Display to Player Group - Player 1 (Red) the text: ((Proper name of u1) + is in combat.)
      • Unit Group - Pick every unit in NotInCombat and do (Actions)
        • Loop - Actions
          • Set u1 = (Picked unit)
          • Set p1 = (Position of u1)
          • Custom script: set udg_i1 = GetHandleId(udg_u1)
          • Custom script: set bj_wantDestroyGroup = true
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units within InCombatEnemyDist of p1 matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A structure) Equal to False) and (((Matching unit) belongs to an enemy of (Owner of u1)) Equal to True))))) Greater than 0
            • Then - Actions
              • Unit Group - Remove u1 from NotInCombat
              • Unit Group - Add (Picked unit) to InCombatGroup
              • Custom script: call SaveInteger( udg_InCombatHash , udg_i1 , StringHash("timer") , udg_InCombatEnemyDur )
            • Else - Actions
          • Custom script: call RemoveLocation(udg_p1)
          • Game - Display to Player Group - Player 1 (Red) the text: ((Proper name of u1) + is not in combat.)
 

Attachments

  • InCombat.w3x
    19.8 KB · Views: 47
Level 37
Joined
Mar 6, 2006
Messages
9,243
You can do it like this:

  • InCombat Cast
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Triggering unit) is in InCombatGroup) Equal to True
          • Or - Any (Conditions) are true
            • Conditions
              • (Ability being cast) Equal to Animate Dead
              • (Ability being cast) Equal to Avatar
    • Actions
or list the abilities into an array and loop through them:

  • For each (Integer loopA) from 1 to NumberOfAbilities, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Ability Being Cast equal to Abilities[loopA]
        • Then - Actions
          • *your actions*
          • Skip Remaining Actions
        • Else - Actions
 
Level 10
Joined
Nov 3, 2009
Messages
687
Maybe u misunderstand me :). I'll give u an example how it should work:
I start attacking/casting spell
Then I enter combat
When I enter combat, some spells become grey or like passive ant its unable to cast.
After a while when not at combat for 4 secs those spells become active and I can cast them again! :)
 
Level 11
Joined
Apr 28, 2008
Messages
696
As an option you can create a dummy unit that casts a buff on a unit when entering combat. By using that, you'll have an icon+tooltip in the units HUD. Further you don't need to handle timers, because of the inbuilt timer of the buff. If a unit tries to cast a spell, simply check if it got the "incombatbuff". After the buff exspires the unit can cast as normal. If the unit stays in combat, simply recast the buff on the unit.
 
Status
Not open for further replies.
Top