• 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.

[JASS] Item System Problem

Status
Not open for further replies.
Hi guys, i am trying to create an item system. It is nearly like dota.
When a hero buys 2 equal items, they merge into 1 item.
I already read all your item tutorials but i was unable to find the answr i was looking for ... can you guys please help me ???

JASS:
function Combination_Conds takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I00A'
endfunction
//====================================================
function Combination_Acts takes nothing returns nothing
    local item i = GetManipulatedItem()
    local integer item_Amount = 2
    local integer  itemSlots= 0
    loop
        exitwhen itemSlots == 6
        //Which action do i do here ???? Confused =s  
    endloop         
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    local trigger Combination = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Combination, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( Combination, Condition( function Combination_Conds ) )
    call TriggerAddAction( Combination, function Combination_Acts )
    set Combination = null
endfunction

As you can see i have an idea about what i am supposed to do ... however i don't know which actions i have to call !!!!
please help =S
 
mmm Imagine that i have 2 claws of attack +5 and bla bla ...

Also the location of "exitwhen" will not affect the loop in time line scale. it only tells the loop when it must quit.

System improvement:

JASS:
function Combination_Conds takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I00A'
endfunction
//====================================================
function Combination_Acts takes nothing returns nothing
    local item i = GetManipulatedItem()
    local integer item_Amount = 2
    local integer  itemSlots= 0
    loop
        exitwhen itemSlots == 6
        //Which action do i do here ???? Confused =s  
        set itemSlots = itemSlots + 1 
    endloop         
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    local trigger Combination = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Combination, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( Combination, Condition( function Combination_Conds ) )
    call TriggerAddAction( Combination, function Combination_Acts )
    set Combination = null
endfunction

thx for the reply. Still a hand ? please =S
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
K, here we go

JASS:
function Combination_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item i = GetManipulatedItem()
    local item ii
    local integer it = GetItemTypeId(GetManipulatedItem())
    local integer int = 0
    loop
        exitwhen int > 5
        set ii = UnitItemInSlot(u,int)
        if GetItemTypeId(ii) == it and i != ii then
            call RemoveItem(i)
            call RemoveItem(ii)
            call UnitAddItemById(u,'Your rawcode')
            exitwhen true
        endif
        set int = int + 1
    endloop
    set i = null
    set ii = null
    set u = null
endfunction

I simplified it, but as a result it only works for recipes with 2 pieces.
 
Last edited:
thx PurplePoot. But still i have some questions:

JASS:
function Combination_Actions takes nothing returns nothing  
    local unit u = GetTriggerUnit() //Buyer
    local item i = GetManipulatedItem() // This is the item i buy
    local item ii  // This is the recipe item
    local integer it = GetItemTypeId(GetManipulatedItem()) //item Amount
    local integer int = 0  //number of slots
    loop  
        exitwhen int > 5 //if this is the slot number, then it should be 6 instead of 5 rit ?
        set ii = UnitItemInSlot(u,int)  
        if GetItemTypeId(ii) == it and i != ii then  
            call RemoveItem(i)  
            call RemoveItem(i2) //If this a variable, then it is an undeclared 1. Do you mean "ii" ?? 
            call UnitAddItemById(u,'Your rawcode')  
            exitwhen true  
        endif  
        set int = int + 1 
    endloop  
    set i = null  
    set ii = null  
    set u = null 
endfunction

Please tell me if the my interpretation of the code is correct.
 
Please, read all posts b4 giving your opinion. As i already said, i already saw all item tutorials this website has, and because i couldn't find what i needed, i decided to ask for help here.

EDIT

Blarg, guys this doesn't seem to be working for me at all .... any help ?

JASS:
function Combination_Actions takes nothing returns nothing  
    local unit u = GetTriggerUnit() //Buyer
    local item i = GetManipulatedItem() // This is the item i buy
    local item ii  // This is the recipe item
    local integer it = GetItemTypeId(GetManipulatedItem()) //item Amount
    local integer IA = 3 //numer of items (3)
    local integer int = 0  //number of slots
    loop  
        exitwhen int > 5 //slot number
        set ii = UnitItemInSlot(u,int)  
        if GetItemTypeId(ii) == it and i != ii and i == IA then  
            call RemoveItem(i)  
            call RemoveItem(ii)
            call UnitAddItemById(u,'Your rawcode')  
            exitwhen true  
        endif  
        set int = int + 1 
    endloop  
    set i = null  
    set ii = null  
    set u = null 
