• 🏆 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...
Well here's my opinion :

Positive
-This System has BonusMod
-This System has Socketing
-This System is simple to use [using JNGP]

Negative
-The Socketing is a bit confusing at start, maybe add an info how to socket? I lost 5 minutes of my life to figure it out

RATING : 5/5

Others
I'm up for the copying 198 abilities if you want xD

EDIT :
The 100th commenter :p
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Well here's my opinion :

Positive
-This System has BonusMod
-This System has Socketing
-This System is simple to use [using JNGP]

Negative
-The Socketing is a bit confusing at start, maybe add an info how to socket? I lost 5 minutes of my life to figure it out

RATING : 5/5

Others
I'm up for the copying 198 abilities if you want xD

Thanks. Yeh alright I will add a head-up for it.

Btw there is a macro that automatically creates 198 abilities for you. Could you elaborate your last line?
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Sorry but your system is not working when i mix it with a vjass bag system. I dont know if it is because the two of them are using u = the unit variable....

http://www.hiveworkshop.com/forums/...tem-133050/?prev=search=inventory&d=list&r=20

Alone its working but compile with this one just nothing...

It is because the mechanics conflict with each other. I am now working on a bag system that syncs with my CSS. You can't use my system with other bag systems I am afraid.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Nice update bro; but to tell you honestly, I can't test it now. Even if I was able to, I can't give you feedback because I'm going to run out of time by then. Also, since I won't be much active any time soon, I just want you to know that even if I'm almost inactive now, I'm still supporting you from the backstage!

+REP!

He he thanks very much =)) Look forward to meeting you again.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
its a bit weird that you provide mana regen in 0.01 * 2^power, but life regen in 2^power?

I mean, you can say to CSS that you want 0.46 mana regen, but you cant say you want 0.46 life regen

It can't be helped. I am using an integer bonus life regen ability. And the mana regen is actually measured in percentage so 0.46 means 46% Increased Mana Regen rather than a 0.46 bonus mana regen point. Although there are real variations for both bonuses, it is kinda complicated to change the whole code so I just left it there.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
kind of necro post, but your LUA script is incredibly stupidly inefficient. If you try to generate the objects, you basically command JassHelper to execute the ObjectManager 198 times(the amount of abilities), which is very inefficient.

I have taken my time to write a lot more efficient LUA script.

JASS:
scope GenerateObjectsLuaCSS

