• 🏆 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!

Atack Speed Library v1.01

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Library 'AttackSpeedBonus' ver 1.01 can add attack speed bonus to a single unit.

1. UnitClearASBonus(unit <whatUnit>) --> clear AS (attack speed) bonus set by this library

2. UnitSetASBonus(unit <whatUnit>, integer <bonus>) -->
This function clears any previously applied bonus on <whatUnit>, and setting
new attack speed bonus. Range: from -80 to +400 (%)
Value outside range will be modified. However in Warcaft3 values lower then -80%
or higher then +400% cannot afftect unit's attack speed more then -80% / +400%.

3. UnitGetASBonus(unit whatUnit) returns integer -->
Returns AS bonus amount currently applied to <whatUnit> by this system.

* Instalation:
copy "AttackSpeedBonus" trigger and paste into your map
copy 3 abilities, and set their raw codes


ASLib%20abi1.jpg


ASLib%20abi2.jpg


ASLib%20pic3.jpg



gui example:

  • esc
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set TempInt = (Random integer number between -80 and 400)
      • Set TempU = Tauren Chieftain 0015 <gen>
      • Custom script: call UnitSetASBonus(udg_TempU, udg_TempInt)
      • Game - Display to (All players) the text: (Bonus attack speed: + (String(TempInt)))


code v1.01:
JASS:
//-----------------------------------------------------------------------------
// Library AttackSpeedBonus can add attack speed bonus to a single unit.
//      made by ZibiTheWand3r3r
//-----------------------------------------------------------------------------
//      functions:
// UnitClearASBonus(unit <whatUnit>) --> clear AS (attack speed) bonus set by this library
// UnitSetASBonus(unit <whatUnit>, integer <bonus>) -->
//      This function clears any previously applied bonus on <whatUnit>, and setting 
//      new attack speed bonus. Range: from -80 to +400 (%)
//      Value outside range will be modified. However in Warcaft3 values lower then -80%
//      or higher then +400% cannot afftect unit's attack speed more then -80% / +400%.
// UnitGetASBonus(unit whatUnit) returns integer -->
//      Returns AS bonus amount currently applied to <whatUnit> by this system.
//-----------------------------------------------------------------------------
// Instalation: 
//      copy this trigger and paste into your map
//      copy 3 abilities, and set below their raw codes
//-----------------------------------------------------------------------------
library AttackSpeedBonus initializer Init
// please make sure these abilities' raw codes are the same as copied into your map:
    globals
        private integer BonusAbility001 = 'A00E'  //AttackSpeedBonus1 ability
        private integer BonusAbility010 = 'A00F'  //AttackSpeedBonus10 ability
        private integer BonusAbility100 = 'A00G'  //AttackSpeedBonus100 ability
    endglobals
//------------------------------------------------------------------------------
// system code : do not edit below --------------------------------------
//------------------------------------------------------------------------------
private function UnitAddAbilityLevel takes unit u, integer abiId, integer level returns nothing
    call UnitAddAbility(u, abiId)
    call SetUnitAbilityLevel(u, abiId, level)
    call UnitMakeAbilityPermanent(u, true, abiId)
endfunction
//-------------------------------
function UnitClearASBonus takes unit u returns nothing
    call UnitRemoveAbility(u, BonusAbility001)
    call UnitRemoveAbility(u, BonusAbility010)
    call UnitRemoveAbility(u, BonusAbility100)
