• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Fullscreen Inventory 2: item array?

Status
Not open for further replies.
Level 2
Joined
Dec 8, 2006
Messages
8
In the Fullscreen Inventory 2, where is the items stored like which varaible, also what script would i need to run to move an item to the inventory screen?
 
Level 2
Joined
Dec 8, 2006
Messages
8
but then how what is the code that activates when a item is sent to the inventory, like for example - i want to make a unit pick up an item and automatically send it to the inventory system, i know there is an autopick up but i want this to work even if they haven't got it on.
 
Level 2
Joined
Dec 8, 2006
Messages
8
yeah thou there is a problem all of it is written in JASS scripting, i only know the basics, which is all conditions are at the bottom, and events and actions are at the top or something similar to that is it possible for anyone that knows JASS well to look at the code and tell me which part i need to copy and exactly how i need to implement it.
 
Level 2
Joined
Dec 8, 2006
Messages
8
thnxs alot anyway to stop you from the trouble of dling the map and looking through here is the trigger:

//################################################################################
//
// script : FSGUI (FullScreen Graphic User Interface)
// version : 2.01
// date : 06.08.2005
//
//
// made by : DimonT aka ZibadaMX
// mail : [email protected]
// icq : 937160
// www : http://dimon.xgm.ru/fsgui/
//
//################################################################################
//
// Module API :
//
// Initialization:
//
// fs_SetTrackableGroup(integer tid, integer g)
// fs_BuildGroupIDs()
//
//
// Variable Handling:
//
// 1. Globals (configuration):
// setcfg(string key, string val)
// cfg(string key)
// cfgi(string key)
// cfgr(string key)
//
// 2. Object Specific:
// set_object_iparam(handle h, string key, integer val)
// set_object_rparam(handle h, string key, real val)
// get_object_iparam(handle h, string key)
// get_object_rparam(handle h, string key)
//
// 3. Session (per-player):
// fs_GetPlayerID()
// set_session_param(string key, string val)
// set_session_iparam(string key, integer val)
// set_session_rparam(string key, real val)
// get_session_param(string key)
// get_session_iparam(string key)
// get_session_rparam(string key)
//
//
//
//
// Trackable grid mapping:
//
// fs_Coords2Id(integer x, integer y)
// fs_GetTrackableGroup(integer tid)
// fs_GetTrackableGroupID(integer tid)
// fs_GetTriggeringTrackableID()
// fs_GetTrackableX(integer tid)
// fs_GetTrackableY(integer tid)
//
// Text Tags:
//
// fs_AddNamedTextTag(string name, real x, real y, string msg, real size)
// fs_SetNamedTextTagText(string name, string msg, real size)
//
// Effects:
//
// fs_AddBackgroundEffectXY(string model, real x, real y, boolean useskin)
// fs_AddBackgroundEffect(string model, integer tid, boolean useskin)
// fs_AddNamedEffectXY(string name, string model, real x, real y, boolean useskin)
// fs_AddNamedEffect(string name, string model, integer tid, boolean useskin)
//
// Callback Functions:
//
// fs_[modname]_Init()
// fs_[modname]_ClickHandler()
// fs_[modname]_HoverHandler()
// fs_[modname]_Exit()
//
//
// In Game API:
//
// fs_LoadModule(int playerID, string modname)
// fs_Shutdown(int playerID)
//
//
//################################################################################


//################################################################################
constant function fs_H2I takes handle h returns integer
return h
return 0
endfunction

constant function fs_I2U takes integer i returns unit
return i
return null
endfunction

constant function fs_I2T takes integer i returns trigger
return i
return null
endfunction

constant function fs_I2TT takes integer i returns texttag
return i
return null
endfunction

constant function fs_I2It takes integer i returns item
return i
return null
endfunction

constant function fs_I2D takes integer i returns destructable
return i
return null
endfunction

constant function fs_I2FM takes integer i returns fogmodifier
return i
return null
endfunction



//################################################################################
function setcfg takes string key, string val returns nothing
call StoreString(udg_fs_cache, "config", key, val)
endfunction

function cfg takes string key returns string
return GetStoredString(udg_fs_cache, "config", key)
endfunction

function cfgr takes string key returns real
return S2R(cfg(key))
endfunction

function cfgi takes string key returns integer
return S2I(cfg(key))
endfunction



//################################################################################
function fs_echo takes integer playerID, string msg returns nothing
if playerID == -1 then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,5.00, msg)
else
call DisplayTimedTextToPlayer(Player(playerID),0,0,5.00, msg)
endif
endfunction


