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

[JASS] Custom Stat System (CSS) v1.5g

I urge all users who are using an earlier version of this system to update as soon as possible to avoid possible issues found in older versions.

For those who already have a previous version (before 1.5j), please copy the code below, paste it into an empty trigger and run it just like how you execute the Implementation Macro. It will patch up the bugged Life Regeneration abilities. I am deeply sorry for the inconvenience. You can also find a copy of this in the test map of v1.5j.

JASS:
// CSS - Life Regeneration
//============================================================================================
//! textmacro LifeRegenAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a Arel $RAWCODE$ Ihpr 1 $VALUE$ anam "CSS - Life Regen ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTexturesCommandButtonsBTNRingSkull.blp
//! endtextmacro

//! runtextmacro LifeRegenAbility("ZxJ0", "+00001", "1")
//! runtextmacro LifeRegenAbility("ZxJ1", "+00002", "2")
//! runtextmacro LifeRegenAbility("ZxJ2", "+00004", "4")
//! runtextmacro LifeRegenAbility("ZxJ3", "+00008", "8")
//! runtextmacro LifeRegenAbility("ZxJ4", "+00016", "16")
//! runtextmacro LifeRegenAbility("ZxJ5", "+00032", "32")
//! runtextmacro LifeRegenAbility("ZxJ6", "+00064", "64")
//! runtextmacro LifeRegenAbility("ZxJ7", "+00128", "128")
//! runtextmacro LifeRegenAbility("ZxJ8", "+00256", "256")
//! runtextmacro LifeRegenAbility("ZxJ9", "+00512", "512")
//! runtextmacro LifeRegenAbility("ZxJa", "+01024", "1024")
//! runtextmacro LifeRegenAbility("ZxJb", "+02048", "2048")
//! runtextmacro LifeRegenAbility("ZxJc", "+04096", "4096")
//! runtextmacro LifeRegenAbility("ZxJd", "+08192", "8192")
//! runtextmacro LifeRegenAbility("ZxJe", "+16384", "16384")
//! runtextmacro LifeRegenAbility("ZxJf", "+32768", "32768")
//! runtextmacro LifeRegenAbility("ZxJg", "+65536", "65536")
//! runtextmacro LifeRegenAbility("ZxJh", "-131072", "-131072")

CUSTOM STAT SYSTEM v1.5g

Features
  • You can now have a fully-functional item with up to 11 types of stats with a single GUI custom script. Abilities for items' passive stats are no longer required.
  • GUI-friendly interface and usage. Configurability relies mainly on global boolean variables.
  • Right Click Item Socketing that transfers the overwhelming benefits from the mechanics of Diablo 2's socketing system to Warcraft 3. Furthermore, this is only an add-on and can be toggled on/off at will.
  • Socketing means empowering an item with another item (usually called a gem). An item that is socketable usually has sockets which are, in a nutshell, holes to which a gem can be inserted. When all the sockets are filled the item can no longer be socketed. Socketing is a way of upgrading your item as you wish to and it is a prominent feature in most RPG games.
  • Quite simple actually. Right-click on the socket item and left click on the target item. A notification will pop-up upon successful socketing.
  • Item info panel that can be accessed with a single chat command (as seen in the screenshot above). Just remember to include it in your map's log.
  • Socket event can be caught with the Event: Game - EVENT_SOCKET_FINISH becomes equal to 1.00. Do not use waits in the response trigger or it is screwed up.
  • BonusMod-like features for extensive usage. Now a standalone part of the system.
  • Easy implementation.
  • Vanilla WE JASS. JNGP is required only for running the Object Merger macro.
  • => A system for epic RPGs (and its other sub-genres such as ORPGs, SPRPGs, etc) as well as any maps that incorporate a large amount of items. Say goodbye to your old-fasioned method of sitting for hours creating stats for your items. CSS is here to stay.

It is easy. Just copy the Map Header Custom Code, CSS Standalone Bonus trigger and the abilities. Then use the system however you want.




JASS:
//************************************************************************************************************
//*                                                                                                          *
//*                              CUSTOM STAT SYSTEM (CSS)                                                    *
//*                                                                                                          *
//*   Author:   Doomlord                                                                                     *
//*   Version:  1.5g                                                                                         *
//*                                                                                                          *
//*   Credits:                                                                                               *
//*   + Earth-Fury:    BonusMod binary algoritm; implementation macro.                                       *
//*   + Crigges:       A great amount of help and support.                                                   *
//*   + Geries:        Help me with the item hashtable values cleanup.                                       *
//*   + rulerofiron99: Item Socketing method referenced from [GUI]Right Click Item Recipe v1.05.             *
//*   + Vexorian:      CSS_SimError [url]http://www.wc3c.net/showthread.php?t=101260[/url]                   *
//*   + Magtheridon96: [Snippet]BoundInt [url]http://www.hiveworkshop.com/forums/2294066-post804.html[/url]  *
//*   + WaterKnight:   Help with the stack for custom Event Response.                                        *
//*   + PurgeandFire:  Pinpoint a possible desync bug with the system.                                       *
//*   + Nestharus:     Mentioning the possible negative life bug in his Bonus lib.                           *
//*                                                                                                          *
//************************************************************************************************************


//**************************************************************************************
//* INTRODUCTION:                                                                      *
//*                                                                                    *
//* An alternative to BonusMod for those who prefer a vanilla JASS approach.           *
//*                                                                                    *
//* Just follow the API and you are pretty much done.                                  *
//**************************************************************************************


//********************************************************************************************************
//* REQUIREMENTS:                                                                                        *
//*                                                                                                      *
//* JNGP [url]http://www.hiveworkshop.com/forums/tools-560/jassnewgenpack-5d-227445[/url] (Recommended)  *
//* OR:                                                                                                  *
//* Your superhuman capability to transfer 198 abilities to your map. (Not Recommended)                  *
//********************************************************************************************************


//************************************************************************************************************************************************
//* INSTALLATION INSTRUCTION:                                                                                                                    *
//*                                                                                                                                              *
//* Step 1: Copy the custom code for bonus handling to your map header.                                                                          *
//* Step 2: Use JNGP to implement the system's abilities through macro. Instruction is included in the Implementation Macro trigger.             *
//* Step 3: Copy the whole CSS folder to your map. Don't forget to turn on "Automatically create unknown variables while pasting trigger data".  *
//* Step 4: Except for this trigger, delete every other useless elements.                                                                        *
//* Step 5: Use this BonusMod alternative however you want.                                                                                      *
//*                                                                                                                                              *
//************************************************************************************************************************************************


//**************************************************************************************
//* Bonus Types Identifier:                                                            *
//*                                                                                    *
//* Armor Bonus:        0                                                              *
//* Attack Speed Bonus: 1                                                              *
//* Damage Bonus:       2                                                              *
//* Agility Bonus:      3                                                              *
//* Intelligence Bonus: 4                                                              *
//* Strength Bonus:     5                                                              *
//* Life Regen Bonus:   6                                                              *
//* Mana Regen Bonus:   7                                                              *
//* Life Bonus:         8                                                              *
//* Mana Bonus:         9                                                              *
//* Sight Range Bonus:  10                                                             *
//**************************************************************************************


//********************************************************************************
//* Generic Bonus APIs                                                           *
//*                                                                              *
//* CSS_GetBonus takes unit u, integer bonusType returns integer                 *
//* CSS_AddBonus takes unit u, integer amount, integer bonusType returns nothing *
//* CSS_ClearBonus takes unit u, integer bonusType                               *
//********************************************************************************

// Clear bonus

function CSS_ClearBonus takes unit u, integer bonusType returns nothing

    if bonusType > 10 or bonusType < 0 or GetUnitTypeId (u) == 0 or IsUnitType (u, UNIT_TYPE_DEAD) then
        return
    endif

    call CSS_AddBonus (u, -LoadInteger (udg_CSS_Hashtable, GetHandleId (u), bonusType), bonusType)
endfunction

// Get current bonus

function CSS_GetBonus takes unit u, integer bonusType returns integer

    if bonusType > 10 or bonusType < 0 or GetUnitTypeId (u) == 0 or IsUnitType (u, UNIT_TYPE_DEAD) then
        return 0
    endif

    return LoadInteger (udg_CSS_Hashtable, GetHandleId (u), bonusType)
endfunction

// For preloading abilities

function CSS_Preload takes nothing returns nothing
    local integer i = 0
    local unit u = CreateUnit(Player(15), 'hfoo', 0, 0, 0.00)

    loop
        exitwhen i > 197
        call UnitAddAbility(u, udg_CSS_Abilities[i])
        set i = i + 1
    endloop

    call RemoveUnit(u)
    set u = null
endfunction

