10:15:17: Error: Unknown data-field "ObjectIsItem".
if typ == eEvtMouseLeftButtonDown and game.CurrentObject.ObjectIsItem and game.UsedItem:isEmpty() then
If game.UsedItem = emptyObject
execute the rest of the actions listed below
else
just clear the currently held item
-- author: SimonS (edited by ste red)
-- Inventory scrolling by mouse wheel
registerEventHandler("mouseEvent", "mouseEvtHandler")
function mouseEvtHandler(evt)
if evt == eEvtMouseWheelUp then
if not game.UsedItem:isEmpty() then
wheelUp()
end
end
if evt == eEvtMouseWheelDown then
if not game.UsedItem:isEmpty() then
wheelDown()
end
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,items[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,items[len])
else
game:setValue(VGameUsedItem,items[i-1])
end
break
end
end
end
end
game:setValue(VGameUsedItemPicked,true)
end
function onItemDrag(eventType)
-- set object under cursor and item which is (maybe) dragged
local curObj=game:getLink(VGameCurrentObject)
if not game.UsedItem:isEmpty() then
-- if an item gets dragged, get its animation
local anim = getObject("ActiveAnimations["..game:getLink(VGameUsedItem):getName().."]")
-- dynamically set the frames for the inactive state to the first half of whole animation and the active part to the second half. This results in having also animated items with an inactive/active state
-- needs a VALUE called "Frames" INSIDE the ITEM. This Value must be set to the same amount of Frames in the whole animation.
local framecount = getObject("Objects["..game:getLink(VGameUsedItem):getName().."].ObjectValues[Frames]"):getInt(VValueInt)
local inactive_first = 1
local inactive_last = framecount/2
local active_first = (framecount/2) +1
local active_last = framecount
-- debug
-- print(""..inactive_first.." "..inactive_last.." "..active_first.." "..active_last.."")
-- if mouse moves over an object or NPC character (current char doesn't get tracked)
if eventType == eEvtMouseMove and (curObj:getId().tableId == eObjects or curObj:getId().tableId == eCharacters ) then
-- set animation to ACTIVE
anim:setValue(VAnimationFirstFrame, active_first)
anim:setValue(VAnimationLastFrame, active_last)
else
-- else set animation to INACTIVE to reset it
anim:setValue(VAnimationFirstFrame, inactive_first)
anim:setValue(VAnimationLastFrame, inactive_last)
end
-- if an item gets dragged and a a CLICK action was used, the animation of the item should also be resetted to prevent "always active items" after successful action
if eventType ~= eEvtMouseMove and not game.UsedItem:isEmpty() and anim ~= nil then
anim:setValue(VAnimationFirstFrame, inactive_first)
anim:setValue(VAnimationLastFrame, inactive_last)
return true
end
end
end
registerEventHandler("mouseEvent", "onItemDrag", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp})
function mouseEvt(typ, pos)
if typ == eEvtMouseLeftButtonDown and game.CurrentObject.IsItem and game.UsedItem:isEmpty() then
game.UsedItem = game.CurrentObject; game.DestinationItemPicked = true
elseif typ == eEvtMouseLeftButtonUp or typ == eEvtMouseRightButtonDown then
if not game.UsedItem:isEmpty() then clearLink(VGameUsedItem); game.ActiveCommand = Interfaces["example"].InterfaceStandardCommand end
end
end
registerEventHandler("mouseEvent", "mouseEvt") -- start the mouse event handler on game launch
registerEventHandler("mouseEvent", "onItemDrag", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp})
if eventType ~= eEvtMouseMove and not game.UsedItem:isEmpty() and anim ~= nil then