Help with fixing Full Inventory System

bowser499

Member
Reaction score
1
I have a Jass system that must combine recipes and charges even when the inventory is full. All is working pretty nice but not the charges combine...
Check this out:
General functions.
JASS:
function SimError takes player ForPlayer, string msg returns nothing
    local sound s = CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
    
    if GetLocalPlayer() == ForPlayer then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer(ForPlayer,.52,-1.,2.,"|cffffcc00"+msg+"|r")
        call StartSound(s)
        call KillSoundWhenDone(s)
    endif
    
    set s = null
endfunction

function GetUnitItemSlot takes unit hero, integer itemid returns integer
    local integer i = 0
    local item si
    
    loop
        exitwhen i > 5
        set si = UnitItemInSlot(hero,i)
        if GetItemTypeId(si) == itemid then
            set si = null
            return i
        endif
        set i = i + 1
    endloop
    
    set si = null
    return -1    
endfunction

function GetUnitItemOfType takes unit u, integer iid returns item
    local integer index = GetUnitItemSlot(u,iid)
    
    if index == -1 then
        return null
    else
        return UnitItemInSlot(u,index)
    endif
endfunction

function Recipe2 takes unit hero, integer id1, integer id2, integer tid returns nothing
    local integer slot1 = GetUnitItemSlot(hero,id1)
    local integer slot2 = GetUnitItemSlot(hero,id2)
    
    call RemoveItem(UnitItemInSlot(hero,slot1))
    call RemoveItem(UnitItemInSlot(hero,slot2))
    
    if IsUnitAlly(hero,Player(0)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl",hero,"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",hero,"origin"))
    endif
    
    call UnitAddItemById(hero,tid)
endfunction

function Recipe3 takes unit hero, integer id1, integer id2, integer id3, integer tid returns nothing
    local integer slot1 = GetUnitItemSlot(hero,id1)
    local integer slot2 = GetUnitItemSlot(hero,id2)
    local integer slot3 = GetUnitItemSlot(hero,id3)
    
    call RemoveItem(UnitItemInSlot(hero,slot1))
    call RemoveItem(UnitItemInSlot(hero,slot2))
    call RemoveItem(UnitItemInSlot(hero,slot3))
    
    if IsUnitAlly(hero,Player(0)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl",hero,"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",hero,"origin"))
    endif
    
    call UnitAddItemById(hero,tid)
endfunction

function Recipe4 takes unit hero, integer id1, integer id2, integer id3, integer id4, integer tid returns nothing
    local integer slot1 = GetUnitItemSlot(hero,id1)
    local integer slot2 = GetUnitItemSlot(hero,id2)
    local integer slot3 = GetUnitItemSlot(hero,id3)
    local integer slot4 = GetUnitItemSlot(hero,id4)
    
    call RemoveItem(UnitItemInSlot(hero,slot1))
    call RemoveItem(UnitItemInSlot(hero,slot2))
    call RemoveItem(UnitItemInSlot(hero,slot3))
    call RemoveItem(UnitItemInSlot(hero,slot4))
    
    if IsUnitAlly(hero,Player(0)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl",hero,"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",hero,"origin"))
    endif
    
    call UnitAddItemById(hero,tid)
endfunction

function Recipe5 takes unit hero, integer id1, integer id2, integer id3, integer id4, integer id5, integer tid returns nothing
    local integer slot1 = GetUnitItemSlot(hero,id1)
    local integer slot2 = GetUnitItemSlot(hero,id2)
    local integer slot3 = GetUnitItemSlot(hero,id3)
    local integer slot4 = GetUnitItemSlot(hero,id4)
    local integer slot5 = GetUnitItemSlot(hero,id5)
    
    call RemoveItem(UnitItemInSlot(hero,slot1))
    call RemoveItem(UnitItemInSlot(hero,slot2))
    call RemoveItem(UnitItemInSlot(hero,slot3))
    call RemoveItem(UnitItemInSlot(hero,slot4))
    call RemoveItem(UnitItemInSlot(hero,slot5))
    
    if IsUnitAlly(hero,Player(0)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl",hero,"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",hero,"origin"))
    endif
    
    call UnitAddItemById(hero,tid)
endfunction

function Recipe6 takes unit hero, integer id1, integer id2, integer id3, integer id4, integer id5, integer id6, integer tid returns nothing
    local integer slot1 = GetUnitItemSlot(hero,id1)
    local integer slot2 = GetUnitItemSlot(hero,id2)
    local integer slot3 = GetUnitItemSlot(hero,id3)
    local integer slot4 = GetUnitItemSlot(hero,id4)
    local integer slot5 = GetUnitItemSlot(hero,id5)
    local integer slot6 = GetUnitItemSlot(hero,id6)
    
    call RemoveItem(UnitItemInSlot(hero,slot1))
    call RemoveItem(UnitItemInSlot(hero,slot2))
    call RemoveItem(UnitItemInSlot(hero,slot3))
    call RemoveItem(UnitItemInSlot(hero,slot4))
    call RemoveItem(UnitItemInSlot(hero,slot5))
    call RemoveItem(UnitItemInSlot(hero,slot6))
    
    if IsUnitAlly(hero,Player(0)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl",hero,"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",hero,"origin"))
    endif
    
    call UnitAddItemById(hero,tid)
endfunction

function UnitHasEmptySlot takes unit u returns boolean
    local integer i = 0
    loop
        exitwhen i > 5
        if UnitItemInSlot(u,i) == null then
            return true
        endif
        set i = i + 1
    endloop
    return false
endfunction

function MakeRecipe takes unit u, integer iid returns item
    return null
endfunction

function RecipeExist takes integer iid returns boolean
    return false
endfunction

function Rune2Normal takes unit hero, item ri, boolean b returns item
    local integer i = 0
    
    loop
        exitwhen i > udg_TotalItems
        if GetItemTypeId(ri) == udg_RuneItem<i> then
        
            if UnitHasEmptySlot(hero) == false then
                
                if RecipeExist(udg_NormalItem<i>) then
                    return MakeRecipe(hero,udg_NormalItem<i>)
                elseif GetItemCharges(ri) &gt; 0 and GetUnitItemSlot(hero,udg_NormalItem<i>) &gt; -1 then
                    call SetItemCharges(ri,GetItemCharges(ri) + GetItemCharges(UnitItemInSlot(hero,GetUnitItemSlot(hero,udg_NormalItem<i>))))
                else
                    call SimError(GetOwningPlayer(hero),&quot;You can&#039;t pick this item up.&quot;)
                    call SetPlayerState(GetOwningPlayer(hero),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(GetOwningPlayer(hero),PLAYER_STATE_RESOURCE_GOLD) + udg_ItemCost<i>)
                endif
                
            else   
                return UnitAddItemById(hero,udg_NormalItem<i>)
            endif
        
        endif
        set i = i + 1
    endloop
endfunction

function Normal2Rune takes item ni, real x, real y returns item
    local integer i = 0
    loop
        exitwhen i &gt; udg_TotalItems
        if udg_NormalItem<i> == GetItemTypeId(ni) then
            return CreateItem(udg_RuneItem<i>,x,y)    
        endif        
        set i = i + 1
    endloop
endfunction

function ItemIsRune takes integer itemid returns boolean
    local integer i = 0
    loop
        exitwhen i &gt; udg_TotalItems
        if udg_RuneItem<i> == itemid then
            return true      
        endif        
        set i = i + 1
    endloop
    return false
endfunction</i></i></i></i></i></i></i></i></i></i>


Trigger controlling pickuping and buying items.
JASS:
function Trig_Pick_Items_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local item i = LoadItemHandle(udg_ItemHash,GetHandleId(t),0)
    local item di = CreateItem(GetItemTypeId(i),GetWidgetX(i),GetWidgetY(i)
    
    call SaveBoolean(udg_ItemHash,GetHandleId(di),1,true)
    call SaveInteger(udg_ItemHash,GetHandleId(di),2,LoadInteger(udg_ItemHash,GetHandleId(i),2))
    
    call FlushChildHashtable(udg_ItemHash,GetHandleId(t))
    call DestroyTimer(t)
    
    set i = null
    set t = null
endfunction

function Trig_Pick_Items_Actions takes nothing returns nothing
    local unit u
    local item i
    local item ni
    local real x
    local real y
    local timer t
    
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_PICKUP_ITEM then
        set u = GetManipulatingUnit()
        set i = GetManipulatedItem()  
        set x = GetWidgetX(i)
        set y = GetWidgetY(i)
        
        call SetItemVisible(i,false)
        
        if LoadBoolean(udg_ItemHash,GetHandleId(i),0) == false or LoadBoolean(udg_ItemHash,GetHandleId(i),0) == null then 
        
            if UnitHasEmptySlot(u) == false and RecipeExist(GetItemTypeId(i)) then
                call SaveBoolean(udg_ItemHash,GetHandleId(Rune2Normal(u,i,true)),0,false)
            elseif GetUnitItemSlot(u,GetItemTypeId(i)) &gt; -1 then   
                call Rune2Normal(u,i,false)  
            elseif UnitHasEmptySlot(u) == false and RecipeExist(GetItemTypeId(i)) == false then 
                if LoadBoolean(udg_ItemHash,GetHandleId(i),1) then
                    set t = CreateTimer()
                    call SimError(GetOwningPlayer(u),&quot;You can&#039;t pick this item up.&quot;)
                    call SaveItemHandle(udg_ItemHash,GetHandleId(t),0,i)
                    call TimerStart(t,.01,false,function Trig_Pick_Items_Timer)
                    set t = null
                endif     
            else
                set ni = Rune2Normal(u,i,false)
                call SetItemCharges(ni,LoadInteger(udg_ItemHash,GetHandleId(i),2))
                call SaveBoolean(udg_ItemHash,GetHandleId(ni),0,false) 
                set ni = null
            endif
            
            call SaveBoolean(udg_ItemHash,GetHandleId(i),0,true)
        else
            call SaveBoolean(udg_ItemHash,GetHandleId(i),0,false)
        endif
    
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_SELL_ITEM then
        set u = GetBuyingUnit()
        set i = GetSoldItem()
        
        call SetItemVisible(i,false)
        
        if LoadBoolean(udg_ItemHash,GetHandleId(i),0) == false or LoadBoolean(udg_ItemHash,GetHandleId(i),0) == null then
            call SaveBoolean(udg_ItemHash,GetHandleId(Rune2Normal(u,i,true)),1,false)
            call SaveBoolean(udg_ItemHash,GetHandleId(i),0,true)
        else
            call SaveBoolean(udg_ItemHash,GetHandleId(i),0,false)
        endif   
    endif
    
    set i = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Pick_Items takes nothing returns nothing
    set gg_trg_Pick_Items = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Pick_Items,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Pick_Items,EVENT_PLAYER_UNIT_SELL_ITEM)
    call TriggerAddAction(gg_trg_Pick_Items,function Trig_Pick_Items_Actions)
endfunction


Trigger controlling drops of items.
JASS:
function Trig_Drop_Items_Conditions takes nothing returns boolean
    return ItemIsRune(GetItemTypeId(GetManipulatedItem())) == false
endfunction

function Trig_Drop_Items_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local item i = LoadItemHandle(udg_ItemHash,GetHandleId(t),0)
    local integer ch = GetItemCharges(i)
    local item it
    
    call SetItemVisible(i,false)
    set it = Normal2Rune(i,GetWidgetX(i),GetWidgetY(i))
    call SaveInteger(udg_ItemHash,GetHandleId(it),2,ch)
    call SetItemCharges(it,ch)
    call SaveBoolean(udg_ItemHash,GetHandleId(it),1,true)

    call BJDebugMsg(I2S(GetItemCharges(it)))
    
    call RemoveItem(i)
    
    call FlushChildHashtable(udg_ItemHash,GetHandleId(t))
    call DestroyTimer(t)
    
    set it = null
    set i = null
    set t = null
endfunction

function Trig_Drop_Items_Actions takes nothing returns nothing
    local item i = GetManipulatedItem()
    local unit u = GetManipulatingUnit()
    local timer t = CreateTimer()
    
    call SaveItemHandle(udg_ItemHash,GetHandleId(t),0,i)
    
    call TimerStart(t,.01,false,function Trig_Drop_Items_Timer)

    set t = null
    set u = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Drop_Items takes nothing returns nothing
    set gg_trg_Drop_Items = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Drop_Items,EVENT_PLAYER_UNIT_DROP_ITEM)
    call TriggerAddCondition(gg_trg_Drop_Items,Condition(function Trig_Drop_Items_Conditions))
    call TriggerAddAction(gg_trg_Drop_Items,function Trig_Drop_Items_Actions)
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top