• 🏆 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!

Movespeed based on mana %

Status
Not open for further replies.
Level 3
Joined
May 2, 2014
Messages
28
Does anyone know how to change a target hero's move speed based on mana %? IE: unit has 100 mana in total, but starts at 50. 50% mana = 250 MS and 100% mana =500 while 0% mana = 0 move speed. (technically, I will make the unit die when it reaches 0, but not important)

I know how to manipulate a units move speed, even based on its mana, but I have no idea how to make it work like this.
 
Level 21
Joined
Nov 4, 2013
Messages
2,017
I would do it like this:

  • Events
    • Time - Every 0.05 seconds of game time
  • Conditions
    • ((Your Unit) is alive) Equal to True
  • Actions
    • Unit - Set (Your Unit)'s movement speed to (((Mana of (Your Unit)) / (Max mana of (Your Unit))) x (100 x Value of movement speed for every 1% of mana)
The value of movement speed for every 1% should not be higher than 5 in this case as in 100% is would be 500 movement speed and the max is 522.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Little bit different calculation:
  • Update Movement Speed
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set TempUnit = YourUnit
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempUnit is dead) Equal to False
        • Then - Actions
          • Unit - Set TempUnit movement speed to ((Percentage mana of TempUnit) x 5.00)
        • Else - Actions
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
No, but lets take a look at what IsUnitAliveBJ() does
JASS:
function IsUnitAliveBJ takes unit whichUnit returns boolean
    return not IsUnitDeadBJ(whichUnit)
endfunction

As you can see, it redirects itself to IsUnitDeadBJ().
If you call IsUnitDeadBJ() instead of IsUnitAliveBJ() you will improve the performance... a little.
 
Level 3
Joined
May 2, 2014
Messages
28
Thanks guys! This actually worked better than I was expecting. I thought the mana thing would over-write any buffs the unit has, but it doesn't. I knew the math would be so simple but I still couldn't figure it out. Though, I was really coming from the wrong direction, thinking I would need to store the units starting MS and have to calculate how high or low it is based on the % of mana the unit has.

Nope.

Just in case anyone has this issue ever again; here is the trigger I went with:

  • Air Reserve
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set AirReserve_UnitGroup = (Units of type Dead Girl)
      • Unit Group - Pick every unit in AirReserve_UnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer((Percentage mana of (Picked unit)))) Equal to 0
            • Then - Actions
              • Unit - Kill (Picked unit)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is dead) Equal to False
                • Then - Actions
                  • Unit - Set (Picked unit) movement speed to ((Percentage mana of (Picked unit)) x 5.00)
                • Else - Actions
      • Custom script: call DestroyGroup(udg_AirReserve_UnitGroup)
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
use for the percentage check, "Less than 1%" or "less than 1mana"
Also, store Picked unit in a variable.
You are using it multiple times so you should put it in a variable and use that one instead.

Also... I am pretty sure that "Units of Type" leaks on its own.
You should rather add all units that are created in the game to that group if they are of that type.
Then you also dont have to create a new group every time.
Make sure to remove them when they are dead.
 
Level 3
Joined
May 2, 2014
Messages
28
use for the percentage check, "Less than 1%" or "less than 1mana"

I tested this as appose to "equal to 0". I didn't notice a difference. Does this make it run more smoothly or something?

Also... I am pretty sure that "Units of Type" leaks on its own.
You should rather add all units that are created in the game to that group if they are of that type.
Then you also dont have to create a new group every time.
Make sure to remove them when they are dead.

I am not sure how to add created units of type to a unit group. The units in question might die, but they are heroes so they will revive. Would I still need to remove them?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
It is kind of for ensurance that it works.
In most cases, a real "is equal to" check is really bad.

If they are heroes, you shouldn't remove them... i think. (did not test it myself)
I have an in-built unit creation event in my event manager (released today) which can be helpfull... however it is JASS only.
There is a tutorial which tells you how you can use it in GUI though.
 
Level 3
Joined
May 2, 2014
Messages
28
Yea I was looking at it an hr ago or so when I was checking out your listed resources. FAR too advanced for me right now ;)

At least it seems there isn't any real simple way to add created units to a unit group like that. Phew, thought I just didn't know how to ;)
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
No, but lets take a look at what IsUnitAliveBJ() does
JASS:
function IsUnitAliveBJ takes unit whichUnit returns boolean
    return not IsUnitDeadBJ(whichUnit)
endfunction

As you can see, it redirects itself to IsUnitDeadBJ().
If you call IsUnitDeadBJ() instead of IsUnitAliveBJ() you will improve the performance... a little.

Oh I see. Well I use GetWidgetLife to check if unit is alive or not which I think reduces the function calls to a minimum.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Yea I was looking at it an hr ago or so when I was checking out your listed resources. FAR too advanced for me right now ;)

At least it seems there isn't any real simple way to add created units to a unit group like that. Phew, thought I just didn't know how to ;)

You have to add all units that enter playable map area... and all units on map initialization.
If you have that, then you have it.
There is one small chance that some units will be added twice or not added at all and that system of mine removes that possibility completely.
That chance however is 0.0001%
 
Status
Not open for further replies.
Top