2nd trigger
//################################################################################
//
// script : FSGUI module - 100-slot inventory
// version : 2.01
// date : 06.08.2005
//
//
// made by : DimonT | Illisor
// mail :
[email protected] |
[email protected]
// icq : 937160 | 221013519
// www :
http://dimon.xgm.ru/fsgui/
//
//################################################################################
//################################################################################
function inv100_ItemID2String takes integer itemid returns string
return fs_chr(itemid/256/256/256) + fs_chr(ModuloInteger(itemid/256/256, 256)) + fs_chr(ModuloInteger(itemid/256, 256)) + fs_chr(ModuloInteger(itemid, 256))
endfunction
//################################################################################
function inv100_GetItemName takes integer itemId returns string
local integer i = 0
if HaveStoredString(udg_fs_cache, I2S(itemId), "name") then
return GetStoredString(udg_fs_cache, I2S(itemId), "name")
endif
return "Unknown Item (" + inv100_ItemID2String(itemId) + ")"
endfunction
//################################################################################
function inv100_GetItemDesc takes integer itemId returns string
local integer i = 0
if HaveStoredString(udg_fs_cache, I2S(itemId), "desc") then
return GetStoredString(udg_fs_cache, I2S(itemId), "desc")
endif
return "Hmm seems like the description is lost...."
endfunction
//################################################################################
function inv100_GetItemFX takes integer itemId returns string
if itemId == 0 then
return "empinv" + get_session_param("fs_skin")
endif
if not HaveStoredInteger(udg_fs_cache, "FX", "inv100_item" + I2S(itemId)) then
set itemId = 'sclp'
endif
return "inv100_item" + I2S(itemId)
endfunction
//################################################################################
function inv100_GetItemCost takes integer itemId returns integer
if HaveStoredInteger(udg_fs_cache, I2S(itemId), "cost") then
return R2I(GetStoredInteger(udg_fs_cache, I2S(itemId), "cost") * cfgr("inv100_sell_rate"))
endif
return 0
endfunction
//################################################################################
function inv100_IsMainInventoryFull takes unit u returns boolean
local integer i = 0
loop
exitwhen i >= 6
if UnitItemInSlot(u, i) == null then
return false
endif
set i = i + 1
endloop
return true
endfunction
//################################################################################
function inv100_IsEnabled takes player p returns boolean
call setcfg("player", I2S(GetPlayerId(p)))
return get_session_iparam("fs_enabled") == 1 and get_session_param("fs_module") == "inv100"
endfunction
//################################################################################
function inv100_UnitItemInSlot takes unit u, integer slot returns item
return fs_I2It(get_object_iparam(u, "inv100_item" + I2S(slot)))
endfunction
//################################################################################
function UnitAddItemToSlotMy takes unit u, item it, integer slot returns nothing
local integer i = 0
// ### following simple order method doesn't seem to work w/ paused units... :/
// call UnitAddItem(u, it)
// call IssueTargetOrderById(u, 852002 + slot, it)
// return
call UnitRemoveItem(u, it)
loop
exitwhen i >= 6 or i > slot
if i < slot then
if UnitItemInSlot(u, i) == null then
call UnitAddItemById(u, 'phlt')
endif
elseif i == slot then
call UnitAddItem(u, it)
endif
set i = i + 1
endloop
set i = 0
loop
exitwhen i >= 6 or i >= slot
if GetItemTypeId(UnitItemInSlot(u, i)) == 'phlt' then
call RemoveItem(UnitItemInSlot(u,i ))
endif
set i = i + 1
endloop
endfunction
//################################################################################
function inv100_UnitAddItemToSlot takes unit u, item it, integer slot returns nothing
if GetItemTypeId(inv100_UnitItemInSlot(u, slot)) != 0 or IsItemPowerup(it) then
return
endif
call UnitRemoveItem(u, it)
call set_object_iparam(u, "inv100_item" + I2S(slot), fs_H2I(it))
call SetItemVisible(it, false)
call SetItemPosition(it, get_session_rparam("fs_base_x") - 100, get_session_rparam("fs_base_y") - 100 + slot * 10)
endfunction
//################################################################################
function inv100_UnitDropItemSlot takes unit u, integer slot returns nothing
local item it = fs_I2It(get_object_iparam(u, "inv100_item" + I2S(slot)))
call SetItemVisible(it, true)
call SetItemPosition(it, GetUnitX(u), GetUnitY(u))
call set_object_iparam(u, "inv100_item" + I2S(slot), 0)
endfunction
//################################################################################
function inv100_UnitHasItem takes unit u, item it returns boolean
local integer i = 0
local integer slots = get_object_iparam(u, "inv100_rows") * get_object_iparam(u, "inv100_cols")
loop
exitwhen i >= slots
if inv100_UnitItemInSlot(u, i) == it then
return true
endif
set i = i + 1
endloop
return false
endfunction
//################################################################################
function inv100_UnitHasItemOfType takes unit u, integer it returns boolean
local integer i = 0
local integer slots = get_object_iparam(u, "inv100_rows") * get_object_iparam(u, "inv100_cols")
loop
exitwhen i >= slots
if GetItemTypeId(inv100_UnitItemInSlot(u, i)) == it then
return true
endif
set i = i + 1
endloop
return false
endfunction
//################################################################################
function inv100_SetInventorySize takes unit u, integer rows, integer cols returns nothing
if rows < 1 then
set rows = 1
elseif rows > 10 then
set rows = 10
endif
if cols < 1 then
set cols = 1
elseif cols > 10 then
set cols = 10
endif
call set_object_iparam(u, "inv100_rows", rows)
call set_object_iparam(u, "inv100_cols", cols)
endfunction
//################################################################################
function inv100_DrawItem takes integer tid, item it returns nothing
call fs_AddNamedEffect("item" + I2S(tid) , inv100_GetItemFX(GetItemTypeId(it)), tid, false)
if GetItemCharges(it) > 0 then
call fs_AddNamedEffectXY("charges" + I2S(tid), "number", fs_GetTrackableX(tid) + 20, fs_GetTrackableY(tid) - 25, false)
call fs_AddNamedTextTag("charges" + I2S(tid), fs_GetTrackableX(tid) + 1.65 * ModuloInteger(tid, 20) + 2, fs_GetTrackableY(tid) - 30 - 1.8 * I2R(R2I(tid / 20)), I2S(GetItemCharges(it)), 0.015)
else
call fs_AddNamedEffectXY("charges" + I2S(tid), "", 0, 0, false)
call fs_AddNamedTextTag("charges" + I2S(tid), 0, 0, "", 0)
endif
endfunction
//################################################################################
function inv100_UseItem takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = fs_I2U(get_object_iparam(t, "unit"))
local integer charges = get_object_iparam(t, "charges")
local integer tid = get_object_iparam(t, "tid")
local integer g = fs_GetTrackableGroup(tid)
local integer slot = fs_GetTrackableGroupID(tid)
local item it = UnitItemInSlot(u, 0)
call setcfg("player", I2S(get_object_iparam(t, "player")))
if GetItemCharges(it) > 0 then
if g == 0 then
call UnitAddItemToSlotMy(u, it, slot)
else
call inv100_UnitAddItemToSlot(u, it, slot)
endif
else
call fs_SetNamedTextTagText("item_name", " ", 0)
call fs_SetNamedTextTagText("item_desc", " ", 0)
call fs_AddNamedEffectXY("cost", "", 0, 0, false)
call fs_SetNamedTextTagText("item_cost", " ", 0)
call fs_SetNamedTextTagText("item_hint", " ", 0)
endif
if GetItemCharges(it) != charges then
call inv100_DrawItem(tid, it)
call fs_PlaySound("Abilities\\Spells\\Items\\AIam\\Tomes.wav")
call set_session_iparam("selected_item", 0)
call set_session_iparam("selected_cell", -1)
call fs_SetNamedTextTagText("item_hint", " ", 0)
call fs_SetNamedTextTagText("button_label", " ", 0)
call fs_AddNamedEffect("item_select", "", 0, false)
call fs_AddNamedEffect("button_sell", "DISBTNSell", get_session_iparam("button_sell_pos"), false)
call fs_AddNamedEffect("button_drop", "DISBTNDrop", get_session_iparam("button_drop_pos"), false)
call fs_AddNamedEffect("button_use" , "DISBTNUse" , get_session_iparam("button_use_pos") , false)
else
call fs_PlaySound("Sound\\Interface\\Error.wav")
call fs_SetNamedTextTagText("item_hint", "|c00ff0000Cannot use this item.|r", 0)
endif
call UnitAddItemToSlotMy(u, inv100_UnitItemInSlot(u, -1), 0)
call set_object_iparam(u, "inv100_item-1", 0)
call PauseUnit(u, true)
call DestroyTimer(t)
call flush_object(t)
endfunction
//################################################################################
function inv100_ClickHandler takes nothing returns nothing
local integer tid = fs_GetTriggeringTrackableID()
local integer g = fs_GetTrackableGroup(tid)
local integer slot = fs_GetTrackableGroupID(tid)
local integer p = fs_GetPlayerID()
local unit u = fs_I2U(get_session_iparam("unit"))
local integer tid2 = get_session_iparam("selected_cell")
local integer g2 = fs_GetTrackableGroup(tid2)
local integer slot2 = fs_GetTrackableGroupID(tid2)
local integer charges
local string str
local item it
local item it2 = fs_I2It(get_session_iparam("selected_item"))
local timer t
if g == -1 then
return
endif
if g == 2 then
call fs_Shutdown(fs_GetPlayerID())
return
endif
// ####### validity checks #######
if g == 3 and not IsItemSellable(it2) then
return
endif
if g == 4 and (GetItemCharges(it2) == 0 or GetItemTypeId(inv100_UnitItemInSlot(u, -1)) != 0) then
return
endif
if g == 5 and GetItemTypeId(it2) == 0 then
return
endif
// ####### auto-pickup button #######
if g == 6 then
if get_object_iparam(u, "inv100_auto_pickup") == 0 then
if inv100_IsMainInventoryFull(u) then
call fs_SetNamedTextTagText("button_label", "|cffffcc00Free at least one slot in your main inventory.|r", 0)
call fs_PlaySound("Sound\\Interface\\Error.wav")
return
endif
call set_object_iparam(u, "inv100_auto_pickup", 1)
call fs_AddNamedEffect("button_pickup_selected", "selector", get_session_iparam("button_pickup_pos"), false)
else
call set_object_iparam(u, "inv100_auto_pickup", 0)
call fs_AddNamedEffect("button_pickup_selected", "", 0, false)
endif
set str = "Pickup to Extended Inventory: |cffffcc00" + fs_iif(get_object_iparam(u, "inv100_auto_pickup") == 1, "ON", "OFF") + "|r"
call fs_SetNamedTextTagText("button_label", str, 0)
call fs_PlaySound("Sound\\Interface\\AutoCastButtonClick1.wav")
return
endif
// ####### use button #######
if g == 4 then
if g2 == 0 then
call UnitRemoveItem(u, it2)
else
call inv100_UnitDropItemSlot(u, slot2)
endif
call inv100_UnitAddItemToSlot(u, UnitItemInSlot(u, 0), -1)
call UnitAddItemToSlotMy(u, it2, 0)
set t = CreateTimer()
call TimerStart(t, 0.02, false, function inv100_UseItem)
call set_object_iparam(t, "unit", fs_H2I(u))
call set_object_iparam(t, "player", p)
call set_object_iparam(t, "charges", GetItemCharges(it2))
call set_object_iparam(t, "tid", tid2)
call PauseUnit(u, false)
call UnitUseItem(u, it2)
return
endif
// ####### deselect current item #######
if tid2 != -1 then
call set_session_iparam("selected_item", 0)
call set_session_iparam("selected_cell", -1)
call fs_SetNamedTextTagText("item_hint", " ", 0)
call fs_AddNamedEffect("item_select", "", 0, false)
call fs_AddNamedEffect("button_sell", "DISBTNSell", get_session_iparam("button_sell_pos"), false)
call fs_AddNamedEffect("button_drop", "DISBTNDrop", get_session_iparam("button_drop_pos"), false)
call fs_AddNamedEffect("button_use" , "DISBTNUse" , get_session_iparam("button_use_pos") , false)
endif
// ####### sell button #######
if g == 3 then
call SetPlayerState(Player(p), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_GOLD) + inv100_GetItemCost(GetItemTypeId(it2)))
if g2 == 1 then
call set_object_iparam(u, "inv100_item" + I2S(slot2), 0)
endif
call RemoveItem(it2)
call inv100_DrawItem(tid2, null)
call fs_SetNamedTextTagText("item_name", " ", 0)
call fs_SetNamedTextTagText("item_desc", " ", 0)
call fs_AddNamedEffectXY("cost", "", 0, 0, false)
call fs_SetNamedTextTagText("item_cost", " ", 0)
call fs_SetNamedTextTagText("item_hint", " ", 0)
call fs_SetNamedTextTagText("button_label", " ", 0)
call fs_PlaySound("Sound\\Interface\\ReceiveGold.wav")
return
endif
// ####### drop button #######
if g == 5 then
if g2 == 0 then
call UnitRemoveItem(u, it2)
else
call inv100_UnitDropItemSlot(u, slot2)
endif
call inv100_DrawItem(tid2, null)
call fs_SetNamedTextTagText("item_name", " ", 0)
call fs_SetNamedTextTagText("item_desc", " ", 0)
call fs_AddNamedEffectXY("cost", "", 0, 0, false)
call fs_SetNamedTextTagText("item_cost", " ", 0)
call fs_SetNamedTextTagText("item_hint", " ", 0)
call fs_SetNamedTextTagText("button_label", " ", 0)
call fs_PlaySound("Sound\\Interface\\BigButtonClick.wav")
return
endif
// ####### item zones #######
if g != 0 and g != 1 then
return
endif
if g == 0 then
set it = UnitItemInSlot(u, slot)
else
set it = inv100_UnitItemInSlot(u, slot)
endif
// ####### select / deselect if clicked on item #######
if GetItemTypeId(it) != 0 then
call fs_PlaySound("Sound\\Interface\\MouseClick1.wav")
if tid == tid2 then
return
endif
call set_session_iparam("selected_item", fs_H2I(it))
call set_session_iparam("selected_cell", tid)
call fs_SetNamedTextTagText("item_hint", "|c00999999Click on empty slot to move this item.|r", 0)
call fs_AddNamedEffect("item_select", "selecter", tid, true)
if IsItemSellable(it) then
call fs_AddNamedEffect("button_sell", "BTNSell", get_session_iparam("button_sell_pos"), false)
endif
if GetItemTypeId(it) != 0 then
call fs_AddNamedEffect("button_drop", "BTNDrop", get_session_iparam("button_drop_pos"), false)
endif
if GetItemCharges(it) > 0 then
call fs_AddNamedEffect("button_use" , "BTNUse" , get_session_iparam("button_use_pos") , false)
endif
return
endif
// ####### clicked on empty slot and no item selected #######
if GetItemTypeId(it2) == 0 then
return
endif
// ####### move item #######
if g2 == 0 then
call UnitRemoveItem(u, it2)
else
call inv100_UnitDropItemSlot(u, slot2)
endif
if g == 0 then
call UnitAddItemToSlotMy(u, it2, slot)
else
call inv100_UnitAddItemToSlot(u, it2, slot)
endif
call inv100_DrawItem(tid2, null)
call inv100_DrawItem(tid , it2)
call fs_PlaySound("Sound\\Interface\\BigButtonClick.wav")
if inv100_IsMainInventoryFull(u) then
call set_object_iparam(u, "inv100_auto_pickup", 0)
call fs_AddNamedEffect("button_pickup_selected", "", 0, false)
endif
endfunction
//################################################################################
function inv100_HoverHandler takes nothing returns nothing
local integer tid = fs_GetTriggeringTrackableID()
local integer g = fs_GetTrackableGroup(tid)
local integer slot = fs_GetTrackableGroupID(tid)
local integer p = fs_GetPlayerID()
local unit u = fs_I2U(get_session_iparam("unit"))
local string str
local item it
if get_session_iparam("selected_cell") != -1 then
set it = fs_I2It(get_session_iparam("selected_item"))
elseif g == 0 then
set it = UnitItemInSlot(u, slot)
elseif g == 1 then
set it = inv100_UnitItemInSlot(u, slot)
else
set it = null
endif
if g == 6 then
set str = "Pickup to Extended Inventory: |cffffcc00" + fs_iif(get_object_iparam(u, "inv100_auto_pickup") == 1, "ON", "OFF") + "|r"
elseif g == 2 then
set str = "Return to Game (|cffffcc00ESC|r)"
elseif g == 3 then
set str = fs_iif(get_session_iparam("selected_cell") != -1 and IsItemSellable(it), "Sell Item", " ")
elseif g == 4 then
set str = fs_iif(get_session_iparam("selected_cell") != -1 and GetItemCharges(it) > 0, "Use Item", " ")
elseif g == 5 then
set str = fs_iif(get_session_iparam("selected_cell") != -1, "Drop Item", " ")
else
set str = " "
endif
call fs_SetNamedTextTagText("button_label", str, 0)
if GetItemTypeId(it) != 0 then
call fs_SetNamedTextTagText("item_name", inv100_GetItemName(GetItemTypeId(it)), 0)
call fs_SetNamedTextTagText("item_desc", inv100_GetItemDesc(GetItemTypeId(it)), 0)
else
call fs_SetNamedTextTagText("item_name", " ", 0)
call fs_SetNamedTextTagText("item_desc", " ", 0)
endif
if IsItemSellable(it) then
call fs_AddNamedEffectXY("cost", "cost", 185, 885, false)
call fs_SetNamedTextTagText("item_cost", "|cffffcc00" + I2S(inv100_GetItemCost(GetItemTypeId(it))) + "|r", 0)
else
call fs_AddNamedEffectXY("cost", "", 0, 0, false)
call fs_SetNamedTextTagText("item_cost", " ", 0)
endif
endfunction
//################################################################################
function inv100_PlayCineFilter takes nothing returns nothing
if cfgi("inv100_fadefilter") == 0 then
return
endif
if Player(fs_GetPlayerID()) != GetLocalPlayer() then
return
endif
call SetCineFilterTexture("ReplaceableTextures\\CameraMasks\\Black_mask.blp")
call SetCineFilterStartColor(0, 0, 0, 255)
call SetCineFilterEndColor(0, 0, 0, 0)
call SetCineFilterDuration(1.00)
call DisplayCineFilter(true)
endfunction
//################################################################################
function inv100_DetectShop takes nothing returns nothing
if GetUnitAbilityLevel(GetEnumUnit(), 'Apit') >= 1 then
call set_session_iparam("allow_sell", 1)
endif
endfunction
//################################################################################
function inv100_Init takes nothing returns nothing
local integer i
local integer tid
local unit u = GetTriggerUnit()
local integer rows
local integer cols
local integer x = 0
local integer y = 0
local item it
local group gr
call set_session_iparam("unit", fs_H2I(u))
call set_session_iparam("selected_cell", -1)
call set_session_iparam("selected_item", 0)
call PauseUnit(u, true)
// ####### validate dimensions #######
set rows = get_object_iparam(u, "inv100_rows")
set cols = get_object_iparam(u, "inv100_cols")
if rows == 0 or cols == 0 then
set rows = cfgi("inv100_default_rows")
set cols = cfgi("inv100_default_cols")
endif
call inv100_SetInventorySize(u, rows, cols)
set rows = get_object_iparam(u, "inv100_rows")
set cols = get_object_iparam(u, "inv100_cols")
// ####### detect nearby shop to allow sell mode #######
call set_session_iparam("allow_sell", 0)
if cfgi("inv100_sell_mode") == 1 then
set gr = CreateGroup()
call GroupEnumUnitsInRange(gr, GetUnitX(u), GetUnitY(u), cfgr("inv100_sell_range"), null)
call ForGroup(gr, function inv100_DetectShop)
call DestroyGroup(gr)
elseif cfgi("inv100_sell_mode") == 2 then
call set_session_iparam("allow_sell", 1)
endif
// ####### attach auto-pickup trigger #######
if get_object_iparam(u, "inv100_enabled") == 0 then
call TriggerRegisterUnitEvent( fs_I2T(cfgi("inv100_exit_trigger")), u, EVENT_UNIT_DEATH )
call TriggerRegisterUnitEvent( fs_I2T(cfgi("inv100_pickup_trigger")), u, EVENT_UNIT_PICKUP_ITEM )
call set_object_iparam(u, "inv100_enabled", 1)
endif
// ####### small inventory #######
call fs_AddBackgroundEffect("cornerUL", fs_Coords2Id(1, 6), true)
call fs_AddBackgroundEffect("cornerUR", fs_Coords2Id(2, 6), true)
call fs_AddBackgroundEffect("borderL" , fs_Coords2Id(1, 7), true)
call fs_AddBackgroundEffect("borderR" , fs_Coords2Id(2, 7), true)
call fs_AddBackgroundEffect("cornerDL", fs_Coords2Id(1, 8), true)
call fs_AddBackgroundEffect("cornerDR", fs_Coords2Id(2, 8), true)
set i = 0
loop
exitwhen i >= 6
set x = ModuloInteger(i, 2) + 1
set y = i / 2 + 6
set tid = fs_Coords2Id(x, y)
call fs_SetTrackableGroup(tid, 0)
call fs_AddBackgroundEffect("central", tid, true)
call inv100_DrawItem(tid, UnitItemInSlot(u, i))
set i = i + 1
endloop
// ####### large inventory #######
call fs_AddBackgroundEffect("cornerUL", fs_Coords2Id(9, 0), true)
call fs_AddBackgroundEffect("cornerUR", fs_Coords2Id(8 + cols, 0), true)
call fs_AddBackgroundEffect("cornerDL", fs_Coords2Id(9, rows - 1), true)
call fs_AddBackgroundEffect("cornerDR", fs_Coords2Id(8 + cols, rows - 1), true)
set y = 0
loop
exitwhen y >= rows
set x = 0
loop
exitwhen x >= cols
set tid = fs_Coords2Id(x + 9, y)
call fs_SetTrackableGroup(tid, 1)
call fs_AddBackgroundEffect("central", tid, true)
set it = inv100_UnitItemInSlot(u, y * cols + x)
if GetItemTypeId(it) == 0 or IsItemOwned(it) or RectContainsItem(it, bj_mapInitialPlayableArea) then
call set_object_iparam(u, "inv100_item" + I2S(y * cols + x), 0)
set it = null
endif
call inv100_DrawItem(tid, it)
set x = x + 1
endloop
set y = y + 1
endloop
call set_object_iparam(u, "inv100_item-1", 0)
set y = 1
loop
exitwhen y >= rows - 1
call fs_AddBackgroundEffect("borderL" , fs_Coords2Id(9, y), true)
call fs_AddBackgroundEffect("borderR" , fs_Coords2Id(8 + cols, y), true)
set y = y + 1
endloop
set x = 1
loop
exitwhen x >= cols - 1
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(x + 9, 0), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(x + 9, rows - 1), true)
set x = x + 1
endloop
// ####### description box #######
call fs_AddBackgroundEffect("description", fs_Coords2Id(4, 1), true)
call fs_AddBackgroundEffect("cornerUL", fs_Coords2Id(1, 0), true)
call fs_AddBackgroundEffect("borderL" , fs_Coords2Id(1, 1), true)
call fs_AddBackgroundEffect("cornerDL", fs_Coords2Id(1, 2), true)
call fs_AddBackgroundEffect("cornerUR", fs_Coords2Id(6, 0), true)
call fs_AddBackgroundEffect("borderR" , fs_Coords2Id(6, 1), true)
call fs_AddBackgroundEffect("cornerDR", fs_Coords2Id(6, 2), true)
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(2, 0), true)
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(3, 0), true)
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(4, 0), true)
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(5, 0), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(2, 2), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(3, 2), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(4, 2), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(5, 2), true)
// ####### buttons #######
set x = 1
set y = 4
call fs_AddBackgroundEffect("cornerUL", fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("cornerDL", fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("central" , fs_Coords2Id(x, y), true)
call fs_SetTrackableGroup(fs_Coords2Id(x, y), 2)
call fs_AddNamedEffect("button_exit", "BTNExit", fs_Coords2Id(x, y), false)
set x = x + 1
if get_session_iparam("allow_sell") == 1 then
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("central" , fs_Coords2Id(x, y), true)
call fs_SetTrackableGroup(fs_Coords2Id(x, y), 3)
call fs_AddNamedEffect("button_sell", "DISBTNSell", fs_Coords2Id(x, y), false)
call set_session_iparam("button_sell_pos", fs_Coords2Id(x, y))
set x = x + 1
else
call set_session_iparam("button_sell_pos", -1)
endif
if cfgi("inv100_allow_use") == 1 then
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("central" , fs_Coords2Id(x, y), true)
call fs_SetTrackableGroup(fs_Coords2Id(x, y), 4)
call fs_AddNamedEffect("button_use" , "DISBTNUse" , fs_Coords2Id(x, y), false)
call set_session_iparam("button_use_pos", fs_Coords2Id(x, y))
set x = x + 1
else
call set_session_iparam("button_use_pos", -1)
endif
if cfgi("inv100_allow_drop") == 1 then
call fs_AddBackgroundEffect("borderU" , fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("borderD" , fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("central" , fs_Coords2Id(x, y), true)
call fs_SetTrackableGroup(fs_Coords2Id(x, y), 5)
call fs_AddNamedEffect("button_drop" , "DISBTNDrop" , fs_Coords2Id(x, y), false)
call set_session_iparam("button_drop_pos", fs_Coords2Id(x, y))
set x = x + 1
else
call set_session_iparam("button_drop_pos", -1)
endif
call fs_AddBackgroundEffect("cornerUR", fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("cornerDR", fs_Coords2Id(x, y), true)
call fs_AddBackgroundEffect("central" , fs_Coords2Id(x, y), true)
call fs_SetTrackableGroup(fs_Coords2Id(x, y), 6)
call fs_AddNamedEffect("button_pickup", "BTNAutoPickup", fs_Coords2Id(x, y), false)
call set_session_iparam("button_pickup_pos", fs_Coords2Id(x, y))
if get_object_iparam(u, "inv100_auto_pickup") == 1 then
call fs_AddNamedEffect("button_pickup_selected", "selector", fs_Coords2Id(x, y), false)
endif
call fs_AddNamedTextTag("button_label", 380, 400 , " ", 0)
call fs_AddNamedTextTag("item_hint", 150, 720, " ", 0)
call fs_AddNamedTextTag("item_desc", 150, 774, " ", 0)
call fs_AddNamedTextTag("item_cost", 185, 874, " ", 0)
call fs_AddNamedTextTag("item_name", 150, 924, " ", 0)
call fs_PlaySound("Sound\\Interface\\RightGlueScreenPopDown.wav")
call inv100_PlayCineFilter()
// call dbg("player " + cfg("player") + " entered inventory")
endfunction
//################################################################################
function inv100_Exit takes nothing returns nothing
call inv100_PlayCineFilter()
call fs_PlaySound("Sound\\Interface\\RightGlueScreenPopUp.wav")
call PauseUnit(fs_I2U(get_session_iparam("unit")), false)
if cfgi("inv100_lock_cam") == 1 then
call SetCameraTargetControllerNoZForPlayer(Player(fs_GetPlayerID()), fs_I2U(get_session_iparam("unit")), 0, 0, false)
endif
// call dbg("player " + cfg("player") + " exited inventory")
endfunction
//################################################################################
function inv100_SaveToCache takes gamecache cache, string missionkey, string label, unit u returns nothing
local integer i = 0
local integer rows = get_object_iparam(u, "inv100_rows")
local integer cols = get_object_iparam(u, "inv100_cols")
call StoreBoolean(cache, missionkey, label + "_inventory", true)
call StoreInteger(cache, missionkey, label + "_rows", rows)
call StoreInteger(cache, missionkey, label + "_cols", cols)
call StoreInteger(cache, missionkey, label + "_auto_pickup", get_object_iparam(u, "inv100_auto_pickup"))
loop
exitwhen i >= rows * cols
call StoreInteger(cache, missionkey, label + "_item" + I2S(i), GetItemTypeId(inv100_UnitItemInSlot(u, i)))
call StoreInteger(cache, missionkey, label + "_charges" + I2S(i), GetItemCharges(inv100_UnitItemInSlot(u, i)))
set i = i + 1
endloop
// call dbg("saved label '" + label + "'...")
endfunction
//################################################################################
function inv100_LoadFromCache takes gamecache cache, string missionkey, string label, unit u returns nothing
local integer i = 0
local integer rows = GetStoredInteger(cache, missionkey, label + "_rows")
local integer cols = GetStoredInteger(cache, missionkey, label + "_cols")
local item it
if not HaveStoredBoolean(cache, missionkey, label + "_inventory") then
return
endif
call inv100_SetInventorySize(u, rows, cols)
set rows = get_object_iparam(u, "inv100_rows")
set cols = get_object_iparam(u, "inv100_cols")
call set_object_iparam(u, "inv100_auto_pickup", GetStoredInteger(cache, missionkey, label + "_auto_pickup"))
loop
exitwhen i >= rows * cols
call RemoveItem(inv100_UnitItemInSlot(u, i))
if GetStoredInteger(cache, missionkey, label + "_item" + I2S(i)) != 0 then
set it = CreateItem(GetStoredInteger(cache, missionkey, label + "_item" + I2S(i)), 0, 0)
call SetItemCharges(it, GetStoredInteger(cache, missionkey, label + "_charges" + I2S(i)))
call inv100_UnitAddItemToSlot(u, it, i)
endif
set i = i + 1
endloop
if get_object_iparam(u, "inv100_enabled") == 0 then
call TriggerRegisterUnitEvent( fs_I2T(cfgi("inv100_pickup_trigger")), u, EVENT_UNIT_PICKUP_ITEM )
call set_object_iparam(u, "inv100_enabled", 1)
endif
// call dbg("loaded label '" + label + "'...")
endfunction
//################################################################################
function inv100_AutoPickupAction takes nothing returns nothing
local integer i = 0
local unit u = GetTriggerUnit()
local integer p = GetPlayerId(GetOwningPlayer(u))
local integer slots = get_object_iparam(u, "inv100_rows") * get_object_iparam(u, "inv100_cols")
call setcfg("player", I2S(GetPlayerId(GetOwningPlayer(u))))
if IsItemPowerup(GetManipulatedItem()) or get_session_iparam("fs_enabled") == 1 or get_object_iparam(u, "inv100_auto_pickup") == 0 then
return
endif
loop
exitwhen i >= slots
if GetItemTypeId(inv100_UnitItemInSlot(u, i)) == 0 then
call inv100_UnitAddItemToSlot(u, GetManipulatedItem(), i)
return
endif
set i = i + 1
endloop
endfunction
//################################################################################
function inv100_ExitEscapeAction takes nothing returns nothing
if cfgi("inv100_allow_escape") == 1 then
call fs_Shutdown(GetPlayerId(GetTriggerPlayer()))
endif
endfunction
//################################################################################
function inv100_ExitOnDeathAction takes nothing returns nothing
local integer p = GetPlayerId(GetOwningPlayer(GetDyingUnit()))
call setcfg("player", I2S(p))
if get_session_iparam("unit") == fs_H2I(GetDyingUnit()) then
call fs_Shutdown(p)
endif
endfunction
//################################################################################
function inv100_EnterAction takes nothing returns nothing
if GetSpellAbilityId() != cfgi("inv100_ability") then
return
endif
call IssueImmediateOrderBJ( GetTriggerUnit(), "stop" )
call TriggerSleepAction( 0.00 )
call fs_LoadModule(GetPlayerId(GetOwningPlayer(GetTriggerUnit())), "inv100")
endfunction
//################################################################################
function InitTrig_inventory_module takes nothing returns nothing
local trigger t
local integer i = 0
set t = CreateTrigger()
call TriggerAddAction(t, function inv100_AutoPickupAction)
call setcfg("inv100_pickup_trigger", I2S(fs_H2I(t)))
set t = CreateTrigger()
call TriggerAddAction(t, function inv100_ExitOnDeathAction)
call setcfg("inv100_exit_trigger", I2S(fs_H2I(t)))
set t = CreateTrigger()
call TriggerAddAction(t, function inv100_ExitEscapeAction)
loop
exitwhen i >= 12
call TriggerRegisterPlayerEventEndCinematic(t, Player(i))
set i = i + 1
endloop
set t = CreateTrigger()
call TriggerAddAction(t, function inv100_EnterAction)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CHANNEL)
endfunction