• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] adding item to stock problem

Status
Not open for further replies.
ok my problem is tht after i add an item to stock after buying it several times it glitches and starts deleting other items in stock. it keeps adding the item u buy like its supposed to i was wondering if anyone could see a problem in my trigger. also any suggestions to improve it are both welcome and appreciated thx to anyone tht helps and here it is.
JASS:
scope HeroAbilitySelection initializer Ability_Selection

globals
    trigger trg_AbilitySelection
    private integer array lumberCost
    private integer array itemIDS
    private integer array abilityIDS
    private unit array abilitySellers
    private integer array itemIntDataArray
endglobals

private function addItemsToStockLoop takes integer p, integer i, integer start, integer end returns nothing
    loop
        exitwhen start > end
        call AddItemToStock( abilitySellers[((p*4)+i)], itemIDS[start], 1, 1)
        set start = start + 1
    endloop
endfunction

private function addItemsToStock takes integer p, integer Loop, integer id returns nothing
    local integer i
    local integer start
    local integer end
    set i = Loop/11
    set start = i*11
    if start > 32 then 
        set end = 39
    else
        set end = start + 10
    endif
    call addItemsToStockLoop( p, i, start, end)
endfunction

private function addNewAbility takes integer p, integer Loop, integer id returns nothing
    if id == itemIDS[0] or id == itemIDS[1] or id == itemIDS[2] or id == itemIDS[3] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[0] = 0
        set itemIntDataArray[1] = 0
        set itemIntDataArray[2] = 0
        set itemIntDataArray[3] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[4] or id == itemIDS[5] or id == itemIDS[6] or id == itemIDS[7] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[4] = 0
        set itemIntDataArray[5] = 0
        set itemIntDataArray[6] = 0
        set itemIntDataArray[7] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[8] or id == itemIDS[9] or id == itemIDS[10] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[8] = 0
        set itemIntDataArray[9] = 0
        set itemIntDataArray[10] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[11] or id == itemIDS[12] or id == itemIDS[13] or id == itemIDS[14] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[11] = 0
        set itemIntDataArray[12] = 0
        set itemIntDataArray[13] = 0
        set itemIntDataArray[14] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[15] or id == itemIDS[16] or id == itemIDS[17] or id == itemIDS[18] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[15] = 0
        set itemIntDataArray[16] = 0
        set itemIntDataArray[17] = 0
        set itemIntDataArray[18] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[19] or id == itemIDS[20] or id == itemIDS[21] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[19] = 0
        set itemIntDataArray[20] = 0
        set itemIntDataArray[21] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[22] or id == itemIDS[23] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[22] = 0
        set itemIntDataArray[23] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[24] or id == itemIDS[25] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[24] = 0
        set itemIntDataArray[25] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[26] or id == itemIDS[27] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[26] = 0
        set itemIntDataArray[27] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[28] or id == itemIDS[29] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[28] = 0
        set itemIntDataArray[29] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[30] or id == itemIDS[31] or id == itemIDS[32] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[30] = 0
        set itemIntDataArray[31] = 0
        set itemIntDataArray[32] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[33] or id == itemIDS[34] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[33] = 0
        set itemIntDataArray[34] = 0
        set itemIntDataArray[Loop] = 1
        call BJDebugMsg( I2S(Loop))
    elseif id == itemIDS[35] or id == itemIDS[36] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[35] = 0
        set itemIntDataArray[36] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[37] or id == itemIDS[38] or id == itemIDS[39] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[37] = 0
        set itemIntDataArray[38] = 0
        set itemIntDataArray[39] = 0
        set itemIntDataArray[Loop] = 1
    endif
endfunction

private function Actions takes nothing returns nothing
    local integer p = GetPlayerId( GetTriggerPlayer())
    local integer start
    local integer end
    local item titem = GetManipulatedItem()
    local integer Loop = 0
    local integer abilvl
    local integer id = GetItemTypeId( titem)
    call RemoveItem( titem)
    loop
        exitwhen Loop > 39
        if id == itemIDS[Loop] then
            set abilvl = GetUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
            if itemIntDataArray[Loop] == 1 then
                if abilvl == 0 then
                    call BJDebugMsg( "add new ability" )
                    call UnitAddAbility( Selected_Hero_Player, abilityIDS[Loop])
                    call addNewAbility( p, Loop, id)
                elseif abilvl == 100 then
                    call BJDebugMsg( "max lvl" )
                    set itemIntDataArray[Loop] = 0
                    call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER)+250))
                    call addItemsToStock( p, Loop, id)
                else
                    call IncUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
                    call addItemsToStock( p, Loop, id)
                endif
            elseif itemIntDataArray[Loop] == 0 then
                call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER)+250))
                call BJDebugMsg( "Sry u cannot buy this item")
                call addItemsToStock( p, Loop, id)
            endif
        endif
        set Loop = Loop + 1
    endloop
    set titem = null
endfunction

private function destroyItems takes nothing returns nothing
    local item Item
    set Item = GetEnumItem()
    call RemoveItem( Item)
    set Item = null
endfunction

private function settingLumberCosts takes nothing returns nothing
    local integer Loop = 33
    local unit u = gg_unit_n01M_0127
    local integer maxLumber = 1000000 // 1 mil
    local integer itemLumber
    local rect r = gg_rct_Delete_Items
    loop
        exitwhen Loop > 39
        call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER, maxLumber)
        call AddItemToStock( u, itemIDS[Loop], 1, 1)
        call IssueNeutralImmediateOrderById( Player(11), u, itemIDS[Loop])
        call RemoveItemFromStock( u, itemIDS[Loop])
        set itemLumber = GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER)
        set lumberCost[Loop] = maxLumber - itemLumber
        set Loop = Loop + 1
    endloop
    call EnumItemsInRect( r, null, function destroyItems)
    call ShowUnit( u, false )
    set u = null
    set r = null
endfunction

private function itemToStockSetup takes nothing returns nothing
    local integer Loop = 0
    local integer i = 0
    local integer index = 0
    local integer ids = 0
    local integer players = 4 // number of max players in map
    local integer abilities = 40 // number of abilities
    local integer loopE = ((abilities*players)-1)
    call BJDebugMsg("runs item to stock setup")
    loop   
        exitwhen Loop > loopE
        call AddItemToStock( abilitySellers[i], itemIDS[ids], 1, 1)
        set itemIntDataArray[Loop] = 1
        if index == 10 or index == 21 or index == 32 then
            set i = i + 1
        elseif index == 39 then
            set i = 0
            set ids = 0
        endif
        set ids = ids + 1
        set index = index + 1
        set Loop = Loop + 1
    endloop
endfunction