//! textmacro LUA_GENERATE_ABILS_CSS takes slash

    $slash$//! externalblock extension=lua ObjectMerger $FILENAME$        
        //! i function set(field, value)
            //! i makechange(current, field, value)
        //! i end

        //! i function setl(field, level, value)
            //! i makechange(current, field, level, value)
        //! i end
        
        //ftc = first three chars of rawcode
        //! i function generate(baseAbil, ftc, toModif, name, icon, partial)
            //! i bonuses = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
            //! i               4096, 8192, 16384, 32768, 65536, -131072 }
            
            //! i vArr = { ftc.."0", ftc.."1", ftc.."2", ftc.."3", ftc.."4",
            //! i           ftc.."5", ftc.."6", ftc.."7", ftc.."8", ftc.."9",
            //! i           ftc.."a", ftc.."b", ftc.."c", ftc.."d", ftc.."e",
            //! i           ftc.."f", ftc.."g", ftc.."h" }
            
            //! i printName = { "+00001", "+00002", "+00004", "+00008", "+00016", "+00032",
            //! i               "+00064", "+00128", "+00256", "+00512", "+01024", "+02048",
            //! i               "+04096", "+08192", "+16384", "+32768", "+65536", "-131072" }
            
            //! i for i=1, 18 do
                //! i createobject(baseAbil, vArr[i])
                //! i set("anam", "CSS - "..name.." ("..printName[i]..")")
                //! i set("aite", 0)
                //! i set("ansf", "")
                //! i set("aart", icon)
                //! i if partial == 1 then
                    //! i setl(toModif, "1", bonuses[i] / 100)
                //! i else
                    //! i setl(toModif, "1", bonuses[i])
                //! i end
            //! i end
        //! i end
        
        //! i function generateSpecial(baseAbil, ftc, toModifSet, toModifUnset1, toModifUnset2,
        //! i                           name, icon, partial)
            //! i bonuses = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
            //! i               4096, 8192, 16384, 32768, 65536, -131072 }
            
            //! i vArr = { ftc.."0", ftc.."1", ftc.."2", ftc.."3", ftc.."4",
            //! i           ftc.."5", ftc.."6", ftc.."7", ftc.."8", ftc.."9",
            //! i           ftc.."a", ftc.."b", ftc.."c", ftc.."d", ftc.."e",
            //! i           ftc.."f", ftc.."g", ftc.."h" }
            
            //! i printName = { "+00001", "+00002", "+00004", "+00008", "+00016", "+00032",
            //! i               "+00064", "+00128", "+00256", "+00512", "+01024", "+02048",
            //! i               "+04096", "+08192", "+16384", "+32768", "+65536", "-131072" }
            
            //! i for i=1,18 do
                //! i createobject(baseAbil, vArr[i])
                //! i set("anam", "CSS - "..name.." ("..printName[i]..")")
                //! i set("aite", 0)
                //! i set("ansf", "")
                //! i set("aart", icon)
                //! i if partial == 1 then
                    //! i setl(toModifSet, "1", bonuses[i] / 100)
                    //! i setl(toModifUnset1, "1", 0)
                    //! i setl(toModifUnset2, "1", 0)
                //! i else
                    //! i setl(toModifSet, "1", bonuses[i])
                    //! i setl(toModifUnset1, "1", 0)
                    //! i setl(toModifUnset2, "1", 0)
                //! i end
            //! i end
        //! i end
        
        //! i setobjecttype("abilities")
        //! i generate("AId1", "ZxA", "Idef", "Armor", "ReplaceableTextures\\CommandButtons\\BTNHumanArmorUpOne.blp", 0)
        //! i generate("AItg", "ZxB", "Iatt", "Damage", "ReplaceableTextures\\CommandButtons\\BTNClawsOfAttack.blp", 0)
        //! i generate("AIsi", "ZxC", "Isib", "Sight Range", "ReplaceableTextures\\CommandButtons\\BTNTelescope.blp", 0)
        //! i generate("AImz", "ZxD", "Iman", "Max Mana", "ReplaceableTextures\\CommandButtons\\BTNPendantOfMana.blp", 0)
        //! i generate("AIlf", "ZxE", "Ilif", "Max Life", "ReplaceableTextures\\CommandButtons\\BTNPeriapt1.blp", 0)
        
        //! i generateSpecial("AIa1", "ZxF", "Istr", "Iagi", "Iint", "Hero STR", "ReplaceableTextures\\CommandButtons\\BTNGauntletsOfOgrePower.blp", 0)
        //! i generateSpecial("AIa1", "ZxG", "Iagi", "Istr", "Iint", "Hero AGI", "ReplaceableTextures\\CommandButtons\\BTNSlippersOfAgility.blp", 0)
        //! i generateSpecial("AIa1", "ZxH", "Iint", "Iagi", "Istr", "Hero INT", "ReplaceableTextures\\CommandButtons\\BTNMantle.blp", 0)
        
        //! i generate("AIsx", "ZxI", "Isx1", "Attack Speed", "ReplaceableTextures\\CommandButtons\\BTNClawsOfAttack.blp", 1)
        //! i generate("Arel", "ZxJ", "Ihpr", "Life Regen", "ReplaceableTextures\\CommandButtons\\BTNRingSkull.blp", 0)
        //! i generate("AIrm", "ZxK", "Imrp", "Mana Regen", "ReplaceableTextures\\CommandButtons\\BTNSobiMask.blp", 1)
    $slash$//! endexternalblock
    
//! endtextmacro

//! runtextmacro LUA_GENERATE_ABILS_CSS("") //put "/" in there after you have generated the objects

endscope

Your object generation takes well above 2 minutes to complete, while this takes around 2.5 seconds to fully create objects

Credits: WaterKnight whos LUA script showed me how to comment LUA block with Textmacro and also for the LUA set and setl functions that I have taken from the very same script
 
I think an update of this would be wonderful. . .

Could you update your custom stat system mainly concerning a bag system addition as well being able to take gems out of the sockets? By the way how do I add more socket options? An easy way to make 10-20 or even below 10 sockets? Basically can I create or reduce socket limits per item?
 