endfunction
//-------------------------------
function UnitSetASBonus takes unit u, integer bonus returns nothing
    local integer a
    call UnitClearASBonus(u)
    if bonus > 0 then // -positive- bonus
        set bonus = IMinBJ(bonus, 400)

        set a = bonus/100 //100
        if a > 0 then
            call UnitAddAbilityLevel(u, BonusAbility100, a)
            set bonus = bonus - (a*100)
        endif
        set a = bonus/10 //10
        if a > 0 then
            call UnitAddAbilityLevel(u, BonusAbility010, a+9)
            set bonus = bonus - (a*10)
        endif
        if bonus > 0 then //1
            call UnitAddAbilityLevel(u, BonusAbility001,  bonus+9)
        endif

    elseif bonus < 0 then // -negative-bonus
        set bonus = IMaxBJ(bonus, -80)
        
        set a = bonus/ (-10) // 10
        if a > 0 then
            call UnitAddAbilityLevel(u, BonusAbility010, a)
            set bonus = bonus + (a*10)
        endif
        set a = -bonus // 1
        if a > 0 then
            call UnitAddAbilityLevel(u, BonusAbility001, a)
        endif
    
    endif
endfunction
//----------------------------------------------------------------
function UnitGetASBonus takes unit u returns integer
    local integer i10 = GetUnitAbilityLevel(u, BonusAbility010)
    local integer i1 = GetUnitAbilityLevel(u, BonusAbility001)
    local integer bonus = 0

    set bonus = GetUnitAbilityLevel(u, BonusAbility100) * 100 // hundreds [+]
    if i10 > 9 then // tens [+]
        set bonus = bonus + ((i10-9)*10)
    elseif i10 > 0 then // tens [-]
        set bonus = - (i10*10)
    endif

    if i1 > 9 then // single [+]
        set bonus = bonus + (i1-9)
    elseif i1 > 0 then // single [-]
        set bonus = bonus - i1
    endif
    return bonus
endfunction
//------------------------------
private function Init takes nothing returns nothing
    local unit u = CreateUnit(Player(15), 'hpea', 0, 0, 0)
        call UnitAddAbility(u, BonusAbility001)
        call UnitAddAbility(u, BonusAbility010)
        call UnitAddAbility(u, BonusAbility100)
    call RemoveUnit(u)
    set u=null
endfunction
endlibrary
//-----------------------------------------------------------------------------

ver 1.01: added Arad MNK's suggestion

Keywords:
attack speed, change, set AS
Contents

AttackSpeed Library v1.01 (Map)

Reviews
19:32, 15th Mar 2016 BPower: Rejected because there are already 3 code submission for bonus manipulation. For more information see the conversation in the thread comments.

Moderator

M

Moderator

19:32, 15th Mar 2016
BPower: Rejected because there are already 3
code submission for bonus manipulation. For more information see the
conversation in the thread comments.
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
It would be nice if you also add a 1000 ability as well. Nice library btw.

Just a suggestion:

JASS:
            call UnitAddAbility(u, BonusAbilitySth)
            call SetUnitAbilityLevel(u, BonusAbilitySth, a)
            call UnitMakeAbilityPermanent(u, true, BonusAbilitySth)

I see this too repetitive. You can just use this custom BJ:

JASS:
function AddAbility takes integer Abil, unit u, integer a returns nothing
    call UnitAddAbility(u, Abil)
    call SetUnitAbilityLevel(u, Abil, a)
    call UnitMakeAbilityPermanent(u, true, Abil)
endfunction

Or make u a dynamic global:

JASS:
globals
    private unit u //has to be private as it's too general
endglobals

function AddAbility takes integer Abil, integer a returns nothing
    call UnitAddAbility(u, Abil)
    call SetUnitAbilityLevel(u, Abil, a)
    call UnitMakeAbilityPermanent(u, true, Abil)
endfunction
 
Level 10
Joined
Aug 21, 2010
Messages
316
if this works with bloodlust , ufrenzy, berserk...etc? I mean, if there are any conflicts with the above.
Have you tested?

When I saw the title I thought this was an attempt to detect the attack speed but this is quite something else.Nothing interesting to me.
 
