• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!

Bonus

Level 21
Joined
Mar 27, 2012
Messages
3,232
Bonusmod code
JASS:
//! import "ExtraConstants.j"

library Bonus initializer in requires ExtraConstants
    globals
        private integer array Abil
        
        integer array Abils
        
        public constant integer DAM = 100
        public constant integer ARM = 200
        public constant integer ATKSPD = 300
        public constant integer INT = 400//For green numbers
        public constant integer STR = 500//
        public constant integer AGI = 600//
        public constant integer LIFE = 700
        public constant integer MANA = 800
        public constant integer LIFEREG = 900
    endglobals
    
    function SetBonus takes unit u, integer bonustype,integer amount returns nothing
        local integer i = bonustype+Abils[bonustype]
        set amount = -amount
        if amount < 0 then
            call UnitAddAbility(u,Abil[bonustype+Abils[bonustype]+1])
            call UnitMakeAbilityPermanent(u,true,Abil[bonustype+Abils[bonustype]+1])
            set amount = Pow2[Abils[bonustype]+1]+amount
        else 
            call UnitMakeAbilityPermanent(u,false,Abil[bonustype+Abils[bonustype]+1])
            call UnitRemoveAbility(u,Abil[bonustype+Abils[bonustype]+1])
        endif
        loop
            exitwhen i < bonustype
            if amount >= Pow2[i-bonustype] then
                call UnitAddAbility(u,Abil[i])
                call UnitMakeAbilityPermanent(u,true,Abil[i])
                set amount = amount - Pow2[i-bonustype]
            else
                call UnitMakeAbilityPermanent(u,false,Abil[i])
                call UnitRemoveAbility(u,Abil[i])
            endif
            set i = i - 1
        endloop
    endfunction
    private function in takes nothing returns nothing
        set Abil[DAM+0] = 'AD-0'
        set Abil[DAM+1] = 'AD-1'
        set Abil[DAM+2] = 'AD-2'
        set Abil[DAM+3] = 'AD-3'
        set Abil[DAM+4] = 'AD-4'
        set Abil[DAM+5] = 'AD-5'
        set Abil[DAM+6] = 'AD-6'
        set Abil[DAM+7] = 'AD-7'
        set Abil[DAM+8] = 'AD-8'
        set Abil[DAM+9] = 'AD-9'
        set Abil[DAM+10] = 'AD+A'
        set Abils[DAM] = 9
        
        set Abil[ATKSPD+0] = 'AS-0'
        set Abil[ATKSPD+1] = 'AS-1'
        set Abil[ATKSPD+2] = 'AS-2'
        set Abil[ATKSPD+3] = 'AS-3'
        set Abil[ATKSPD+4] = 'AS-4'
        set Abil[ATKSPD+5] = 'AS-5'
        set Abil[ATKSPD+6] = 'AS-6'
        set Abil[ATKSPD+7] = 'AS-7'
        set Abil[ATKSPD+8] = 'AS+8'
        set Abils[ATKSPD] = 7
        
        set Abil[ARM+0] = 'AR-0'
        set Abil[ARM+1] = 'AR-1'
        set Abil[ARM+2] = 'AR-2'
        set Abil[ARM+3] = 'AR-3'
        set Abil[ARM+4] = 'AR-4'
        set Abil[ARM+5] = 'AR-5'
        set Abil[ARM+6] = 'AR-6'
        set Abil[ARM+7] = 'AR-7'
        set Abil[ARM+8] = 'AR-8'
        set Abil[ARM+9] = 'AR-9'
        set Abil[ARM+10] = 'AR+A'
        set Abils[ARM] = 9
        
        set Abil[INT+0] = 'IN-0'
        set Abil[INT+1] = 'IN-1'
        set Abil[INT+2] = 'IN-2'
        set Abil[INT+3] = 'IN-3'
        set Abil[INT+4] = 'IN-4'
        set Abil[INT+5] = 'IN-5'
        set Abil[INT+6] = 'IN-6'
        set Abil[INT+7] = 'IN-7'
        set Abil[INT+8] = 'IN-8'
        set Abil[INT+9] = 'IN-9'
        set Abil[INT+10] = 'IN+A'
        set Abils[INT] = 9
        
        set Abil[AGI+0] = 'AG-0'
        set Abil[AGI+1] = 'AG-1'
        set Abil[AGI+2] = 'AG-2'
        set Abil[AGI+3] = 'AG-3'
        set Abil[AGI+4] = 'AG-4'
        set Abil[AGI+5] = 'AG-5'
        set Abil[AGI+6] = 'AG-6'
        set Abil[AGI+7] = 'AG-7'
        set Abil[AGI+8] = 'AG-8'
        set Abil[AGI+9] = 'AG-9'
        set Abil[AGI+10] = 'AG+A'
        set Abils[AGI] = 9
        
        set Abil[STR+0] = 'ST-0'
        set Abil[STR+1] = 'ST-1'
        set Abil[STR+2] = 'ST-2'
        set Abil[STR+3] = 'ST-3'
        set Abil[STR+4] = 'ST-4'
        set Abil[STR+5] = 'ST-5'
        set Abil[STR+6] = 'ST-6'
        set Abil[STR+7] = 'ST-7'
        set Abil[STR+8] = 'ST-8'
        set Abil[STR+9] = 'ST-9'
        set Abil[STR+10] = 'ST+A'
        set Abils[STR] = 9
        
        set Abil[LIFE+0] = 'LP-0'
        set Abil[LIFE+1] = 'LP-1'
        set Abil[LIFE+2] = 'LP-2'
        set Abil[LIFE+3] = 'LP-3'
        set Abil[LIFE+4] = 'LP-4'
        set Abil[LIFE+5] = 'LP-5'
        set Abil[LIFE+6] = 'LP-6'
        set Abil[LIFE+7] = 'LP-7'
        set Abil[LIFE+8] = 'LP-8'
        set Abil[LIFE+9] = 'LP-9'
        set Abil[LIFE+10] = 'LP-A'
        set Abil[LIFE+11] = 'LP-B'
        set Abil[LIFE+12] = 'LP-C'
        set Abil[LIFE+13] = 'LP-D'
        set Abil[LIFE+14] = 'LP+E'
        set Abils[LIFE] = 13
        
        set Abil[MANA+0] = 'MP-0'
        set Abil[MANA+1] = 'MP-1'
        set Abil[MANA+2] = 'MP-2'
        set Abil[MANA+3] = 'MP-3'
        set Abil[MANA+4] = 'MP-4'
        set Abil[MANA+5] = 'MP-5'
        set Abil[MANA+6] = 'MP-6'
        set Abil[MANA+7] = 'MP-7'
        set Abil[MANA+8] = 'MP-8'
        set Abil[MANA+9] = 'MP-9'
        set Abil[MANA+10] = 'MP-A'
        set Abil[MANA+11] = 'MP-B'
        set Abil[MANA+12] = 'MP-C'
        set Abil[MANA+13] = 'MP-D'
        set Abil[MANA+14] = 'MP+E'
        set Abils[MANA] = 13
        
        set Abil[LIFEREG+0] = 'LR-0'
        set Abil[LIFEREG+1] = 'LR-1'
        set Abil[LIFEREG+2] = 'LR-2'
        set Abil[LIFEREG+3] = 'LR-3'
        set Abil[LIFEREG+4] = 'LR-4'
        set Abil[LIFEREG+5] = 'LR-5'
        set Abil[LIFEREG+6] = 'LR-6'
        set Abil[LIFEREG+7] = 'LR-7'
        set Abil[LIFEREG+8] = 'LR-8'
        set Abil[LIFEREG+9] = 'LR-9'
        set Abil[LIFEREG+10] = 'LR+A'
        set Abils[LIFEREG] = 9
    endfunction