private function preloadAbilities takes nothing returns nothing
    local unit u
    local integer Loop = 0
    set u = CreateUnit( Player(11), 'hfoo', 0, 0, 0)
    call ShowUnit( u, false)
    loop
        exitwhen Loop > 39
        call UnitAddAbility( u, abilityIDS[Loop])
        call UnitRemoveAbility( u, abilityIDS[Loop])
        set Loop = Loop + 1
    endloop
    set u = null
endfunction

private function startup takes nothing returns nothing //this whole thing just sets the data in arrays
    set itemIDS[0] = 'I004' // Divine Shield ITEM ID
    set itemIDS[1] = 'I005' // Mana Shield ITEM ID
    set itemIDS[2] = 'I006' // Mirror Image ITEM ID
    set itemIDS[3] = 'I007' // Wind Walk ITEM ID
    set itemIDS[4] = 'I00E' // Volcano ITEM ID
    set itemIDS[5] = 'I00F' // Earthquake ITEM ID
    set itemIDS[6] = 'I00G' // Stampede ITEM ID
    set itemIDS[7] = 'I00H' // Flame Strike ITEM ID
    set itemIDS[8] = 'I00O' // Shadow Strike ITEM ID
    set itemIDS[9] = 'I00P' // Storm Bolt ITEM ID
    set itemIDS[10] = 'I00Q' // Soul Burn ITEM ID
    set itemIDS[11] = 'I00R' // Bash ITEM ID
    set itemIDS[12] = 'I00S' // Critical Strike ITEM ID
    set itemIDS[13] = 'I00T' // Spiked Carapace ITEM ID
    set itemIDS[14] = 'I00U' // Cleaving Attack ITEM ID
    set itemIDS[15] = 'I00X' // Death Coil ITEM ID
    set itemIDS[16] = 'I00Y' // Holy Light ITEM ID
    set itemIDS[17] = 'I00Z' // Death Pact ITEM ID
    set itemIDS[18] = 'I010' // Life Drain ITEM ID
    set itemIDS[19] = 'I008' // Avatar ITEM ID
    set itemIDS[20] = 'I009' // Metamorphosis ITEM ID
    set itemIDS[21] = 'I00A' // Vengeance ITEM ID
    set itemIDS[22] = 'I00I' // Tornado ITEM ID
    set itemIDS[23] = 'I00J' // Bladestorm ITEM ID
    set itemIDS[24] = 'I00K' // Incinerate ITEM ID
    set itemIDS[25] = 'I00L' // Immolation ITEM ID
    set itemIDS[26] = 'I00M' // Impale ITEM ID
    set itemIDS[27] = 'I00N' // Carrion Swarm ITEM ID
    set itemIDS[28] = 'I00V' // Sleep ITEM ID
    set itemIDS[29] = 'I00W' // Charm ITEM ID
    set itemIDS[30] = 'I011' // Fan of Knives ITEM ID
    set itemIDS[31] = 'I012' // Thunder Clap ITEM ID
    set itemIDS[32] = 'I013' // Howl of Terror ITEM ID
    set itemIDS[33] = 'I001' // Chain Lightning ITEM ID
    set itemIDS[34] = 'I000' // Forked Lightning ITEM ID
    set itemIDS[35] = 'I002' // Blink ITEM ID
    set itemIDS[36] = 'I003' // Mass Teleport ITEM ID
    set itemIDS[37] = 'I00B' // Blizzard ITEM ID
    set itemIDS[38] = 'I00C' // Rain of Fire ITEM ID
    set itemIDS[39] = 'I00D' // Starfall ITEM ID
    set abilityIDS[0] = 'A017' // Divine Shield ITEM ID
    set abilityIDS[1] = 'A02D' // Mana Shield ITEM ID
    set abilityIDS[2] = 'A006' // Mirror Image ITEM ID
    set abilityIDS[3] = 'A00I' // Wind Walk ITEM ID
    set abilityIDS[4] = 'A02F' // Volcano ITEM ID
    set abilityIDS[5] = 'A003' // Earthquake ITEM ID
    set abilityIDS[6] = 'A02I' // Stampede ITEM ID
    set abilityIDS[7] = 'A018' // Flame Strike ITEM ID
    set abilityIDS[8] = 'A02L' // Shadow Strike ITEM ID
    set abilityIDS[9] = 'A01X' // Storm Bolt ITEM ID
    set abilityIDS[10] = 'A02M' // Soul Burn ITEM ID
    set abilityIDS[11] = 'A012' // Bash ITEM ID
    set abilityIDS[12] = 'A002' // Critical Strike ITEM ID
    set abilityIDS[13] = 'A023' // Spiked Carapace ITEM ID
    set abilityIDS[14] = 'A02N' // Cleaving Attack ITEM ID
    set abilityIDS[15] = 'A00Q' // Death Coil ITEM ID
    set abilityIDS[16] = 'A01B' // Holy Light ITEM ID
    set abilityIDS[17] = 'A00R' // Death Pact ITEM ID
    set abilityIDS[18] = 'A02P' // Life Drain ITEM ID
    set abilityIDS[19] = 'A010' // Avatar ITEM ID
    set abilityIDS[20] = 'A029' // Metamorphosis ITEM ID
    set abilityIDS[21] = 'A02B' // Vengeance ITEM ID
    set abilityIDS[22] = 'A02J' // Tornado ITEM ID
    set abilityIDS[23] = 'A020' // Bladestorm ITEM ID
    set abilityIDS[24] = 'A02K' // Incinerate ITEM ID
    set abilityIDS[25] = 'A028' // Immolation ITEM ID
    set abilityIDS[26] = 'A021' // Impale ITEM ID
    set abilityIDS[27] = 'A00P' // Carrion Swarm ITEM ID
    set abilityIDS[28] = 'A022' // Sleep ITEM ID
    set abilityIDS[29] = 'A02Q' // Charm ITEM ID
    set abilityIDS[30] = 'A027' // Fan of Knives ITEM ID
    set abilityIDS[31] = 'A01Z' // Thunder Clap ITEM ID
    set abilityIDS[32] = 'A02Q' // Howl of Terror ITEM ID
    set abilityIDS[33] = 'A000' // Chain Lightning ITEM ID
    set abilityIDS[34] = 'A02C' // Forked Lightning ITEM ID
    set abilityIDS[35] = 'A024' // Blink ITEM ID
    set abilityIDS[36] = 'A01E' // Mass Teleport ITEM ID
    set abilityIDS[37] = 'A014' // Blizzard ITEM ID
    set abilityIDS[38] = 'A02E' // Rain of Fire ITEM ID
    set abilityIDS[39] = 'A02A' // Starfall ITEM ID
    set abilitySellers[0] = gg_unit_n01L_0119
    set abilitySellers[1] = gg_unit_n01L_0120
    set abilitySellers[2] = gg_unit_n01L_0121
    set abilitySellers[3] = gg_unit_n01L_0122
    set abilitySellers[4] = gg_unit_n01L_0123
    set abilitySellers[5] = gg_unit_n01L_0124
    set abilitySellers[6] = gg_unit_n01L_0125
    set abilitySellers[7] = gg_unit_n01L_0126
    call preloadAbilities()
    call itemToStockSetup()
    call settingLumberCosts()
