• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Movement speed depending on HP and mana

Status
Not open for further replies.
Level 8
Joined
Apr 23, 2011
Messages
322
So I'm trying to make a periodic trigger that will set all units' MS according to their HP and mana.

MS of all units on the map depends on their current HP.

100% HP=100% MS
85% HP=90% MS
70% HP=80% MS
55% HP=70% MS
40% HP=60% MS
25% HP=50% MS
10% HP=40% MS
<1% HP=30% MS
Table should have numbers in the middle as well.(77% HP=85% MS)I could write for each %, but you get the point.
(the table doesn't have to look literally the same)

On the other hand, MS of all alive (not undead) units depends on their current mana as well.

100% MP=100 MS
...
same as above

Examples:
Footman (alive) 40% HP=60% MS
Ghoul (undead) 85% HP=90% MS (if a unit has only HP, it doesn't matter if it's undead or alive)

Priest (alive) 100% HP, 0 MP=65% MS (not sure about this)
Sorceress (alive) 10% HP, 70 MP=60% MS (not sure about this)

Necromancer (undead) 100% HP, 0 MP=100% MS (undead casters' MP doesn't affect their MS)
Banshee (undead) 25% HP, 100% MP=50% MS (undead casters' MP doesn't affect their MS)

The current trigger is pretty bad and needs fixing.
According to the current one, 50% HP=50% MS, which is bad.
(note that there are MS increasing auras in the map)

  • Speed
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set AllunitsMana = (Units in (Playable map area) matching (((Matching unit) is Undead) Equal to False))
      • Unit Group - Pick every unit in AllunitsMana and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) movement speed to ((Default movement speed of (Picked unit)) x ((Percentage mana of (Picked unit)) / 100.00))
      • Custom script: call DestroyGroup (udg_AllunitsMana)
      • Set AllunitsAlive = (Units in (Playable map area))
      • Unit Group - Pick every unit in AllunitsAlive and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) movement speed to ((Current movement speed of (Picked unit)) x ((Percentage life of (Picked unit)) / 100.00))
      • Custom script: call DestroyGroup (udg_AllunitsAlive)
 
Level 8
Joined
Dec 22, 2008
Messages
207
Just a quick reply:

Wouldn't it be better to use the event:

  • Unit - A unit Takes damage
?

Then calculate the final movement speed of the subject depending on how much health he has left.

Then the same for mana, but then use:

  • Unit - A unit Starts the effect of an ability

Also, what I mean with the 'takes damage' event, you would need to use this trigger (then leave the event part out of the trigger in the first example, of course):
  • Events
    • Unit - A unit enters (Playable map area)
  • Conditions
  • Actions
    • Trigger - Add to Spell Trigger <gen> the event (Unit - (Entering unit) Takes damage)
I think this would be better because it wouldn't run iterate every single second, only when triggered under specific conditions, naturally.
 
Level 8
Joined
Apr 23, 2011
Messages
322
Yes, it would be better.
On the other hand, that doesn't support heals, mana replenishes, positive/negative hp/mana regeneration...
Which is really bad.
like...after the fight, the footman is left with 50 hp (about 60% ms), overtime he will regenerate hp, but still, his ms remains the same (reduced)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
You should do what Daredeamon suggested. Except save the units in a hashtable. Then u can use a condition to see if the unit is stored in the hashtable. This will help u limit the units that u want the movement speed to affect.
If u want it to affect every unit in the map then keep it the way Daredeamon suggested.
As for ur problem it lies in ur math. U need to get the percent value then convert it into a real number. instead of using the percent to determine the percent of the MS.

Edit: if u want it to take all of those into affect then u need to iterate every second.
 
Level 8
Joined
Apr 23, 2011
Messages
322
As for ur problem it lies in ur math. U need to get the percent value then convert it into a real number. instead of using the percent to determine the percent of the MS.

Edit: if u want it to take all of those into affect then u need to iterate every second.

Well, the formula is the actual answer I'm searching for...damn math...
 
Level 8
Joined
Dec 22, 2008
Messages
207
Yes, it would be better.
On the other hand, that doesn't support heals, mana replenishes, positive/negative hp/mana regeneration...
Which is really bad.
like...after the fight, the footman is left with 50 hp (about 60% ms), overtime he will regenerate hp, but still, his ms remains the same (reduced)

Well I suppose it doesn't take in account default mana and hp regeneration either, but I always turn those off in anything I start because I think it's unrealistic. (I always use heal spells or mana pots etc.)

Anyway, ability affected units can still be handled:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
  • Or - Any (Conditions) are true
    • Conditions
      • (Ability being cast) Equal to ManaChargeTargetSpell
      • (Ability being cast) Equal to HealthChargeTargetSpell
  • Actions
    • Set UnitHealth = (Percentage health of (Target unit of ability being cast))
    • Set UnitMana = (Percentage mana of (Target unit of ability being cast))
Since the trigger fires after the effect has started, instant health and mana changes should already have taken effect. Any triggered ability health/mana changing instances should be manually changed within their respective triggers.

I still recommend using my way over the 'one second loop'- trigger (unless you want to take in account default mana/health regeneration).
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
HP and mana regeneratrion will stay :p
another problem occurs with unholy/healing aura...

Is there a way to detect unit's hp/mana change?