//################################################################################

function get_object_iparam takes handle h, string key returns integer
return GetStoredInteger(udg_fs_cache, I2S(fs_H2I(h)), key)
endfunction

function set_object_iparam takes handle h, string key, integer val returns nothing
call StoreInteger(udg_fs_cache, I2S(fs_H2I(h)), key, val)
endfunction

function get_object_rparam takes handle h, string key returns real
return GetStoredReal(udg_fs_cache, I2S(fs_H2I(h)), key)
endfunction

function set_object_rparam takes handle h, string key, real val returns nothing
call StoreReal(udg_fs_cache, I2S(fs_H2I(h)), key, val)
endfunction

function flush_object takes handle h returns nothing
call FlushStoredMission(udg_fs_cache, I2S(fs_H2I(h)))
endfunction

//################################################################################

function get_session_iparam takes string key returns integer
return GetStoredInteger(udg_fs_cache, "session" + cfg("player"), key)
endfunction

function set_session_iparam takes string key, integer val returns nothing
call StoreInteger(udg_fs_cache, "session" + cfg("player"), key, val)
endfunction

function get_session_rparam takes string key returns real
return GetStoredReal(udg_fs_cache, "session" + cfg("player"), key)
endfunction

function set_session_rparam takes string key, real val returns nothing
call StoreReal(udg_fs_cache, "session" + cfg("player"), key, val)
endfunction

function get_session_param takes string key returns string
return GetStoredString(udg_fs_cache, "session" + cfg("player"), key)
endfunction

function set_session_param takes string key, string val returns nothing
call StoreString(udg_fs_cache, "session" + cfg("player"), key, val)
endfunction


//################################################################################
function fs_chr takes integer i returns string
local string abc = "abcdefghijklmnopqrstuvwxyz"
local string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local string digits = "0123456789"
if i >= 65 and i <= 90 then
return SubString(ABC, i-65,i-64)
elseif i >= 97 and i <= 122 then
return SubString(abc, i-97,i-96)
elseif i >= 48 and i <= 57 then
return SubString(digits, i-48,i-47)
endif
return ""
endfunction


//################################################################################
function fs_iif takes boolean cond, string s1, string s2 returns string
if cond then
return s1
endif
return s2
endfunction


//################################################################################
constant function fs_Coords2Id takes integer x, integer y returns integer
return y * 20 + x
endfunction


//################################################################################
function fs_BuildGroupIDs takes nothing returns nothing
local integer i = 0
local integer g
local integer array count
loop
exitwhen i >= 200
set g = get_session_iparam("tk_group" + I2S(i))
if g != -1 then
call set_session_iparam("tk_groupid" + I2S(i), count[g])
set count[g] = count[g] + 1
else
call set_session_iparam("tk_groupid" + I2S(i), -1)
endif
set i = i + 1
endloop
endfunction


//################################################################################
function fs_SetTrackableGroup takes integer tid, integer g returns nothing
call set_session_iparam("tk_group" + I2S(tid), g)
endfunction


//################################################################################
function fs_GetTrackableGroup takes integer tid returns integer
return get_session_iparam("tk_group" + I2S(tid))
endfunction


//################################################################################
function fs_GetTrackableGroupID takes integer tid returns integer
return get_session_iparam("tk_groupid" + I2S(tid))
endfunction

//################################################################################
function fs_GetTriggeringTrackableID takes nothing returns integer
return get_session_iparam("fs_trigger_tid")
endfunction


//################################################################################
function fs_GetPlayerID takes nothing returns integer
return cfgi("player")
endfunction

//################################################################################
function fs_GetTrackableX takes integer tid returns real
return cfgr("tk_" + I2S(tid) + "_x" + I2S(fs_GetPlayerID()))
return get_session_rparam("tk_x" + I2S(tid))
endfunction

//################################################################################
function fs_GetTrackableY takes integer tid returns real
return cfgr("tk_" + I2S(tid) + "_y" + I2S(fs_GetPlayerID()))
return get_session_rparam("tk_y" + I2S(tid))
endfunction


//################################################################################
function fs_AddNamedTextTag takes string name, real x, real y, string msg, real size returns nothing
local texttag tt
local integer id = get_session_iparam("fs_texttags")

call DestroyTextTag(fs_I2TT(get_session_iparam("fs_texttag_" + name)))