endfunction

private function conditions takes nothing returns boolean
    local integer id = GetItemTypeId( GetManipulatedItem())
    return id==itemIDS[0] or id==itemIDS[1] or id==itemIDS[2] or id==itemIDS[3] or id==itemIDS[4] or id==itemIDS[5] or id==itemIDS[6] or id==itemIDS[7] or id==itemIDS[8] or id==itemIDS[9] or id==itemIDS[10] or id==itemIDS[11] or id==itemIDS[12] or id==itemIDS[13] or id==itemIDS[14] or id==itemIDS[15] or id==itemIDS[16] or id==itemIDS[17] or id==itemIDS[18] or id==itemIDS[19] or id==itemIDS[20] or id==itemIDS[21] or id==itemIDS[22] or id==itemIDS[23] or id==itemIDS[24] or id==itemIDS[25] or id==itemIDS[26] or id==itemIDS[27] or id==itemIDS[28] or id==itemIDS[29] or id==itemIDS[30] or id==itemIDS[31] or id==itemIDS[32] or id==itemIDS[33] or id==itemIDS[34] or id==itemIDS[35] or id==itemIDS[36] or id==itemIDS[37] or id==itemIDS[38] or id==itemIDS[39]
endfunction

//===========================================================================
private function Ability_Selection takes nothing returns nothing
    set trg_AbilitySelection = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(0), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(1), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(2), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(3), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call startup()
    call TriggerAddAction( trg_AbilitySelection, function Actions )
    call TriggerAddCondition( trg_AbilitySelection, function conditions )
endfunction

endscope
 
Last edited:
Level 4
Joined
Jan 27, 2010
Messages
133
You seem like an intelligent person. It surprises me that you have not yet chosen to learn how to harness the power of structs. Your coding has a lot of potential, but I fear that a task like this is very hard to debug and maintain without more sophisticated tools.

Imagine if you could have an ItemIDGroup, working like a unit group. Then everything would become a lot easier, would it not?. That is the point of structs, it allows you to create new types.

It could work something like this:

JASS:
// Custom type ItemIDGroup:

// To CREATE a new group
// local ItemIDGroup whatEverYouCallIt = ItemIDGroup.create()  

// To add an item id to a group
// whatEverYouCallIt.add( 'I031' )

// To check if an item id is in a group
// if whatEverYouCallIt.contains( 'Iphw' ) then

struct ItemIDGroup
    public integer array iid[32] // 32 is the maximum amount of itemIDs a group can hold. Change to a larger number if needed.
    public integer N

    static method create takes nothing returns ItemIDGroup
        local ItemIDGroup iig = ItemIDGroup.allocate()
        set iig.N=0
        return iig
    endmethod

    method add takes integer itemid returns nothing
        set .iid[N]=itemid
        set .N=.N+1
    endmethod

    method contains takes integer itemid returns boolean
        local integer i=0
        loop
            exitwhen i>=.N
            if itemid==.iid[i] then
                return true
            endif
            set i=i+1
        endloop
        return false
    endmethod
endstruct

JASS:
globals
     private ItemIDGroup fireItems
endglobals

// ==================================================

private function ChangeStock takes ItemIDGroup idgroup returns nothing
    local integer i=0
    loop
        exitwhen i>=idgroup.N
        call RemoveItemFromStock( ..., idgroup.iid[i] )
        set i=i+1
    endloop
endfunction

private function Actions takes nothing returns nothing
    local integer solditemtype = GetItemTypeId(GetManipulatedItem())

    if fireItems.contains( solditemtype ) then
        call ChangeStock( fireItems )
    endif
endfunction

//====================================

private function onInit takes nothing returns nothing
    set fireItems = ItemIDGroup.create()
    call fireItems.add('I000')
    call fireItems.add('I002')
endfunction

PS. You probably will want to add data about the selling unit to the ItemIDGroup.
 
ya i really gotta spend some time and learn structs lol. i know the very basics just not how to store or call specific info from them like in this i made items when bought it gives the hero an ability. so i put both in an array abilityIDS array and itemIDS array. tht way when i go to look up the info i use a loop when the id is matched the Loop stops on tht integer then it uses the Loop integer to set which array from item and fro the abilities so the ability added to the unit is the same as the item in the shop. i dont know how to allocate(i believe thts the right word lol) structs to do this. also as u probably noticed i used groups of items. when one of those items is bought it removes the others in the group everything works fine except it screws up when an ability tht is added to a unit goes over blizzards preset lvl. what i mean in tht is for example u buy tornado it removes the other items fine on the first buy when u buy it again it lvls it to 2. when u buy it the third time the lvl is still changed to 3 but it removes the item from the marketplace tht is to the right of tornado.

the way u add
JASS:
private function onInit takes nothing returns nothing
    set fireItems = ItemIDGroup.create()
    call fireItems.add('I000')
    call fireItems.add('I002')
endfunction
is tht basically adding it to an array like 'I000' = fireitems[0] and 'I002' = fireitems[1] ?
 
Level 4
Joined
Jan 27, 2010
Messages
133
The problem right now is that the code is getting complex, and hard to debug. You can split some stuff into separate functions. If you make a separate function and name it well your code will be much more easy to follow.

The loop, for instance, does not need to cover all of the main-function. Better to make a separate function:

JASS:
private function GetArrayPos takes integer itemid returns integer
    local integer id
    loop
        exitwhen Loop > 39
        if id == itemIDS[Loop] then
            return id
        endif
    endloop
    return -1 // In case the item type was not included.
endfunction

JASS:
function Actions ...
    local ...
    local integer Loop = GetArrayPos( GetItemTypeId(GetManipulatedItem()) ) 
 // Ah, so it returns the item's position in the array
    ....

    if Loop!=-1 then
        // GO ahead and check with the items...
 // ...

is that basically adding it to an array like 'I000' = fireitems[0] and 'I002' = fireitems[1] ?