not any way thats practical that i can think of, besides checking every .03 on what there hp and mp are.

here is the math. its actually really simple just get the percent mana or life and use that value as the movement speed. The highest movement speed will be 100 when using this.
change the peasant to the unit u want affected. And i use percentage life. so change that to mana if u want.
  • Actions
    • Set tempUnit = Peasant 0001 <gen>
    • Set tempReal = (Percentage life of tempUnit)
    • Unit - Set tempUnit movement speed to tempReal
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
ooo its not 50% MS its 50 MS. So u want it to be 50% hp = 70% of the max Ms ( 522)?

if so then use this one.
  • Actions
    • Set tempUnit = Peasant 0001 <gen>
    • Set tempReal = (Percentage life of tempUnit)
    • Set tempReal = ((1.13 + tempReal) / 100.00)
    • Set tempReal = (tempReal x 522.00)
    • Unit - Set tempUnit movement speed to tempReal
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
yes basically.
This one changes the unit MS based on there default value.

it was rather easy lol.
Here is a test map btw. Its not the exact numbers but u can see how u like it. The movement speed will change every .5 seconds and display on screen with the movement speed value.
The numbers fluctuate a little with the calculations because of the inaccuracy of reals. It wont be noticeable.

Heres trigger
  • Actions
    • Set tempUnit = Peasant 0001 <gen>
    • Set tempReal = (Percentage life of tempUnit)
    • Set tempReal = ((1.13 + tempReal) / 100.00)
    • Set tempReal = (tempReal x (Default movement speed of tempUnit))
    • Unit - Set tempUnit movement speed to tempReal
    • Game - Display to (All players) the text: (String(tempReal))
 

Attachments

  • Movement Speed calc for Shade Da Scout.w3x
    12.3 KB · Views: 85
Level 8
Joined
Apr 23, 2011
Messages
322
1.13 is a good medium basically every 1 percent adds 1.13 percent movement speed. So for example 70% hp = 79.1% Ms. 45% hp = 50.83% Ms. 10% hp = 11.3% Ms.
I think its a good value. u can tweak it if u want lol


YOU ARE A GENIUS!
this-changes-everything.jpg
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
ok all done lol

The mana reduces by 5 every second so u can see the MS drop. You can set the mana to max by pressing Esc so that u know it works. And get attacked like the old map to see that the MS depends on both health and mana. Also there is a second unit i added so u can see that it works with units that have Mana and units that dont have mana.

If it needs to be tweaked tell me.

u have to change tempUnit in the triggers to see the Ms difference for the unit with no mana.
 

Attachments

  • Movement Speed calc for Shade Da Scout.w3x
    13.1 KB · Views: 47
Level 8
Joined
Apr 23, 2011
Messages
322
yes it can.

I've just figured it out.(I changed my mind about some things)

  • Speed
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set AllunitsAlive = (Units in (Playable map area) matching (((Matching unit) is alive) Equal to True))
      • Unit Group - Pick every unit in AllunitsAlive and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) movement speed to ((Default movement speed of (Picked unit)) x ((1.20 + (((Real((Integer((Percentage life of (Picked unit)))))) + (Real((Integer((Percentage mana of (Picked unit))))))) / 2.00)) / 100.00))
      • Custom script: call DestroyGroup (udg_AllunitsAlive)
Is this trigger ok?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
do this.

This is more efficient and wont bug up. You will need another trigger that adds units to the group. and a trigger that removes the dead units from the group.
  • Check Hp and Mp
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in allUnitsAliveGroup and do (Actions)
        • Loop - Actions
          • Set tempUnit = (Picked unit)
          • Set tempReal1 = (Percentage life of tempUnit)
          • Set tempReal = (Max mana of tempUnit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempReal Less than or equal to 0.00
            • Then - Actions
              • Set tempReal = (((1.13 + tempReal1) / 100.00) x (Default movement speed of tempUnit))
            • Else - Actions
              • Set tempReal = (((1.13 + ((tempReal1 + (Percentage mana of tempUnit)) / 2.00)) / 100.00) x (Default movement speed of tempUnit))
          • Unit - Set tempUnit movement speed to tempReal
          • Game - Display to (All players) the text: (String(tempReal))
  • Register units to group
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
    • Actions
      • Unit Group - Add (Triggering unit) to allUnitsAliveGroup
  • unRegister units to group
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Unit Group - Remove (Triggering unit) from allUnitsAliveGroup
 

Attachments

  • Movement Speed calc for Shade Da Scout.w3x
    13.2 KB · Views: 32
Level 29
Joined
Oct 24, 2012
Messages
6,543
Shouldn't this cover that up?
  • Set AllunitsAlive = (Units in (Playable map area) matching (((Matching unit) is alive) Equal to True))

i uploaded the new map with those changes.
The reason my method is more efficient is because in urs u create a new group and add all units to it then loop. Also u leak a group.
In mine u loop through the units in the group.

Also anything u use twice or more should be stored into a variable. u should then use a variable. Variables are faster and they wont bug up (if handled correctly).

You should always care about efficiency. If u want to do advanced triggering or anything periodically it needs to be efficient as possible.
This may help u learn more about good coding with GUI. http://www.hiveworkshop.com/forums/tutorial-submission-283/things-gui-user-should-know-233242/
 
Status
Not open for further replies.
Top