//===========================================================================
function InitTrig_CSS_Standalone_Bonus takes nothing returns nothing
    local integer i = 0
    local integer a = 1

    set udg_CSS_Abilities[0] = 'ZxA0'
    set udg_CSS_Abilities[1] = 'ZxA1'
    set udg_CSS_Abilities[2] = 'ZxA2'
    set udg_CSS_Abilities[3] = 'ZxA3'
    set udg_CSS_Abilities[4] = 'ZxA4'
    set udg_CSS_Abilities[5] = 'ZxA5'
    set udg_CSS_Abilities[6] = 'ZxA6'
    set udg_CSS_Abilities[7] = 'ZxA7'
    set udg_CSS_Abilities[8] = 'ZxA8'
    set udg_CSS_Abilities[9] = 'ZxA9'
    set udg_CSS_Abilities[10] = 'ZxAa'
    set udg_CSS_Abilities[11] = 'ZxAb'
    set udg_CSS_Abilities[12] = 'ZxAc'
    set udg_CSS_Abilities[13] = 'ZxAd'
    set udg_CSS_Abilities[14] = 'ZxAe'
    set udg_CSS_Abilities[15] = 'ZxAf'
    set udg_CSS_Abilities[16] = 'ZxAg'
    set udg_CSS_Abilities[17] = 'ZxAh'
    set udg_CSS_Abilities[18] = 'ZxI0'
    set udg_CSS_Abilities[19] = 'ZxI1'
    set udg_CSS_Abilities[20] = 'ZxI2'
    set udg_CSS_Abilities[21] = 'ZxI3'
    set udg_CSS_Abilities[22] = 'ZxI4'
    set udg_CSS_Abilities[23] = 'ZxI5'
    set udg_CSS_Abilities[24] = 'ZxI6'
    set udg_CSS_Abilities[25] = 'ZxI7'
    set udg_CSS_Abilities[26] = 'ZxI8'
    set udg_CSS_Abilities[27] = 'ZxI9'
    set udg_CSS_Abilities[28] = 'ZxIa'
    set udg_CSS_Abilities[29] = 'ZxIb'
    set udg_CSS_Abilities[30] = 'ZxIc'
    set udg_CSS_Abilities[31] = 'ZxId'
    set udg_CSS_Abilities[32] = 'ZxIe'
    set udg_CSS_Abilities[33] = 'ZxIf'
    set udg_CSS_Abilities[34] = 'ZxIg'
    set udg_CSS_Abilities[35] = 'ZxIh'
    set udg_CSS_Abilities[36] = 'ZxB0'
    set udg_CSS_Abilities[37] = 'ZxB1'
    set udg_CSS_Abilities[38] = 'ZxB2'
    set udg_CSS_Abilities[39] = 'ZxB3'
    set udg_CSS_Abilities[40] = 'ZxB4'
    set udg_CSS_Abilities[41] = 'ZxB5'
    set udg_CSS_Abilities[42] = 'ZxB6'
    set udg_CSS_Abilities[43] = 'ZxB7'
    set udg_CSS_Abilities[44] = 'ZxB8'
    set udg_CSS_Abilities[45] = 'ZxB9'
    set udg_CSS_Abilities[46] = 'ZxBa'
    set udg_CSS_Abilities[47] = 'ZxBb'
    set udg_CSS_Abilities[48] = 'ZxBc'
    set udg_CSS_Abilities[49] = 'ZxBd'
    set udg_CSS_Abilities[50] = 'ZxBe'
    set udg_CSS_Abilities[51] = 'ZxBf'
    set udg_CSS_Abilities[52] = 'ZxBg'
    set udg_CSS_Abilities[53] = 'ZxBh'
    set udg_CSS_Abilities[54] = 'ZxG0'
    set udg_CSS_Abilities[55] = 'ZxG1'
    set udg_CSS_Abilities[56] = 'ZxG2'
    set udg_CSS_Abilities[57] = 'ZxG3'
    set udg_CSS_Abilities[58] = 'ZxG4'
    set udg_CSS_Abilities[59] = 'ZxG5'
    set udg_CSS_Abilities[60] = 'ZxG6'
    set udg_CSS_Abilities[61] = 'ZxG7'
    set udg_CSS_Abilities[62] = 'ZxG8'
    set udg_CSS_Abilities[63] = 'ZxG9'
    set udg_CSS_Abilities[64] = 'ZxGa'
    set udg_CSS_Abilities[65] = 'ZxGb'
    set udg_CSS_Abilities[66] = 'ZxGc'
    set udg_CSS_Abilities[67] = 'ZxGd'
    set udg_CSS_Abilities[68] = 'ZxGe'
    set udg_CSS_Abilities[69] = 'ZxGf'
    set udg_CSS_Abilities[70] = 'ZxGg'
    set udg_CSS_Abilities[71] = 'ZxGh'
    set udg_CSS_Abilities[72] = 'ZxH0'
    set udg_CSS_Abilities[73] = 'ZxH1'
    set udg_CSS_Abilities[74] = 'ZxH2'
    set udg_CSS_Abilities[75] = 'ZxH3'
    set udg_CSS_Abilities[76] = 'ZxH4'
    set udg_CSS_Abilities[77] = 'ZxH5'
    set udg_CSS_Abilities[78] = 'ZxH6'
    set udg_CSS_Abilities[79] = 'ZxH7'
    set udg_CSS_Abilities[80] = 'ZxH8'
    set udg_CSS_Abilities[81] = 'ZxH9'
    set udg_CSS_Abilities[82] = 'ZxHa'
    set udg_CSS_Abilities[83] = 'ZxHb'
    set udg_CSS_Abilities[84] = 'ZxHc'
    set udg_CSS_Abilities[85] = 'ZxHd'
    set udg_CSS_Abilities[86] = 'ZxHe'
    set udg_CSS_Abilities[87] = 'ZxHf'
    set udg_CSS_Abilities[88] = 'ZxHg'
    set udg_CSS_Abilities[89] = 'ZxHh'
    set udg_CSS_Abilities[90] = 'ZxF0'
    set udg_CSS_Abilities[91] = 'ZxF1'
    set udg_CSS_Abilities[92] = 'ZxF2'
    set udg_CSS_Abilities[93] = 'ZxF3'
    set udg_CSS_Abilities[94] = 'ZxF4'
    set udg_CSS_Abilities[95] = 'ZxF5'
    set udg_CSS_Abilities[96] = 'ZxF6'
    set udg_CSS_Abilities[97] = 'ZxF7'
    set udg_CSS_Abilities[98] = 'ZxF8'
    set udg_CSS_Abilities[99] = 'ZxF9'
    set udg_CSS_Abilities[100] = 'ZxFa'
    set udg_CSS_Abilities[101] = 'ZxFb'
    set udg_CSS_Abilities[102] = 'ZxFc'
    set udg_CSS_Abilities[103] = 'ZxFd'
    set udg_CSS_Abilities[104] = 'ZxFe'
    set udg_CSS_Abilities[105] = 'ZxFf'
    set udg_CSS_Abilities[106] = 'ZxFg'
    set udg_CSS_Abilities[107] = 'ZxFh'
    set udg_CSS_Abilities[108] = 'ZxJ0'
    set udg_CSS_Abilities[109] = 'ZxJ1'
    set udg_CSS_Abilities[110] = 'ZxJ2'
    set udg_CSS_Abilities[111] = 'ZxJ3'
    set udg_CSS_Abilities[112] = 'ZxJ4'
    set udg_CSS_Abilities[113] = 'ZxJ5'
    set udg_CSS_Abilities[114] = 'ZxJ6'
    set udg_CSS_Abilities[115] = 'ZxJ7'
    set udg_CSS_Abilities[116] = 'ZxJ8'
    set udg_CSS_Abilities[117] = 'ZxJ9'
    set udg_CSS_Abilities[118] = 'ZxJa'
    set udg_CSS_Abilities[119] = 'ZxJb'
    set udg_CSS_Abilities[120] = 'ZxJc'
    set udg_CSS_Abilities[121] = 'ZxJd'
    set udg_CSS_Abilities[122] = 'ZxJe'
    set udg_CSS_Abilities[123] = 'ZxJf'
    set udg_CSS_Abilities[124] = 'ZxJg'
    set udg_CSS_Abilities[125] = 'ZxJh'
    set udg_CSS_Abilities[126] = 'ZxK0'
    set udg_CSS_Abilities[127] = 'ZxK1'
    set udg_CSS_Abilities[128] = 'ZxK2'
    set udg_CSS_Abilities[129] = 'ZxK3'
    set udg_CSS_Abilities[130] = 'ZxK4'
    set udg_CSS_Abilities[131] = 'ZxK5'
    set udg_CSS_Abilities[132] = 'ZxK6'
    set udg_CSS_Abilities[133] = 'ZxK7'
    set udg_CSS_Abilities[134] = 'ZxK8'
    set udg_CSS_Abilities[135] = 'ZxK9'
    set udg_CSS_Abilities[136] = 'ZxKa'
    set udg_CSS_Abilities[137] = 'ZxKb'
    set udg_CSS_Abilities[138] = 'ZxKc'
    set udg_CSS_Abilities[139] = 'ZxKd'
    set udg_CSS_Abilities[140] = 'ZxKe'
    set udg_CSS_Abilities[141] = 'ZxKf'
    set udg_CSS_Abilities[142] = 'ZxKg'
    set udg_CSS_Abilities[143] = 'ZxKh'
    set udg_CSS_Abilities[144] = 'ZxE0'
    set udg_CSS_Abilities[145] = 'ZxE1'
    set udg_CSS_Abilities[146] = 'ZxE2'
    set udg_CSS_Abilities[147] = 'ZxE3'
    set udg_CSS_Abilities[148] = 'ZxE4'
    set udg_CSS_Abilities[149] = 'ZxE5'
    set udg_CSS_Abilities[150] = 'ZxE6'
    set udg_CSS_Abilities[151] = 'ZxE7'
    set udg_CSS_Abilities[152] = 'ZxE8'
    set udg_CSS_Abilities[153] = 'ZxE9'
    set udg_CSS_Abilities[154] = 'ZxEa'
    set udg_CSS_Abilities[155] = 'ZxEb'
    set udg_CSS_Abilities[156] = 'ZxEc'
    set udg_CSS_Abilities[157] = 'ZxEd'
    set udg_CSS_Abilities[158] = 'ZxEe'
    set udg_CSS_Abilities[159] = 'ZxEf'
    set udg_CSS_Abilities[160] = 'ZxEg'
    set udg_CSS_Abilities[161] = 'ZxEh'
    set udg_CSS_Abilities[162] = 'ZxD0'
    set udg_CSS_Abilities[163] = 'ZxD1'
    set udg_CSS_Abilities[164] = 'ZxD2'
    set udg_CSS_Abilities[165] = 'ZxD3'
    set udg_CSS_Abilities[166] = 'ZxD4'
    set udg_CSS_Abilities[167] = 'ZxD5'
    set udg_CSS_Abilities[168] = 'ZxD6'
    set udg_CSS_Abilities[169] = 'ZxD7'
    set udg_CSS_Abilities[170] = 'ZxD8'
    set udg_CSS_Abilities[171] = 'ZxD9'
    set udg_CSS_Abilities[172] = 'ZxDa'
    set udg_CSS_Abilities[173] = 'ZxDb'
    set udg_CSS_Abilities[174] = 'ZxDc'
    set udg_CSS_Abilities[175] = 'ZxDd'
    set udg_CSS_Abilities[176] = 'ZxDe'
    set udg_CSS_Abilities[177] = 'ZxDf'
    set udg_CSS_Abilities[178] = 'ZxDg'
    set udg_CSS_Abilities[179] = 'ZxDh'
    set udg_CSS_Abilities[180] = 'ZxC0'
    set udg_CSS_Abilities[181] = 'ZxC1'
    set udg_CSS_Abilities[182] = 'ZxC2'
    set udg_CSS_Abilities[183] = 'ZxC3'
    set udg_CSS_Abilities[184] = 'ZxC4'
    set udg_CSS_Abilities[185] = 'ZxC5'
    set udg_CSS_Abilities[186] = 'ZxC6'
    set udg_CSS_Abilities[187] = 'ZxC7'
    set udg_CSS_Abilities[188] = 'ZxC8'
    set udg_CSS_Abilities[189] = 'ZxC9'
    set udg_CSS_Abilities[190] = 'ZxCa'
    set udg_CSS_Abilities[191] = 'ZxCb'
    set udg_CSS_Abilities[192] = 'ZxCc'
    set udg_CSS_Abilities[193] = 'ZxCd'
    set udg_CSS_Abilities[194] = 'ZxCe'
    set udg_CSS_Abilities[195] = 'ZxCf'
    set udg_CSS_Abilities[196] = 'ZxCg'
    set udg_CSS_Abilities[197] = 'ZxCh'

    loop
        exitwhen i > 30
        set udg_CSS_Power[i] = a
        set a = a*2
        set i = i + 1
    endloop

    set udg_CSS_Hashtable = InitHashtable()

    if udg_CSS_PreloadBoolean then
        call CSS_Preload()
    endif
endfunction
JASS:
//************************************************************************************************************
//*                                                                                                          *
//*                              CUSTOM STAT SYSTEM (CSS)                                                    *
//*                                                                                                          *
//*   Author:   Doomlord                                                                                     *
//*   Version:  1.5g                                                                                         *
//*                                                                                                          *
//*   Credits:                                                                                               *
//*   + Earth-Fury:    BonusMod binary algoritm; implementation macro.                                       *
//*   + Crigges:       A great amount of help and support.                                                   *
//*   + Geries:        Help me with the item hashtable values cleanup.                                       *
//*   + rulerofiron99: Item Socketing method referenced from [GUI]Right Click Item Recipe v1.05.             *
//*   + Vexorian:      CSS_SimError [url]http://www.wc3c.net/showthread.php?t=101260[/url]                   *
//*   + Magtheridon96: [Snippet]BoundInt [url]http://www.hiveworkshop.com/forums/2294066-post804.html[/url]  *
//*   + WaterKnight:   Help with the stack for custom Event Response.                                        *
//*   + PurgeandFire:  Pinpoint a possible desync bug with the system.                                       *
//*   + Nestharus:     Mentioning the possible negative life bug in his Bonus lib.                           *
//*                                                                                                          *
//************************************************************************************************************


//**************************************************************************************
//* INTRODUCTION:                                                                      *
//*                                                                                    *
//* 1 item - 11 passive stats with one custom script. This is Custom Stat System (CSS) *
//*                                                                                    *
//* A system that aims to get rid of mapmakers' annoyance of having to do a boring and *
//* repetitive job of creating a multitude of item passive stat abilities. At the      *
//* same time it also possesses generic bonus mod features to let you modify a unit's  *
//* stats freely and easily. It is also quite GUI friendly since everything can be     *
//* achieved solely through custom scripts.                                            *
//*                                                                                    *
//* Version 1.2 and onwards supports item socketing.                                   *
//**************************************************************************************


//**********************************************************************************************************************************
//* FEATURES:                                                                                                                      *
//*                                                                                                                                *
//* Pros:                                                                                                                          *
//* + Simple and GUI-friendly item passive stats registration.                                                                     *
//* + Has little effect on performance.                                                                                            *
//* + Quick implementation of system and system abilities through macro.                                                           *
//* + You no longer have to sit for hours creating item passive abilities for your map.                                            *
//* + Use only 1 hashtable (udg_CSS_Hashtable).                                                                                    *
//* + Pure JASS, only require JNGP for ability implementation.                                                                     *
//* + BonusMod-like features with better range for some stats.                                                                     *
//* + Bonus Range: -131072 to 131071.                                                                                              *
//* + Right Click Item Socketing.                                                                                                  *
//* + Socket event can be caught with the Event: EVENT_SOCKET_FINISH becomes equal to 1.00.                                        *
//* + In JASS: call TriggerRegisterVariableEvent(trigger, "EVENT_SOCKET_FINISH", EQUAL, 1.00).                                     *                                                                                                   *
//*                                                                                                                                *
//* Cons:                                                                                                                          *
//* + Does not include movement speed.                                                                                             *
//* + May bug if a unit somehow surpasses the bonus limit in some occasion.                                                        *
//* -> Fix: Don't allow a unit to achieve near-limit for a stat i.e keep it at a reasonable level.                                 *
//* + Limited configurability.                                                                                                     *
//* + Insufficient item tooltip, which is unavoidable because it is hard-coded.                                                    *
//**********************************************************************************************************************************


//********************************************************************************************************
//* REQUIREMENTS:                                                                                        *
//*                                                                                                      *
//* JNGP [url]http://www.hiveworkshop.com/forums/tools-560/jassnewgenpack-5d-227445[/url] (Recommended)  *
//* OR:                                                                                                  *
//* Your superhuman capability to transfer 198 abilities to your map. (Not Recommended)                  *
//********************************************************************************************************


//************************************************************************************************************************************************
//* INSTALLATION INSTRUCTION:                                                                                                                    *
//*                                                                                                                                              *
//* Step 1: Copy the custom code for bonus handling to your map header.                                                                          *
//* Step 2: Use JNGP to implement the system's abilities through macro. Instruction is included in the Implementation Macro trigger.             *
//* Step 3: Copy the whole CSS folder to your map. Don't forget to turn on "Automatically create unknown variables while pasting trigger data".  *
//* Step 4: Put the CSS trigger on top of your Item Declaration trigger.                                                                         *
//* Step 5: Register your items as examplified in the Item Declaration trigger. Remember to use Map Initialization event.                        *
//* Step 6: Set the global variables to modify your settings.                                                                                    *
//*         + udg_CSS_GemLevel: set a level identifier for your gem items. Gem Items must have a level higher than this value to function,       *
//*         + udg_CSS_Preload: set to true if you want to preload system abilities. Increase loading time but prevents first lags.               *
//*         + udg_CSS_SocketingEnabled: set to true if you want to enable the Right Click Item Socketing feature.                                *
//*         + udg_CSS_GemBonusBoolean: set to true if you want to allow wielded gems to display its bonuses.                                     *
//*         + udg_CSS_CustomSwitch: set to true if you want the item to give bonus only when it is fully socketed.                               *
//************************************************************************************************************************************************


