-- author: SimonS
-- Inventory scrolling by mouse wheel
registerEventHandler("mouseEvent", "mouseEvtHandler")
function mouseEvtHandler(evt)
if evt == eEvtMouseWheelUp then
wheelUp()
end
if evt == eEvtMouseWheelDown then
wheelDown()
end
end
function wheelUp ()
local items = game:getLink(VGameCurrentCharacter):getLinks(VCharacterItems)
local len = table.getn (items)
local usedItem = game:getLink(VGameUsedItem)
if len == 0 then
game:setValue(VGameUsedItem,getObject("(-1,-1)"))
else
if usedItem:isEmpty() then
game:setValue(VGameUsedItem,items[1])
else
for index = 0, len-1, 1 do
if items[len-index]:getName() == usedItem:getName() then
if len-index == len then
game:setValue(VGameUsedItem,getObject("(-1,-1)"))
else
game:setValue(VGameUsedItem,items[len-index+1])
end
break
end
end
end
end
game:setValue(VGameUsedItemPicked,true)
end
function wheelDown ()
local character = getObject("Game.GameCurrentCharacter")
local items = character:getLinks(VCharacterItems)
local len = table.getn (items)
local usedItem = game:getLink(VGameUsedItem)
if len == 0 then
game:setValue(VGameUsedItem,empty)
else
if usedItem:isEmpty() then
game:setValue(VGameUsedItem,items[len])
else
for i = 1, len, 1 do
if items[i]:getName() == usedItem:getName() then
if i == 1 then
game:setValue(VGameUsedItem,getObject("(-1,-1)"))
else
game:setValue(VGameUsedItem,items[i-1])
end
break
end
end
end
end
game:setValue(VGameUsedItemPicked,true)
end