endlibrary

Ability creation (takes LONG, so disable this after use)
JASS:
//! external ObjectMerger w3a AItg AD-0 anam "AD" Iatt 1 -1 |
//! external ObjectMerger w3a AItg AD-1 anam "AD" Iatt 1 -2 |
//! external ObjectMerger w3a AItg AD-2 anam "AD" Iatt 1 -4 |
//! external ObjectMerger w3a AItg AD-3 anam "AD" Iatt 1 -8 |
//! external ObjectMerger w3a AItg AD-4 anam "AD" Iatt 1 -16 |
//! external ObjectMerger w3a AItg AD-5 anam "AD" Iatt 1 -32 |
//! external ObjectMerger w3a AItg AD-6 anam "AD" Iatt 1 -64 |
//! external ObjectMerger w3a AItg AD-7 anam "AD" Iatt 1 -128 |
//! external ObjectMerger w3a AItg AD-8 anam "AD" Iatt 1 -256 |
//! external ObjectMerger w3a AItg AD-9 anam "AD" Iatt 1 -512 |
//! external ObjectMerger w3a AItg AD+A anam "AD" Iatt 1 1024 |

//! external ObjectMerger w3a AIsx AS-0 anam "AS" Isx1 1 -0.01 |
//! external ObjectMerger w3a AIsx AS-1 anam "AS" Isx1 1 -0.02 |
//! external ObjectMerger w3a AIsx AS-2 anam "AS" Isx1 1 -0.04 |
//! external ObjectMerger w3a AIsx AS-3 anam "AS" Isx1 1 -0.08 |
//! external ObjectMerger w3a AIsx AS-4 anam "AS" Isx1 1 -0.16 |
//! external ObjectMerger w3a AIsx AS-5 anam "AS" Isx1 1 -0.32 |
//! external ObjectMerger w3a AIsx AS-6 anam "AS" Isx1 1 -0.64 |
//! external ObjectMerger w3a AIsx AS-7 anam "AS" Isx1 1 -1.28 |
//! external ObjectMerger w3a AIsx AS+8 anam "AS" Isx1 1 2.56 |