//**************************************************************************************
//* Item Registration API                                                              *
//*                                                                                    *
//* call CSS_ItemInitialize (integer itemRawCode, integer armorBonus,                  *
//* integer attackSpeedBonus, integer damageBonus, integer agilityBonus,               *
//* integer intelligenceBonus, integer strengthBonus, integer lifeRegenBonus,          *
//* integer manaRegenBonus, integer lifeBonus, integer manaBonus,                      *
//* integer sightRangeBonus, integer socket)                                           *
//**************************************************************************************


//**************************************************************************************
//* Gem Registration API                                                               *
//*                                                                                    *
//* call CSS_GemInitialize (integer itemRawCode, integer armorBonus,                   *
//* integer attackSpeedBonus, integer damageBonus, integer agilityBonus,               *
//* integer intelligenceBonus, integer strengthBonus, integer lifeRegenBonus,          *
//* integer manaRegenBonus, integer lifeBonus, integer manaBonus,                      *
//* integer sightRangeBonus)                                                           *
//**************************************************************************************

//===========================================================================
// Only needed if you decided to use Right Click Item Socketing

// Item socket effect

constant function CSS_ItemSocketEffect takes nothing returns string
    return "Abilities\\Spells\\Items\\AIlm\\AIlmTarget.mdl"
endfunction

// Item socket effect attachment point

constant function CSS_ISEAttachPoint takes nothing returns string
    return "origin"
endfunction

// Item preload

function CSS_ItemPreload takes nothing returns nothing
    local unit u = CreateUnit(Player(15), 'Hpal', 0, 0, 0.00)
    local integer i = 0
    local integer j = LoadInteger (udg_CSS_Hashtable, -5, -5)
    local item array it

    loop
        exitwhen i > j
        set it[i] = CreateItem (LoadInteger (udg_CSS_Hashtable, -5, i), 0, 0)
        call UnitAddItem (u, it[i])
        set i = i + 1
    endloop

    set i = 0

    loop
        exitwhen i > j
        call RemoveItem (it[i])
        set it[i] = null
        set i = i + 1
    endloop

    call RemoveUnit (u)
    call FlushChildHashtable (udg_CSS_Hashtable, -5)
    set u = null
endfunction
//===========================================================================

// Fail-safe mechanism, only use in specific cases to avoid possible collision with other systems
// Refresh and update the unit's stats given by items in its inventory
// In a nutshell, do not use this unless you know what you are doing

function CSS_StatUpdate takes unit u returns nothing
    local integer i = 0
    local integer j = 0
    local integer k = GetHandleId (u)

    loop
        exitwhen j > 10
        call CSS_AddBonus (u, -LoadInteger (udg_CSS_Hashtable, k, j - 11), j)
        call SaveInteger (udg_CSS_Hashtable, k, j - 11, 0)
        set j = j + 1
    endloop

    loop
        exitwhen i > 5
        set j = 0

        loop
            exitwhen j > 10
            call CSS_AddBonus (u, LoadInteger (udg_CSS_Hashtable, GetHandleId (UnitItemInSlot (u, i)), j), j)
            call SaveInteger (udg_CSS_Hashtable, k, j - 11, LoadInteger (udg_CSS_Hashtable, k, j - 11) + LoadInteger (udg_CSS_Hashtable, GetHandleId (UnitItemInSlot (u, i)), j))
            set j = j + 1
        endloop

        set i = i + 1
    endloop
endfunction

// Item Socket Info Panel

function CSS_ItemInfoSocketPanel takes nothing returns boolean
    local group g = CreateGroup ()
    local item it
    local unit u
    local integer i
    local integer j = 0
    local player p = GetTriggerPlayer ()
    local integer k
    local string s

    if not udg_CSS_SocketingEnabled then
        call CSS_SimError ("Socketing feature is not enabled")
        call DestroyGroup (g)

        set p = null
        set g = null
        return false
    endif

    call GroupEnumUnitsSelected(g, p, null)

    if CountUnitsInGroup (g) > 1 then
        call CSS_SimError ("Invalid Selection")
        call DestroyGroup (g)

        set p = null
        set g = null
        return false
    else
        set u = FirstOfGroup (g)

        if not IsUnitOwnedByPlayer (u, p) then
            call CSS_SimError ("You must select an owned unit")
        else
            set it = UnitItemInSlot (u, S2I(SubString(GetEventPlayerChatString(), 16, StringLength(GetEventPlayerChatString()))) - 1)

            if it == null or not LoadBoolean (udg_CSS_Hashtable, GetItemTypeId (it), -4) then
                call CSS_SimError ("No item in chosen slot or chosen item is not registered with CSS")
            else

                call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + "Item Name: " + "|r" + udg_CSS_String[12] + GetItemName (it) + "|r")
                call DisplayTimedTextToPlayer (p, 0, 0, 15, "\n")

                set i = GetHandleId (it)
                set k = GetItemTypeId (it)

                loop
                    exitwhen j == LoadInteger (udg_CSS_Hashtable, k, -2)

                    set s = LoadStr (udg_CSS_Hashtable, i, -31 - j)

                    if s == null then
                        set s = "Not Socketed"
                    endif

                    call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + "Socket " + "#" + I2S (j + 1) + ": " + "|r" + udg_CSS_String[11] + s + "|r")
                    set s = ""
                    set j = j + 1
                endloop

            endif

            set it = null
        endif

        set u = null
    endif

    call DestroyGroup (g)
    set g = null
    set p = null

    return false
endfunction

// Item Info Panel

function CSS_ItemInfoPanel takes nothing returns boolean
    local group g = CreateGroup ()
    local item it
    local unit u
    local integer i
    local integer j = 0
    local player p = GetTriggerPlayer ()
    local integer k
    local integer l
    local string s1
    local string s2

    call GroupEnumUnitsSelected(g, p, null)

    if CountUnitsInGroup (g) > 1 then
        call CSS_SimError ("Invalid Selection")
        call DestroyGroup (g)

        set p = null
        set g = null
        return false
    else
        set u = FirstOfGroup (g)

        if not IsUnitOwnedByPlayer (u, p) then
            call CSS_SimError ("You must select an owned unit")
        else
            set it = UnitItemInSlot (u, S2I(SubString(GetEventPlayerChatString(), 10, StringLength(GetEventPlayerChatString()))) - 1)

            if it == null or not LoadBoolean (udg_CSS_Hashtable, GetItemTypeId (it), -4) then
                call CSS_SimError ("No item in chosen slot or chosen item is not registered with CSS")
            else

                set i = GetHandleId (it)
                set k = GetItemTypeId (it)

                if udg_CSS_SocketingEnabled then
                    call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + "Item Name: " + "|r" + udg_CSS_String[12] + GetItemName (it) + "|r")
                    call DisplayTimedTextToPlayer (p, 0, 0, 15, "\n")
                else
                    call DisplayTimedTextToPlayer (p, 0, 0, 15, "\n\n\n" + udg_CSS_String[25] + "Item Name: " + "|r" + udg_CSS_String[12] + GetItemName (it) + "|r")
                    call DisplayTimedTextToPlayer (p, 0, 0, 15, "\n")
                endif

                loop
                    exitwhen j > 10

                    if udg_CSS_SocketingEnabled then
                        set l = LoadInteger (udg_CSS_Hashtable, i, j)

                        if l > 0 then
                            set s2 = "+"
                        else
                            set s2 = ""
                        endif

                        if l - LoadInteger (udg_CSS_Hashtable, k, j) > 0 then
                            set s1 = udg_CSS_String[24] + " +" + I2S (l - LoadInteger (udg_CSS_Hashtable, k, j)) + "|r"
                        elseif l - LoadInteger (udg_CSS_Hashtable, k, j) < 0 then
                            set s1 = udg_CSS_String[24] + " -" + I2S (LoadInteger (udg_CSS_Hashtable, k, j) - l) + "|r"
                        else
                            set s1 = ""
                        endif

                        if j == 1 or j == 7 and s1 != "" then
                            set s1 = s1 + udg_CSS_String[24] + "%|r"
                        endif

                        if j == 1 or j == 7 then
                            call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + udg_CSS_String[j] + "|r" + udg_CSS_String[13+j] + s2 + I2S (LoadInteger (udg_CSS_Hashtable, k, j)) + "%|r" + s1)
                        else
                            call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + udg_CSS_String[j] + "|r" + udg_CSS_String[13+j] + s2 + I2S (LoadInteger (udg_CSS_Hashtable, k, j)) + "|r" + s1)
                        endif

                        set s1 = ""
                        set s2 = ""
                    else
                        set l = LoadInteger (udg_CSS_Hashtable, k, j)

                        if l > 0 then
                            set s2 = "+"
                        else
                            set s2 = ""
                        endif

                        if j == 1 or j == 7 then
                            call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + udg_CSS_String[j] + "|r" + udg_CSS_String[13+j] + s2 + I2S (LoadInteger (udg_CSS_Hashtable, k, j)) + "%|r")
                        else
                            call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + udg_CSS_String[j] + "|r" + udg_CSS_String[13+j] + s2 + I2S (LoadInteger (udg_CSS_Hashtable, k, j)) + "|r")
                        endif

                        set s2 = ""
                    endif

                    set j = j + 1
                endloop

                if udg_CSS_SocketingEnabled then
                    call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + "\nNumber of sockets: " + "|r" + udg_CSS_String[26] + I2S (LoadInteger (udg_CSS_Hashtable, k, -2)) + "|r")

                    if not HaveSavedInteger (udg_CSS_Hashtable, i, -2) then
                        call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + "Number of empty sockets: " + "|r" + udg_CSS_String[26] + I2S (LoadInteger (udg_CSS_Hashtable, k, -2)) + "|r")
                    else
                        call DisplayTimedTextToPlayer (p, 0, 0, 15, udg_CSS_String[25] + "Number of empty sockets: " + "|r" + udg_CSS_String[26] + I2S (LoadInteger (udg_CSS_Hashtable, i, -2)) + "|r")
                    endif
                endif

            endif

            set it = null
        endif

        set u = null
    endif

    call DestroyGroup (g)
    set g = null
    set p = null

    return false
endfunction

// Item sell event check

function CSS_ItemPawnCheck takes nothing returns boolean
    local unit u = GetTriggerUnit ()
    local integer i = GetHandleId (GetSoldItem ())
    local integer k = GetItemTypeId (GetSoldItem ())
    local trigger trig
    local integer t
    local integer j = 0
    local integer m = GetHandleId (u)

    loop
        exitwhen j > 10

        if udg_CSS_SocketingEnabled then
            call CSS_AddBonus(u, -LoadInteger (udg_CSS_Hashtable, i, j), j)
            call SaveInteger (udg_CSS_Hashtable, m, j - 11, LoadInteger (udg_CSS_Hashtable, m, j - 11) - LoadInteger (udg_CSS_Hashtable, i, j))
        else
            call CSS_AddBonus(u, -LoadInteger (udg_CSS_Hashtable, k, j), j)
            call SaveInteger (udg_CSS_Hashtable, m, j - 11, LoadInteger (udg_CSS_Hashtable, m, j - 11) - LoadInteger (udg_CSS_Hashtable, k, j))
        endif

        set j = j + 1
    endloop

    if LoadBoolean (udg_CSS_Hashtable, i, -6) then
        set trig = LoadTriggerHandle (udg_CSS_Hashtable, i, -10)
        set t = GetHandleId (trig)
        call SaveInteger (udg_CSS_Hashtable, t, 1, LoadInteger (udg_CSS_Hashtable, t, 1) + 1)

        if LoadInteger (udg_CSS_Hashtable, t, 1) == LoadInteger (udg_CSS_Hashtable, t, 0) then

            call DestroyTrigger (trig)
            call FlushChildHashtable (udg_CSS_Hashtable, t)

            if LoadTriggerHandle (udg_CSS_Hashtable, -10, -1) == trig then
                call RemoveSavedHandle (udg_CSS_Hashtable, -10, -1)
            endif

        endif

        set trig = null
        call FlushChildHashtable (udg_CSS_Hashtable, i)
    endif

    set u = null
    return false
endfunction

// Only needed if you decided to use Right Click Item Socketing

// Item socket event check