endfunction
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
Just wrote it up... here you are

JASS:
function CountItemsInInventory takes unit who, integer itemType returns integer
    local integer i = 0
    local integer num = 0
    loop
        exitwhen i > 5
        if GetItemTypeId(UnitItemInSlot(who,i)) == itemType then
            set num = num + 1
        endif
        set i = i + 1
    endloop
    return num
endfunction
 
Ok, thx, i assume that is the "call" i was needing =).

please review my interpretation, because if i want to use your code, i must fully understand it first.

JASS:
function CountItemsInInventory takes unit who, integer itemType returns integer  
    local integer i = 0 //Item slots available 
    local integer num = 0 //Item Amount
    loop  
        exitwhen i > 5 
        if GetItemTypeId(UnitItemInSlot(who,i)) == itemType then  
            set num = num + 1 
        endif  
        set i = i + 1 
    endloop  
    return num 
endfunction  //werrmm, now, if num ==3 i will call the actions that will add the recipe correct ?
 
Well, ere it is... this is the best i was able to do =s

JASS:
function Comb_conds takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I000' //The Item that simulats the recipe
endfunction
//=================================================================
function CountItemsInInventory takes unit who, integer itemType returns integer  
    local integer i = 0 //Item slots available 
    local integer num = 0 //Item Amount
    loop  
        exitwhen i > 5 
        if GetItemTypeId(UnitItemInSlot(who,i)) == 'I022' then  //The raw code of the item i have to buy 3 times
            set num = num + 1 
        endif  
        set i = i + 1 
    endloop  
    return num 
endfunction 
//=====================================================================
function I_dunno_what_i_am_doing takes nothing returns nothing
    local unit who = GetTriggerUnit()
    local integer i2 = 0
    local itemtype IR= 'I000' //Item that simulates the recipe
    local itemtype IB= 'I022' // rawcode of the item i buyed 3 times
    local itemtype IG= 'I033' //rawcode of the item that will replace the recipe and the 3 items  (the comboniation)
    if CountItemsInInventory() == 3 then
        loop 
            exitwhen i2 > 5
            call UnitRemoveItem(who, IB)  //Here i remove all IB items from slots 
        endloop
        set i2 = i2 + 1
        call UnitRemoveItem(who, IR) 
        call UnitAddItem(who, IG)
    endif
    set who = null
    set IR = null
    set IB = null
    set IG = null 