if msg == "" then
call set_session_iparam("fs_texttag_" + name, 0)
return
endif
if size == 0 then
set size = cfgr("fs_texttag_size")
endif

set tt = CreateTextTag()
call SetTextTagPos(tt, get_session_rparam("fs_base_x") + x, get_session_rparam("fs_base_y") + y, 0)
call SetTextTagColor(tt, 255, 255, 255, 255)
call SetTextTagVelocity(tt, 0, 0)
call SetTextTagVisibility(tt, true)
call SetTextTagText(tt, msg, size)
call SetTextTagPermanent(tt, true)

call set_session_iparam("fs_texttag_" + name, fs_H2I(tt))
call set_session_iparam("fs_texttag" + I2S(id), fs_H2I(tt))
call set_session_iparam("fs_texttags", id + 1)
// call debugMsg("fs_AddNamedTextTag: name = " + name + " x = " + R2SW(x, 0, 0) + ", y = " + R2SW(y, 0, 0) + ", msg = " + msg)
endfunction


//################################################################################
function fs_SetNamedTextTagText takes string name, string msg, real size returns nothing
local texttag tt = fs_I2TT(get_session_iparam("fs_texttag_" + name))
if size == 0 then
set size = cfgr("fs_texttag_size")
endif
call SetTextTagText(tt, msg, size)
endfunction



//################################################################################
function fs_PlaySound takes string soundfile returns nothing
if cfgi("fs_sound") == 0 then
return
endif
if Player(fs_GetPlayerID()) == GetLocalPlayer() then
call PlaySound(soundfile)
endif
endfunction


//################################################################################
function fs_RegisterEffect takes integer id, string name returns nothing
call StoreInteger(udg_fs_cache, "FX", name, id)
endfunction



//################################################################################
function fs_AddBackgroundEffectXY takes string modelfile, real x, real y, boolean useskin returns destructable
local destructable d
local integer id = get_session_iparam("fs_effects")

if useskin then
set modelfile = modelfile + get_session_param("fs_skin")
endif
set d = CreateDestructable(GetStoredInteger(udg_fs_cache, "FX", modelfile), get_session_rparam("fs_base_x") + x, get_session_rparam("fs_base_y") + y, 0, 1.0, 1)

call set_session_iparam("fs_effect" + I2S(id), fs_H2I(d))
call set_session_iparam("fs_effects", id + 1)
return d
endfunction


//################################################################################
function fs_AddBackgroundEffect takes string modelfile, integer tid, boolean useskin returns destructable
return fs_AddBackgroundEffectXY(modelfile, fs_GetTrackableX(tid), fs_GetTrackableY(tid), useskin)
endfunction


//################################################################################
function fs_AddNamedEffectXY takes string name, string modelfile, real x, real y, boolean useskin returns nothing
call RemoveDestructable(fs_I2D(get_session_iparam("fs_effect_" + name)))
if modelfile != "" then
call set_session_iparam("fs_effect_" + name, fs_H2I(fs_AddBackgroundEffectXY(modelfile, x, y, useskin)))
else
call set_session_iparam("fs_effect_" + name, 0)
endif
endfunction


//################################################################################
function fs_AddNamedEffect takes string name, string modelfile, integer tid, boolean useskin returns nothing
call fs_AddNamedEffectXY(name, fs_iif(tid >= 0, modelfile, ""), fs_GetTrackableX(tid), fs_GetTrackableY(tid), useskin)
endfunction


//################################################################################
function fs_ClickHandler takes nothing returns nothing
local integer tid = get_object_iparam(GetTriggeringTrackable(), "id")
local integer p = get_object_iparam(GetTriggeringTrackable(), "p")

call setcfg("player", I2S(p))
if get_session_iparam("fs_enabled") == 0 then
return
endif

call set_session_iparam("fs_trigger_tid", tid)

call ExecuteFunc(get_session_param("fs_module") + "_ClickHandler")
endfunction


//################################################################################
function fs_HoverHandler takes nothing returns nothing
local integer tid = get_object_iparam(GetTriggeringTrackable(), "id")
local integer p = get_object_iparam(GetTriggeringTrackable(), "p")

call setcfg("player", I2S(p))
if get_session_iparam("fs_enabled") == 0 then
return
endif

call set_session_iparam("fs_trigger_tid", tid)

call ExecuteFunc(get_session_param("fs_module") + "_HoverHandler")
endfunction