function CSS_ItemSocketCheck takes nothing returns boolean
    local item itemMain
    local item itemSocket
    local integer itemSlot
    local unit u
    local integer j = 0
    local integer i
    local integer k
    local integer l
    local integer m
    local integer n

    if GetOrderTargetItem() != null then
        set u = GetTriggerUnit()
        set itemSlot = GetIssuedOrderId() - 852002
        set itemMain = UnitItemInSlot (u, itemSlot)
        set itemSocket = GetOrderTargetItem()
        set i = GetItemTypeId (itemSocket)
        set k = GetItemTypeId (itemMain)
        set l = GetHandleId (itemMain)
        set m = GetHandleId (itemSocket)

        if not HaveSavedInteger (udg_CSS_Hashtable, l, -2) then
            call SaveInteger (udg_CSS_Hashtable, l, -2, LoadInteger (udg_CSS_Hashtable, k, -2))
        endif

        set n = LoadInteger (udg_CSS_Hashtable, l, -2)

        if itemMain != null and itemSocket != null and itemMain != itemSocket then

            if (LoadBoolean (udg_CSS_Hashtable, i, -3) and LoadBoolean (udg_CSS_Hashtable, k, -3)) or (not LoadBoolean (udg_CSS_Hashtable, i, -4) and LoadBoolean (udg_CSS_Hashtable, k, -3)) or (not LoadBoolean (udg_CSS_Hashtable, k, -4) and LoadBoolean (udg_CSS_Hashtable, i, -3)) or (not LoadBoolean (udg_CSS_Hashtable, i, -4) and not LoadBoolean (udg_CSS_Hashtable, k, -3)) or (not LoadBoolean (udg_CSS_Hashtable, k, -4) and not LoadBoolean (udg_CSS_Hashtable, i, -3)) or (LoadBoolean (udg_CSS_Hashtable, k, -7) and LoadBoolean (udg_CSS_Hashtable, i, -7)) then
                set itemSocket = null
                set itemMain = null
                set u = null
                return false
            endif

            if GetItemLevel (itemSocket) > udg_CSS_GemLevel and GetItemLevel (itemMain) < udg_CSS_GemLevel and n > 0 then

                loop
                    exitwhen j > 10
                    call SaveInteger (udg_CSS_Hashtable, l, j, LoadInteger (udg_CSS_Hashtable, l, j) + LoadInteger (udg_CSS_Hashtable, i, j))

                    if not udg_CSS_GemBonusBoolean and not udg_CSS_CustomSwitch then
                        call CSS_AddBonus(u, LoadInteger (udg_CSS_Hashtable, i, j), j)
                    endif

                    call SaveInteger (udg_CSS_Hashtable, GetHandleId (u), j - 11, LoadInteger (udg_CSS_Hashtable, GetHandleId (u), j - 11) + LoadInteger (udg_CSS_Hashtable, i, j))
                    set j = j + 1
                endloop

                call SaveStr (udg_CSS_Hashtable, l, -30 - LoadInteger (udg_CSS_Hashtable, k, -2) + n - 1, GetItemName(itemSocket))
                call CSS_SimNotification (GetItemName(itemMain) + " has been socketed with " + GetItemName(itemSocket) + " - " + I2S(n - 1) + " sockets left")
                call SaveBoolean (udg_CSS_Hashtable, m, -1, true)

                call SaveBoolean (udg_CSS_Hashtable, m, -1, false)
                call DestroyEffect (AddSpecialEffectTarget (CSS_ItemSocketEffect(), u, CSS_ISEAttachPoint ()))
                call SaveInteger (udg_CSS_Hashtable, l, -2, n - 1)

                set j = 0

                if udg_CSS_CustomSwitch and LoadInteger (udg_CSS_Hashtable, l, -2) == 0 then

                    loop
                        exitwhen j > 10
                        call CSS_AddBonus(u, LoadInteger (udg_CSS_Hashtable, l, j), j)
                        set j = j + 1
                    endloop

                endif

                set udg_CSS_Counter = udg_CSS_Counter + 1
                set udg_CSS_EventMainItemStacked[udg_CSS_Counter] = itemMain
                set udg_CSS_EventSocketItemStacked[udg_CSS_Counter] = itemSocket
                set udg_CSS_EventUnitStacked[udg_CSS_Counter] = u
                set udg_CSS_EventMainItem = itemMain
                set udg_CSS_EventSocketItem = itemSocket
                set udg_CSS_EventUnit = u
                set udg_EVENT_SOCKET_FINISH = 1
                set udg_EVENT_SOCKET_FINISH = 0
                set udg_CSS_EventMainItem = null
                set udg_CSS_EventSocketItem = null
                set udg_CSS_EventUnit = null
                set udg_CSS_EventMainItemStacked[udg_CSS_Counter] = null
                set udg_CSS_EventSocketItemStacked[udg_CSS_Counter] = null
                set udg_CSS_EventUnitStacked[udg_CSS_Counter] = null
                set udg_CSS_Counter = udg_CSS_Counter - 1

                call RemoveItem (itemSocket)

            elseif LoadInteger (udg_CSS_Hashtable, l, -2) == 0 and LoadBoolean (udg_CSS_Hashtable, k, -3) then
                call CSS_SimError ("Main item is fully socketed")
            endif
        endif

        set u = null
        set itemMain = null
        set itemSocket = null
    endif

    return false
endfunction

// Item drop event check

function CSS_ItemDropCheck takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer i = GetHandleId (GetManipulatedItem())
    local integer k = GetItemTypeId (GetManipulatedItem())
    local integer j = 0
    local integer m = GetHandleId (u)

    if not LoadBoolean (udg_CSS_Hashtable, i, -1) then

        if not LoadBoolean (udg_CSS_Hashtable, k, -3) and LoadBoolean (udg_CSS_Hashtable, k, -5) then
            set u = null
            return false
        endif

        if udg_CSS_CustomSwitch and (not HaveSavedInteger (udg_CSS_Hashtable, i, -2) or LoadInteger (udg_CSS_Hashtable, i, -2) != 0) then
            set u = null
            return false
        endif

        loop
            exitwhen j > 10

            if udg_CSS_SocketingEnabled then
                call CSS_AddBonus(u, -LoadInteger (udg_CSS_Hashtable, i, j), j)
                call SaveInteger (udg_CSS_Hashtable, m, j - 11, LoadInteger (udg_CSS_Hashtable, m, j - 11) - LoadInteger (udg_CSS_Hashtable, i, j))
            else
                call CSS_AddBonus(u, -LoadInteger (udg_CSS_Hashtable, k, j), j)
                call SaveInteger (udg_CSS_Hashtable, m, j - 11, LoadInteger (udg_CSS_Hashtable, m, j - 11) - LoadInteger (udg_CSS_Hashtable, k, j))
            endif

            set j = j + 1
        endloop

    endif

    set u = null
    return false
endfunction

// Only needed if you decided to use Right Click Item Socketing

// Function for clearing dead/removed items' hashtable

function CSS_Event_Fire takes nothing returns boolean
    local trigger trig = GetTriggeringTrigger ()
    local integer t = GetHandleId (trig)

    call SaveInteger (udg_CSS_Hashtable, t, 1, LoadInteger (udg_CSS_Hashtable, t, 1) + 1)

    if LoadInteger (udg_CSS_Hashtable, t, 1) == LoadInteger (udg_CSS_Hashtable, t, 0) then

        call DestroyTrigger (trig)
        call FlushChildHashtable (udg_CSS_Hashtable, t)

        if LoadTriggerHandle (udg_CSS_Hashtable, -10, -1) == trig then
            call RemoveSavedHandle (udg_CSS_Hashtable, -10, -1)
        endif

    endif

    call FlushChildHashtable (udg_CSS_Hashtable, GetHandleId (GetTriggerWidget()))
    set trig = null

    return false
endfunction

// Item acquisition event check

function CSS_ItemAcquireCheck takes nothing returns boolean
    local trigger t = LoadTriggerHandle(udg_CSS_Hashtable, -10, -1)
    local integer l = GetHandleId (t)
    local unit u = GetTriggerUnit()
    local integer i = GetItemTypeId(GetManipulatedItem())
    local integer k = GetHandleId(GetManipulatedItem())
    local integer j = 0

    if not LoadBoolean (udg_CSS_Hashtable, k, -6) and LoadBoolean (udg_CSS_Hashtable, i, -4) and udg_CSS_SocketingEnabled then

        if t == null or LoadInteger (udg_CSS_Hashtable, l, 0) == 100 then
            set t = CreateTrigger ()
            set l = GetHandleId (t)
            call SaveInteger (udg_CSS_Hashtable, l, 0, 1)
            call SaveInteger (udg_CSS_Hashtable, l, 1, 0)
            call SaveTriggerHandle (udg_CSS_Hashtable, -10, -1, t)
            call TriggerAddCondition (t, Condition(function CSS_Event_Fire))
        else
            call SaveInteger (udg_CSS_Hashtable, l, 0, LoadInteger (udg_CSS_Hashtable, l, 0) + 1)
        endif

        call SaveTriggerHandle (udg_CSS_Hashtable, k, -10, t)
        call TriggerRegisterDeathEvent (t, GetManipulatedItem())
        call SaveBoolean (udg_CSS_Hashtable, k, -6, true)
    endif

    if not LoadBoolean (udg_CSS_Hashtable, i, -5) then

        loop
            exitwhen j > 10

            if not HaveSavedInteger (udg_CSS_Hashtable, k, j) then
                call SaveInteger (udg_CSS_Hashtable, k, j, LoadInteger (udg_CSS_Hashtable, i, j))
            endif

            set j = j + 1
        endloop

        if udg_CSS_CustomSwitch and (not HaveSavedInteger (udg_CSS_Hashtable, k, -2) or LoadInteger (udg_CSS_Hashtable, k, -2) != 0) then
            set t = null
            set u = null
            return false
        endif

        set j = 0

        loop
            exitwhen j > 10

            if udg_CSS_SocketingEnabled then
                call CSS_AddBonus(u, LoadInteger (udg_CSS_Hashtable, k, j), j)
                call SaveInteger (udg_CSS_Hashtable, GetHandleId (u), j - 11, LoadInteger (udg_CSS_Hashtable, GetHandleId (u), j - 11) + LoadInteger (udg_CSS_Hashtable, k, j))
            else
                call CSS_AddBonus(u, LoadInteger (udg_CSS_Hashtable, i, j), j)
                call SaveInteger (udg_CSS_Hashtable, GetHandleId (u), j - 11, LoadInteger (udg_CSS_Hashtable, GetHandleId (u), j - 11) + LoadInteger (udg_CSS_Hashtable, i, j))
            endif

            set j = j + 1
        endloop

    endif

    set t = null
    set u = null
    return false
endfunction

// Item Database Initialize

function CSS_ItemInitialize takes integer itemRawCode, integer armorBonus, integer attackSpeedBonus, integer damageBonus, integer agilityBonus, integer intelligenceBonus, integer strengthBonus, integer lifeRegenBonus, integer manaRegenBonus, integer lifeBonus, integer manaBonus, integer sightRangeBonus, integer socket returns nothing
    local integer j = LoadInteger (udg_CSS_Hashtable, -5, -5)

    call SaveInteger (udg_CSS_Hashtable, -5, j, itemRawCode)
    call SaveInteger (udg_CSS_Hashtable, -5, -5, j + 1)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 0, armorBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 1, attackSpeedBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 2, damageBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 3, agilityBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 4, intelligenceBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 5, strengthBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 6, lifeRegenBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 7, manaRegenBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 8, lifeBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 9, manaBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 10, sightRangeBonus)
    call SaveBoolean (udg_CSS_Hashtable, itemRawCode, -4, true)

    if udg_CSS_SocketingEnabled then
        call SaveInteger (udg_CSS_Hashtable, itemRawCode, -2, socket)
        call SaveBoolean (udg_CSS_Hashtable, itemRawCode, -3, true)
    endif

endfunction

// Gem Database Initialize

function CSS_GemInitialize takes integer itemRawCode, integer armorBonus, integer attackSpeedBonus, integer damageBonus, integer agilityBonus, integer intelligenceBonus, integer strengthBonus, integer lifeRegenBonus, integer manaRegenBonus, integer lifeBonus, integer manaBonus, integer sightRangeBonus returns nothing
    local integer j = LoadInteger (udg_CSS_Hashtable, -5, -5)

    call SaveInteger (udg_CSS_Hashtable, -5, j, itemRawCode)
    call SaveInteger (udg_CSS_Hashtable, -5, -5, j + 1)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 0, armorBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 1, attackSpeedBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 2, damageBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 3, agilityBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 4, intelligenceBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 5, strengthBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 6, lifeRegenBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 7, manaRegenBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 8, lifeBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 9, manaBonus)
    call SaveInteger (udg_CSS_Hashtable, itemRawCode, 10, sightRangeBonus)
    call SaveBoolean (udg_CSS_Hashtable, itemRawCode, -4, true)

    if udg_CSS_SocketingEnabled then
        call SaveBoolean (udg_CSS_Hashtable, itemRawCode, -7, true)

        if not udg_CSS_GemBonusBoolean then
            call SaveBoolean (udg_CSS_Hashtable, itemRawCode, -5, true)
        endif
    endif
endfunction