Level 18
Joined
Nov 21, 2012
Messages
835
@Arad MNK Thanks for suggestion
@zv27 of course it works with any AS abilities like bloodlust unholy frenzy slow, etc. It stacks: unit with slow (-25%) and with +100% AS from this library will have +75%AS
@BPower No, this Lib doesnt offer anything more then BonusMod do. True.
BonusMod works, but it is in graveyard. It has 2 math mistakes that user must fix yourself (it was commented on 1st page). Btw Im not sure but does Object Merger work with all new Windows versions?
This Lib is easy to import /3 custom abilities/. User can switch between maps and CnP abilities without macros.

Imagine what if someone wants to upload spell to spell section where hero's AS varies during this spell. Should he force users to additionally download BonusMod and expand it with AS, and tell the user to fix those 2 math mistakes?

If you decide this Lib should not be uploaded here I respect it and will remove Library.
 
Level 10
Joined
Aug 21, 2010
Messages
316
From the above it can be concluded the following. Constantly repeating the same systems, same shit from day to day , from year to year.What this then means?Should we remove half or more from this section?Of course not!
This system should be approved because it is very easy to import and could also be useful to people who do not like complicated things .(Of course , if everything works right)
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Nest also made his version of Bonusmod, he just named it Bonus though.
https://github.com/nestharus/JASS/blob/master/jass/Systems/Bonus/script.j
JASS:
library Bonus /* v2.0.0.2
*************************************************************************************
*
*   Adds bonuses to units. In the ini area, these bonuses can be enabled and disabled.
*   Ranges of bonus values can also be modified.
*
*   Bonuses
*       -   Armor                   any unit                        non percent bonus
*       -   Damage                  units with attack only          non percent bonus
*       -   Agility                 hero only                       non percent bonus
*       -   Strength                hero only                       non percent bonus
*       -   Intelligence            hero only                       non percent bonus
*       -   Life                    any unit                        non percent bonus
*       -   Life Regeneration       any unit                        non percent bonus
*       -   Mana                    any unit                        non percent bonus
*       -   Mana Regeneration       units with mana only            percent bonus
*       -   Sight Range             any unit                        non percent bonus
*       -   Attack Speed            units with attack only          percent bonus
*
*************************************************************************************
*
*   */uses/*
*       */ UnitIndexer /*       hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*       */ Table /*             hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
************************************************************************************
*   SETTINGS
*/
globals
    /*************************************************************************************
    *
    *                                   PRELOAD
    *
    *   Preloads all bonus abilities. This will add a hefty load time to the map but will
    *   prevent lag in game.
    *
    *************************************************************************************/
    private constant boolean PRELOAD = false