Level 3
Joined
May 17, 2012
Messages
15
The small range of bonuses for this system was not large enough for my needs. So I made an edit which allows you to set the maximum range of bonuses, up to 2^29 (you don't really need a bonus greater than 1073741824).

Instructions on how to change the range are in the map.
 

Attachments

  • Custom Stat System v1.5g_ed.w3x
    69.5 KB · Views: 52
The small range of bonuses for this system was not large enough for my needs. So I made an edit which allows you to set the maximum range of bonuses, up to 2^29 (you don't really need a bonus greater than 1073741824).

Instructions on how to change the range are in the map.

Could you include the extra abilities required as well in the improved edit?
 
Level 3
Joined
May 17, 2012
Messages
15
Could you include the extra abilities required as well in the improved edit?

You should really use the implementation macro to generate the abilities instead. Main reason for that is because the last generated bonus ability for each bonus type has to be the negative modifier. Other reason is because it's faster than copying and pasting everything and then creating additional bonus abilities by hand.

That said, I attached a map of the edit which has bonuses up to 2^21 [-2097152, 2097151]. If you're copying these abilities and you aren't using a macro for ability generation, you'll have to replace the relevant bonus abilities.
 

Attachments

  • Custom Stat System v1.5g_ed.w3x
    71.7 KB · Views: 42
Level 23
Joined
Apr 16, 2012
Messages
4,041
well I dont know where the problem lies, but before I published it I tested it for speed against the current method in this resource, and this was considerably faster and successfully generated the abilities for me on the test map I used
 
Well this is the code, I don't see what's wrong with it.
[jass=]
//TESH.scrollpos=115
//TESH.alwaysfold=0
//! textmacro LUA_GENERATE_ABILS_CSS takes slash

$slash$//! externalblock extension=lua ObjectMerger $FILENAME$

// You should set this value to the same amount as CSS_MaxPower.
//! i bonusCount = 21

// That's everything worth mentioning.

//! i function set(field, value)
//! i makechange(current, field, value)
//! i end

//! i function setl(field, level, value)
//! i makechange(current, field, level, value)
//! i end

//ftc = first three chars of rawcode
//! i function generate(baseAbil, ftc, toModif, name, icon, partial)
///! i bonuses = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
///! i 4096, 8192, 16384, 32768, 65536, -131072 }

///! i vArr = { ftc.."0", ftc.."1", ftc.."2", ftc.."3", ftc.."4",
///! i ftc.."5", ftc.."6", ftc.."7", ftc.."8", ftc.."9",
///! i ftc.."a", ftc.."b", ftc.."c", ftc.."d", ftc.."e",
///! i ftc.."f", ftc.."g", ftc.."h" }

///! i printName = { "+00001", "+00002", "+00004", "+00008", "+00016", "+00032",
///! i "+00064", "+00128", "+00256", "+00512", "+01024", "+02048",
///! i "+04096", "+08192", "+16384", "+32768", "+65536", "-131072" }
//! i bonuses = {}
//! i vArr = {}
//! i printName = {}

//! i bonuses[bonusCount + 1] = -1 * (2 ^ (bonusCount))
//! i if (bonusCount + 1) > 10 then
//! i vArr[bonusCount + 1] = ftc .. string.char(86 + bonusCount + 1)
//! i else
//! i vArr[bonusCount + 1] = ftc .. string.char(47 + bonusCount + 1)
//! i end
//! i printName[bonusCount + 1] = bonuses[bonusCount + 1]

//! i padAmt = string.len(bonuses[bonusCount + 1]) - 1
//! i for i = 1, bonusCount do
//! i bonuses = 2 ^ (i - 1)
//! i if i > 10 then
//! i vArr = ftc .. string.char(86 + i)
//! i else
//! i vArr = ftc .. string.char(47 + i)
//! i end
//! i printName = "+"
//! i local j = 0
//! i while j < (padAmt - string.len(bonuses)) do
//! i printName = printName .. "0"
//! i j = j + 1
//! i end
//! i printName = printName .. bonuses
//! i end

//! i for i=1, bonusCount+1 do
//! i createobject(baseAbil, vArr)
//! i set("anam", "CSS - "..name.." ("..printName..")")
//! i set("aite", 0)
//! i set("ansf", "")
//! i set("aart", icon)
//! i if partial == 1 then
//! i setl(toModif, "1", bonuses / 100)
//! i else
//! i setl(toModif, "1", bonuses)
//! i end
//! i end
//! i end

//! i function generateSpecial(baseAbil, ftc, toModifSet, toModifUnset1, toModifUnset2,
//! i name, icon, partial)
///! i bonuses = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
///! i 4096, 8192, 16384, 32768, 65536, -131072 }

///! i vArr = { ftc.."0", ftc.."1", ftc.."2", ftc.."3", ftc.."4",
///! i ftc.."5", ftc.."6", ftc.."7", ftc.."8", ftc.."9",
///! i ftc.."a", ftc.."b", ftc.."c", ftc.."d", ftc.."e",
///! i ftc.."f", ftc.."g", ftc.."h" }

///! i printName = { "+00001", "+00002", "+00004", "+00008", "+00016", "+00032",
///! i "+00064", "+00128", "+00256", "+00512", "+01024", "+02048",
///! i "+04096", "+08192", "+16384", "+32768", "+65536", "-131072" }
//! i bonuses = {}
//! i vArr = {}
//! i printName = {}

//! i bonuses[bonusCount + 1] = -1 * (2 ^ (bonusCount))
//! i if (bonusCount + 1) > 10 then
//! i vArr[bonusCount + 1] = ftc .. string.char(86 + bonusCount + 1)
//! i else
//! i vArr[bonusCount + 1] = ftc .. string.char(47 + bonusCount + 1)
//! i end
//! i printName[bonusCount + 1] = bonuses[bonusCount + 1]

//! i padAmt = string.len(bonuses[bonusCount + 1]) - 1
//! i for i = 1, bonusCount do
//! i bonuses = 2 ^ (i - 1)
//! i if i > 10 then
//! i vArr = ftc .. string.char(86 + i)
//! i else
//! i vArr = ftc .. string.char(47 + i)
//! i end
//! i printName = "+"
//! i local j = 0
//! i while j < (padAmt - string.len(bonuses)) do
//! i printName = printName .. "0"
//! i j = j + 1
//! i end
//! i printName = printName .. bonuses
//! i end

//! i for i=1, bonusCount+1 do
//! i createobject(baseAbil, vArr)
//! i set("anam", "CSS - "..name.." ("..printName..")")
//! i set("aite", 0)
//! i set("ansf", "")
//! i set("aart", icon)
//! i if partial == 1 then
//! i setl(toModifSet, "1", bonuses / 100)
//! i setl(toModifUnset1, "1", 0)
//! i setl(toModifUnset2, "1", 0)
//! i else
//! i setl(toModifSet, "1", bonuses)
//! i setl(toModifUnset1, "1", 0)
//! i setl(toModifUnset2, "1", 0)
//! i end
//! i end
//! i end

//! i setobjecttype("abilities")
//! i generate("AId1", "ZxA", "Idef", "Armor", "ReplaceableTextures\\CommandButtons\\BTNHumanArmorUpOne.blp", 0)
//! i generate("AItg", "ZxB", "Iatt", "Damage", "ReplaceableTextures\\CommandButtons\\BTNClawsOfAttack.blp", 0)
//! i generate("AIsi", "ZxC", "Isib", "Sight Range", "ReplaceableTextures\\CommandButtons\\BTNTelescope.blp", 0)
//! i generate("AImz", "ZxD", "Iman", "Max Mana", "ReplaceableTextures\\CommandButtons\\BTNPendantOfMana.blp", 0)
//! i generate("AIlf", "ZxE", "Ilif", "Max Life", "ReplaceableTextures\\CommandButtons\\BTNPeriapt1.blp", 0)

//! i generateSpecial("AIa1", "ZxF", "Istr", "Iagi", "Iint", "Hero STR", "ReplaceableTextures\\CommandButtons\\BTNGauntletsOfOgrePower.blp", 0)
//! i generateSpecial("AIa1", "ZxG", "Iagi", "Istr", "Iint", "Hero AGI", "ReplaceableTextures\\CommandButtons\\BTNSlippersOfAgility.blp", 0)
//! i generateSpecial("AIa1", "ZxH", "Iint", "Iagi", "Istr", "Hero INT", "ReplaceableTextures\\CommandButtons\\BTNMantle.blp", 0)

//! i generate("AIsx", "ZxI", "Isx1", "Attack Speed", "ReplaceableTextures\\CommandButtons\\BTNClawsOfAttack.blp", 1)
//! i generate("Arel", "ZxJ", "Ihpr", "Life Regen", "ReplaceableTextures\\CommandButtons\\BTNRingSkull.blp", 0)
//! i generate("AIrm", "ZxK", "Imrp", "Mana Regen", "ReplaceableTextures\\CommandButtons\\BTNSobiMask.blp", 1)
$slash$//! endexternalblock

//! endtextmacro

//! runtextmacro LUA_GENERATE_ABILS_CSS("") //put "/" in there after you have generated the objects (OR YOU KNOW, COMMENT OUT/REMOVE THE LINE)
[/code]
 
Level 3
Joined
May 17, 2012
Messages
15
What checkbox? Of course I have newgen and jasshelper enabled.
This box in the red circle needs to be checked:
0PQOZPB.png

The trigger in the orange circle should not be disabled.

the bonuses, vArr or printName shouldnt be commented, neither are they in my original code, maybe if you change the ///! into //! it will work fine

I commented that out because I generate the field values instead of hardcoding them. The code that does that is here:
JASS:
            //! i bonuses = {}
            //! i vArr = {}
            //! i printName = {}
            //! i bonuses[bonusCount + 1] = -1 * (2 ^ (bonusCount))
            //! i if (bonusCount + 1) > 10 then
                //! i vArr[bonusCount + 1] = ftc .. string.char(86 + bonusCount + 1)
            //! i else
                //! i vArr[bonusCount + 1] = ftc .. string.char(47 + bonusCount + 1)
            //! i end
            //! i printName[bonusCount + 1] = bonuses[bonusCount + 1]
            
            //! i padAmt = string.len(bonuses[bonusCount + 1]) - 1
            //! i for i = 1, bonusCount do
                //! i bonuses[i] = 2 ^ (i - 1)
                //! i if i > 10 then
                    //! i vArr[i] = ftc .. string.char(86 + i)
                //! i else
                    //! i vArr[i] = ftc .. string.char(47 + i)
                //! i end
                //! i printName[i] = "+"
                //! i local j = 0
                //! i while j < (padAmt - string.len(bonuses[i])) do
                    //! i printName[i] = printName[i] .. "0"
                    //! i j = j + 1
                //! i end
                //! i printName[i] = printName[i] .. bonuses[i]
            //! i end
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
doomlords is not lua script. Mine is lua script, his is just a external program invocation with command line arguments.

Like when you open console and write:

gcc -lm -Wall -Werror ...

In this case, gcc is ObjectMerger, and -lm -Wall -Werror ... is the rest of the line
 
Ah, then I definitely will have to stick with Doomlords because lua script is broken and likely won't be fixed. You use windows XP?

In this case then lua is slower since it will never work for me, I hope Doomlord doesn't replace his macro script with yours, maybe just add yours as an option for people who have old windows/systems and/or slow pc's. Thanks anyways.
 

sentrywiz

S

sentrywiz

What about modifying items? Not just sockets, but enchanting them for special effects, +X them for extra bonus stats. Can the system save all that?

Also I use win7 x64. Is this system broken for me?
 
Level 4
Joined
Feb 18, 2011
Messages
62
I was looking for a way to tweak maximum hp(aka install the standalone bonus) since handicap tweaking has a certain issue, but at the installation instructions, it says nothing about WEX (JNGP is outdated nowadays so... )

Can someone guide me on installation? Thanks in advance!

Edit: Figured out an super easy way, without using this :grin: (since all I wanted was max hp)
 
Last edited:
Well, since I linked to this system that I use extensively, I should really rate it now.

This is a really powerful system that should be in basically any map that wants to use item extensively or implement complex mechanics to alter unit stats!

If anyone needs help with importing this using the text macro, you should post here (or feel free to message me). There are many people willing to help, don't get discouraged because it uses some non-vanilla editor functionalities, since this system is bonkers awesome.
 
Top