JediPope
New Member
- Reaction score
- 0
I am trying to create a simple inventory system where six slots are devoted to to charged items (which may stack) and six slots to permanent items (for summons, which do not stack). The two bags are swiched using a dummy ability 'A000' or by trigger, on the unit type 'H000'. Its a single player RPG so it doesn't have to be MUI. My intention is that only one bag be shown at a time, and that the bags automatically switch when an item type does not match the bag type.
Two problems I have come across, one, the items in the charged bag no longer stack, and secondly, the items won't go to the proper bag if the wrong bag is open.
Two problems I have come across, one, the items in the charged bag no longer stack, and secondly, the items won't go to the proper bag if the wrong bag is open.
Code:
function Trig_Inventory2_Conditions takes nothing returns boolean
if ( udg_Item_Real2 == 1.00 and GetUnitTypeId(GetTriggerUnit()) == 'H000' ) then
return true
endif
// call UnitDropItemPointLoc( GetTriggerUnit(), GetManipulatedItem(), GetUnitLoc( GetTriggerUnit() ) )
return false
endfunction
//saving items
function Subroutine1 takes nothing returns nothing
local integer i = 5
loop
call SaveItemHandle( udg_Item_Hash, 1, (i + 1), ( UnitItemInSlot( GetTriggerUnit(), i) ) )
exitwhen i == 0
set i = i - 1
endloop
endfunction
//saving summons
function Subroutine2 takes nothing returns nothing
local integer i = 5
loop
call SaveItemHandle( udg_Item_Hash, 1, (i + 7), ( UnitItemInSlot( GetTriggerUnit(), i) ) )
exitwhen i == 0
set i = i - 1
endloop
endfunction
//charged items
function Subroutine3 takes nothing returns nothing
local integer i = 0
local integer charges
if ( GetItemCharges(GetItemOfTypeFromUnitBJ(GetTriggerUnit(), GetItemTypeId(GetManipulatedItem()))) > 99 ) then
// call UnitRemoveItemSwapped( GetItemOfTypeFromUnitBJ(GetTriggerUnit(), GetItemTypeId(GetManipulatedItem())), GetTriggerUnit() )
call UnitDropItemPointLoc( GetTriggerUnit(), GetManipulatedItem(), GetUnitLoc( GetTriggerUnit() ) )
return
else
set i = 0
loop
if ( GetItemTypeId(UnitItemInSlot(GetTriggerUnit(), i)) == GetItemTypeId(GetManipulatedItem() ) and GetItemCharges(UnitItemInSlot(GetTriggerUnit(), i)) != 0 and UnitItemInSlot(GetTriggerUnit(), i) != GetManipulatedItem() ) then
set charges = ( GetItemCharges(UnitItemInSlotBJ(GetTriggerUnit(), i)) + 1 )
call SetItemCharges( UnitItemInSlot(GetTriggerUnit(), i), charges )
call RemoveItem( GetManipulatedItem() )
else
call DoNothing( )
endif
exitwhen i == 5
set i = i + 1
endloop
endif
endfunction
function Trig_Inventory2_Actions takes nothing returns nothing
local integer i = 0
set udg_Item_Real2 = 0.00
if ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_CHARGED ) then
if ( udg_Item_Real1 == 1.00 ) then
call SaveItemHandle( udg_Item_Hash, 1, 13, GetManipulatedItem() )
call UnitRemoveItemSwapped( GetManipulatedItem(), GetTriggerUnit() )
call TriggerExecute( gg_trg_Bag_Switch )
set udg_Item_Real2 = 1.00
call UnitAddItemSwapped( LoadItemHandle( udg_Item_Hash, 1, 13), GetTriggerUnit() )
else
call Subroutine3()
call Subroutine1()
endif
else
if ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_PERMANENT ) then
if ( udg_Item_Real1 == 0.00 ) then
call SaveItemHandle( udg_Item_Hash, 1, 13, GetManipulatedItem() )
call UnitRemoveItemSwapped( GetManipulatedItem(), GetTriggerUnit() )
call TriggerExecute( gg_trg_Bag_Switch )
call UnitAddItemSwapped( LoadItemHandle( udg_Item_Hash, 1, 13), GetTriggerUnit() )
call Subroutine2()
else
call Subroutine2()
endif
else
call DoNothing( )
endif
endif
set udg_Item_Real2 = 1.00
endfunction
//===========================================================================
function InitTrig_Pick_Up_Items takes nothing returns nothing
set gg_trg_Pick_Up_Items = CreateTrigger( )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Pick_Up_Items, Player(0), EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Pick_Up_Items, Condition( function Trig_Inventory2_Conditions ) )
call TriggerAddAction( gg_trg_Pick_Up_Items, function Trig_Inventory2_Actions )
endfunction
Code:
function Trig_Inventory1_Conditions takes nothing returns boolean
if ( GetSpellAbilityId() != 'A000' ) then
return false
endif
if ( GetUnitTypeId(GetSpellAbilityUnit()) != 'H000' ) then
return false
endif
if ( GetOwningPlayer(GetSpellAbilityUnit()) != Player(0) ) then
return false
endif
return true
endfunction
function Inventory1_Actions takes nothing returns nothing
local integer i = 5
set udg_Item_Real2 = 0.00
if ( udg_Item_Real1 == 0.00 ) then
loop
if ( UnitItemInSlot( GetSpellAbilityUnit(), i) == null ) then
call RemoveSavedHandle(udg_Item_Hash, 1, (i + 1))
else
if ( LoadItemHandle( udg_Item_Hash, 1, (i + 1)) != ( UnitItemInSlot( GetSpellAbilityUnit(), i) ) ) then
call SaveItemHandle( udg_Item_Hash, 1, (i + 1), ( UnitItemInSlot( GetSpellAbilityUnit(), i) ) )
call UnitRemoveItemFromSlot( GetSpellAbilityUnit(), i )
call SetWidgetLife( LoadWidgetHandle( udg_Item_Hash, 1, (i + 1)), 0.00 )
else
call UnitRemoveItemFromSlot( GetSpellAbilityUnit(), i )
call SetWidgetLife( LoadWidgetHandle( udg_Item_Hash, 1, (i + 1)), 0.00 )
endif
endif
exitwhen i == 0
set i = i - 1
endloop
set i = 1
loop
call UnitAddItem( GetSpellAbilityUnit(), LoadItemHandle( udg_Item_Hash, 1, (i+6)))
exitwhen i == 6
set i = i + 1
endloop
call LeaderboardSetLabel( udg_Action, "Summon Inventory" )
else
set i = 5
loop
if ( ( UnitItemInSlot( GetSpellAbilityUnit(), i) ) == null ) then
call RemoveSavedHandle(udg_Item_Hash, 1, (i + 7))
else
if ( LoadItemHandle( udg_Item_Hash, 1, (i + 7)) != ( UnitItemInSlot( GetSpellAbilityUnit(), i) ) ) then
call SaveItemHandle( udg_Item_Hash, 1, (i + 7), ( UnitItemInSlot( GetSpellAbilityUnit(), i) ) )
call UnitRemoveItemFromSlot( GetSpellAbilityUnit(), i )
call SetWidgetLife( LoadWidgetHandle( udg_Item_Hash, 1, (i + 7)), 0.00 )
else
call UnitRemoveItemFromSlot( GetSpellAbilityUnit(), i )
call SetWidgetLife( LoadWidgetHandle( udg_Item_Hash, 1, (i + 7)), 0.00 )
endif
endif
exitwhen i == 0
set i = i - 1
endloop
set i = 1
loop
call UnitAddItem( GetSpellAbilityUnit(), LoadItemHandle( udg_Item_Hash, 1, i))
call SetItemCharges( UnitItemInSlot( GetSpellAbilityUnit(), i), GetItemCharges(LoadItemHandle( udg_Item_Hash, 1, i)) )
exitwhen i == 6
set i = i + 1
endloop
call LeaderboardSetLabel( udg_Action, "Item Inventory" )
endif
if ( udg_Item_Real1 == 1.00 ) then
set udg_Item_Real1 = 0.00
else
set udg_Item_Real1 = 1.00
endif
set udg_Item_Real2 = 1.00
endfunction
//===========================================================================
function InitTrig_Bag_Switch takes nothing returns nothing
set gg_trg_Bag_Switch = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Bag_Switch, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( gg_trg_Bag_Switch, Condition( function Trig_Inventory1_Conditions ) )
call TriggerAddAction( gg_trg_Bag_Switch, function Inventory1_Actions )
endfunction