//! external ObjectMerger w3a AId1 AR-0 anam "AR" Idef 1 -1 |
//! external ObjectMerger w3a AId1 AR-1 anam "AR" Idef 1 -2 |
//! external ObjectMerger w3a AId1 AR-2 anam "AR" Idef 1 -4 |
//! external ObjectMerger w3a AId1 AR-3 anam "AR" Idef 1 -8 |
//! external ObjectMerger w3a AId1 AR-4 anam "AR" Idef 1 -16 |
//! external ObjectMerger w3a AId1 AR-5 anam "AR" Idef 1 -32 |
//! external ObjectMerger w3a AId1 AR-6 anam "AR" Idef 1 -64 |
//! external ObjectMerger w3a AId1 AR-7 anam "AR" Idef 1 -128 |
//! external ObjectMerger w3a AId1 AR-8 anam "AR" Idef 1 -256 |
//! external ObjectMerger w3a AId1 AR-9 anam "AR" Idef 1 -512 |
//! external ObjectMerger w3a AId1 AR+A anam "AR" Idef 1 1024 |

//! external ObjectMerger w3a AIi1 IN-0 anam "INT" Iint 1 -1 |
//! external ObjectMerger w3a AIi1 IN-1 anam "INT" Iint 1 -2 |
//! external ObjectMerger w3a AIi1 IN-2 anam "INT" Iint 1 -4 |
//! external ObjectMerger w3a AIi1 IN-3 anam "INT" Iint 1 -8 |
//! external ObjectMerger w3a AIi1 IN-4 anam "INT" Iint 1 -16 |
//! external ObjectMerger w3a AIi1 IN-5 anam "INT" Iint 1 -32 |
//! external ObjectMerger w3a AIi1 IN-6 anam "INT" Iint 1 -64 |
//! external ObjectMerger w3a AIi1 IN-7 anam "INT" Iint 1 -128 |
//! external ObjectMerger w3a AIi1 IN-8 anam "INT" Iint 1 -256 |
//! external ObjectMerger w3a AIi1 IN-9 anam "INT" Iint 1 -512 |
//! external ObjectMerger w3a AIi1 IN+A anam "INT" Iint 1 1024 |