Yeah, sort of. I could have done it in another way though. Consider unit groups; we don't know if they use arrays or binary trees or linked lists or whatev. And we don't care, because they get the job done for us. A good struct type should work the same way (my example doesn't really do this the best way possible, but I wanted to keep it simple).
 
ive added a few notes tht should help with how it works and i might change it into multiple functions tht would probably make more sense. the thing i noticed is it seems to mess up because of the preset max lvl blizzard has made but i dont understand y its deleting the next item in the shop. since i have them in arrays and i dont use set itemIDS[] in any other spot other than the setup function. u have any clue as to y tht is happening ? thanks for all ur help btw
 
Level 4
Joined
Jan 27, 2010
Messages
133
What an infuriating problem! Are you certain that it is appropriate to use null for an integer-value...?

JASS:
           set abilvl = GetUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
            call BJDebugMsg( I2S(abilvl))
            if abilvl == null then

What does your BJs tell you? Theoretically, it would seem like "Add Unit Ability Level" should not be able to remove abilities items-sellings! However, there is a lot of ifs and not to mention the loop covering everything... I'd say at least tidy up that loop, just to make sure we don't have any funny side effects from the design.
 
one sec ill paste a pic of what happens hopefully thtll help u. also it removes the items from the shop. not the abilities from the hero.
 

Attachments

  • original items.PNG
    original items.PNG
    139.7 KB · Views: 121
  • this is after buying it once the right item is removed.PNG
    this is after buying it once the right item is removed.PNG
    860 KB · Views: 106
  • what happens after buying tornado a couple times.PNG
    what happens after buying tornado a couple times.PNG
    1.7 MB · Views: 111
i already add them by triggers the function startup in the post above shows were they r added i hade tht bug earlier and got the answer and it has since been fixed. thts when this problem arose. the only thing i found even remotely plausible is to add the items into an item array for each player for each marketplace and then add them every time but thts slower and not as efficient and id also have to watch to see if add item would stop if it returns null when trying to add an item tht i have removed from the array. ex add item[0] add item[1] add item[2] add item[3] if item 1 or 2 is null then will it continue to item 3 ? or just error out of the function. also it will be slower because adding 10 or so items every time i buy an item doesnt sound fast lol
 
Last edited:
solved i just added an item array and an integer array to keep track of the items if anyone has any suggestions on optimization plz feel free to tell me. heres the new trigger. also if anyone can tell me ways to make it stop lagging on first execution tht would be greatly appreciated.
JASS:
scope HeroAbilitySelection initializer Ability_Selection

globals
    trigger trg_AbilitySelection
    private integer array itemIDS
    private integer array abilityIDS
    private unit array abilitySellers
    private integer array itemIntDataArray
endglobals

private function addItemsToStockLoop takes integer p, integer i, integer start, integer end returns nothing
    loop
        exitwhen start > end
        call AddItemToStock( abilitySellers[((p*4)+i)], itemIDS[start], 1, 1)
        set start = start + 1
    endloop
endfunction

private function addItemsToStock takes integer p, integer Loop, integer id returns nothing
    local integer i
    local integer start
    local integer end
    set i = Loop/11
    set start = i*11
    if start > 32 then 
        set end = 39
    else
        set end = start + 10
    endif
    call addItemsToStockLoop( p, i, start, end)
endfunction

private function addNewAbility takes integer id, integer p, integer Loop returns nothing
    if id == itemIDS[0] or id == itemIDS[1] or id == itemIDS[2] or id == itemIDS[3] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[0] = 0
        set itemIntDataArray[1] = 0
        set itemIntDataArray[2] = 0
        set itemIntDataArray[3] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[4] or id == itemIDS[5] or id == itemIDS[6] or id == itemIDS[7] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[4] = 0
        set itemIntDataArray[5] = 0
        set itemIntDataArray[6] = 0
        set itemIntDataArray[7] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[8] or id == itemIDS[9] or id == itemIDS[10] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[8] = 0
        set itemIntDataArray[9] = 0
        set itemIntDataArray[10] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[11] or id == itemIDS[12] or id == itemIDS[13] or id == itemIDS[14] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[11] = 0
        set itemIntDataArray[12] = 0
        set itemIntDataArray[13] = 0
        set itemIntDataArray[14] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[15] or id == itemIDS[16] or id == itemIDS[17] or id == itemIDS[18] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[15] = 0
        set itemIntDataArray[16] = 0
        set itemIntDataArray[17] = 0
        set itemIntDataArray[18] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[19] or id == itemIDS[20] or id == itemIDS[21] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[19] = 0
        set itemIntDataArray[20] = 0
        set itemIntDataArray[21] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[22] or id == itemIDS[23] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[22] = 0
        set itemIntDataArray[23] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[24] or id == itemIDS[25] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[24] = 0
        set itemIntDataArray[25] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[26] or id == itemIDS[27] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[26] = 0
        set itemIntDataArray[27] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[28] or id == itemIDS[29] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[28] = 0
        set itemIntDataArray[29] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[30] or id == itemIDS[31] or id == itemIDS[32] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[30] = 0
        set itemIntDataArray[31] = 0
        set itemIntDataArray[32] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[33] or id == itemIDS[34] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[33] = 0
        set itemIntDataArray[34] = 0
        set itemIntDataArray[Loop] = 1
        call BJDebugMsg( I2S(Loop))
    elseif id == itemIDS[35] or id == itemIDS[36] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[35] = 0
        set itemIntDataArray[36] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[37] or id == itemIDS[38] or id == itemIDS[39] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[37] = 0
        set itemIntDataArray[38] = 0
        set itemIntDataArray[39] = 0
        set itemIntDataArray[Loop] = 1
    endif
endfunction

private function Actions takes nothing returns nothing
    local integer p = GetPlayerId( GetTriggerPlayer())
    local integer start
    local integer end
    local item titem = GetManipulatedItem()
    local integer Loop = 0
    local integer abilvl
    local integer id = GetItemTypeId( titem)
    call RemoveItem( titem)
    loop
        exitwhen Loop > 39
        if id == itemIDS[Loop] then
            set abilvl = GetUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
            if itemIntDataArray[Loop] == 1 then
                if abilvl == 0 then
                    call BJDebugMsg( "add new ability" )
                    call UnitAddAbility( Selected_Hero_Player, abilityIDS[Loop])
                    call addNewAbility( id, p, Loop)
                elseif abilvl == 100 then
                    call BJDebugMsg( "max lvl" )
                else
                    call BJDebugMsg( "add unit ability lvl" )
                    call IncUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
                    call addItemsToStock( p, Loop, id)
                endif
            elseif itemIntDataArray[Loop] == 0 then
                call BJDebugMsg( "Sry u cannot buy this item")
                call addItemsToStock( p, Loop, id)
            endif
        endif
        set Loop = Loop + 1
    endloop
    set titem = null
endfunction

private function itemToStockSetup takes nothing returns nothing
    local integer Loop = 0
    local integer i = 0
    local integer index = 0
    local integer ids = 0
    local integer players = 4 // number of max players in map
    local integer abilities = 40 // number of abilities
    local integer loopE = ((abilities*players)-1)
    loop   
        exitwhen Loop > loopE
        call AddItemToStock( abilitySellers[i], itemIDS[ids], 1, 1)
        set itemIntDataArray[Loop] = 1
        if index == 10 or index == 21 or index == 32 then
            set i = i + 1
        elseif index == 39 then
            set i = 0
            set ids = 0
        endif
        set ids = ids + 1
        set index = index + 1
        set Loop = Loop + 1
    endloop
endfunction

private function startup takes nothing returns nothing //this whole thing just sets the data in arrays
    set itemIDS[0] = 'I004' // Divine Shield ITEM ID
    set itemIDS[1] = 'I005' // Mana Shield ITEM ID
    set itemIDS[2] = 'I006' // Mirror Image ITEM ID
    set itemIDS[3] = 'I007' // Wind Walk ITEM ID
    set itemIDS[4] = 'I00E' // Volcano ITEM ID
    set itemIDS[5] = 'I00F' // Earthquake ITEM ID
    set itemIDS[6] = 'I00G' // Stampede ITEM ID
    set itemIDS[7] = 'I00H' // Flame Strike ITEM ID
    set itemIDS[8] = 'I00O' // Shadow Strike ITEM ID
    set itemIDS[9] = 'I00P' // Storm Bolt ITEM ID
    set itemIDS[10] = 'I00Q' // Soul Burn ITEM ID
    set itemIDS[11] = 'I00R' // Bash ITEM ID
    set itemIDS[12] = 'I00S' // Critical Strike ITEM ID
    set itemIDS[13] = 'I00T' // Spiked Carapace ITEM ID
    set itemIDS[14] = 'I00U' // Cleaving Attack ITEM ID
    set itemIDS[15] = 'I00X' // Death Coil ITEM ID
    set itemIDS[16] = 'I00Y' // Holy Light ITEM ID
    set itemIDS[17] = 'I00Z' // Death Pact ITEM ID
    set itemIDS[18] = 'I010' // Life Drain ITEM ID
    set itemIDS[19] = 'I008' // Avatar ITEM ID
    set itemIDS[20] = 'I009' // Metamorphosis ITEM ID
    set itemIDS[21] = 'I00A' // Vengeance ITEM ID
    set itemIDS[22] = 'I00I' // Tornado ITEM ID
    set itemIDS[23] = 'I00J' // Bladestorm ITEM ID
    set itemIDS[24] = 'I00K' // Incinerate ITEM ID
    set itemIDS[25] = 'I00L' // Immolation ITEM ID
    set itemIDS[26] = 'I00M' // Impale ITEM ID
    set itemIDS[27] = 'I00N' // Carrion Swarm ITEM ID
    set itemIDS[28] = 'I00V' // Sleep ITEM ID
    set itemIDS[29] = 'I00W' // Charm ITEM ID
    set itemIDS[30] = 'I011' // Fan of Knives ITEM ID
    set itemIDS[31] = 'I012' // Thunder Clap ITEM ID
    set itemIDS[32] = 'I013' // Howl of Terror ITEM ID
    set itemIDS[33] = 'I001' // Chain Lightning ITEM ID
    set itemIDS[34] = 'I000' // Forked Lightning ITEM ID
    set itemIDS[35] = 'I002' // Blink ITEM ID
    set itemIDS[36] = 'I003' // Mass Teleport ITEM ID
    set itemIDS[37] = 'I00B' // Blizzard ITEM ID
    set itemIDS[38] = 'I00C' // Rain of Fire ITEM ID
    set itemIDS[39] = 'I00D' // Starfall ITEM ID
    set abilityIDS[0] = 'A017' // Divine Shield ITEM ID
    set abilityIDS[1] = 'A02D' // Mana Shield ITEM ID
    set abilityIDS[2] = 'A006' // Mirror Image ITEM ID
    set abilityIDS[3] = 'A00I' // Wind Walk ITEM ID
    set abilityIDS[4] = 'A02F' // Volcano ITEM ID
    set abilityIDS[5] = 'A003' // Earthquake ITEM ID
    set abilityIDS[6] = 'A02I' // Stampede ITEM ID
    set abilityIDS[7] = 'A018' // Flame Strike ITEM ID
    set abilityIDS[8] = 'A02L' // Shadow Strike ITEM ID
    set abilityIDS[9] = 'A01X' // Storm Bolt ITEM ID
    set abilityIDS[10] = 'A02M' // Soul Burn ITEM ID
    set abilityIDS[11] = 'A012' // Bash ITEM ID
    set abilityIDS[12] = 'A002' // Critical Strike ITEM ID
    set abilityIDS[13] = 'A023' // Spiked Carapace ITEM ID
    set abilityIDS[14] = 'A02N' // Cleaving Attack ITEM ID
    set abilityIDS[15] = 'A00Q' // Death Coil ITEM ID
    set abilityIDS[16] = 'A01B' // Holy Light ITEM ID
    set abilityIDS[17] = 'A00R' // Death Pact ITEM ID
    set abilityIDS[18] = 'A02P' // Life Drain ITEM ID
    set abilityIDS[19] = 'A010' // Avatar ITEM ID
    set abilityIDS[20] = 'A029' // Metamorphosis ITEM ID
    set abilityIDS[21] = 'A02B' // Vengeance ITEM ID
    set abilityIDS[22] = 'A02J' // Tornado ITEM ID
    set abilityIDS[23] = 'A020' // Bladestorm ITEM ID
    set abilityIDS[24] = 'A02K' // Incinerate ITEM ID
    set abilityIDS[25] = 'A028' // Immolation ITEM ID
    set abilityIDS[26] = 'A021' // Impale ITEM ID
    set abilityIDS[27] = 'A00P' // Carrion Swarm ITEM ID
    set abilityIDS[28] = 'A022' // Sleep ITEM ID
    set abilityIDS[29] = 'A02Q' // Charm ITEM ID
    set abilityIDS[30] = 'A027' // Fan of Knives ITEM ID
    set abilityIDS[31] = 'A01Z' // Thunder Clap ITEM ID
    set abilityIDS[32] = 'A02Q' // Howl of Terror ITEM ID
    set abilityIDS[33] = 'A000' // Chain Lightning ITEM ID
    set abilityIDS[34] = 'A02C' // Forked Lightning ITEM ID
    set abilityIDS[35] = 'A024' // Blink ITEM ID
    set abilityIDS[36] = 'A01E' // Mass Teleport ITEM ID
    set abilityIDS[37] = 'A014' // Blizzard ITEM ID
    set abilityIDS[38] = 'A02E' // Rain of Fire ITEM ID
    set abilityIDS[39] = 'A02A' // Starfall ITEM ID
    set abilitySellers[0] = gg_unit_n01L_0119
    set abilitySellers[1] = gg_unit_n01L_0120
    set abilitySellers[2] = gg_unit_n01L_0121
    set abilitySellers[3] = gg_unit_n01L_0122
    set abilitySellers[4] = gg_unit_n01L_0123
    set abilitySellers[5] = gg_unit_n01L_0124
    set abilitySellers[6] = gg_unit_n01L_0125
    set abilitySellers[7] = gg_unit_n01L_0126
    call itemToStockSetup()
endfunction

private function conditions takes nothing returns boolean
    local integer id = GetItemTypeId( GetManipulatedItem())
    return id==itemIDS[0] or id==itemIDS[1] or id==itemIDS[2] or id==itemIDS[3] or id==itemIDS[4] or id==itemIDS[5] or id==itemIDS[6] or id==itemIDS[7] or id==itemIDS[8] or id==itemIDS[9] or id==itemIDS[10] or id==itemIDS[11] or id==itemIDS[12] or id==itemIDS[13] or id==itemIDS[14] or id==itemIDS[15] or id==itemIDS[16] or id==itemIDS[17] or id==itemIDS[18] or id==itemIDS[19] or id==itemIDS[20] or id==itemIDS[21] or id==itemIDS[22] or id==itemIDS[23] or id==itemIDS[24] or id==itemIDS[25] or id==itemIDS[26] or id==itemIDS[27] or id==itemIDS[28] or id==itemIDS[29] or id==itemIDS[30] or id==itemIDS[31] or id==itemIDS[32] or id==itemIDS[33] or id==itemIDS[34] or id==itemIDS[35] or id==itemIDS[36] or id==itemIDS[37] or id==itemIDS[38] or id==itemIDS[39]
endfunction

//===========================================================================
private function Ability_Selection takes nothing returns nothing
    set trg_AbilitySelection = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(0), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(1), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(2), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(3), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call startup()
    call TriggerAddAction( trg_AbilitySelection, function Actions )
    call TriggerAddCondition( trg_AbilitySelection, function conditions )
endfunction

endscope
 
Last edited:
Your solution to counter the bug is the best. It's really an annoying bug.
About the lag, you have to preload the items at map initialization :
- Make a loop that instantatly creates/destroys every item-type of your array.
- I think it's even better to create a dummy hero and give him the items right before you destroy them. Remove the dummy hero at the end of the process.
- If it still lags, use call Preload("ReplaceableTextures\\...") with the paths of your items' icons.

I'm not a pro of preloading ^^'. But that's the kind of method you'd use.

Also, you can optimize your script with loops and divisions instead of those if/then. For instance :
JASS:
    if Loop==0 or Loop==1 or Loop==2 or Loop==3 or Loop==4 or Loop==5 or Loop==6 or Loop==7 or Loop==8 or Loop==9 or Loop==10 then
        set start = 0
        set end = 10
        set i = 0
    elseif Loop==11 or Loop==12 or Loop==13 or Loop==14 or Loop==15 or Loop==16 or Loop==17 or Loop==18 or Loop==19 or Loop==20 or Loop==21 then
        set start = 11
        set end = 21
        set i = 1
    elseif Loop==22 or Loop==23 or Loop==24 or Loop==25 or Loop==26 or Loop==27 or Loop==28 or Loop==29 or Loop==30 or Loop==31 or Loop==32 then
        set start = 22
        set end = 32
        set i = 2
    elseif Loop==33 or Loop==34 or Loop==35 or Loop==36 or Loop==37 or Loop==38 or Loop==39 then
        set start = 33
        set end = 39
        set i = 3
    endif
replace it with :
JASS:
    set i = Loop/11
    set start = i*11
    set end = IMinBJ(i*11+10, 39)
 
Ooo nice catch I can't believe I didn't see tht lol. I normally look for math solutions to shorten the code thts a very nice catch thx and ill try the preloading when I can if u see anything else to improve plz tell me. thanks a lot just changed tht over to wat u said ( not the prloading part didnt do tht yet) and it made me notice i had a redundant piece of code which made me be able to shorten the code by almost 30 lines. works great now i think im gonna have to prelaod each individual item path tho which sucks but thts ok. its funny tho i noticed tht chain lightning when selected doesnt lag but when tornado is selected it does lag only for first cast so i think the preloading will help all of tht thanks again. + rep

edit: wats the easiest way to find the item icon path ?
 
Last edited:
well heres the new updated code everything works perfectly no glitches tht ive found now its just optimization if anyone has any suggestions ?
JASS:
scope HeroAbilitySelection initializer Ability_Selection

globals
    trigger trg_AbilitySelection
    private integer array lumberCost
    private integer array itemIDS
    private integer array abilityIDS
    private unit array abilitySellers
    private integer array itemIntDataArray
endglobals

private function addItemsToStockLoop takes integer p, integer i, integer start, integer end returns nothing
    loop
        exitwhen start > end
        call AddItemToStock( abilitySellers[((p*4)+i)], itemIDS[start], 1, 1)
        set start = start + 1
    endloop
endfunction

private function addItemsToStock takes integer p, integer Loop, integer id returns nothing
    local integer i
    local integer start
    local integer end
    set i = Loop/11
    set start = i*11
    if start > 32 then 
        set end = 39
    else
        set end = start + 10
    endif
    call addItemsToStockLoop( p, i, start, end)
endfunction

private function addNewAbility takes integer p, integer Loop, integer id returns nothing
    if id == itemIDS[0] or id == itemIDS[1] or id == itemIDS[2] or id == itemIDS[3] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[0] = 0
        set itemIntDataArray[1] = 0
        set itemIntDataArray[2] = 0
        set itemIntDataArray[3] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[4] or id == itemIDS[5] or id == itemIDS[6] or id == itemIDS[7] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[4] = 0
        set itemIntDataArray[5] = 0
        set itemIntDataArray[6] = 0
        set itemIntDataArray[7] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[8] or id == itemIDS[9] or id == itemIDS[10] then
        call AddItemToStock( abilitySellers[(p*4)], id, 1, 1)
        set itemIntDataArray[8] = 0
        set itemIntDataArray[9] = 0
        set itemIntDataArray[10] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[11] or id == itemIDS[12] or id == itemIDS[13] or id == itemIDS[14] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[11] = 0
        set itemIntDataArray[12] = 0
        set itemIntDataArray[13] = 0
        set itemIntDataArray[14] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[15] or id == itemIDS[16] or id == itemIDS[17] or id == itemIDS[18] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[15] = 0
        set itemIntDataArray[16] = 0
        set itemIntDataArray[17] = 0
        set itemIntDataArray[18] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[19] or id == itemIDS[20] or id == itemIDS[21] then
        call AddItemToStock( abilitySellers[((p*4)+1)], id, 1, 1)
        set itemIntDataArray[19] = 0
        set itemIntDataArray[20] = 0
        set itemIntDataArray[21] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[22] or id == itemIDS[23] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[22] = 0
        set itemIntDataArray[23] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[24] or id == itemIDS[25] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[24] = 0
        set itemIntDataArray[25] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[26] or id == itemIDS[27] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[26] = 0
        set itemIntDataArray[27] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[28] or id == itemIDS[29] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[28] = 0
        set itemIntDataArray[29] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[30] or id == itemIDS[31] or id == itemIDS[32] then
        call AddItemToStock( abilitySellers[((p*4)+2)], id, 1, 1)
        set itemIntDataArray[30] = 0
        set itemIntDataArray[31] = 0
        set itemIntDataArray[32] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[33] or id == itemIDS[34] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[33] = 0
        set itemIntDataArray[34] = 0
        set itemIntDataArray[Loop] = 1
        call BJDebugMsg( I2S(Loop))
    elseif id == itemIDS[35] or id == itemIDS[36] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[35] = 0
        set itemIntDataArray[36] = 0
        set itemIntDataArray[Loop] = 1
    elseif id == itemIDS[37] or id == itemIDS[38] or id == itemIDS[39] then
        call AddItemToStock( abilitySellers[((p*4)+3)], id, 1, 1)
        set itemIntDataArray[37] = 0
        set itemIntDataArray[38] = 0
        set itemIntDataArray[39] = 0
        set itemIntDataArray[Loop] = 1
    endif
endfunction

private function Actions takes nothing returns nothing
    local integer p = GetPlayerId( GetTriggerPlayer())
    local integer start
    local integer end
    local item titem = GetManipulatedItem()
    local integer Loop = 0
    local integer abilvl
    local integer id = GetItemTypeId( titem)
    call RemoveItem( titem)
    loop
        exitwhen Loop > 39
        if id == itemIDS[Loop] then
            set abilvl = GetUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
            if itemIntDataArray[Loop] == 1 then
                if abilvl == 0 then
                    call BJDebugMsg( "add new ability" )
                    call UnitAddAbility( Selected_Hero_Player, abilityIDS[Loop])
                    call addNewAbility( p, Loop, id)
                elseif abilvl == 100 then
                    call BJDebugMsg( "max lvl" )
                    set itemIntDataArray[Loop] = 0
                    call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER)+250))
                    call addItemsToStock( p, Loop, id)
                else
                    call IncUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
                    call addItemsToStock( p, Loop, id)
                endif
            elseif itemIntDataArray[Loop] == 0 then
                call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER)+250))
                call BJDebugMsg( "Sry u cannot buy this item")
                call addItemsToStock( p, Loop, id)
            endif
        endif
        set Loop = Loop + 1
    endloop
    set titem = null
