• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Custom Units

Status
Not open for further replies.
Hello there, I'm making a system for a friend sort of as for practice.

Here it is:

JASS:
globals
    constant integer multiplierStats = 2 //Adjust this value to change the units attack to HP ratio. 50 means the unit has 50x as much HP as it has attack.
    constant integer atkAbil = 'A001'
endglobals

library maxHealth
constant function MaxStateModifierId takes unitstate u returns integer
    if u == UNIT_STATE_MAX_LIFE then
        return 'A000' //Maxlife Abil Rawcode
    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

function addedATK takes unit addUnit, real addedHP returns nothing
    call UnitAddAbility(addUnit,atkAbil)
    if addedHP>512*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,10)
    elseif addedHP>256*multiplierStats then //512, 256, etc, refer to the stats in the ability with the rawcode 'A001'. Press control+d in the unit ability editor to see the abilities raw codes.
        call SetUnitAbilityLevel(addUnit,atkAbil,9)
    elseif addedHP>128*multiplierStats then //If you're using more than 10 levels for the ability, you need to modify this trigger for the new levels with the new values.
        call SetUnitAbilityLevel(addUnit,atkAbil,8)
    elseif addedHP>64*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,7)
    elseif addedHP>32*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,6)
    elseif addedHP>16*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,5)
    elseif addedHP>8*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,4)
    elseif addedHP>4*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,3)
    elseif addedHP>2*multiplierStats then
        call SetUnitAbilityLevel(addUnit,atkAbil,2)
    endif
endfunction

function setUnitStats takes unit whichUnit, real life, string modelFile returns nothing
    call SetUnitMaxState(whichUnit,UNIT_STATE_MAX_LIFE,R2I(life))
    call addedATK(whichUnit,life)
    call AddSpecialEffectTarget(modelFile,whichUnit,"origin")
endfunction
endlibrary

All so he can use:

  • TestTrigger
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • -------- call setUnitStats(unit,life,model) --------
      • Unit - Create 1 Enemy for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
      • Set unit = (Last created unit)
      • Custom script: call setUnitStats(udg_unit,20.00,"units\human\WaterElemental\WaterElemental.mdl")
      • Unit - Create 1 Enemy for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
      • Set unit = (Last created unit)
      • Custom script: call setUnitStats(udg_unit,50.00,"units\creeps\WendigoShaman\WendigoShaman.mdl")
To create custom units in basically 1 line.

But it doesn't work >.<

When I save the map it returns a syntax error in the custom script lines (apparently nothing wrong with the library)

Because this is going into someone elses map I'd appreciate any other tips besides the fix.
 
Status
Not open for further replies.
Top