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

Calculating how many units are in playable map area to evenly distribute damage

Status
Not open for further replies.
Level 5
Joined
Aug 8, 2008
Messages
113
Im trying to evenly distribute damage but I cant figure out how to calculate how many units are within the playable map area? is that possible?
 
Level 9
Joined
Jul 10, 2011
Messages
562
set a group units in playable map area and the loop through them and set an integer value +1 everytime. then youll have the exact number.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Heres an example:

  • Distribute Damage
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • -------- Just To Show it Counts Properly --------
      • Game - Display to (All players) for 30.00 seconds the text: (String((Number of units in (Units in (Playable map area) matching (((Matching unit) belongs to an enemy of (Owner of Peasant 0000 <gen>)) Equal to True)))))
      • -------- Pick Players --------
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) belongs to an enemy of (Owner of Peasant 0000 <gen>)) Equal to True)) and do (Actions)
        • Loop - Actions
          • -------- The "Peasent" Will Deal 500 damage divided by the number of enemy units. --------
          • -------- In other words, will split up the 500 damage evenly among the enemy units. --------
          • Unit - Cause Peasant 0000 <gen> to damage (Picked unit), dealing (500.00 / (Real((Number of units in (Units in (Playable map area) matching (((Matching unit) belongs to an enemy of (Owner of Peasant 0000 <gen>)) Equal to True)))))) damage of attack type Spells and damage type Normal
And in case you still don't get it.
 

Attachments

  • Distribute Damage.w3x
    17.1 KB · Views: 31
Level 5
Joined
Aug 8, 2008
Messages
113
never mind figured it out just wondering if there is an easier way so im gonna post it in triggers
edit: Thx for replying the code I came up with can be found here
 
Level 5
Joined
Aug 8, 2008
Messages
113
So its not working and I've tried two possible ways... ok and what radicool gave is not it. Basically its an item that calculates how many people are near the person with the item. THen when one of these units get attack it lowers the damage of the attacked unit by evenly distributing 24% of the damaged unit. Basically if Bloodmage is attacked and receives 300 damage the actual damage he takes not counting armor bonuses should deal around 228 damage. Then the other 7 units owned by himself and nearby allies should recieve 10.28 damage each.
 
This is extremely easy to do...

pseudo jass code ;p
JASS:
GroupEnumUnitsInRect(whichGroup, world bounds)
loop
    set u = FirstOfGroup(whichGroup)
    exitwhen null == u
    call GroupRemoveUnit(whichGroup, u)

    if (IsUnitAlly(u, GetOwningPlayer(GetTriggerUnit() and u != GetTriggerUnit()) then
        set count = count + 1
        call GroupAddUnit(group2, u) //for distributing damage later
    endif
endloop

if (count != 0) then
    set damage = GetEventDamage()*.24

    //might have the wrong order of params here, winging this
    //need a DDS to properly do this as the damage may have killed the unit
    call SetWidgetLife(GetTriggerUnit(), GetWidgetLife(GetTriggerUnit()) + damage)

    loop
        set u = FirstOfGroup(group2)
        exitwhen null == u
        call GroupRemoveUnit(group2, u)

        //should probably use UnitDamageTarget here
        call SetWidgetLife(u, GetWidgetLife(u) - damage/count)
    endloop
endif


You can also do a GroupEnumUnitsInRange instead of GroupEnumUnitsInRect to apply the damage to only nearby allied units.


To someone that understands the above code and wants to do it with the GUI for squelch, go for it ;p
 
Status
Not open for further replies.
Top