• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

DamageReductionTable

Well, a system for setting and retrieving customized damage and spell reduction values for units...


JASS:
//This is a custom Damage Reduction system that provides easy setting and changing of
//a unit's damage reduction and spell reduction by just using some function calls
//No object data needed to be created in the Object editor
//This system is useful for maps that will be having a custom damage system

//////////////////////////////////////////////////////////////////////////////
//--------------HOW TO USE--------------------------------------------------//
//--------------HOW TO INITIALIZE-------------------------------------------//
//First you need to initialize each unit that will use this system using    //
//                                                                          //
//DamageReduction.create(unit target, real damagered, real spellred)        //
//                                                                          //
//unit target = unit to be initialized                                      //
//                                                                          //
//real damagered = damage reduction value                                   //
//                                                                          //
//real spellred = spell reduction value                                     //
//                                                                          //
//-------------HOW TO GET VALUES--------------------------------------------//
//                                                                          //
//To get the value of spell or damage reduction just use these 2 functions: //
//                                                                          //
//DamageReduction.GetDamageReduction(unit u)                                //
//                                                                          //
//DamageReduction.GetSpellReduction(unit u)                                 //
//                                                                          //
//-------------HOW TO MODIFY VALUES IN-GAME---------------------------------//
//                                                                          //
//To modify values in-game just use these 2 functions:                      //
//                                                                          //
//DamageReduction.AddSpellReduction(unit target, real value, boolean add)   //
//                                                                          //
//DamageReduction.AddDamageReduction(unit target, real value, boolean add)  //
//                                                                          //
//unit target is the unit whose reduction value you want to change          //
//                                                                          //
//real value is the value of reduction to be used                           //
//                                                                          //
//boolean add if true will add real value to the current reduction          //
//                                                                          //
//while if false will set reduction to real value                           //
//                                                                          //
//NOTE: these two functions returns the new reduction values so if you need //
//to use those right away, you can directly use these function rather than  //
//using the Add function and then using the Get functions afterwards        //
//                                                                          //
//------------REMOVING INSTANCES--------------------------------------------//
//                                                                          //
//The system already checks every UPDATE_TIME interval for instances that   //
//                                                                          //
//are already unused due to the unit being dead and destroys that instance  //
//                                                                          //
//automatically.                                                            //
//                                                                          //
//You can destroy an instance directly by using                             //
//DamageReduction.Clear(unit u)                                             //
//////////////////////////////////////////////////////////////////////////////



library DamageReductionTable
//Version 1.1c
//By: Adiktuz
    
    globals
        private constant real UPDATE_TIME = 1.00
        //This is the timer interval between the system's check for dead units to remove their instances
        private integer array DRI
        private integer TOTAL = 0
        private timer DRT_TIMER = CreateTimer()
    endglobals
    
    struct DamageReduction
        real DAMAGE_REDUCTION
        real SPELL_REDUCTION
        unit u
        static thistype data
        
        //Used by the methods in this system to translate the unit parameter
        //into its struct instance
        static method GetInstance takes unit target returns thistype
            local integer i = 0
            loop
                exitwhen i == TOTAL
                set data = DRI[i]
                if target == data.u then
                    set i = TOTAL
                else
                    set i = i + 1
                    set data = 0
                endif
            endloop
            return data
        endmethod
        
        //Methods for Getting and setting reduction data
        static method GetDamageReduction takes unit u returns real
            return data.GetInstance(u).DAMAGE_REDUCTION
        endmethod
        
        static method GetSpellReduction takes unit u returns real
            return data.GetInstance(u).SPELL_REDUCTION
        endmethod
        
        static method AddSpellReduction takes unit target, real value ,boolean add returns real
            set data = DamageReduction.GetInstance(target)
            if add then
                set data.SPELL_REDUCTION = data.SPELL_REDUCTION + value
            else
                set data.SPELL_REDUCTION = value
            endif
            return data.SPELL_REDUCTION
        endmethod
        
        static method AddDamageReduction takes unit target, real value ,boolean add returns real
            set data = DamageReduction.GetInstance(target)
            if add then
                set data.DAMAGE_REDUCTION = data.DAMAGE_REDUCTION + value
            else
                set data.DAMAGE_REDUCTION = value
            endif
            return data.DAMAGE_REDUCTION
        endmethod
        
        
        
        //Method for clearing a unit's instance immediately
        static method Clear takes unit u returns nothing
            local integer i = 0
            set data = DamageReduction.GetInstance(u)
            loop
                exitwhen i == TOTAL
                if data == DRI[i] then
                    set TOTAL = TOTAL - 1
                    set DRI[i] = DRI[TOTAL]
                    set i = TOTAL
                    call data.destroy()
                else
                    set i = i + 1
                endif
            endloop
        endmethod
        
        //This method scans for instanced units that are already dead
        //and destroy's their instance
        static method update takes nothing returns nothing
            local integer i = 0
            loop
                exitwhen i == TOTAL
                set data = DRI[i]
                if data.u == null or GetWidgetLife(data.u) < .405 then
                    set TOTAL = TOTAL - 1
                    set DRI[i] = DRI[TOTAL]
                    set i = i - 1
                    call data.destroy()
                endif
                set i = i + 1
            endloop
            if TOTAL == 0 then
                call PauseTimer(DRT_TIMER)
            endif
        endmethod
        
        //This method is used to initialize each unit for the system
        static method create takes unit target, real damagered, real spellred returns thistype
            set data = DamageReduction.allocate()
            set data.DAMAGE_REDUCTION = damagered
            set data.SPELL_REDUCTION = spellred
            set data.u = target
            set DRI[TOTAL] = data
            if TOTAL == 0 then
                call TimerStart(DRT_TIMER, UPDATE_TIME, true, function DamageReduction.update)
            endif
            set TOTAL = TOTAL + 1
            return data
        endmethod
    endstruct
    