endfunction

private function destroyItems takes nothing returns nothing
    local item Item
    set Item = GetEnumItem()
    call RemoveItem( Item)
    set Item = null
endfunction

private function settingLumberCosts takes nothing returns nothing
    local integer Loop = 33
    local unit u = gg_unit_n01M_0127
    local integer maxLumber = 1000000 // 1 mil
    local integer itemLumber
    local rect r = gg_rct_Delete_Items
    loop
        exitwhen Loop > 39
        call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER, maxLumber)
        call AddItemToStock( u, itemIDS[Loop], 1, 1)
        call IssueNeutralImmediateOrderById( Player(11), u, itemIDS[Loop])
        call RemoveItemFromStock( u, itemIDS[Loop])
        set itemLumber = GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER)
        set lumberCost[Loop] = maxLumber - itemLumber
        set Loop = Loop + 1
    endloop
    call EnumItemsInRect( r, null, function destroyItems)
    call ShowUnit( u, false )
    set u = null
    set r = null
endfunction

private function itemToStockSetup takes nothing returns nothing
    local integer Loop = 0
    local integer i = 0
    local integer index = 0
    local integer ids = 0
    local integer players = 4 // number of max players in map
    local integer abilities = 40 // number of abilities
    local integer loopE = ((abilities*players)-1)
    call BJDebugMsg("runs item to stock setup")
    loop   
        exitwhen Loop > loopE
        call AddItemToStock( abilitySellers[i], itemIDS[ids], 1, 1)
        set itemIntDataArray[Loop] = 1
        if index == 10 or index == 21 or index == 32 then
            set i = i + 1
        elseif index == 39 then
            set i = 0
            set ids = 0
        endif
        set ids = ids + 1
        set index = index + 1
        set Loop = Loop + 1
    endloop