//################################################################################
constant function fs_GetRaceID takes integer p returns string
local race r = GetPlayerRace(Player(p))
if r == RACE_NIGHTELF then
return "4"
elseif r == RACE_UNDEAD then
return "2"
elseif r == RACE_ORC then
return "3"
endif
return "1"
endfunction



//################################################################################
function fs_Shutdown takes integer p returns nothing
local integer i
local destructable d
local texttag tt

local real x
local real y

call setcfg("player", I2S(p))

if get_session_iparam("fs_enabled") == 0 then
return
endif


// ############ reset camera and visibility ############
if Player(p) == GetLocalPlayer() then
call SetCameraBoundsToRect(bj_mapInitialCameraBounds)
call ResetToGameCamera(0)
call SetCameraPosition(get_session_rparam("fs_cam_x"), get_session_rparam("fs_cam_y"))
endif

set x = get_session_rparam("fs_base_x")
set y = get_session_rparam("fs_base_y")

call DestroyFogModifier(fs_I2FM(get_session_iparam("fs_fogmodifier")))
call SetFogStateRect(Player(p), FOG_OF_WAR_MASKED, Rect(x + 100 , y + 100, x + 2100, y + 1100), false)


// ##### exec module shutdown func #####

call ExecuteFunc(get_session_param("fs_module") + "_Exit")

// ########## do some cleanup ###########

set i = get_session_iparam("fs_effects") - 1
loop
exitwhen i < 0
set d = fs_I2D(get_session_iparam("fs_effect" + I2S(i)))
call RemoveDestructable(d)
set i = i - 1
endloop

set i = get_session_iparam("fs_texttags") - 1
loop
exitwhen i < 0
set tt = fs_I2TT(get_session_iparam("fs_texttag" + I2S(i)))
call DestroyTextTag(tt)
set i = i - 1
endloop


call set_session_iparam("fs_enabled", 0)
endfunction


//################################################################################
function fs_LoadModule takes integer p, string modname returns nothing
local integer i = 0
local real x
local real y
local fogmodifier fm

if p >= cfgi("max_players") then
call fs_echo(p, "|c00ff0000ERROR:|r cannot access fullscreen interface")
call fs_echo(p, "(try increasing max_players setting in map configuration)")
return
endif

call setcfg("player", I2S(p))

if get_session_iparam("fs_enabled") == 1 then
call fs_Shutdown(p)
endif

call FlushStoredMission(udg_fs_cache, "session" + I2S(p))

set x = cfgr("fs_base_x" + I2S(p))
set y = cfgr("fs_base_y" + I2S(p))
call set_session_rparam("fs_base_x", x)
call set_session_rparam("fs_base_y", y)


set fm = CreateFogModifierRect(Player(p), FOG_OF_WAR_VISIBLE, Rect(x + 100 , y + 100, x + 2100, y + 1100), false, false)
call set_session_iparam("fs_fogmodifier", fs_H2I(fm))
call FogModifierStart(fm)

set x = x + 1024
set y = y + 512

// ############# set camera #############

call set_session_param("fs_module", modname)
call set_session_rparam("fs_cam_x", GetCameraTargetPositionX())
call set_session_rparam("fs_cam_y", GetCameraTargetPositionY())

if Player(p) == GetLocalPlayer() then
call SetCameraPosition(x,y)
call SetCameraBounds(x,y,x,y,x,y,x,y)
endif



// ############## init vars #############

call set_session_iparam("fs_enabled", 1)
call set_session_iparam("fs_effect_count", 0)

if cfgi("fs_skin") == 0 then
call set_session_param("fs_skin", fs_GetRaceID(p))
else
call set_session_param("fs_skin", cfg("fs_skin"))
endif

loop
exitwhen i >= 200
call set_session_iparam("tk_group" + I2S(i), -1)
set i = i + 1
endloop

// ##### exec module init functions #####

call ExecuteFunc(modname + "_Init")
call fs_BuildGroupIDs()
endfunction


//################################################################################
function fs_InitPlayer takes nothing returns nothing
local timer tm = GetExpiredTimer()
local integer p = cfgi("player")
local integer i = 0
local integer j
local trackable tk
local trigger t
local real x
local real y

if p >= cfgi("max_players") then
call DestroyTimer(tm)
return
endif



set x = cfgr("base_x")
set y = cfgr("base_y") + p * 1200

if y + 1100 > GetRectMaxY(GetWorldBounds()) then
call fs_echo(-1, "|c00ff0000WARNING:|r FSGUI Init: not enough map space for players " + I2S(p + 1) + "+")
call fs_echo(-1, "(try increasing your map height)")
call setcfg("max_players", I2S(p))
call DestroyTimer(tm)
return
endif