//! external ObjectMerger w3a AIa1 AG-0 anam "AGI" Iagi 1 -1 |
//! external ObjectMerger w3a AIa1 AG-1 anam "AGI" Iagi 1 -2 |
//! external ObjectMerger w3a AIa1 AG-2 anam "AGI" Iagi 1 -4 |
//! external ObjectMerger w3a AIa1 AG-3 anam "AGI" Iagi 1 -8 |
//! external ObjectMerger w3a AIa1 AG-4 anam "AGI" Iagi 1 -16 |
//! external ObjectMerger w3a AIa1 AG-5 anam "AGI" Iagi 1 -32 |
//! external ObjectMerger w3a AIa1 AG-6 anam "AGI" Iagi 1 -64 |
//! external ObjectMerger w3a AIa1 AG-7 anam "AGI" Iagi 1 -128 |
//! external ObjectMerger w3a AIa1 AG-8 anam "AGI" Iagi 1 -256 |
//! external ObjectMerger w3a AIa1 AG-9 anam "AGI" Iagi 1 -512 |
//! external ObjectMerger w3a AIa1 AG+A anam "AGI" Iagi 1 1024 |

//! external ObjectMerger w3a AIs1 ST-0 anam "AGI" Istr 1 -1 |
//! external ObjectMerger w3a AIs1 ST-1 anam "AGI" Istr 1 -2 |
//! external ObjectMerger w3a AIs1 ST-2 anam "AGI" Istr 1 -4 |
//! external ObjectMerger w3a AIs1 ST-3 anam "AGI" Istr 1 -8 |
//! external ObjectMerger w3a AIs1 ST-4 anam "AGI" Istr 1 -16 |
//! external ObjectMerger w3a AIs1 ST-5 anam "AGI" Istr 1 -32 |
//! external ObjectMerger w3a AIs1 ST-6 anam "AGI" Istr 1 -64 |
//! external ObjectMerger w3a AIs1 ST-7 anam "AGI" Istr 1 -128 |
//! external ObjectMerger w3a AIs1 ST-8 anam "AGI" Istr 1 -256 |
//! external ObjectMerger w3a AIs1 ST-9 anam "AGI" Istr 1 -512 |
//! external ObjectMerger w3a AIs1 ST+A anam "AGI" Istr 1 1024 |

//! external ObjectMerger w3a AIlz LP-0 anam "LIFE" Ilif 1 -1 |
//! external ObjectMerger w3a AIlz LP-1 anam "LIFE" Ilif 1 -2 |
//! external ObjectMerger w3a AIlz LP-2 anam "LIFE" Ilif 1 -4 |
//! external ObjectMerger w3a AIlz LP-3 anam "LIFE" Ilif 1 -8 |
//! external ObjectMerger w3a AIlz LP-4 anam "LIFE" Ilif 1 -16 |
//! external ObjectMerger w3a AIlz LP-5 anam "LIFE" Ilif 1 -32 |
//! external ObjectMerger w3a AIlz LP-6 anam "LIFE" Ilif 1 -64 |
//! external ObjectMerger w3a AIlz LP-7 anam "LIFE" Ilif 1 -128 |
//! external ObjectMerger w3a AIlz LP-8 anam "LIFE" Ilif 1 -256 |
//! external ObjectMerger w3a AIlz LP-9 anam "LIFE" Ilif 1 -512 |
//! external ObjectMerger w3a AIlz LP-A anam "LIFE" Ilif 1 -1024 |
//! external ObjectMerger w3a AIlz LP-B anam "LIFE" Ilif 1 -2048 |
//! external ObjectMerger w3a AIlz LP-C anam "LIFE" Ilif 1 -4096 |
//! external ObjectMerger w3a AIlz LP-D anam "LIFE" Ilif 1 -8192 |
//! external ObjectMerger w3a AIlz LP+E anam "LIFE" Ilif 1 16384 |

