Decrease, Increase mana Problem

Expelliarmus

Where to change the sig?
Reaction score
48
You know when you try to

[the unit's health is greater than the increase value (100; call Set 225 = 200 + 100)] and it doesn't work? Anyone know a solution to this?
This is my solution, but it doesn't seem to work.

JASS:
function Increase_Mana takes nothing returns boolean 

local real diff
local unit caster
local real increase
local real mana

    if true then 
    set caster = GetTriggerUnit()
    set mana = GetUnitState(caster, UNIT_STATE_MANA)
    set increase = GetUnitState(GetFilterUnit(), UNIT_STATE_MANA) 
    
        if increase < 150 then // less than substract amount
            call SetUnitState(GetFilterUnit(), UNIT_STATE_MANA, 0 )
            call SetUnitState(caster,UNIT_STATE_MANA, mana + increase ) // assume that caster mana > 150
        else
            call SetUnitState(GetFilterUnit(), UNIT_STATE_MANA, mana - 150 )
            // caster condition : less than 150?
            set diff = GetUnitState(caster,  UNIT_STATE_MAX_MANA) - GetUnitState(caster, UNIT_STATE_MANA) // mana left
                if diff <= 150  then
                    call SetUnitState(caster , UNIT_STATE_MANA, GetUnitState(caster, UNIT_STATE_MANA) + diff)
        
                    call BJDebugMsg("less")
                else
                    // greater than spellevel
                    call SetUnitState(caster,  UNIT_STATE_MANA,  GetUnitState(caster , UNIT_STATE_MANA) +  150)
                    call BJDebugMsg("greater")
                endif
        endif
    endif 
    set caster = null
    return false // no group formed
endfunction


Thanks
 

Chocobo

White-Flower
Reaction score
409
JASS:
function Increase_Mana takes nothing returns boolean 
local unit caster=GetTriggerUnit() //trg unit
local real diff=GetUnitState(caster, UNIT_STATE_MAX_MANA) - GetUnitState(caster, UNIT_STATE_MANA) //max mp - current mp
local real increase=GetUnitState(GetFilterUnit(), UNIT_STATE_MANA) //current mp of filtered unit?
local real mana=GetUnitState(caster, UNIT_STATE_MANA) //current mp
local real toSub=150.0 //substracter
        if increase < toSub then // current mp of filter < toSub
            call SetUnitState(GetFilterUnit(), UNIT_STATE_MANA, 0) //reset filter unit mp to0
            call SetUnitState(caster,UNIT_STATE_MANA, mana + increase ) // current mp of caster + current mp of filtered unit
            set caster = null
            return true //done
        else
            call SetUnitState(GetFilterUnit(), UNIT_STATE_MANA, mana - toSub) //current mp - toSub AND if not current mp of filter < toSun
            // second condition
                if diff <= toSub then
                    call SetUnitState(caster , UNIT_STATE_MANA, GetUnitState(caster, UNIT_STATE_MANA) + diff) //toSub + caster max mp
                    call BJDebugMsg("less")
                    set caster = null
                    return true //done
                else
                    call SetUnitState(caster,  UNIT_STATE_MANA,  GetUnitState(caster , UNIT_STATE_MANA) + toSub) //toSub x2 + caster max mp + caster mp
                    call BJDebugMsg("greater")
                    set caster = null
                    return true //done
                endif
        endif
    set caster = null
    return false // no group formed and nothing did fire? (impossible through)
endfunction

function Increase_Mana_Alg takes nothing returns boolean 
local unit caster=GetTriggerUnit() //trg unit
local real a=GetUnitState(caster, UNIT_STATE_MAX_MANA) - GetUnitState(caster, UNIT_STATE_MANA) //max mp - current mp
local real b=GetUnitState(GetFilterUnit(), UNIT_STATE_MANA) //current mp of filtered unit?
local real c=GetUnitState(caster, UNIT_STATE_MANA) //current mp
local real d=150.0 //substracter
        if b < d then //
            call SetUnitState(GetFilterUnit(), UNIT_STATE_MANA, 0) //if b<d then state(filter mp)=0
            call SetUnitState(caster,UNIT_STATE_MANA, c + b) //if b<d then state(filter mp)=c+b = sum of both units mp
            set caster = null
            return true //done
        else
            call SetUnitState(GetFilterUnit(), UNIT_STATE_MANA, c - d) //else mp=c-d=current mp-substracter
            // second condition
                if a <= d then //caster(max mp-current mp) <= substacter
                    call SetUnitState(caster , UNIT_STATE_MANA, GetUnitState(caster, UNIT_STATE_MANA) + a) //if a<=d then caster mp+a = c+a = max mp
                    call BJDebugMsg("less")
                    set caster = null
                    return true //done
                else
                    call SetUnitState(caster,  UNIT_STATE_MANA,  GetUnitState(caster , UNIT_STATE_MANA) + d) //if a>d then caster mp+d = c+toSub
                    call BJDebugMsg("greater")
                    set caster = null
                    return true //done
                endif
        endif
    set caster = null
    return false // no group formed and nothing did fire? (impossible through)
endfunction


I don't get exactly what you want from the script.


>[the unit's health is greater than the increase value (100; call Set 225 = 200 + 100)]
health 200+100 if max 225 = health 225 not 300?
 

Expelliarmus

Where to change the sig?
Reaction score
48
My bad, I added this earlier
JASS:
call GroupEnumUnitsInRange(g, GetUnitX(caster),GetUnitY(caster), AoE(), Condition(function Increase_Mana))

in the actions.
I don't get exactly what you want from the script.
Basically, when you set a unit's state to unit state + x (say current unit state is 300, max is 400) and x = 150 ( increase by 150 from current unit state ), it won't work. The script uses 'if' to check whether the the unit can add the x without overloading.
 

Expelliarmus

Where to change the sig?
Reaction score
48
Set unit state greater than max value
Yes, and when setting unit state negative values (subtracting 150 from 100 mana). What should happen? Slight changes (9. - 10.) are added / removed (including mana cost, which was 90) in my case.
 

Builder Bob

Live free or don't
Reaction score
249
Basically, when you set a unit's state to unit state + x (say current unit state is 300, max is 400) and x = 150 ( increase by 150 from current unit state ), it won't work. The script uses 'if' to check whether the the unit can add the x without overloading.


scenario for mana:
current state: 300
max state: 400This will change the unit's mana to 400. Try it with a spell that doesn't use mana to see for sure.
If you try to set a unit's mana to less than 0, it's mana will be set to 0.
If you try to set a unit's mana to greater than it's max mana, it's mana will be set to max.

If this isn't how it works in your map, there must be something else preventing it somewhere.

Btw, I didn't read your solution, because there shouldn't be any problem to solve.
 

Expelliarmus

Where to change the sig?
Reaction score
48
Ok.. I did some testing

Scenario 1

Current Mana: 0
Max Mana : 300
Mana Cost : 0
Increment: 400
Result: 300 mana

Scenario 2

Current Mana: 40
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 300 mana

Scenario 2 Continued

Current Mana: 225
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 235 mana

Scenario 2 Continued

Current Mana: 300
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 235 260 mana
EDIT: Scenario 2 cont 2 result changed
 

Builder Bob

Live free or don't
Reaction score
249
Ok.. I did some testing

Scenario 1

Current Mana: 0
Max Mana : 300
Mana Cost : 0
Increment: 400
Result: 300 mana

Scenario 2

Current Mana: 40
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 300 mana

Scenario 2 Continued

Current Mana: 225
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 235 mana

Scenario 2 Continued

Current Mana: 300
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 235 260 mana
EDIT: Scenario 2 cont 2 result changed

would you mind uploading the map or show the triggers? I'd be interested in taking a look at it.

edit: a stripped down map with only the triggers and abilities involved would be best
 

Expelliarmus

Where to change the sig?
Reaction score
48
Ok
Thanks for that :thup:
Note
Thunder Claps = 0 Mana
Bloodmage = 40 Mana, keep using Frost Armor
 

Builder Bob

Live free or don't
Reaction score
249
This is what happens for me:
First mana is set to max, then mana is taken away for the ability.

The Blood Mage consistently ends up with 375(max) - 40(mana cost) = 335 mana.


Am I understanding you right that you want a unit to be able to reach maximum mana even on a spell cast that requires mana?
If it is, that can easily be achieved by using the event [Unit - A unit Finishes casting an ability] together with setting the Blood Mage's [Art - Animation - Cast Backswing] to 0.
 

Expelliarmus

Where to change the sig?
Reaction score
48
Am I understanding you right that you want a unit to be able to reach maximum mana even on a spell cast that requires mana?
Yes. Perfect Wording ^_^

Have you tried with 325 or so mana? It increases/ decreases 10 - 15 each for me, which is what I find odd.

If it is, that can easily be achieved by using the event [Unit - A unit Finishes casting an ability] together with setting the Blood Mage's [Art - Animation - Cast Backswing] to 0.
Yes, I figured that 2 seconds later (only for the finishes cast..) =p
 

Expelliarmus

Where to change the sig?
Reaction score
48
you mean adding 325 mana instead of 300?
For Bloodmage, who has 375
Edit: Solved
Solution:
Post #11
- Scenario 2 Continued... dunno what happens to it, but finishes + no animation fixes it
 

Builder Bob

Live free or don't
Reaction score
249
I'm sorry, but I can't produce any odd results no matter which numbers I change

Scenario 2 Continued

Current Mana: 225
Max Mana : 300
Mana Cost : 40
Increment: 300
Result: 235 mana

All the scenarios you showed are correct, except this one. Are you able to reproduce it?
 

Expelliarmus

Where to change the sig?
Reaction score
48
All the scenarios you showed are correct, except this one. Are you able to reproduce it?
Hmm.. odd, well that's for Starts an effect.
- numbers I change
I too changed the numbers according to Bloodmage and got the results - 10 per cast with initial mana of '335' (40 off Max)
But it doesn't matter now, since finishes + no animation solved it.

And I must ask, does this apply to health as well?
 

Darius34

New Member
Reaction score
30
Just to add on to the solutions: you could also use a 0-second wait/timer callback, if you wanted your hero to retain its backswing time. The delay causes the spell's mana cost to be subtracted first, and whatever comes after it to... well, come after it.

Changing mana without the wait/timer would cause something like what you described in the fourth scenario to happen - the mana cost of the spell would only be subtracted later, after the change in mana.

Edit:
And I must ask, does this apply to health as well?
For the Unit Takes Damage specific event (and for my method, with the timer/wait), yes. The timer/wait allows you to control when you heal your unit, and allows the accurate reduction/mitigation of damage (without a SetUnitMaxState() system).
 

Builder Bob

Live free or don't
Reaction score
249
With finishes or Starts?

Only with [Unit - A unit Starts the effect of an ability].
No timer callback is needed for [Unit - A unit Finishes casting an ability].

Darius34 is right that life is subtracted from a damage event after everything you put in the trigger takes place, so you get the same problem there.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top