Ability Level up System 2.0

This bundle is marked as approved. It works and satisfies the submission rules.

Ability Level up System

Created on request for Spartipilo

You can buy item from shop and learn or level up your ability.
Difference from other systems is that this one will check some conditions like:

Has hero enough stats or level.


  • Globals
    • Events
    • Conditions
    • Actions
      • Set KSHash = (Last created hashtable)
JASS:
    // ---------------------------------------------------------
    //                ABILITY LEVEL UP SYSTEM 
    //             CREATED BY -KOBAS- ON REQUEST
    //                      VERSION 2.0
    // ---------------------------------------------------------


function ItemSystemSetup takes nothing returns nothing
    local integer ItemId
    set udg_KSHash = InitHashtable()
    
    set ItemId = 'I000' //FOR ITEM -> 'I000'
    call SaveInteger(udg_KSHash, ItemId,  0,    0  ) //Required Agility
    call SaveInteger(udg_KSHash, ItemId,  1,   40  ) //Required Intelligence
    call SaveInteger(udg_KSHash, ItemId,  2,    0  ) //Required Strength
    call SaveInteger(udg_KSHash, ItemId,  3,    0  ) //Required Level
    call SaveInteger(udg_KSHash, ItemId,  4,   10  ) //Ability Max Level
    call SaveInteger(udg_KSHash, ItemId,  5,    0  ) //Item Gold Cost
    call SaveInteger(udg_KSHash, ItemId,  6,    2  ) //Item Lumber Cost
    call SaveInteger(udg_KSHash, ItemId,  7, 'A000') //Ability Id
    
    set ItemId = 'I001' //FOR ITEM -> 'I001'
    call SaveInteger(udg_KSHash, ItemId,  0,    0  ) //Required Agility
    call SaveInteger(udg_KSHash, ItemId,  1,    0  ) //Required Intelligence
    call SaveInteger(udg_KSHash, ItemId,  2,   40  ) //Required Strength
    call SaveInteger(udg_KSHash, ItemId,  3,    0  ) //Required Level
    call SaveInteger(udg_KSHash, ItemId,  4,   10  ) //Ability Max Level
    call SaveInteger(udg_KSHash, ItemId,  5,    3  ) //Item Gold Cost
    call SaveInteger(udg_KSHash, ItemId,  6,    0  ) //Item Lumber Cost
    call SaveInteger(udg_KSHash, ItemId,  7, 'A001') //Ability Id
    
    // ---------------------------------------------------------
    //        HERE YOU CAN EDIT MSG DISPLAYED TO PLAYER
    // ---------------------------------------------------------
    call SaveStr(udg_KSHash, 0,  0, "Hero ability is already max level") //MSG Shown when unit has already ability level set to max
    call SaveStr(udg_KSHash, 0,  1, "Hero stats are low")                //MSG Shown when unit don't have required stats
    call SaveStr(udg_KSHash, 0,  2, "Hero level is low")                 //MSG Shown when unit don't have required level
    // ---------------------------------------------------------
    //   HERE YOU CAN EDIT SPECIAL EFFECTS DISPLAYED TO PLAYERS
    // ---------------------------------------------------------
    call SaveStr(udg_KSHash, 1,  0, "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl") //Special Effect path: Learn ability
    call SaveStr(udg_KSHash, 1,  1, "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl") //Special Effect path: level up ability
    call SaveStr(udg_KSHash, 1,  2, "Abilities\\Spells\\Items\\AIil\\AIilTarget.mdl")             //Special Effect path: Error
    // ---------------------------------------------------------
endfunction

function ItemSystemCleanUp takes integer id, integer i returns nothing
    call SetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER, ( GetPlayerState( GetTriggerPlayer() ,PLAYER_STATE_RESOURCE_LUMBER) + LoadInteger(udg_KSHash, id, 6) ) ) // We add lumber back to player
    call SetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState( GetTriggerPlayer() ,PLAYER_STATE_RESOURCE_GOLD) + LoadInteger(udg_KSHash, id, 5) ) )     // We add gold back to player
    call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, LoadStr(udg_KSHash, 0, i))
    call DestroyEffect(AddSpecialEffect(LoadStr(udg_KSHash, 1, 2),GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit())))
endfunction