//===========================================================================
function InitTrig_CSS_Item_Functions takes nothing returns nothing
    local trigger acquireItem = CreateTrigger()
    local trigger dropItem = CreateTrigger()
    local trigger itemInfo = CreateTrigger()
    local trigger itemSocketInfo = CreateTrigger()
    local trigger socketItem
    local trigger pawnItem
    local integer j = 0

    call SaveInteger (udg_CSS_Hashtable, -5, -5, 0)

    call TriggerRegisterAnyUnitEventBJ(acquireItem, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(acquireItem, Condition(function CSS_ItemAcquireCheck))
    call TriggerRegisterAnyUnitEventBJ(dropItem, EVENT_PLAYER_UNIT_DROP_ITEM)
    call TriggerAddCondition(dropItem, Condition(function CSS_ItemDropCheck))

    set udg_CSS_String[0] = "Armor Bonus: "
    set udg_CSS_String[1] = "Attack Speed Bonus: "
    set udg_CSS_String[2] = "Damage Bonus: "
    set udg_CSS_String[3] = "Agility Bonus: "
    set udg_CSS_String[4] = "Intelligence Bonus: "
    set udg_CSS_String[5] = "Strength Bonus: "
    set udg_CSS_String[6] = "Life Regen Bonus: "
    set udg_CSS_String[7] = "Mana Regen Bonus: "
    set udg_CSS_String[8] = "Life Bonus: "
    set udg_CSS_String[9] = "Mana Bonus: "
    set udg_CSS_String[10] = "Sight Range Bonus: "
 
    loop
        call TriggerRegisterPlayerChatEvent(itemInfo, Player(j), "-iteminfo", false)
        call TriggerRegisterPlayerChatEvent(itemSocketInfo, Player(j), "-itemsocketinfo", false)
        set j = j + 1
        exitwhen j > 15
    endloop

    call TriggerAddCondition(itemInfo, Condition(function CSS_ItemInfoPanel))
    call TriggerAddCondition(itemSocketInfo, Condition(function CSS_ItemInfoSocketPanel))

    if udg_CSS_SocketingEnabled then
        set socketItem = CreateTrigger ()
        set pawnItem = CreateTrigger ()

        call TriggerRegisterAnyUnitEventBJ(socketItem, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
        call TriggerAddCondition(socketItem, Condition(function CSS_ItemSocketCheck))
        call TriggerRegisterAnyUnitEventBJ(pawnItem, EVENT_PLAYER_UNIT_PAWN_ITEM)
        call TriggerAddCondition(pawnItem, Condition(function CSS_ItemPawnCheck))


        set socketItem = null
        set pawnItem = null
    endif

    set itemInfo = null
    set itemSocketInfo = null
    set acquireItem = null
    set dropItem = null

endfunction

JASS:
// Map header custom code

// SimError by Vexorian at wc3c.net

// Sim Error (modified)

function CSS_SimError takes string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + s + "|r"
    local player ForPlayer = GetTriggerPlayer()
    local sound error = CreateSoundFromLabel("InterfaceError", false, false, false, 10, 10)

    if GetLocalPlayer() == ForPlayer then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer(ForPlayer, 0.52, 0.96, 2.00, msg)
        call StartSound(error)
    endif

    set ForPlayer = null
endfunction

function CSS_SimNotification takes string s returns nothing
    local string msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cff32cd32" + s + "|r"
    local player ForPlayer = GetTriggerPlayer()
    local sound notify = CreateSoundFromLabel("ItemReward", false, false, false, 10, 10)

    if GetLocalPlayer() == ForPlayer then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer(ForPlayer, 0.52, 0.96, 2.00, msg)
        call StartSound (notify)
    endif

    set ForPlayer = null
endfunction

// Bound Int by Magtheridon96 at hiveworkshop.com

// BoundInt

function BoundInt takes integer i, integer min, integer max returns integer
    return IMaxBJ(IMinBJ(i, max), min)
endfunction

// Bonus Handling Code

function CSS_AddBonus takes unit u, integer amount, integer bonusType returns nothing
    local integer max = udg_CSS_Power[17]
    local integer min = -udg_CSS_Power[17]
    local integer i = 16
    local integer j = LoadInteger (udg_CSS_Hashtable, GetHandleId(u), bonusType)

    if amount > max - 1 or amount < min then
        call CSS_SimError ("Value too high or too low")
        return
    endif

    if amount + j >= max or amount + j <= min then
        call CSS_SimError ("Current value at maximum or minimum")
        return
    endif

    set amount = amount + j
    call BoundInt (amount, min, max - 1)

    if bonusType < 0 or bonusType > 10 then
        call CSS_SimError ("CSS Error: Invalid bonus type (" + I2S(bonusType) + ")")
        return
    elseif bonusType == 8 or bonusType == 9 then

        if bonusType == 8 and amount*1. + GetUnitState(u, UNIT_STATE_MAX_LIFE) <= 0 then
            call CSS_SimError ("Unit's current max life is lower than the negative bonus amount. Unable to subtract.")
            return
        elseif bonusType == 9 and amount*1. + GetUnitState(u, UNIT_STATE_MAX_MANA) <= 0 then
            call CSS_SimError ("Unit's current max mana is lower than the negative bonus amount. Unable to subtract.")
            return
        endif

        call SaveInteger(udg_CSS_Hashtable, GetHandleId(u), bonusType, amount)

        if amount < 0 then
            set amount = max + amount
        else
            call UnitRemoveAbility(u, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
        endif

        loop
            if amount >= udg_CSS_Power[i] then
                call UnitAddAbility(u, udg_CSS_Abilities[bonusType*18 + i])
                call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[bonusType*18 + i])
                set amount = amount - udg_CSS_Power[i]
            else
                call UnitRemoveAbility(u, udg_CSS_Abilities[bonusType*18 + i])
            endif
        
            set i = i - 1
            exitwhen i < 0
        endloop

        if LoadInteger(udg_CSS_Hashtable, GetHandleId(u), bonusType) < 0 then
            call UnitAddAbility(u, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
            call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
        endif

    else

        call SaveInteger(udg_CSS_Hashtable, GetHandleId(u), bonusType, amount)

        if amount < 0 then
            set amount = max + amount
            call UnitAddAbility(u, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
            call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
        else
            call UnitRemoveAbility(u, udg_CSS_Abilities[(bonusType+1)*18 - 1])
        endif

        loop
            if amount >= udg_CSS_Power[i] then
                call UnitAddAbility(u, udg_CSS_Abilities[bonusType*18 + i])
                call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[bonusType*18 + i])
                set amount = amount - udg_CSS_Power[i]
            else
                call UnitRemoveAbility(u, udg_CSS_Abilities[bonusType*18 + i])
            endif
        
            set i = i - 1
            exitwhen i < 0
        endloop

    endif
endfunction

JASS:
// CSS Implementation Macro based on BonusMod's Implementation Macro
// Full credit goes to Earth-Fury
// The text below is extracted from BonusMod's

// About these macros:
//
// The first parameter is the rawcode for the ability. The convention used here by default is:
// Zx followed by an uppercase letter, unique to the bonus, followed by a 0-9-a-z representing
// the base of two the ability applys.
//
// The second parameter is the display value of the ability. This is so that they all line up
// neatly in the object editor.
//
// The third parameter is the actual value the bonus ability applys.
//
// Note that you should copy this in to its own trigger, save once, close the map and re-open
// it in the World Editor, then disable the trigger you copied this in to. If you do not
// disable the trigger, saving will take an insane ammount of time every time you save. If you
// make any changes below, you can simply enable the trigger again, save again, then disable
// the trigger again.

// CSS - Armor
//============================================================================================
//! textmacro ArmorAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AId1 $RAWCODE$ Idef 1 $VALUE$ anam "CSS - Armor ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNHumanArmorUpOne.blp
//! endtextmacro

//! runtextmacro ArmorAbility("ZxA0", "+00001", "1")
//! runtextmacro ArmorAbility("ZxA1", "+00002", "2")
//! runtextmacro ArmorAbility("ZxA2", "+00004", "4")
//! runtextmacro ArmorAbility("ZxA3", "+00008", "8")
//! runtextmacro ArmorAbility("ZxA4", "+00016", "16")
//! runtextmacro ArmorAbility("ZxA5", "+00032", "32")
//! runtextmacro ArmorAbility("ZxA6", "+00064", "64")
//! runtextmacro ArmorAbility("ZxA7", "+00128", "128")
//! runtextmacro ArmorAbility("ZxA8", "+00256", "256")
//! runtextmacro ArmorAbility("ZxA9", "+00512", "512")
//! runtextmacro ArmorAbility("ZxAa", "+01024", "1024")
//! runtextmacro ArmorAbility("ZxAb", "+02048", "2048")
//! runtextmacro ArmorAbility("ZxAc", "+04096", "4096")
//! runtextmacro ArmorAbility("ZxAd", "+08192", "8192")
//! runtextmacro ArmorAbility("ZxAe", "+16384", "16384")
//! runtextmacro ArmorAbility("ZxAf", "+32768", "32768")
//! runtextmacro ArmorAbility("ZxAg", "+65536", "65536")
//! runtextmacro ArmorAbility("ZxAh", "-131072", "-131072")

// CSS - Damage
//============================================================================================
//! textmacro DamageAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AItg $RAWCODE$ Iatt 1 $VALUE$ anam "CSS - Damage ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNClawsOfAttack.blp
//! endtextmacro

//! runtextmacro DamageAbility("ZxB0", "+00001", "1")
//! runtextmacro DamageAbility("ZxB1", "+00002", "2")
//! runtextmacro DamageAbility("ZxB2", "+00004", "4")
//! runtextmacro DamageAbility("ZxB3", "+00008", "8")
//! runtextmacro DamageAbility("ZxB4", "+00016", "16")
//! runtextmacro DamageAbility("ZxB5", "+00032", "32")
//! runtextmacro DamageAbility("ZxB6", "+00064", "64")
//! runtextmacro DamageAbility("ZxB7", "+00128", "128")
//! runtextmacro DamageAbility("ZxB8", "+00256", "256")
//! runtextmacro DamageAbility("ZxB9", "+00512", "512")
//! runtextmacro DamageAbility("ZxBa", "+01024", "1024")
//! runtextmacro DamageAbility("ZxBb", "+02048", "2048")
//! runtextmacro DamageAbility("ZxBc", "+04096", "4096")
//! runtextmacro DamageAbility("ZxBd", "+08192", "8192")
//! runtextmacro DamageAbility("ZxBe", "+16384", "16384")
//! runtextmacro DamageAbility("ZxBf", "+32768", "32768")
//! runtextmacro DamageAbility("ZxBg", "+65536", "65536")
//! runtextmacro DamageAbility("ZxBh", "-131072", "-131072")

// CSS - Sight Range
//============================================================================================
//! textmacro SightRangeAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIsi $RAWCODE$ Isib 1 $VALUE$ anam "CSS - Sight Range ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNTelescope.blp
//! endtextmacro

//! runtextmacro SightRangeAbility("ZxC0", "+00001", "1")
//! runtextmacro SightRangeAbility("ZxC1", "+00002", "2")
//! runtextmacro SightRangeAbility("ZxC2", "+00004", "4")
//! runtextmacro SightRangeAbility("ZxC3", "+00008", "8")
//! runtextmacro SightRangeAbility("ZxC4", "+00016", "16")
//! runtextmacro SightRangeAbility("ZxC5", "+00032", "32")
//! runtextmacro SightRangeAbility("ZxC6", "+00064", "64")
//! runtextmacro SightRangeAbility("ZxC7", "+00128", "128")
//! runtextmacro SightRangeAbility("ZxC8", "+00256", "256")
//! runtextmacro SightRangeAbility("ZxC9", "+00512", "512")
//! runtextmacro SightRangeAbility("ZxCa", "+01024", "1024")
//! runtextmacro SightRangeAbility("ZxCb", "+02048", "2048")
//! runtextmacro SightRangeAbility("ZxCc", "+04096", "4096")
//! runtextmacro SightRangeAbility("ZxCd", "+08192", "8192")
//! runtextmacro SightRangeAbility("ZxCe", "+16384", "16384")
//! runtextmacro SightRangeAbility("ZxCf", "+32768", "32768")
//! runtextmacro SightRangeAbility("ZxCg", "+65536", "65536")
//! runtextmacro SightRangeAbility("ZxCh", "-131072", "-131072")

// CSS - Max Mana
//============================================================================================
//! textmacro MaxManaAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AImz $RAWCODE$ Iman 1 $VALUE$ anam "CSS - Max Mana ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNPendantOfMana.blp
//! endtextmacro

//! runtextmacro MaxManaAbility("ZxD0", "+00001", "1")
//! runtextmacro MaxManaAbility("ZxD1", "+00002", "2")
//! runtextmacro MaxManaAbility("ZxD2", "+00004", "4")
//! runtextmacro MaxManaAbility("ZxD3", "+00008", "8")
//! runtextmacro MaxManaAbility("ZxD4", "+00016", "16")
//! runtextmacro MaxManaAbility("ZxD5", "+00032", "32")
//! runtextmacro MaxManaAbility("ZxD6", "+00064", "64")
//! runtextmacro MaxManaAbility("ZxD7", "+00128", "128")
//! runtextmacro MaxManaAbility("ZxD8", "+00256", "256")
//! runtextmacro MaxManaAbility("ZxD9", "+00512", "512")
//! runtextmacro MaxManaAbility("ZxDa", "+01024", "1024")
//! runtextmacro MaxManaAbility("ZxDb", "+02048", "2048")
//! runtextmacro MaxManaAbility("ZxDc", "+04096", "4096")
//! runtextmacro MaxManaAbility("ZxDd", "+08192", "8192")
//! runtextmacro MaxManaAbility("ZxDe", "+16384", "16384")
//! runtextmacro MaxManaAbility("ZxDf", "+32768", "32768")
//! runtextmacro MaxManaAbility("ZxDg", "+65536", "65536")
//! runtextmacro MaxManaAbility("ZxDh", "-131072", "-131072")

// CSS - Max Life
//============================================================================================
//! textmacro MaxLifeAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIlf $RAWCODE$ Ilif 1 $VALUE$ anam "CSS - Max Life ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNPeriapt1.blp
//! endtextmacro

//! runtextmacro MaxLifeAbility("ZxE0", "+00001", "1")
//! runtextmacro MaxLifeAbility("ZxE1", "+00002", "2")
//! runtextmacro MaxLifeAbility("ZxE2", "+00004", "4")
//! runtextmacro MaxLifeAbility("ZxE3", "+00008", "8")
//! runtextmacro MaxLifeAbility("ZxE4", "+00016", "16")
//! runtextmacro MaxLifeAbility("ZxE5", "+00032", "32")
//! runtextmacro MaxLifeAbility("ZxE6", "+00064", "64")
//! runtextmacro MaxLifeAbility("ZxE7", "+00128", "128")
//! runtextmacro MaxLifeAbility("ZxE8", "+00256", "256")
//! runtextmacro MaxLifeAbility("ZxE9", "+00512", "512")
//! runtextmacro MaxLifeAbility("ZxEa", "+01024", "1024")
//! runtextmacro MaxLifeAbility("ZxEb", "+02048", "2048")
//! runtextmacro MaxLifeAbility("ZxEc", "+04096", "4096")
//! runtextmacro MaxLifeAbility("ZxEd", "+08192", "8192")
//! runtextmacro MaxLifeAbility("ZxEe", "+16384", "16384")
//! runtextmacro MaxLifeAbility("ZxEf", "+32768", "32768")
//! runtextmacro MaxLifeAbility("ZxEg", "+65536", "65536")
//! runtextmacro MaxLifeAbility("ZxEh", "-131072", "-131072")

// CSS - Strength
//============================================================================================
//! textmacro HeroStrAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIa1 $RAWCODE$ Iagi 1 0 Iint 1 0 Istr 1 $VALUE$ anam "CSS - Hero STR ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNGauntletsOfOgrePower.blp
//! endtextmacro

//! runtextmacro HeroStrAbility("ZxF0", "+00001", "1")
//! runtextmacro HeroStrAbility("ZxF1", "+00002", "2")
//! runtextmacro HeroStrAbility("ZxF2", "+00004", "4")
//! runtextmacro HeroStrAbility("ZxF3", "+00008", "8")
//! runtextmacro HeroStrAbility("ZxF4", "+00016", "16")
//! runtextmacro HeroStrAbility("ZxF5", "+00032", "32")
//! runtextmacro HeroStrAbility("ZxF6", "+00064", "64")
//! runtextmacro HeroStrAbility("ZxF7", "+00128", "128")
//! runtextmacro HeroStrAbility("ZxF8", "+00256", "256")
//! runtextmacro HeroStrAbility("ZxF9", "+00512", "512")
//! runtextmacro HeroStrAbility("ZxFa", "+01024", "1024")
//! runtextmacro HeroStrAbility("ZxFb", "+02048", "2048")
//! runtextmacro HeroStrAbility("ZxFc", "+04096", "4096")
//! runtextmacro HeroStrAbility("ZxFd", "+08192", "8192")
//! runtextmacro HeroStrAbility("ZxFe", "+16384", "16384")
//! runtextmacro HeroStrAbility("ZxFf", "+32768", "32768")
//! runtextmacro HeroStrAbility("ZxFg", "+65536", "65536")
//! runtextmacro HeroStrAbility("ZxFh", "-131072", "-131072")

// CSS - Agility
//============================================================================================
//! textmacro HeroAgiAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIa1 $RAWCODE$ Iagi 1 $VALUE$ Iint 1 0 Istr 1 0 anam "CSS - Hero AGI ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNSlippersOfAgility.blp
//! endtextmacro

//! runtextmacro HeroAgiAbility("ZxG0", "+00001", "1")
//! runtextmacro HeroAgiAbility("ZxG1", "+00002", "2")
//! runtextmacro HeroAgiAbility("ZxG2", "+00004", "4")
//! runtextmacro HeroAgiAbility("ZxG3", "+00008", "8")
//! runtextmacro HeroAgiAbility("ZxG4", "+00016", "16")
//! runtextmacro HeroAgiAbility("ZxG5", "+00032", "32")
//! runtextmacro HeroAgiAbility("ZxG6", "+00064", "64")
//! runtextmacro HeroAgiAbility("ZxG7", "+00128", "128")
//! runtextmacro HeroAgiAbility("ZxG8", "+00256", "256")
//! runtextmacro HeroAgiAbility("ZxG9", "+00512", "512")
//! runtextmacro HeroAgiAbility("ZxGa", "+01024", "1024")
//! runtextmacro HeroAgiAbility("ZxGb", "+02048", "2048")
//! runtextmacro HeroAgiAbility("ZxGc", "+04096", "4096")
//! runtextmacro HeroAgiAbility("ZxGd", "+08192", "8192")
//! runtextmacro HeroAgiAbility("ZxGe", "+16384", "16384")
//! runtextmacro HeroAgiAbility("ZxGf", "+32768", "32768")
//! runtextmacro HeroAgiAbility("ZxGg", "+65536", "65536")
//! runtextmacro HeroAgiAbility("ZxGh", "-131072", "-131072")

// CSS - Intelligence
//============================================================================================
//! textmacro HeroIntAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIa1 $RAWCODE$ Iagi 1 0 Iint 1 $VALUE$ Istr 1 0 anam "CSS - Hero INT ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNMantle.blp
//! endtextmacro

//! runtextmacro HeroIntAbility("ZxH0", "+00001", "1")
//! runtextmacro HeroIntAbility("ZxH1", "+00002", "2")
//! runtextmacro HeroIntAbility("ZxH2", "+00004", "4")
//! runtextmacro HeroIntAbility("ZxH3", "+00008", "8")
//! runtextmacro HeroIntAbility("ZxH4", "+00016", "16")
//! runtextmacro HeroIntAbility("ZxH5", "+00032", "32")
//! runtextmacro HeroIntAbility("ZxH6", "+00064", "64")
//! runtextmacro HeroIntAbility("ZxH7", "+00128", "128")
//! runtextmacro HeroIntAbility("ZxH8", "+00256", "256")
//! runtextmacro HeroIntAbility("ZxH9", "+00512", "512")
//! runtextmacro HeroIntAbility("ZxHa", "+01024", "1024")
//! runtextmacro HeroIntAbility("ZxHb", "+02048", "2048")
//! runtextmacro HeroIntAbility("ZxHc", "+04096", "4096")
//! runtextmacro HeroIntAbility("ZxHd", "+08192", "8192")
//! runtextmacro HeroIntAbility("ZxHe", "+16384", "16384")
//! runtextmacro HeroIntAbility("ZxHf", "+32768", "32768")
//! runtextmacro HeroIntAbility("ZxHg", "+65536", "65536")
//! runtextmacro HeroIntAbility("ZxHh", "-131072", "-131072")

// CSS - Attack Speed
//============================================================================================
//! textmacro AttackSpeedAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIsx $RAWCODE$ Isx1 1 $VALUE$ anam "CSS - Attack Speed ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNGlove.blp
//! endtextmacro

//! runtextmacro AttackSpeedAbility("ZxI0", "+00001", "0.01")
//! runtextmacro AttackSpeedAbility("ZxI1", "+00002", "0.02")
//! runtextmacro AttackSpeedAbility("ZxI2", "+00004", "0.04")
//! runtextmacro AttackSpeedAbility("ZxI3", "+00008", "0.08")
//! runtextmacro AttackSpeedAbility("ZxI4", "+00016", "0.16")
//! runtextmacro AttackSpeedAbility("ZxI5", "+00032", "0.32")
//! runtextmacro AttackSpeedAbility("ZxI6", "+00064", "0.64")
//! runtextmacro AttackSpeedAbility("ZxI7", "+00128", "1.28")
//! runtextmacro AttackSpeedAbility("ZxI8", "+00256", "2.56")
//! runtextmacro AttackSpeedAbility("ZxI9", "+00512", "5.12")
//! runtextmacro AttackSpeedAbility("ZxIa", "+01024", "10.24")
//! runtextmacro AttackSpeedAbility("ZxIb", "+02048", "20.48")
//! runtextmacro AttackSpeedAbility("ZxIc", "+04096", "40.96")
//! runtextmacro AttackSpeedAbility("ZxId", "+08192", "81.92")
//! runtextmacro AttackSpeedAbility("ZxIe", "+16384", "163.84")
//! runtextmacro AttackSpeedAbility("ZxIf", "+32768", "327.68")
//! runtextmacro AttackSpeedAbility("ZxIg", "+65536", "655.36")
//! runtextmacro AttackSpeedAbility("ZxIh", "-131072", "-1310.72")

// CSS - Life Regeneration
//============================================================================================
//! textmacro LifeRegenAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a Arel $RAWCODE$ Ihpr 1 $VALUE$ anam "CSS - Life Regen ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNRingSkull.blp
//! endtextmacro

//! runtextmacro LifeRegenAbility("ZxJ0", "+00001", "1")
//! runtextmacro LifeRegenAbility("ZxJ1", "+00002", "2")
//! runtextmacro LifeRegenAbility("ZxJ2", "+00004", "4")
//! runtextmacro LifeRegenAbility("ZxJ3", "+00008", "8")
//! runtextmacro LifeRegenAbility("ZxJ4", "+00016", "16")
//! runtextmacro LifeRegenAbility("ZxJ5", "+00032", "32")
//! runtextmacro LifeRegenAbility("ZxJ6", "+00064", "64")
//! runtextmacro LifeRegenAbility("ZxJ7", "+00128", "128")
//! runtextmacro LifeRegenAbility("ZxJ8", "+00256", "256")
//! runtextmacro LifeRegenAbility("ZxJ9", "+00512", "512")
//! runtextmacro LifeRegenAbility("ZxJa", "+01024", "1024")
//! runtextmacro LifeRegenAbility("ZxJb", "+02048", "2048")
//! runtextmacro LifeRegenAbility("ZxJc", "+04096", "4096")
//! runtextmacro LifeRegenAbility("ZxJd", "+08192", "8192")
//! runtextmacro LifeRegenAbility("ZxJe", "+16384", "16384")
//! runtextmacro LifeRegenAbility("ZxJf", "+32768", "32768")
//! runtextmacro LifeRegenAbility("ZxJg", "+65536", "65536")
//! runtextmacro LifeRegenAbility("ZxJh", "-131072", "-131072")

// CSS - Mana Regeneration
//============================================================================================
//! textmacro ManaRegenAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AIrm $RAWCODE$ Imrp 1 $VALUE$ anam "CSS - Mana Regen ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNSobiMask.blp
//! endtextmacro

//! runtextmacro ManaRegenAbility("ZxK0", "+00001", "0.01")
//! runtextmacro ManaRegenAbility("ZxK1", "+00002", "0.02")
//! runtextmacro ManaRegenAbility("ZxK2", "+00004", "0.04")
//! runtextmacro ManaRegenAbility("ZxK3", "+00008", "0.08")
//! runtextmacro ManaRegenAbility("ZxK4", "+00016", "0.16")
//! runtextmacro ManaRegenAbility("ZxK5", "+00032", "0.32")
//! runtextmacro ManaRegenAbility("ZxK6", "+00064", "0.64")
//! runtextmacro ManaRegenAbility("ZxK7", "+00128", "1.28")
//! runtextmacro ManaRegenAbility("ZxK8", "+00256", "2.56")
//! runtextmacro ManaRegenAbility("ZxK9", "+00512", "5.12")
//! runtextmacro ManaRegenAbility("ZxKa", "+01024", "10.24")
//! runtextmacro ManaRegenAbility("ZxKb", "+02048", "20.48")
//! runtextmacro ManaRegenAbility("ZxKc", "+04096", "40.96")
//! runtextmacro ManaRegenAbility("ZxKd", "+08192", "81.92")
//! runtextmacro ManaRegenAbility("ZxKe", "+16384", "163.84")
//! runtextmacro ManaRegenAbility("ZxKf", "+32768", "327.68")
//! runtextmacro ManaRegenAbility("ZxKg", "+65536", "655.36")
//! runtextmacro ManaRegenAbility("ZxKh", "-131072", "-1310.72")

// Don't let a //! external command be the last line in a trigger!

  • Color Code Setting
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Color codes for the item info panel can be set here --------
      • -------- If you want a text to be colored white as default, set the color code to |cffffffff --------
      • -------- Don't touch the indexes, modify the value only --------
      • -------- Socket Item Name --------
      • Set CSS_String[11] = |cffff0000
      • -------- Item Name --------
      • Set CSS_String[12] = |cff32cd32
      • -------- Bonus Stat --------
      • Set CSS_String[24] = |cFF0000FF
      • -------- Other Text --------
      • Set CSS_String[25] = |cffffffff
      • -------- Numbers other than stat --------
      • Set CSS_String[26] = |cFFFFA500
      • -------- Color Codes for Stats --------
      • -------- Armor --------
      • Set CSS_String[13] = |cFFFFA500
      • -------- Attack Speed --------
      • Set CSS_String[14] = |cFF800080
      • -------- Damage --------
      • Set CSS_String[15] = |CFF7EBFF1
      • -------- Agility --------
      • Set CSS_String[16] = |cFFFFD700
      • -------- Intelligence --------
      • Set CSS_String[17] = |cFF000000
      • -------- Strength --------
      • Set CSS_String[18] = |cff00ff00
      • -------- Life Regen --------
      • Set CSS_String[19] = |cff32cd32
      • -------- Mana Regen --------
      • Set CSS_String[20] = |CFFFFFF01
      • -------- Life --------
      • Set CSS_String[21] = |CFF1CB619
      • -------- Mana --------
      • Set CSS_String[22] = |CFF106246
      • -------- Sight Range --------
      • Set CSS_String[23] = |CFF4E2A04
  • Variable Creation
    • Events
    • Conditions
    • Actions
      • Set CSS_Abilities[0] = Acid Bomb
      • Set CSS_GemBonusBoolean = False
      • Set CSS_GemLevel = 0
      • Set CSS_Hashtable = (Last created hashtable)
      • Set CSS_Power[0] = 0
      • Set CSS_PreloadBoolean = False
      • Set CSS_SocketingEnabled = False
      • Set EVENT_SOCKET_FINISH = 0.00
      • Set CSS_EventMainItem = (Last created item)
      • Set CSS_EventSocketItem = (Last created item)
      • Set CSS_EventUnit = (Last created unit)
      • Set CSS_EventMainItemStacked[0] = (Last created item)
      • Set CSS_EventSocketItemStacked[0] = (Last created item)
      • Set CSS_EventUnitStacked[0] = (Last created unit)
      • Set CSS_Counter = 0
Known Issue: May bug if a unit somehow surpasses the bonus limit in some occasion.
-> Fix: Don't allow a unit to achieve near-limit for a stat i.e keep it at a reasonable level.


Currently the macro script will not work on Windows 64 computers because of a Microsoft patch and/or Warcraft III patch that broke LUA.



How easy can you register an item? For example I wish to register my "Alleria's Flute of Accuracy" (raw code 'afac') with these following stats:
  • 150 bonus Armor.
  • 400% bonus Attack Speed.
  • 800 bonus Damage.
  • 15 bonus Agility.
  • 45 bonus Intelligence.
  • 55 bonus Strength.
  • 85 bonus Life Regen.
  • 100% bonus Mana Regen.
  • 100 bonus Life.
  • 1000 bonus Mana.
  • 10 bonus Sight Range.
  • 3 sockets
Instead of creating 11 item abilities, I would only need a few trigger lines:
  • Item Declaration
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Item Declaration --------
      • Custom script: call CSS_ItemInitialize('afac', 150, 400, 800, 15, 45, 55, 85, 100, 100, 1000, 10, 3)
      • -------- Item Declaration End --------
      • -------- After item declaration, add the custom script below to prevent first pickup lag. --------
      • -------- Item Preload --------
      • Custom script: call CSS_ItemPreload()
      • -------- Item Preload End --------

+ v1.0: Initial release.
+ v1.0a: Temporarily remove the Object Merger Macro
+ v1.0b: Fixed a bug with sight range bonus plus making some changes to the test map for better testing.
+ v1.1: Revamped the code almost completely according to Mag's extremely helpful review. Thanks very much. Object Merger Macro is also readded.
+ v1.1a: Added credit for SimError by Vexorian. Now uses the BoundInt snippet by Magtheridon96.
+ v1.2: Added item socketing. Fixed some bugs.
+ v1.3: Fixed all bugs related to item socketing.
+ v1.4: Added a boolean to toggle Right Click Item Socketing on/off. Now supports quick and easy item info panel through chat command.
+ Quick Update: Added a color code setting trigger for item info panel.
+ Fix: Fixed an item pawn bug found by Almia.
+ v1.5: Added a function for refreshing item bonuses.
+ v1.5b: Fixed a minor bug with item info panel.
+ v1.5c: Fixed a bug with item socket info panel.
+ v1.5d: Added item info panel support for core system functionality i.e item stat registration.
+ v1.5e: Added variable creation method and a new sound when a unit successfully socket an item.
+ v1.5f: Added a prefix for SimError to avoid collision. Fixed a minor bug with Item Socket Info.
+ v1.5g: Added custom event response for successful item socketing.
+ v1.5h: Fixed a possible desync issue with item info panel.
+ v1.5i: Fixed a critical bug with selling items. BonusMod alternative is now a standalone part of the system.
+ ==Quick Fix==: Fixed a minor issue with a test trigger.
+ v1.5j: Fixed a critical bug with Life Regen abilities found by leonguyen112.
+ v1.5g: Added a new boolean that prevent items from giving bonuses until fully socketed.


Another thing I would like to point out is that I left the Implementation Macro in the test map. If you need to use this system, just ask a friend who uses a Windows version that doesn't conflict with the LUA object generator to run the macro and create the abilities for you.

One may wonder, why is this system called "Custom Stat" when it mainly deals with items rather than stats?
- Well tbh it was originally only a plain custom stat system but now that it has a lot of extensions, I am too lazy to do a complete function prefix change for the system itself :p

Thanks to Almia, -Kobas- and leonguyen112 for spotting bugs with the system.


FINAL WORDS
+All feedback, testing, criticism, suggestions, etc. are welcome as this is my first system submission. Thanks in advance.
+If you need help with this system, contact me or post in this thread.
+Credit is not required but recommended.
+Humans are bound to make mistakes. Don't hesitate to tell me if you find any bug.

Keywords:
item, bonus, stat, system, socketing, right, click, ORPG, RPG, custom, armor, hp, mp, damage, sight, life, mana, whatever, blah blah blah
Contents

Custom Stat System v1.5g (Map)

Reviews
17:28, 17th Feb 2013 Purgeandfire: Approved and highly recommended. This system is now completely flexible, allowing you to implement the bonus mod separately. It is very well documented and a lot of work has been done to get it bug-free. The...
Level 16
Joined
Dec 15, 2011
Messages
1,423
i tested and dont work, you can test again, pick 2 same item type, insert socket to 1st one then insert another socket to 2nd one and see what happen

i dont heard yet about that loop, this is the jasscraft result , i thought if it is a native then dont loop inside

Yes indeed the socket thing doesn't work. Fixing it now.

There are a lot things that don't need to be done locally such as requirements because it applies to all the items of that type. You should optimize your code and split it into local and global values for better handling.

SimError is recommended by mods :p

How do you detect when an item is removed or destroyed?
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
There are a lot things that don't need to be done locally such as requirements because it applies to all the items of that type. You should optimize your code and split it into local and global values for better handling.

u dont got it why i made that :p
example what happen if u want create item with random stat and with same item type?
example: 2 item but one give 5 damage another 6? u create 2 item type? that possible but what if u need 100 item? u create 100 item?

my old orpg system used mover 300 item, and now only few just coz i save locally, easy to make random stat equipment after i already must saved locally the refine level and inserted gems, the saveing other things aren't big deal, yeah, assign to itemtypeid is pretty good until you dont want many potentional variation on your map :)

How do you detect when an item is removed or destroyed?

1st i used a periodical loop, like:
it = item array
i = index

when u drop a item or create item to ground then:
i= i + 1
it = your item

in periodic trigger u can check via loop if it[x] == null

now i dont use periodic trigger, i use max item amount, its mean
if i > 100 then remove the oldest item, coz i want avoid the item flood on ground
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
u dont got it why i made that :p
example what happen if u want create item with random stat and with same item type?
example: 2 item but one give 5 damage another 6? u create 2 item type? that possible but what if u need 100 item? u create 100 item?

my old orpg system used mover 300 item, and now only few just coz i save locally, easy to make random stat equipment after i already must saved locally the refine level and inserted gems, the saveing other things aren't big deal, yeah, assign to itemtypeid is pretty good until you dont want many potentional variation on your map :)

Ah I see. My bad then.

1st i used a periodical loop, like:
it = item array
i = index

when u drop a item or create item to ground then:
i= i + 1
it = your item

in periodic trigger u can check via loop if it[x] == null

now i dont use periodic trigger, i use max item amount, its mean
if i > 100 then remove the oldest item, coz i want avoid the item flood on ground


Nice. I think I had an idea on how to do this.
 
Have you tried this with Item Drops?(those on-death)

Just got in my mind.

edit

I found a bug.

Try getting items then sell it.
The stats remains even though the item is gone.

Here is the screeny:
attachment.php


:D

edit edit

WOOOOH!!! My Hero is a God :
attachment.php
 

Attachments

  • j.JPG
    j.JPG
    157.8 KB · Views: 360
  • j2.JPG
    j2.JPG
    151 KB · Views: 303
Last edited:
Level 17
Joined
Nov 13, 2006
Messages
1,814
oh, just a ideea, u can avoid the useing hashtable and triggers for item death if u make items invulnarable when user buy it and map init a item pick playable map
JASS:
call SetItemInvulnerable(whichItem, flag)

i guess i also will do same for avoid the useless item checking, so only the selling left and item removeing by trigger :)
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
oh, just a ideea, u can avoid the useing hashtable and triggers for item death if u make items invulnarable when user buy it and map init a item pick playable map
JASS:
call SetItemInvulnerable(whichItem, flag)

i guess i also will do same for avoid the useless item checking, so only the selling left and item removeing by trigger :)

My system aims to be as GUI-friendly as possible and your method won't work with native item removal. It also disables the kill option, narrowing the user's variety of choice.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Hmm, nice try but imo its not flexible enough, and there are already quite a lot of these systems that all look the same.

1. You cant have stats like for example +20% damage, can you?
2. It only handles item stats, what about buffs?
3. It doesnt support "soft stats", like Spellpower or other user-defined stats.

BonusMod however is useful, since its meant to be used on a low layer.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Hmm, nice try but imo its not flexible enough, and there are already quite a lot of these systems that all look the same.

1. You cant have stats like for example +20% damage, can you?
2. It only handles item stats, what about buffs?
3. It doesnt support "soft stats", like Spellpower or other user-defined stats.

BonusMod however is useful, since its meant to be used on a low layer.

I am sorry if this system doesn't live up to your expectations. I simply don't have the necessary capability to fulfill your needs but I will try my best.

Another thing, I am really tired of getting my system compared to BonusMod already. Why won't anyone look at both the advantages and disadvantages rather than locking on its inevitable flaw?
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Hmm, nice try but imo its not flexible enough, and there are already quite a lot of these systems that all look the same.

1. You cant have stats like for example +20% damage, can you?
2. It only handles item stats, what about buffs?
3. It doesnt support "soft stats", like Spellpower or other user-defined stats.

BonusMod however is useful, since its meant to be used on a low layer.

1. how cant be 20% damage? save damage to variavle and divide with 5 and add that much damage to unit :p
2. have buff systems
3. spell power just change a variable there absolute no big deal at all :p
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Another thing, I am really tired of getting my system compared to BonusMod already. Why won't anyone look at both the advantages and disadvantages rather than locking on its inevitable flaw?

im sry, but the 4. bullet in your feature list is:
"BonusMod-like features for extensive usage."

1. how cant be 20% damage? save damage to variavle and divide with 5 and add that much damage to unit :p
no, if you add an item that grants +20% damage you expect it to boost the overall damage of that unit by 20%, not the current damage value. Also you get problems if you remove the items in a different order. Example
- unit has 100 dmg
- picks up item with +100 dmg (-> has 200 dmg)
- picks up item with +10% Damage (-> has 220 dmg)
- drops item with +100 dmg (-> has 120 dmg)
- drops item with +10% dmg (-> has 109 dmg)

2. have buff systems
inventory system and buff system are the two basic components that modify unit stats. Thus they should share the same backend code for applying stats.
3. spell power just change a variable there absolute no big deal at all :p
exactly, but while making items you want to handle spellpower and damage as if they were the same kind of stat. You do not want a special treatment for spellpower and other "softstats", you use a system that handles stats so you want it to handle all of them.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
im sry, but the 4. bullet in your feature list is:
"BonusMod-like features for extensive usage."


no, if you add an item that grants +20% damage you expect it to boost the overall damage of that unit by 20%, not the current damage value. Also you get problems if you remove the items in a different order. Example
- unit has 100 dmg
- picks up item with +100 dmg (-> has 200 dmg)
- picks up item with +10% Damage (-> has 220 dmg)
- drops item with +100 dmg (-> has 120 dmg)
- drops item with +10% dmg (-> has 109 dmg)


inventory system and buff system are the two basic components that modify unit stats. Thus they should share the same backend code for applying stats.

exactly, but while making items you want to handle spellpower and damage as if they were the same kind of stat. You do not want a special treatment for spellpower and other "softstats", you use a system that handles stats so you want it to handle all of them.

its bonus mod system what i never watched yet any bonus mod system what cover every bonus stat, its just show the direction else it isnt lightweight

example damage detection system dont make the spells for u with special damage types :p

about ur calculation is wrong in that point if u use flat amount then never left 109 hp since it is flat 120=>100 after drop the 20 damage

another side its easily replaceables the flat abilities to percentage one (what i dont really like, in low game the percentages are ok but if someone what use it for wide level range map then its will be hard to make balance)

whatever about damage % most easiest way with dds and variable instead create more ability and call it amplify and not x% damage boost :p
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
its bonus mod system what i never watched yet any bonus mod system what cover every bonus stat, its just show the direction else it isnt lightweight

example damage detection system dont make the spells for u with special damage types :p
Its not supposed to cover every possible bonus stat, it simply should allow you to define exactly the stats you need.

about ur calculation is wrong in that point if u use flat amount then never left 109 hp since it is flat 120=>100 after drop the 20 damage
That means you had to store the (absolute) damage you added, which (as far as i understand) cant be done using this system. Right? Well that sucks too since the bonus you get depends on the order in which you pick up the items.

another side its easily replaceables the flat abilities to percentage one (what i dont really like, in low game the percentages are ok but if someone what use it for wide level range map then its will be hard to make balance)

whatever about damage % most easiest way with dds and variable instead create more ability and call it amplify and not x% damage boost :p
Im not talking about replacing the absolute damage stat with percentual damage. I just said there are situations where you might want to have both absolute and percentual damage and more generally more flexible stat definitions.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
i dont see the problem with it, just add another abilities and same function handle that too...

you mean, alter the system?
Cause this:
Code:
//* Item Registration API                                                              *
//*                                                                                    *
//* call CSS_ItemInitialize (integer itemRawCode, integer armorBonus,                  *
//* integer attackSpeedBonus, integer damageBonus, integer agilityBonus,               *
//* integer intelligenceBonus, integer strengthBonus, integer lifeRegenBonus,          *
//* integer manaRegenBonus, integer lifeBonus, integer manaBonus,                      *
//* integer sightRangeBonus, integer socket)
doenst look like the system is designed to allow such adaptions.

I still think the system is good, but the design lacks flexibility.

But il rep you for this:
Code:
//********************************************************************************************************
//* REQUIREMENTS:                                                                                        *
//*                                                                                                      *
//* JNGP [url]http://www.hiveworkshop.com/forums/tools-560/jassnewgenpack-5d-227445[/url] (Recommended)  *
//* OR:                                                                                                  *
//* Your superhuman capability to transfer 198 abilities to your map. (Not Recommended)                  *
//********************************************************************************************************
Very phunny :p
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
you mean, alter the system?
Cause this:
Code:
//* Item Registration API                                                              *
//*                                                                                    *
//* call CSS_ItemInitialize (integer itemRawCode, integer armorBonus,                  *
//* integer attackSpeedBonus, integer damageBonus, integer agilityBonus,               *
//* integer intelligenceBonus, integer strengthBonus, integer lifeRegenBonus,          *
//* integer manaRegenBonus, integer lifeBonus, integer manaBonus,                      *
//* integer sightRangeBonus, integer socket)
doenst look like the system is designed to allow such adaptions.

if u add + 1 integer and few ability then its allow pretty well ;)