call setcfg("fs_base_x" + I2S(p), R2S(x))
call setcfg("fs_base_y" + I2S(p), R2S(y))

set i = 0
loop
exitwhen i >= 10
set j = 0
loop
exitwhen j >= 20
set tk = CreateTrackable("square.mdx", x + 74 + 100 * j, y + 962 - 100 * i, 0)
set t = CreateTrigger()
call TriggerRegisterTrackableHitEvent(t, tk)
call TriggerAddAction(t, function fs_ClickHandler)
set t = CreateTrigger()
call TriggerRegisterTrackableTrackEvent(t, tk)
call TriggerAddAction(t, function fs_HoverHandler)
call set_object_iparam(tk, "p", p)
call set_object_iparam(tk, "id", i * 20 + j)

call setcfg("tk_" + I2S(i * 20 + j) + "_x" + I2S(p), R2S(74 + (100*j)))
call setcfg("tk_" + I2S(i * 20 + j) + "_y" + I2S(p), R2S(1024 - 62 - (100*i)))
set j = j + 1
endloop

// ### dummy left & right border trackables
call CreateTrackable("square.mdx", x + 74 + 2000, y + 962 - 100 * i, 0)
call CreateTrackable("square.mdx", x + 74 - 100 , y + 962 - 100 * i, 0)

set i = i + 1
endloop

// ### dummy top & bottom border trackables

set i = -1
loop
exitwhen i > 20
call CreateTrackable("square.mdx", x + 74 + 100 * i, y + 1062 , 0)
call CreateTrackable("square.mdx", x + 74 + 100 * i, y - 38, 0)

set i = i + 1
endloop

call setcfg("player", I2S(p + 1))

endfunction

//################################################################################
function fs_Initialize takes nothing returns nothing
local integer i = 0
local integer p = 0
local integer j
local trigger t
local timer tm
local real x
local real y

// ############### set up workspace ##############
call setcfg("base_x", R2S(GetRectMinX(bj_mapInitialPlayableArea) + 100.00))
call setcfg("base_y", R2S(GetRectMinY(bj_mapInitialPlayableArea) + 100.00))

set bj_mapInitialPlayableArea = Rect(cfgr("base_x") + 2300, GetRectMinY(bj_mapInitialPlayableArea), GetRectMaxX(bj_mapInitialPlayableArea), GetRectMaxY(bj_mapInitialPlayableArea))


// ############### set up path blocker line ##############
set x = cfgr("base_x") + 2200
set y = GetRectMinY(GetWorldBounds())

loop
exitwhen y > GetRectMaxY(GetWorldBounds())
call CreateDestructable('BX00', x, y, 0, 1.28, 0)
set y = y + 128
endloop

// ############### auto detect max players if necessary ##############
if cfgi("max_players") <= 0 then
loop
exitwhen i >= 12
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
call setcfg("max_players", I2S(i + 1))
endif
set i = i + 1
endloop
endif

set tm = CreateTimer()
call TimerStart(tm, 0.00, true, function fs_InitPlayer)
endfunction



//################################################################################
function fs_ForceCameraAction takes nothing returns nothing
if GetStoredInteger(udg_fs_cache, "session" + I2S(GetPlayerId(GetLocalPlayer())), "fs_enabled") != 1 then
return
endif
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 269.00, 0 )
call SetCameraField(CAMERA_FIELD_ROTATION, 90.00, 0 )
call SetCameraField(CAMERA_FIELD_FARZ, 5000.00, 0 )
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 3100.00, 0 )
call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 44.00, 0 )
endfunction




//################################################################################
function InitTrig_FSGUI_main_script takes nothing returns nothing
local trigger t

set t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, 0.05)
call TriggerAddAction(t, function fs_ForceCameraAction)

set gg_trg_FSGUI_main_script = CreateTrigger()
call TriggerAddAction(gg_trg_FSGUI_main_script, function fs_Initialize)

set udg_fs_cache = InitGameCache("FSGUI.w3v")
call FlushGameCache(udg_fs_cache)
call SaveGameCache(udg_fs_cache)
set udg_fs_cache = InitGameCache("FSGUI.w3v")
endfunction


ps. i tried e-mailing him the project i found out was abandoned along time ago :( and thnxs for helping
 
Level 2
Joined
Dec 8, 2006
Messages
8
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
 
Status
Not open for further replies.
Top