endlibrary


    

    
endlibrary

I've also uploaded it in the spells section DRT but xBlackRose suggested that it should be in the JASS submissions... ^^
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
After reading some of it, I see some seriously problems.

Problem #1: You need to use a unit indexer to relate your data to the units... your loop method is idiotic >.>

->This method is used to initialize each unit for the system
>.<

Do damage/spell reduction based on unit type id, and then let people manipulate from there...

You need to also be able to do damage reduction for specific damage types (siege, piercing, etc). This means you need a GetDamageType(unitTypeId) script >.>, which I happily know how to do. If you want, I can write it up for you = ). I can even write something to automatically retrieve % damage reduction for each armor/damage type = P.

You need to be able to reduce both by value and by percent.

If you really want to support custom damage systems, you need to support custom attack types and custom armor types.

Really, this design is poor for supporting custom damage systems...

You should be able to do this-
Attack:
--psychic: 30
--physical: 60
--ice: 10
--fire: 5

Defense: (a combination of armors and nature with both resistance and absorption by % and value)
Super armor 3 (super armor*3)
--physical 5%
--psychic 2%
--ice 6%
--fire 6%

Magic Absorber Armor x1
--physical -500
--non-physical 160

Natural:
--physical 50%

Resistance % is just a value between 0 and 1. Extra damage % and absorption % are values > 1 and < 0. What this means is that resistances apply to a pool that is capped at 1 (negative resistance is norm) and absorptions add on to whatever the resistances are.

So resistance of .15, .65, .95 and absorption of .02, .05, and .09 would be
.15 + .65 + .95 = 1.75 = 1 (cap it)

.02 + .05 + .09 = .16

1 + .16 = 1.16 (heal 16% of attack per hit)

life-(100-100*1.16) = life-(-16+other vals)

now if you have by value resistance and by value absorption, you just take w/e the above value is and add by value resistance/by value absorption to it.

500 damage (resistance)
100 damage (absorb)

JASS:
if (damage > 0) then
    set damage = damage - resistance
endif
set damage = damage - absorb

or
life-(-16-100) = life + 116


Now, given that doing the above requires a 100% rewrite and should really be done within multiple resources, I think you should just focus on normal wc3 damage, k? Also I'm already planning to right the above as I'm doing a full combat suite = ). There is sadly no resource out atm that manipulates regular wc3 combat /cry.
 
well I have one based on unit type id but the problem with that is if for example you have a spell that reduces or increases armor, since its unit-typeid based then you cannot modify it for specific units only...

about the loop, you can remove it... its just so that you dont need to manually remove instances for units that die...

it supports both value and percent reduction, it will depend on how you use the system... for example you can initialize it with integers and then maybe do something like
Set Damage = Damage*(100-DamageReduction.GetDamageReduction(unit)) for percent reduction and do
Set Damage = Damage-DamageReduction.GetDamageReduction(unit) for value reduction

I can try doing support for different armor types that is definable by the player... or maybe not since you said you will be writing something like your suggestion... ^^

but I dont think I'll add support for the normal wc3 system if I update this...
 
->but I dont think I'll add support for the normal wc3 system if I update this...

->I can try doing support for different armor types that is definable by the player... or maybe not since you said you will be writing something like your suggestion... ^^

then I must ask why anyone in their right mind would use this : P

I'll say they must use yours when you finish it... ^^
 
Top