coz here u dont must change nearly nothing

JASS:
function CSS_AddBonus takes unit u, integer amount, integer bonusType returns nothing
    local integer max = udg_CSS_Power[17]
    local integer min = -udg_CSS_Power[17]
    local integer i = 16
    local integer j = LoadInteger (udg_CSS_Hashtable, GetHandleId(u), bonusType)

    if amount > max - 1 or amount < min then
        call SimError ("Value too high or too low")
        return
    endif

    if amount + j >= max or amount + j <= min then
        call SimError ("Current value at maximum or minimum")
    endif

    set amount = amount + j
    call BoundInt (amount, min, max - 1)

    if bonusType < 0 or bonusType > 10 then
        call SimError ("CSS Error: Invalid bonus type (" + I2S(bonusType) + ")")
        return
    elseif bonusType == 8 or bonusType == 9 then

        if bonusType == 8 and amount*1. + GetUnitState(u, UNIT_STATE_MAX_LIFE) <= 0 then
            call SimError ("Unit's current max life is lower than the negative bonus amount. Unable to subtract.")
            return
        elseif bonusType == 9 and amount*1. + GetUnitState(u, UNIT_STATE_MAX_MANA) <= 0 then
            call SimError ("Unit's current max mana is lower than the negative bonus amount. Unable to subtract.")
            return
        endif

        call SaveInteger(udg_CSS_Hashtable, GetHandleId(u), bonusType, amount)

        if amount < 0 then
            set amount = max + amount
        else
            call UnitRemoveAbility(u, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
        endif

        loop
            if amount >= udg_CSS_Power[i] then
                call UnitAddAbility(u, udg_CSS_Abilities[bonusType*18 + i])
                call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[bonusType*18 + i])
                set amount = amount - udg_CSS_Power[i]
            else
                call UnitRemoveAbility(u, udg_CSS_Abilities[bonusType*18 + i])
            endif
        
            set i = i - 1
            exitwhen i < 0
        endloop

        if LoadInteger(udg_CSS_Hashtable, GetHandleId(u), bonusType) < 0 then
            call UnitAddAbility(u, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
            call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
        endif

    else

        call SaveInteger(udg_CSS_Hashtable, GetHandleId(u), bonusType, amount)

        if amount < 0 then
            set amount = max + amount
            call UnitAddAbility(u, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
            call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[(bonusType + 1)*18 - 1])
        else
            call UnitRemoveAbility(u, udg_CSS_Abilities[(bonusType+1)*18 - 1])
        endif

        loop
            if amount >= udg_CSS_Power[i] then
                call UnitAddAbility(u, udg_CSS_Abilities[bonusType*18 + i])
                call UnitMakeAbilityPermanent(u, true, udg_CSS_Abilities[bonusType*18 + i])
                set amount = amount - udg_CSS_Power[i]
            else
                call UnitRemoveAbility(u, udg_CSS_Abilities[bonusType*18 + i])
            endif
        
            set i = i - 1
            exitwhen i < 0
        endloop

    endif
endfunction
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Resources should essentially run themselves, just cnp into the map and done. Having to modify a resource makes everything more sloppy and harder to find >.>.

For example, many resources use Event lib so that other resources can dynamically plugin to them. Having to plug the resource in manually is crazy : o.


Requiring users to modify a resource is poor design.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Thanks everyone for participating in discussions. Please allow me to point out a few things:
  • It is simply impossible to predict the amount of so-called soft stats that a map will need. Thus it is also impossible to make a one-size-fits-all API (I am not friggin' Nestharus for goodness' sake). I do believe that my system only needs configuration, not code alteration as long as you stick to the original functionality. And about the percentage thing and buff handling, gives me some time to think of a way to do it.
  • Then again, concerning BonusMod, I should remind you guys that it serves only as the foundation of this system and nothing more; and yes I do say that it is for /extensive/ usage, which is inevitable due to obvious reasons.
  • I would gratefully receive any further suggestions on how to improve this system's flexibility. It is what I have been looking for these days.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
[*]It is simply impossible to predict the amount of so-called soft stats that a map will need. Thus it is also impossible to make a one-size-fits-all API (I am not friggin' Nestharus for goodness' sake). I do believe that my system only needs configuration, not code alteration as long as you stick to the original functionality. And about the percentage thing and buff handling, gives me some time to think of a way to do it.

You dont have to predict the amount of soft-stats, you just have to make the system flexible enough so it scales.
Storing these values isnt a problem, you can use hashtables or linkedlists, you just have to think about how you register items. So instead this:
JASS:
call CSS_ItemInitialize('afac', 150, 400, 800, 15, 45, 55, 85, 100, 100, 1000, 10, 3)
you can use a function that only sets one value, like this:
JASS:
call CSS_ItemAddStat('afac', STAT_DAMAGE, 100)
call CSS_ItemAddStat('afac', STAT_SPELLPOWER, 40)
etc.
This looks like its a lot more code to write compared to your solution, but keep in mind that usually not all items make use of all stats, so you will only need a couple of these calls to register one item. And its more flexible since you can add another stat (by defining one of these STAT_**** constants) without rendering existing item definitions invalid.

About the creation of new stats, all you have to do is to write a function that allocates IDs for the stats. For stats that are no softstats (and for example need to change abilities) you have to provide functions that are called when the stat is changed. (You can use event libs for this purpose).
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
You dont have to predict the amount of soft-stats, you just have to make the system flexible enough so it scales.
Storing these values isnt a problem, you can use hashtables or linkedlists, you just have to think about how you register items. So instead this:
JASS:
call CSS_ItemInitialize('afac', 150, 400, 800, 15, 45, 55, 85, 100, 100, 1000, 10, 3)
you can use a function that only sets one value, like this:
JASS:
call CSS_ItemAddStat('afac', STAT_DAMAGE, 100)
call CSS_ItemAddStat('afac', STAT_SPELLPOWER, 40)
etc.
This looks like its a lot more code to write compared to your solution, but keep in mind that usually not all items make use of all stats, so you will only need a couple of these calls to register one item. And its more flexible since you can add another stat (by defining one of these STAT_**** constants) without rendering existing item definitions invalid.

About the creation of new stats, all you have to do is to write a function that allocates IDs for the stats. For stats that are no softstats (and for example need to change abilities) you have to provide functions that are called when the stat is changed. (You can use event libs for this purpose).

That would mean a complete rework of the system's code. I will be making a survey and deciding later. I greatly appreciate your good will in suggesting this but please allow me some more time to think.

EDIT: Here is the survey thread and I will be monitoring it for a while before making the final decision.
 
Level 5
Joined
Dec 3, 2012
Messages
117
This might be an extremely stupid question... but I copied the CSS SYstem folder, but the only variable it copied is CSS_String, should I just customly replicate the other variables, or copy them some other way? D:
 
Alrighty, here is my review. :)

  • For the sake of easy implementation, you should include all your globals in the trigger "Color Code Setting" (and probably rename the trigger appropriately). This means setting them to 0 or initialize them or whatever it may be. This way, when someone copies over the system into the map, they'll have all the globals ready as long as they have "Preferences -> Create custom variables while pasting" checked.
  • In the "Main System Code", the function "CSS_ItemInfoSocketPanel" seems a bit iffy. From what I see, it may have a chance of desyncing with the way GetLocalPlayer() is used. Imagine if you group the enum units selected for Player 1, and it is 5, whereas with player 2 it is 1. The group would be destroyed locally for Player 1 and thus, it would cause a desync.

    However, this shouldn't be too difficult to fix! It seems like you mostly did it just to shorthand the trigger actions. Instead, you should loop through the players and perform the necessary actions. I also recommend that you use a global variable for the group and just reuse it throughout the trigger, rather than creating one and destroying one each time:
    http://www.thehelper.net/threads/how-to-use-groups-without-leaking.123810/
  • Same thing as above for "CSS_ItemInfoPanel".
  • Assuming my chrome's "Find" function is working properly, you make the function for preloading items but you never end up calling it. You may also want to consider merging the functions for preloading items and preloading abilities, but it isn't really much of an issue.