endfunction
//=====================================================================
function InitTrig_Combination1 takes nothing returns nothing
    local trigger Combo1 = CreateTrigger()
    local integer index = 0
    loop
        exitwhen index == 16
        call TriggerRegisterPlayerUnitEvent(Combo1, Player(index), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
        set index = index + 1
    endloop
    call TriggerAddCondition( Combo1, Condition( function Comb_conds) )
    call TriggerAddAction( Combo1, function I_dunno_what_i_am_doing)
    set Combo1 = null
endfunction

Here you may see that the script is very messed up .... that's why i need your help =S
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
CountItemsInInventory takes parameters, remember?

Here is what you should have;

JASS:
function Comb_conds takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I000'//The Item that simulats the recipe
endfunction

function CountItemsInInventory takes unit who, integer itemType returns integer
    local integer i = 0 //Item slots available
    local integer num = 0 //Item Amount
    loop
        exitwhen i > 5
        if GetItemTypeId(UnitItemInSlot(who,i)) == itemType then//don't replace this! It's a parameter
            set num = num + 1                                    //for this function so that it can
        endif                                                    //be used in any situation!
        set i = i + 1
    endloop
    return num
endfunction

function I_dunno_what_i_am_doing takes nothing returns nothing
    local unit who = GetTriggerUnit()
    local integer i = 0
    local integer IR= 'I000' //Item that simulates the recipe
    local integer IB= 'I022' // rawcode of the item i buyed 3 times
    local integer IG= 'I033' //rawcode of the item that will replace the recipe and the 3 items (the comboniation)
    call RemoveItem(GetManipulatedItem())
    if CountItemsInInventory(who,IB) == 3 then
        loop
            exitwhen i > 5
            if GetItemTypeId(UnitItemInSlot(who,i)) == IB then
                call RemoveItem(UnitItemInSlot(who,i))
            endif
            set i = i + 1
        endloop
        call UnitAddItemById(who,IG)
    endif
    set who = null
endfunction

function InitTrig_Combination1 takes nothing returns nothing
    local integer index = 0
    set gg_trg_Combination1 = CreateTrigger()
    loop
        exitwhen index == 16
        call TriggerRegisterPlayerUnitEvent(gg_trg_Combination1, Player(index), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
        set index = index + 1
    endloop
    call TriggerAddCondition( gg_trg_Combination1, Condition( function Comb_conds) )
    call TriggerAddAction( gg_trg_Combination1, function I_dunno_what_i_am_doing)
endfunction
 
I tested it and it nearly works . Thx.
There is 1 small problem. If i buy the lv2 recipe without having the 3 items it just disapears and i don't want that. How do i fix that issue ?

EDIT

I tried to find a way to solve the problem, but i don't know ... does this works ?!??

JASS:
function Comb_conds takes nothing returns boolean  
    return GetItemTypeId(GetManipulatedItem()) == 'I000'//The Item that simulats the recipe 
endfunction 
//===============================================================================
function CountItemsInInventory takes unit who, integer itemType returns integer  
    local integer i = 0 //Item slots available  
    local integer num = 0 //Item Amount  
    loop  
        exitwhen i > 5 
        if GetItemTypeId(UnitItemInSlot(who,i)) == itemType then //don't replace this! It's a parameter  
            set num = num + 1                                       //for this function so that it can  
        endif                                                    //be used in any situation!  
        set i = i + 1 
    endloop  
    return num 
endfunction 
//===============================================================================
function I_dunno_what_i_am_doing takes nothing returns nothing  
    local unit who = GetTriggerUnit()  
    local integer i = 0 
    local integer IR= 'I000' //Item that simulates the recipe  
    local integer IB= 'I022' // rawcode of the item i buyed 3 times  
    local integer IG= 'I033' //rawcode of the item that will replace the recipe and the 3 items (the comboniation)  
    call RemoveItem(GetManipulatedItem())  
    if CountItemsInInventory(who,IB) == 3 then  
        loop  
            exitwhen i > 5 
            if GetItemTypeId(UnitItemInSlot(who,i)) == IB then  
                call RemoveItem(UnitItemInSlot(who,i))  
            endif  
            set i = i + 1 
        endloop  
        call UnitAddItemById(who,IG)  
    else 
        call DoNothing()
    endif  
    set who = null 
endfunction
//=============================================================================== 
function InitTrig_Combination1 takes nothing returns nothing  
    local integer index = 0 
    set gg_trg_Combination1 = CreateTrigger()  
    loop  
        exitwhen index == 16 
        call TriggerRegisterPlayerUnitEvent(gg_trg_Combination1, Player(index), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)  
        set index = index + 1 
    endloop  
    call TriggerAddCondition( gg_trg_Combination1, Condition( function Comb_conds) )  
    call TriggerAddAction( gg_trg_Combination1, function I_dunno_what_i_am_doing) 
endfunction

EDIT EDIT: Other problem i found. If i have 4 items instead of 3, then the system doesn't work as well .... what do i do !?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Problem 1:

move RemoveItem(GetManipulatedItem) inside the if-statement

Problem 2:

Change CountUnitsInInventory(...) == 3 to CountUnitsInInventory(...) > 2

Also, you don't need the else or DoNothing.

Fixed and cleaned:

JASS:
function Comb_conds takes nothing returns boolean  
    return GetItemTypeId(GetManipulatedItem()) == 'I000'//The Item that simulats the recipe 
endfunction 
//===============================================================================
function CountItemsInInventory takes unit who, integer itemType returns integer  
    local integer i = 0 //Item slots available  
    local integer num = 0 //Item Amount  
    loop  
        exitwhen i > 5 
        if GetItemTypeId(UnitItemInSlot(who,i)) == itemType then //don't replace this! It's a parameter  
            set num = num + 1                                       //for this function so that it can  
        endif                                                    //be used in any situation!  
        set i = i + 1 
    endloop  
    return num 
endfunction 
//===============================================================================
function I_dunno_what_i_am_doing takes nothing returns nothing  
    local unit who = GetTriggerUnit()  
    local integer i = 0 
    local integer IR= 'I000' //Item that simulates the recipe  
    local integer IB= 'I022' // rawcode of the item i buyed 3 times  
    local integer IG= 'I033' //rawcode of the item that will replace the recipe and the 3 items (the comboniation)  
    if CountItemsInInventory(who,IB) > 2 then
        call RemoveItem(GetManipulatedItem())  
        loop
            exitwhen i > 5
            if GetItemTypeId(UnitItemInSlot(who,i)) == IB then
                call RemoveItem(UnitItemInSlot(who,i))
            endif
            set i = i + 1
        endloop
        call UnitAddItemById(who,IG)
    endif  
    set who = null 
endfunction
//=============================================================================== 
function InitTrig_Combination1 takes nothing returns nothing  
    local integer index = 0 
    set gg_trg_Combination1 = CreateTrigger()  
    loop  
        exitwhen index == 16 
        call TriggerRegisterPlayerUnitEvent(gg_trg_Combination1, Player(index), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)  
        set index = index + 1 
    endloop  
    call TriggerAddCondition( gg_trg_Combination1, Condition( function Comb_conds) )  
    call TriggerAddAction( gg_trg_Combination1, function I_dunno_what_i_am_doing) 
endfunction

Oh, and this will consume all the items, not just 3.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Here we go, then

JASS:
function Comb_conds takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I000'//The Item that simulats the recipe
endfunction

function CountItemsInInventory takes unit who, integer itemType returns integer
    local integer i = 0 //Item slots available
    local integer num = 0 //Item Amount
    loop
        exitwhen i > 5
        if GetItemTypeId(UnitItemInSlot(who,i)) == itemType then //don't replace this! It's a parameter
            set num = num + 1                                       //for this function so that it can
        endif                                                    //be used in any situation!  
        set i = i + 1
    endloop
    return num
endfunction

function I_dunno_what_i_am_doing takes nothing returns nothing
    local unit who = GetTriggerUnit()
    local integer i = 0
    local integer IR= 'I000' //Item that simulates the recipe
    local integer IB= 'I022' // rawcode of the item i buyed 3 times
    local integer IG= 'I033' //rawcode of the item that will replace the recipe and the 3 items (the comboniation)
    local integer cnt = 0
    if CountItemsInInventory(who,IB) > 2 then
        call RemoveItem(GetManipulatedItem())  
        loop
            exitwhen i > 5 or cnt > 2
            if GetItemTypeId(UnitItemInSlot(who,i)) == IB then
                call RemoveItem(UnitItemInSlot(who,i))
                set cnt = cnt + 1
            endif
            set i = i + 1
        endloop
        call UnitAddItemById(who,IG)
    endif  
    set who = null 
endfunction
//=============================================================================== 
function InitTrig_Combination1 takes nothing returns nothing  
    local integer index = 0 
    set gg_trg_Combination1 = CreateTrigger()  
    loop  
        exitwhen index == 16 
        call TriggerRegisterPlayerUnitEvent(gg_trg_Combination1, Player(index), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)  
        set index = index + 1 
    endloop  
    call TriggerAddCondition( gg_trg_Combination1, Condition( function Comb_conds) )  
    call TriggerAddAction( gg_trg_Combination1, function I_dunno_what_i_am_doing) 
endfunction
 
OMG, thx by the system, i don't know if it works yet but i will see it right now =)

EDIT Your system works in perfection for what i want, really thx.

Maybe i will post that system on our spell section, i really thin people can benefict from it as it is the best and yet the most simple system i've ever saw.

Only if you approve ofc. But it is only an high idea, not sure.

Anyway, don't know if it means a lot to you (you have 100000000) but i think you deserve + rep =). lol

EDIT EDIT : AARGGHH stupid rep system (lol) i can't give you rep points .... must "spread" them ... anyway, i will give you as soon as i can (lol). Really thx.
 
Last edited:
Status
Not open for further replies.
Top