endfunction

private function preloadAbilities takes nothing returns nothing
    local unit u
    local integer Loop = 0
    set u = CreateUnit( Player(11), 'hfoo', 0, 0, 0)
    call ShowUnit( u, false)
    loop
        exitwhen Loop > 39
        call UnitAddAbility( u, abilityIDS[Loop])
        call UnitRemoveAbility( u, abilityIDS[Loop])
        set Loop = Loop + 1
    endloop
    set u = null
endfunction

private function startup takes nothing returns nothing //this whole thing just sets the data in arrays
    set itemIDS[0] = 'I004' // Divine Shield ITEM ID
    set itemIDS[1] = 'I005' // Mana Shield ITEM ID
    set itemIDS[2] = 'I006' // Mirror Image ITEM ID
    set itemIDS[3] = 'I007' // Wind Walk ITEM ID
    set itemIDS[4] = 'I00E' // Volcano ITEM ID
    set itemIDS[5] = 'I00F' // Earthquake ITEM ID
    set itemIDS[6] = 'I00G' // Stampede ITEM ID
    set itemIDS[7] = 'I00H' // Flame Strike ITEM ID
    set itemIDS[8] = 'I00O' // Shadow Strike ITEM ID
    set itemIDS[9] = 'I00P' // Storm Bolt ITEM ID
    set itemIDS[10] = 'I00Q' // Soul Burn ITEM ID
    set itemIDS[11] = 'I00R' // Bash ITEM ID
    set itemIDS[12] = 'I00S' // Critical Strike ITEM ID
    set itemIDS[13] = 'I00T' // Spiked Carapace ITEM ID
    set itemIDS[14] = 'I00U' // Cleaving Attack ITEM ID
    set itemIDS[15] = 'I00X' // Death Coil ITEM ID
    set itemIDS[16] = 'I00Y' // Holy Light ITEM ID
    set itemIDS[17] = 'I00Z' // Death Pact ITEM ID
    set itemIDS[18] = 'I010' // Life Drain ITEM ID
    set itemIDS[19] = 'I008' // Avatar ITEM ID
    set itemIDS[20] = 'I009' // Metamorphosis ITEM ID
    set itemIDS[21] = 'I00A' // Vengeance ITEM ID
    set itemIDS[22] = 'I00I' // Tornado ITEM ID
    set itemIDS[23] = 'I00J' // Bladestorm ITEM ID
    set itemIDS[24] = 'I00K' // Incinerate ITEM ID
    set itemIDS[25] = 'I00L' // Immolation ITEM ID
    set itemIDS[26] = 'I00M' // Impale ITEM ID
    set itemIDS[27] = 'I00N' // Carrion Swarm ITEM ID
    set itemIDS[28] = 'I00V' // Sleep ITEM ID
    set itemIDS[29] = 'I00W' // Charm ITEM ID
    set itemIDS[30] = 'I011' // Fan of Knives ITEM ID
    set itemIDS[31] = 'I012' // Thunder Clap ITEM ID
    set itemIDS[32] = 'I013' // Howl of Terror ITEM ID
    set itemIDS[33] = 'I001' // Chain Lightning ITEM ID
    set itemIDS[34] = 'I000' // Forked Lightning ITEM ID
    set itemIDS[35] = 'I002' // Blink ITEM ID
    set itemIDS[36] = 'I003' // Mass Teleport ITEM ID
    set itemIDS[37] = 'I00B' // Blizzard ITEM ID
    set itemIDS[38] = 'I00C' // Rain of Fire ITEM ID
    set itemIDS[39] = 'I00D' // Starfall ITEM ID
    set abilityIDS[0] = 'A017' // Divine Shield ITEM ID
    set abilityIDS[1] = 'A02D' // Mana Shield ITEM ID
    set abilityIDS[2] = 'A006' // Mirror Image ITEM ID
    set abilityIDS[3] = 'A00I' // Wind Walk ITEM ID
    set abilityIDS[4] = 'A02F' // Volcano ITEM ID
    set abilityIDS[5] = 'A003' // Earthquake ITEM ID
    set abilityIDS[6] = 'A02I' // Stampede ITEM ID
    set abilityIDS[7] = 'A018' // Flame Strike ITEM ID
    set abilityIDS[8] = 'A02L' // Shadow Strike ITEM ID
    set abilityIDS[9] = 'A01X' // Storm Bolt ITEM ID
    set abilityIDS[10] = 'A02M' // Soul Burn ITEM ID
    set abilityIDS[11] = 'A012' // Bash ITEM ID
    set abilityIDS[12] = 'A002' // Critical Strike ITEM ID
    set abilityIDS[13] = 'A023' // Spiked Carapace ITEM ID
    set abilityIDS[14] = 'A02N' // Cleaving Attack ITEM ID
    set abilityIDS[15] = 'A00Q' // Death Coil ITEM ID
    set abilityIDS[16] = 'A01B' // Holy Light ITEM ID
    set abilityIDS[17] = 'A00R' // Death Pact ITEM ID
    set abilityIDS[18] = 'A02P' // Life Drain ITEM ID
    set abilityIDS[19] = 'A010' // Avatar ITEM ID
    set abilityIDS[20] = 'A029' // Metamorphosis ITEM ID
    set abilityIDS[21] = 'A02B' // Vengeance ITEM ID
    set abilityIDS[22] = 'A02J' // Tornado ITEM ID
    set abilityIDS[23] = 'A020' // Bladestorm ITEM ID
    set abilityIDS[24] = 'A02K' // Incinerate ITEM ID
    set abilityIDS[25] = 'A028' // Immolation ITEM ID
    set abilityIDS[26] = 'A021' // Impale ITEM ID
    set abilityIDS[27] = 'A00P' // Carrion Swarm ITEM ID
    set abilityIDS[28] = 'A022' // Sleep ITEM ID
    set abilityIDS[29] = 'A02Q' // Charm ITEM ID
    set abilityIDS[30] = 'A027' // Fan of Knives ITEM ID
    set abilityIDS[31] = 'A01Z' // Thunder Clap ITEM ID
    set abilityIDS[32] = 'A02Q' // Howl of Terror ITEM ID
    set abilityIDS[33] = 'A000' // Chain Lightning ITEM ID
    set abilityIDS[34] = 'A02C' // Forked Lightning ITEM ID
    set abilityIDS[35] = 'A024' // Blink ITEM ID
    set abilityIDS[36] = 'A01E' // Mass Teleport ITEM ID
    set abilityIDS[37] = 'A014' // Blizzard ITEM ID
    set abilityIDS[38] = 'A02E' // Rain of Fire ITEM ID
    set abilityIDS[39] = 'A02A' // Starfall ITEM ID
    set abilitySellers[0] = gg_unit_n01L_0119
    set abilitySellers[1] = gg_unit_n01L_0120
    set abilitySellers[2] = gg_unit_n01L_0121
    set abilitySellers[3] = gg_unit_n01L_0122
    set abilitySellers[4] = gg_unit_n01L_0123
    set abilitySellers[5] = gg_unit_n01L_0124
    set abilitySellers[6] = gg_unit_n01L_0125
    set abilitySellers[7] = gg_unit_n01L_0126
    call preloadAbilities()
    call itemToStockSetup()
    call settingLumberCosts()