Other than that it looks like a pretty solid system. :)
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Is there a way to use only the CSS_AddBonus function and not the others?

I will try to find a way. Sorry but, you know, frigging exams.

Is there a function/group of functions in JASS that allows you to add a stat to a unit like CSS does?

There are functions to add attributes but for other stats, no.
 
You could at least make the Dummy Owner move inside a constant function, but that is optional.

JASS:
constant function CSS_GemLevel takes nothing returns integer
    return udg_CSS_GemLevel
endfunction

I don't see the use of this, just use the variable directly.

Cache GetHandleId(u) and GetHandleId (UnitItemInSlot (u, i)) in the StatUpdate func.

Actually, you can just use a Global group instead of local group.

JASS:
if LoadStr (udg_CSS_Hashtable, i, -31 - j) == null then
    set s = "Not Socketed"
else
    set s = LoadStr (udg_CSS_Hashtable, i, -31 - j)
endif

->

JASS:
set s = LoadStr (udg_CSS_Hashtable, i, -31 - j)
if s == "" then
    set s = "Not Socketed"
endif

JASS:
    local integer i = GetHandleId (GetSoldItem ())
    local integer k = GetItemTypeId (GetSoldItem ())
cache GetSoldItem

LoadInteger (udg_CSS_Hashtable, i, j)
Cache this in the ItemSpawnCheck.

local integer i = GetHandleId (GetManipulatedItem())
local integer k = GetItemTypeId (GetManipulatedItem())

Cache GetManipulatedItem

LoadInteger (udg_CSS_Hashtable, k, j)
In the ItemDropCheck, cache this.

Use TriggerAddCondition instead of TriggerAddAction(Actions create new thread) and also don't forget to put return false.

In the ItemAcquireCheck, cache this : LoadInteger (udg_CSS_Hashtable, k, j)

Btw, Because of what I have discovered about the JASS Compiler,where the functions are allowed to be used, make sure to warn them that replace the code of the oldest with the code of this system,or perhaps,move the system's code to the Map Header and just create an auto-initializer(which I discovered also).

To create an auto-initializer, you must use one variable(any type,recommended is boolean). When a main function of the system runs(esp. the StatUpdate or anything that is the system's core that the user can use) Add this lines:
JASS:
if udg_CSS_Initialized == false then // Initialized is boolean
    call CSS_Init()
    set udg_CSS_Initialized = true
endif

So that if the user runs a function, initializer gets initialized too.


This is just a short review from me.
 
Top