//! external ObjectMerger w3a AImz MP-0 anam "MANA" Iman 1 -1 |
//! external ObjectMerger w3a AImz MP-1 anam "MANA" Iman 1 -2 |
//! external ObjectMerger w3a AImz MP-2 anam "MANA" Iman 1 -4 |
//! external ObjectMerger w3a AImz MP-3 anam "MANA" Iman 1 -8 |
//! external ObjectMerger w3a AImz MP-4 anam "MANA" Iman 1 -16 |
//! external ObjectMerger w3a AImz MP-5 anam "MANA" Iman 1 -32 |
//! external ObjectMerger w3a AImz MP-6 anam "MANA" Iman 1 -64 |
//! external ObjectMerger w3a AImz MP-7 anam "MANA" Iman 1 -128 |
//! external ObjectMerger w3a AImz MP-8 anam "MANA" Iman 1 -256 |
//! external ObjectMerger w3a AImz MP-9 anam "MANA" Iman 1 -512 |
//! external ObjectMerger w3a AImz MP-A anam "MANA" Iman 1 -1024 |
//! external ObjectMerger w3a AImz MP-B anam "MANA" Iman 1 -2048 |
//! external ObjectMerger w3a AImz MP-C anam "MANA" Iman 1 -4096 |
//! external ObjectMerger w3a AImz MP-D anam "MANA" Iman 1 -8192 |
//! external ObjectMerger w3a AImz MP+E anam "MANA" Iman 1 16384 |

//! external ObjectMerger w3a Arel LR-0 anam "LIFEREG" Ihpr 1 -1 |
//! external ObjectMerger w3a Arel LR-1 anam "LIFEREG" Ihpr 1 -2 |
//! external ObjectMerger w3a Arel LR-2 anam "LIFEREG" Ihpr 1 -4 |
//! external ObjectMerger w3a Arel LR-3 anam "LIFEREG" Ihpr 1 -8 |
//! external ObjectMerger w3a Arel LR-4 anam "LIFEREG" Ihpr 1 -16 |
//! external ObjectMerger w3a Arel LR-5 anam "LIFEREG" Ihpr 1 -32 |
//! external ObjectMerger w3a Arel LR-6 anam "LIFEREG" Ihpr 1 -64 |
//! external ObjectMerger w3a Arel LR-7 anam "LIFEREG" Ihpr 1 -128 |
//! external ObjectMerger w3a Arel LR-8 anam "LIFEREG" Ihpr 1 -256 |
//! external ObjectMerger w3a Arel LR-9 anam "LIFEREG" Ihpr 1 -512 |
//! external ObjectMerger w3a Arel LR+A anam "LIFEREG" Ihpr 1 1024 |

Requirements:
JASS:
//
//                  Extrafunctions
//
//       This library provides functions that extend
//       the editor functionality and/or make things
//       more efficient.
//
//

globals
    integer ExtraInt
    real ExtraReal
    real ExtraX
    real ExtraY
    unit ExtraUnit
    group ExtraGroup
    unit array ExtraU
    integer ExtraUs = 0
endglobals