endglobals
/*
*************************************************************************************
*
*   Bonuses
*
*       constant integer BONUS_ARMOR
*       constant integer BONUS_DAMAGE
*       constant integer BONUS_AGILITY
*       constant integer BONUS_STRENGTH
*       constant integer BONUS_INTELLIGENCE
*       constant integer BONUS_LIFE
*       constant integer BONUS_LIFE_REGEN
*       constant integer BONUS_MANA
*       constant integer BONUS_MANA_REGEN
*       constant integer BONUS_ATTACK_SPEED
*       constant integer BONUS_SIGHT
*
*   Functions
*
*       function GetUnitBonus takes unit whichUnit, integer whichBonus returns integer
*       function SetUnitBonus takes unit whichUnit, integer whichBonus, integer value returns nothing
*       function AddUnitBonus takes unit whichUnit, integer whichBonus, integer value returns nothing
*
************************************************************************************/
    //! runtextmacro BONUS_SCRIPT()
    function SetUnitBonus takes unit u, integer b, integer v returns nothing
        local boolean n
        local integer a
        local integer p
        local integer on
        local integer i
        local integer nch
        local integer nb
        debug if (not IsUnitIndexed(u)) then
            debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT BONUS ERROR: INVALID UNIT")
            debug return
        debug endif
        debug if (0==pm[b]) then
            debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT BONUS ERROR: INVALID BONUS TYPE")
            debug return
        debug endif
        set i=GetUnitUserData(u)
        if (v != cb[i][b]) then
            set nch=0
            if (ir[b]) then
                set n=0>v
                set cb[i][b]=v
                set p=b+pm[b]-1
                set on=p+1
                call UnitRemoveAbility(u,bo[on])
                if (n) then
                    set v=v-ps[on]
                endif
                loop
                    if (0>v-ps) then
                        call UnitRemoveAbility(u,bo)
                    else
                        call UnitAddAbility(u,bo)
                        call UnitMakeAbilityPermanent(u,true,bo)
                        set v=v-ps
                    endif
                    exitwhen p==b
                    set p=p-1
                endloop
                if (n) then
                    call UnitAddAbility(u,bo[on])
                    call UnitMakeAbilityPermanent(u,true,bo[on])
                endif
            else
                set nb=v
                set v=v-cb[i][b]
                set cb[i][b]=nb
                set a=bo[b]
                set on=b+pm[b]+1
                loop
                    loop
                        exitwhen 0<v
                        set v=v-ps[on]
                        set nch=nch+1
                    endloop
                    set p=b+pm[b]
                    loop
                        if (0<=v-ps) then
                            set v=v-ps
                            call UnitAddAbility(u,a)
                            call SetUnitAbilityLevel(u,a,bp+2)
                            call UnitRemoveAbility(u,a)
                        else
                            set p=p-1
                            exitwhen p==b
                        endif
                    endloop
                    exitwhen 0==v
                endloop
                loop
                    exitwhen 0==nch
                    set nch=nch-1
                    call UnitAddAbility(u,a)
                    call SetUnitAbilityLevel(u,a,(-bp[on])+2)
                    call UnitRemoveAbility(u,a)
                endloop
            endif
        endif
    endfunction
    function GetUnitBonus takes unit u, integer b returns integer
        return cb[GetUnitUserData(u)][b]
    endfunction
    function AddUnitBonus takes unit u, integer b, integer v returns nothing
        call SetUnitBonus(u,b,GetUnitBonus(u,b)+v)
    endfunction
endlibrary
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
BonusMod works, but it is in graveyard.
BonusMod is submitted on wc3.net, what is in the graveyard is not the actual version.

It has 2 math mistakes that user must fix yourself (it was commented on 1st page).
Can you link me to the comment?

Btw Im not sure but does Object Merger work with all new Windows versions?
Yes it works.

Imagine what if someone wants to upload spell to spell section where hero's AS varies during this spell. Should he force users to additionally download BonusMod and expand it with AS, and tell the user to fix those 2 math mistakes?
BonusMod is very powerful, also useful. Furthermore you can disable all bonus types you don't need.

If you decide this Lib should not be uploaded here I respect it and will remove Library.
Personally, if BonusMod is flawed ( I'm not aware of that ), I would appreciate if someone
makes a similar working resource. I'm also fine with yours. I just feel it's incomplete.
 
Level 18
Joined
Nov 21, 2012
Messages
835
BonusMod is submitted on wc3.net, what is in the graveyard is not the actual version.
I didnt know that. Maybe I depend on Hive to much:D And can't we just delete this old graveyarded version to not confuse people. Btw I also didn't know about Nestharus version on his web side. Sorry.

With 2 math mistakes I refer to this graveyarded version on Hive.
http://www.hiveworkshop.com/forums/graveyard-418/system-bonus-mod-setunitmaxstate-65622/#post1028553

for macros I found this: http://www.hiveworkshop.com/forums/spells-569/jass-custom-stat-system-css-v1-5g-229885/#post2288086

Personally I'm fan of small snippets / libraries, when user can install only those acctually needed. It seems to me I said all I want to. Do as you want.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Bonus and BonusMod can be reduced to the purpose of your submission.
You can actually decided which Bonus types should be created,
by running or not running the respective textmacro.

Then there is CSS, which is also very similar.

I'll put this one to Need Fix because I dislike the Rejected status for resources.
Contact me if you disagree.
 
Top