function ItemSystem takes nothing returns nothing
    local integer ItemId = GetItemTypeId(GetManipulatedItem())
    local unit u = GetTriggerUnit()
    
    // ---------------------------------------------------------
    //                   NO NEED TO BE CHANGED
    // ---------------------------------------------------------
    if GetHeroLevel(u) >= LoadInteger(udg_KSHash, ItemId, 3) then
        if GetHeroAgi(u, false) >= LoadInteger(udg_KSHash, ItemId, 0) and GetHeroInt(u, false) >= LoadInteger(udg_KSHash, ItemId, 1) and GetHeroStr(u, false) >= LoadInteger(udg_KSHash, ItemId, 2) then
            if GetUnitAbilityLevel(u, LoadInteger(udg_KSHash, ItemId, 7)) == 0 then
                call UnitAddAbility(u, LoadInteger(udg_KSHash, ItemId, 7))
                call UnitMakeAbilityPermanent(u,true, LoadInteger(udg_KSHash, ItemId, 7))
                call DestroyEffect(AddSpecialEffect(LoadStr(udg_KSHash, 1, 0),GetUnitX(u),GetUnitY(u)))
            elseif GetUnitAbilityLevel(u, LoadInteger(udg_KSHash, ItemId, 7)) == LoadInteger(udg_KSHash, ItemId, 4) then
                call ItemSystemCleanUp(ItemId, 0)
            else
                call IncUnitAbilityLevel(u, LoadInteger(udg_KSHash, ItemId, 7))
                call DestroyEffect(AddSpecialEffect(LoadStr(udg_KSHash, 1, 1),GetUnitX(u),GetUnitY(u)))
            endif
        else
            call ItemSystemCleanUp(ItemId, 1)
        endif
    else
        call ItemSystemCleanUp(ItemId, 2)
    endif
    call SetWidgetLife(GetManipulatedItem(),0.406)
    call RemoveItem(GetManipulatedItem())
    set u = null
endfunction

    // ---------------------------------------------------------
    // BJ BELOW WILL TRIGGER THIS FOR ANY PLAYER SO NO NEED FOR 
    // CORRECTIONS, OFC EDIT IT IN CASE YOU USE THIS FOR 1 PLAYER
    // EXAMPLE FOR PLAYER RED:
    // TriggerRegisterPlayerUnitEvent(gg_trg_Kobas_System, player(0), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
    // ---------------------------------------------------------
function InitTrig_Kobas_System takes nothing returns nothing
    set gg_trg_Kobas_System = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Kobas_System, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Kobas_System, function ItemSystem )
    call ItemSystemSetup()
endfunction
Version 2.0
- Fixed another small error pointed by Maker
Version 1.9
- Fixed small errors pointed by Maker
Version 1.8
- Optimized
Version 1.7
- Replaced vjass globals with user defined globals
- Added gui trigger for easier import
Version 1.6
- Used hashtables
Version 1.5
- Added Special Effects
- Replaced globals with user defined globals
- Added GUI trigger for easy import
- Optimized script a little
Version 1.4
- Fixed silly bag (Thanks to Magtheridon96 for creating and fixing same :razz:)
Version 1.3
- Fixed that Remove Item problems
- Optimized code a little
Version 1.2
- Replaced annoying if the else block (Thanks to Magtheridon96)
- Added permanent ability thing (Thanks to Maker)
Version 1.1
- Uploaded spell here

Opinions please.

Keywords:
Ability, Item, Learn, Level up, Requirements, System, -Kobas-
Contents

ABILITY LEVEL UP SYSTEM (Map)

Reviews
Approved. You could set triggering unit into a local variable in cleanup trigger. Additionally, you don't have to save 0 values for integers into hashtable. Integers are 0 by default. That could make it easier to add new item types...
Level 37
Joined
Mar 6, 2006
Messages
9,242

JASS:
function ItemSystemSetup takes nothing returns nothing
    set udg_KSHash = InitHashtable()
    
    //FOR ITEM -> 'I000'
    call SaveInteger(udg_KSHash, 'I000',  0,    0  ) //Required Agility
    call SaveInteger(udg_KSHash, 'I000',  1,   40  ) //Required Intelligence
    call SaveInteger(udg_KSHash, 'I000',  2,    0  ) //Required Strength
    call SaveInteger(udg_KSHash, 'I000',  3,    0  ) //Required Level
    call SaveInteger(udg_KSHash, 'I000',  4,   10  ) //Ability Max Level
    call SaveInteger(udg_KSHash, 'I000',  5,    0  ) //Item Gold Cost
    call SaveInteger(udg_KSHash, 'I000',  6,    2  ) //Item Lumber Cost
    call SaveInteger(udg_KSHash, 'I000',  7, 'A000') //Ability Id
->
JASS:
function ItemSystemSetup takes nothing returns nothing
    local integer ID
    set udg_KSHash = InitHashtable()
    
    //FOR ITEM -> 'I000'
    set ID = 'I000'
    call SaveInteger(udg_KSHash, ID,  0,    0  ) //Required Agility
    call SaveInteger(udg_KSHash, ID,  1,   40  ) //Required Intelligence
    call SaveInteger(udg_KSHash, ID,  2,    0  ) //Required Strength
    call SaveInteger(udg_KSHash, ID,  3,    0  ) //Required Level
    ...



I don't see much use for
JASS:
if udg_KSBoolean == false then 
        set udg_KSBoolean = true
        call ItemSystemSetup ()
    endif
Do the function call in the initializer function.

Save TriggeringUnit into a local variable in ItemSystem.
 
Level 37
Joined
Mar 6, 2006
Messages
9,242
JASS:
function InitTrig_Kobas_System takes nothing returns nothing
    set gg_trg_Kobas_System = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Kobas_System, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Kobas_System, function ItemSystem )
    call ItemSystemSetup()
endfunction
 
Top