library ExtraFunctions
    //System stuff that shouldn't be used outside
    function UnitTypeIsInteger takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) == ExtraInt
    endfunction
    
    function ClosestUnitLoop takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real x = GetUnitX(u) - ExtraX
        local real y = GetUnitY(u) - ExtraY
        local real r = SquareRoot(x * x + y * y)
        if r < ExtraReal then
            set ExtraReal = r
            set ExtraUnit = u
        endif
        set u = null
    endfunction
    
    function GroupEmpty takes nothing returns nothing
        call GroupRemoveUnit(ExtraGroup,GetEnumUnit())
    endfunction
    
    //Actual functions
    function AngleBetweenPointsEx takes real x, real y, real x2, real y2 returns real
        return bj_RADTODEG * Atan2(y2 - y, x2 - x)
    endfunction

    function RealDistance takes real x, real y, real x2, real y2 returns real
        local real dx = x2 - x
        local real dy = y2 - y
        return SquareRoot(dx * dx + dy * dy)
    endfunction

    function EmptyGroup takes group g returns nothing
        set ExtraGroup = g
        call ForGroup(ExtraGroup,function GroupEmpty)
        set ExtraGroup = null
    endfunction
    
    function BoolAddResource takes boolean b,player p,playerstate res,integer amount returns boolean
        if b then
            call SetPlayerState(p,res,GetPlayerState(p,res)+amount)
        endif
        return b
    endfunction
    
    function Debug takes string s returns nothing
        call DisplayTextToPlayer(GetLocalPlayer(),0,0,s)
    endfunction
    
    function GetClosestUnitOfGroup takes group g,real x,real y returns unit
        set ExtraReal = 100000
        set ExtraX = x
        set ExtraY = y
        set ExtraUnit = null
        call ForGroup(g, function ClosestUnitLoop)
        return ExtraUnit
    endfunction
    
    function GetNClosestOfGroup takes group g,real x,real y, integer n returns nothing
        local group backup = CreateGroup()
        local unit u
        set ExtraUs = 0
        loop
            set u = GetClosestUnitOfGroup(g,x,y)
            exitwhen ExtraUs > n or u == null
            call GroupRemoveUnit(g,u)
            call GroupAddUnit(backup,u)
            set ExtraUs = ExtraUs + 1
            set ExtraU[ExtraUs] = u
        endloop
        call DestroyGroup(g)
        set g = backup
        set g = null
        set backup = null
    endfunction
    
    function FindClosestUnitOfType takes integer UnitType,real x,real y returns unit
        local group g = CreateGroup()
        local unit u
        set ExtraInt = UnitType
        call GroupEnumUnitsInRange(g,0,0,100000,function UnitTypeIsInteger)
        set u = GetClosestUnitOfGroup(g,x,y)
        //Clearing up
        call DestroyGroup(g)
        set g = null
        return u
    endfunction
    
    function IntPower takes integer number,integer power returns integer
        local integer i = 1
        local integer resultnumber = number
        if power == 0 then
            return 1
        endif
        loop
            exitwhen i == power
            set resultnumber = resultnumber*number
            set i = i + 1
        endloop
        return resultnumber
    endfunction
    
    function AddUnitState takes unit u, unitstate us, real amount returns nothing
        static if LIBRARY_DamageEngine then
            if us = UNIT_STATE_LIFE then
                call SetUnitLife(u,GetUnitLife(u)+amount)
            endif
        else
            call SetUnitState(u,us,GetUnitState(u,us)+amount)
        endif
    endfunction
    function CurrentOrderComp takes unit u,string order returns boolean
        return GetUnitCurrentOrder(u) == OrderId(order)
    endfunction
endlibrary
JASS:
//! import "ExtraFunctions.j"
library ExtraConstants initializer i requires ExtraFunctions
    globals
        integer array Pow2
    endglobals
    private function i takes nothing returns nothing
        set Pow2[0] = 1
        set Pow2[1] = 2
        set Pow2[2] = 4
        set Pow2[3] = 8
        set Pow2[4] = 16
        set Pow2[5] = 32
        set Pow2[6] = 64
        set Pow2[7] = 128
        set Pow2[8] = 256
        set Pow2[9] = 512
        set Pow2[10] = 1024
        set Pow2[11] = 2048
        set Pow2[12] = 4096
        set Pow2[13] = 8192
        set Pow2[14] = 16384
        set Pow2[15] = 32768
        set Pow2[16] = 65536
        set Pow2[17] = 131072
        set Pow2[18] = 262144
        set Pow2[19] = 524288
        set Pow2[20] = 1048576
        set Pow2[21] = 2097152
        set Pow2[22] = 4194304
        set Pow2[23] = 8388608
        set Pow2[24] = 16777216
        set Pow2[25] = 33554432
        set Pow2[26] = 67108864
        set Pow2[27] = 134217728
        set Pow2[28] = 268435456
        set Pow2[29] = 536870912
        set Pow2[30] = 1073741824
        set Pow2[31] = 2147483648
    endfunction
endlibrary
Top