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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top