• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Want to increase spell lvl (increase max mana)

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
When a building is completed the constructing city shall have its max mana increased. But it just doens't work.

I'e made 100% sure its the correct unit and ability.

JASS:
private function OnConstructionFinish takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local integer bIndex = GetBuildingIndex(u)
        local integer cIndex = owningCity[GetUnitUserData(u)]
        call BJDebugMsg(I2S(cIndex))
        //local player p = GetOwningPlayer(u)
        //local integer pId = GetPlayerId(p)
        call city[cIndex].dec_bTypCount(0)
        call city[cIndex].inc_bTypCount(bIndex)
        call GroupRemoveUnit(gConstruction, u) 
        
        if GetUnitTypeId(u) == GRANARY then 
            //call SetUnitState(city[cIndex].main, UNIT_STATE_MAX_MANA, GetUnitState(city[cIndex].main, UNIT_STATE_MAX_MANA) + 1000.)
            call IncUnitAbilityLevel(city[cIndex].main, GRANARY_MANA_BONUS) 
            
        endif
        set u = null
        return false
    endfunction
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Yes, this is something that would work.
If you wish to go one step further, you can use a special technique that'll handle all stat changes.

Basically every number can be made from numbers based on 2.(** means power)
2**0=1
2**1=2
2**2=4
2**3=8
etc

If you wanted to make a bonus of 1337(or any size really) you'll just need to go through the abilities. I'll assume that the largest bonus ability is 4096.
First you'll check if the bonus is at least 4096(>=).
It isn't, so let's keep going.
Is it at least 2048? No
Is it at least 1024? Yes. Add this ability and reduce remaining bonus by 1024. Remaining bonus is now 309.
Is it at least 512? No
Is it at least 256? Yes. Add the ability and reduce remaining bonus by 256.
Continue like this until you run out of abilities to test against.
For the sake of convenience, I recommend using a loop for this process.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I have 2 abilities both based of Item Health Bonus and Item Mana Bonus.
They have 11 levels with all a fixed amount of health/mana
Level 1: 0 bonus
Level 2: -1 bonus
Level 3: -10 bonus
Level 4: -100 bonus
Level 5: -1000 bonus
Level 6: -10000 bonus
Level 7: 1 bonus
Level 8: 10 bonus
Level 9: 100 bonus
Level 10: 1000 bonus
Level 11: 10000 bonus

Then make a trigger and place this in it:
JASS:
globals
    integer udg_Max_Health_Bonus    = 'A000'
    integer udg_Max_Mana_Bonus      = 'A001'
endglobals





library maxstatsmodifier
    function AddMaxHealth takes unit whichUnit, integer amount returns nothing
        if amount == 0 or GetHandleId(whichUnit) == 0 then
            return
        endif
        
        loop
            exitwhen amount < 10000 and amount > -10000
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 11)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount + 10000
            else
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 6)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount - 10000
            endif
        endloop
        
        loop
            exitwhen amount < 1000 and amount > -1000
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 10)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount + 1000
            else
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 5)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount - 1000
            endif
        endloop
        
        loop
            exitwhen amount < 100 and amount > -100
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 9)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount + 100
            else
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 4)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount - 100
            endif
        endloop
        
        loop
            exitwhen amount < 10 and amount > -10
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 8)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount + 10
            else
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 3)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount - 10
            endif
        endloop
        
        loop
            exitwhen amount == 0
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 7)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount + 1
            else
                call UnitAddAbility(whichUnit, udg_Max_Health_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Health_Bonus, 2)
                call UnitRemoveAbility(whichUnit, udg_Max_Health_Bonus)
                
                set amount = amount - 1
            endif
        endloop
    endfunction
    function AddMaxMana takes unit whichUnit, integer amount returns nothing
        if amount == 0 or GetHandleId(whichUnit) == 0 then
            return
        endif
        
        loop
            exitwhen amount < 10000 and amount > -10000
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 11)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount + 10000
            else
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 6)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount - 10000
            endif
        endloop
        
        loop
            exitwhen amount < 1000 and amount > -1000
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 10)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount + 1000
            else
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 5)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount - 1000
            endif
        endloop
        
        loop
            exitwhen amount < 100 and amount > -100
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 9)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount + 100
            else
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 4)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount - 100
            endif
        endloop
        
        loop
            exitwhen amount < 10 and amount > -10
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 8)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount + 10
            else
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 3)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount - 10
            endif
        endloop
        
        loop
            exitwhen amount == 0
            if amount < 0 then
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 7)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount + 1
            else
                call UnitAddAbility(whichUnit, udg_Max_Mana_Bonus)
                call SetUnitAbilityLevel(whichUnit, udg_Max_Mana_Bonus, 2)
                call UnitRemoveAbility(whichUnit, udg_Max_Mana_Bonus)
                
                set amount = amount - 1
            endif
        endloop
    endfunction
endlibrary

Then you can increase health/mana by calling those functions in custom scripts...
I am sure that there are more efficient ways to do it but it works and I cant notice any lagg... even when used very frequently.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Changing ability level doesn't change the current bonus given by it. However, removing the ability reduces mana by the amount that the ability was supposed to give. Wietlol's solution abuses this to change max mana by setting the ability to a different level(does nothing) and then removing it(removing the bonus that never existed in the first place = max health increased).
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
It works wonders Wietlol. Great. Thansk you two!

Just wondering, could your system be tightened if you sent in how much you want to add, and how much you already added as well as having a fixed increment of 100, 500 or 1000 instead of being able to add dynamic numbers?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
When I give a unit an ability, it is set to level 1 by default.

So I now have a unit with Max HP Bonus of lvl 1 (0 bonus)

Now I will increase the level to 4.

The unit has now got a Max HP Bonus of lvl 4 (-100 bonus)
However, because of a bug, the hp has not changed.

Now I will remove that ability again.
So I remove Max HP Bonus lvl 4 of that unit and have to reduce his max health by -100 to negate the effect of the removed ability.
(-100 removed = 100 added)

Now, my unit has not got the ability but does have an increased max health.

Because of that the HP/MP does not change when changing the level, the removed hp (-100) is not the same as the added hp (0) and thus you can increase HP/MP with this method.

In that function of mine, you can set an amount like 2736 and it will add/level/remove that ability enough times to give you that amount.

Setting max health/mana is this:
AddMaxHealth(u, 100 - currentHP)

EDIT:
To know how much you added... is not required to make it work properly so it will not be part of the system (snippet)
You can save an integer value in an array if you have a unit indexer or in a hashtable if you dont have it.
 
Status
Not open for further replies.
Top