Adding hp to units

NightMagi

Member
Reaction score
5
This is similar to the one i wanted with the "Changing ownership of units"
But this time i wants to add hp to units i have selected.

e.x.
-hpx2
-hpx3
-hpx4
...

my current trigger remade from the one free_killing gave me:

Trigger:
  • adding hp
    • Events
      • Player - Player 1 (Red) types a chat message containing -hpx2 as An exact match
    • Conditions
    • Actions
      • Set AddingHpSelection = (Units currently selected by Player 1 (Red))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in AddingHpSelection) Less than or equal to 1
        • Then - Actions
          • Custom script: call DestroyGroup(udg_AddingHpSelection)
          • Skip remaining actions
        • Else - Actions
          • Do nothing
      • Unit Group - Pick every unit in AddingHpSelection and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Max Life of (Picked unit)) x 2.00)
      • Custom script: call DestroyGroup(udg_AddingHpSelection)


but it doesn't work! :( help!
 
Reaction score
341
That won't work, the SetUnitLife(unit, UNIT_STATE_MAX_LIFE) function doesn't do what you would think it does.

Your going to need something like this.
 

NightMagi

Member
Reaction score
5
I tried merging both of the triggers:

Trigger:
  • adding hp
    • Events
      • Player - Player 1 (Red) types a chat message containing life as A substring
    • Conditions
      • (Substring((Entered chat string), 1, 4)) Equal to life
    • Actions
      • Set AddingHpSelection = (Units currently selected by Player 1 (Red))
      • Set AddingHpInt = (Integer((Substring((Entered chat string), 5, (Length of (Entered chat string))))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in AddingHpSelection) Less than or equal to 1
        • Then - Actions
          • Custom script: call DestroyGroup(udg_AddingHpSelection)
          • Skip remaining actions
        • Else - Actions
          • Do nothing
      • Unit Group - Pick every unit in AddingHpSelection and do (Actions)
        • Loop - Actions
          • Custom script: call SetUnitMaxState(udg_AddingHpSelection, UNIT_STATE_MAX_LIFE, udg_AddingHpInt)
      • Custom script: call DestroyGroup(udg_AddingHpSelection)


but now i get a compile error:


Line 393: Expected a function name
Code:
call SetUnitMaxState(udg_AddingHpSelection, UNIT_STATE_MAX_LIFE, udg_AddingHpInt)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
There is a map in the link that TriggerHappy submitted, you need to download it and import the ssystem that is in it ;)

Just copy this text to the map header:

JASS:
constant function MaxStateModifierId takes unitstate u returns integer
    if u == UNIT_STATE_MAX_LIFE then
        return 'A000' // Rawcode of the Max Life Modifier ability.
    elseif u == UNIT_STATE_MAX_MANA then
        return 'A001' // Rawcode of the Max Mana Modifier ability.
    endif
    return 0
endfunction

function SetUnitMaxState takes unit whichUnit, unitstate whichUnitState, integer newVal returns boolean
    local integer c = newVal-R2I(GetUnitState(whichUnit, whichUnitState))
    local integer i = MaxStateModifierId(whichUnitState)
    if i == 0 then
        return false
    endif
    if c > 0 then
        loop
            exitwhen c == 0
            call UnitAddAbility(whichUnit, i)
            if c >= 100 then
                set c = c - 100
                call SetUnitAbilityLevel(whichUnit, i, 4)
            elseif c >= 10 then
                set c = c - 10
                call SetUnitAbilityLevel(whichUnit, i, 3)
            else
                set c = c - 1
                call SetUnitAbilityLevel(whichUnit, i, 2)
            endif
            call UnitRemoveAbility(whichUnit, i)
        endloop
    elseif c < 0 then
        set c = -c
        loop
            exitwhen c == 0
            call UnitAddAbility(whichUnit, i)
            if c >= 100 then
                set c = c - 100
                call SetUnitAbilityLevel(whichUnit, i, 7)
            elseif c >= 10 then
                set c = c - 10
                call SetUnitAbilityLevel(whichUnit, i, 6)
            else
                set c = c - 1
                call SetUnitAbilityLevel(whichUnit, i, 5)
            endif
            call UnitRemoveAbility(whichUnit, i)
        endloop
    endif
    return true
endfunction


Also check the Read Me trigger, so you can learn how to use the system ;)

Or use this library (You'll need JASS Newgen Pack to be able to use any of these scripts) :

JASS:
library MaxState

constant function MaxStateModifierId takes unitstate u returns integer
    if u == UNIT_STATE_MAX_LIFE then
        return 'A000' // Rawcode of the Max Life Modifier ability.
    elseif u == UNIT_STATE_MAX_MANA then
        return 'A001' // Rawcode of the Max Mana Modifier ability.
    endif
    return 0
endfunction

function SetUnitMaxState takes unit whichUnit, unitstate whichUnitState, integer newVal returns boolean
    local integer c = newVal-R2I(GetUnitState(whichUnit, whichUnitState))
    local integer i = MaxStateModifierId(whichUnitState)
    if i == 0 then
        return false
    endif
    if c > 0 then
        loop
            exitwhen c == 0
            call UnitAddAbility(whichUnit, i)
            if c >= 100 then
                set c = c - 100
                call SetUnitAbilityLevel(whichUnit, i, 4)
            elseif c >= 10 then
                set c = c - 10
                call SetUnitAbilityLevel(whichUnit, i, 3)
            else
                set c = c - 1
                call SetUnitAbilityLevel(whichUnit, i, 2)
            endif
            call UnitRemoveAbility(whichUnit, i)
        endloop
    elseif c < 0 then
        set c = -c
        loop
            exitwhen c == 0
            call UnitAddAbility(whichUnit, i)
            if c >= 100 then
                set c = c - 100
                call SetUnitAbilityLevel(whichUnit, i, 7)
            elseif c >= 10 then
                set c = c - 10
                call SetUnitAbilityLevel(whichUnit, i, 6)
            else
                set c = c - 1
                call SetUnitAbilityLevel(whichUnit, i, 5)
            endif
            call UnitRemoveAbility(whichUnit, i)
        endloop
    endif
    return true
endfunction

endlibrary


Just create a new trigger, go to Edit -> Convert to Custom Text
Remove all text in that trigger
Then copy and paste this text into that trigger and use this custom script to set the max life or mana:
Life
JASS:
call SetUnitMaxState(Your_Unit, UNIT_STATE_MAX_LIFE, Amount)


Mana
JASS:
call SetUnitMaxState(Your_Unit, UNIT_STATE_MAX_MANA, Amount)


Note: To be able to use any of these scripts you'll need import the spells, "Max Life Modifier" and "Max Mana Modifier" into your map from the map in the link provided by TriggerHappy, and you'll need to check which ID the spells have in your map by pressing Ctrl + D in your Object Editor, and put the first 4 letters or numbers in here:

JASS:
constant function MaxStateModifierId takes unitstate u returns integer
    if u == UNIT_STATE_MAX_LIFE then
        return 'A000' // Rawcode of the Max Life Modifier ability.
    elseif u == UNIT_STATE_MAX_MANA then
        return 'A001' // Rawcode of the Max Mana Modifier ability.
    endif
    return 0
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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