(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > Submissions

Submissions Submit JASS resources! If approved, they will be moved to their proper section.
Please read me first.

Reply
 
LinkBack Thread Tools Display Modes
Old 08-29-2008, 09:48 PM   #1 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

UnitAddDamage

Changes a unit's damage without showing +(amount) or -(amount). A testmap with the needed abilities is attached at the bottom; to test the system, type a number ingame, and the mortar team's damage will change by that number.

Note: The Demo Map's code is a little older and thus should not be used, instead use the code in this thread.

Known bugs

  • Does not work on units with any form of Unit Inventory (IE an inventory which can store but not use items) Note: this applies even if it is an ability which requires an upgrade which has not yet been researched.



Maintenance

  • When imported, the DamageModifierId function must be changed to have the correct item IDs of the tomes.
  • The HasNoInventory function should be updated to include any custom inventories based off Inventory (Hero), or any other inventory which allows use of items.



Behavior in detail

  • When used, the unit's Base Damage will increase by 'amount' (or decrease of amount is negative)
  • If a damage value (minimum or maximum) becomes negative, it will be treated and displayed as 0 but still stored as negative, meaning that if you give a unit with 1-1 damage -2 damage, it will display as 0-0, but adding 1 damage will cause it to remain at 0-0. Adding an additional point of damage would move it to 1-1.



Use in GUI

  • If using vJass/JassNewGenPack, put the vJass script in a new trigger (I recommend calling it UnitAddDamage, but it doesn't matter).
  • If not using vJass/JassNewGenPack, copy this script to the "Custom Script Section", which is accessed by clicking on what looks like your map file on the top of the trigger tree in the Trigger Editor. Paste the non-vJass code in the bottom box on the right.
  • In your trigger, use the following custom script:
    Custom script: call UnitAddDamage(<YourUnit>,<Amount>)
  • Note that variables are prefixed by udg_. For example, to add TempInt life to TempUnit, you would do
    Custom script: call UnitAddDamage(udg_TempUnit,udg_TempInt)



vJass

library UnitAddDamage
    globals
        private integer ans
    endglobals
    private function HasNoInventory takes unit u returns boolean
        return GetUnitAbilityLevel(u,'AInv') == 0
    endfunction
    private function DamageModifierId takes real amount returns integer
        if amount >= 10 then
            set ans = 10
            return 'I001'//+10 damage
elseif amount >= 1 then
            set ans = 1
            return 'I000'//+1 damage
        elseif amount <= -10 then
            set ans = -10
            return 'I003'//-10 damage
        elseif amount <= -1 then
            set ans = -1
            return 'I002'//-1 damage
        endif
        return 0
    endfunction
    function UnitAddDamage takes unit u, integer amount returns nothing
        local boolean b = HasNoInventory(u)
        if b then
            call UnitAddAbility(u,'AInv')
        endif
        loop
            exitwhen amount == 0
            call UnitAddItemById(u,DamageModifierId(amount))
            set amount = amount - ans
        endloop
        if b then
            call UnitRemoveAbility(u,'AInv')
        endif
    endfunction
endlibrary



Jass

function HasNoInventory takes unit u returns boolean
    return GetUnitAbilityLevel(u,'AInv') == 0
endfunction
function DamageModifierId takes real amount returns integer
    if amount >= 10 then
        return 'I001'//+10 damage
    elseif amount >= 1 then
        return 'I000'//+1 damage
    elseif amount <= -10 then
        return 'I003'//-10 damage
    elseif amount <= -1 then
        return 'I002'//-1 damage
    endif
    return 0
endfunction
function UnitAddDamage takes unit u, integer amount returns nothing
    local boolean b = HasNoInventory(u)
    if b then
        call UnitAddAbility(u,'AInv')
    endif
    loop
        exitwhen amount == 0
        call UnitAddItemById(u,DamageModifierId(amount))
        if amount >= 10 then
            set amount = amount - 10
        elseif amount >= 1 then
            set amount = amount - 1
        elseif amount <= -10 then
            set amount = amount + 10
        elseif amount <= -1 then
            set amount = amount + 1
        endif
    endloop
    if b then
        call UnitRemoveAbility(u,'AInv')
    endif
endfunction

Attached Files
File Type: w3x UnitAddDamage.w3x (17.3 KB, 2 views)

Last edited by PurplePoot; 11-22-2008 at 07:24 PM.. Reason: Fixed bugginess in the test map
PurplePoot is offline   Reply With Quote
Old 08-31-2008, 06:33 PM   #2 (permalink)
 
The_Reborn_Devil's Avatar

Fear me!
 
Join Date: Dec 2006
Posts: 249

The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)


You should have this line: elseif amount <= -10 then before elseif amount <= -1 then else it will always return 'I002' when it's <= -1.
__________________
The_Reborn_Devil is offline   Reply With Quote
Old 08-31-2008, 06:36 PM   #3 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Good point, fail @ me. I doubt it matters much either way, but still, blah.
PurplePoot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

All times are GMT. The time now is 09:14 AM.






Your link here 
Mortgages | Car Loan | Die Casting Company | Deals On Products | 0 Credit Cards
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Copyright©Ralle