endfunction

private function conditions takes nothing returns boolean
    local integer id = GetItemTypeId( GetManipulatedItem())
    return id==itemIDS[0] or id==itemIDS[1] or id==itemIDS[2] or id==itemIDS[3] or id==itemIDS[4] or id==itemIDS[5] or id==itemIDS[6] or id==itemIDS[7] or id==itemIDS[8] or id==itemIDS[9] or id==itemIDS[10] or id==itemIDS[11] or id==itemIDS[12] or id==itemIDS[13] or id==itemIDS[14] or id==itemIDS[15] or id==itemIDS[16] or id==itemIDS[17] or id==itemIDS[18] or id==itemIDS[19] or id==itemIDS[20] or id==itemIDS[21] or id==itemIDS[22] or id==itemIDS[23] or id==itemIDS[24] or id==itemIDS[25] or id==itemIDS[26] or id==itemIDS[27] or id==itemIDS[28] or id==itemIDS[29] or id==itemIDS[30] or id==itemIDS[31] or id==itemIDS[32] or id==itemIDS[33] or id==itemIDS[34] or id==itemIDS[35] or id==itemIDS[36] or id==itemIDS[37] or id==itemIDS[38] or id==itemIDS[39]
endfunction

//===========================================================================
private function Ability_Selection takes nothing returns nothing
    set trg_AbilitySelection = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(0), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(1), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(2), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(3), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
    call startup()
    call TriggerAddAction( trg_AbilitySelection, function Actions )
    call TriggerAddCondition( trg_AbilitySelection, function conditions )
endfunction

endscope
 
Status
Not open for further replies.
Top