Custom Item-Dragging System

From The Official Visionaire Studio: Adventure Game Engine Wiki
Name Type By
Custom Item-Dragging System Definition Christopher A. Summer


This script is an alternative for the default item-dragging in Visionaire Studio. It renders a clicked item next to the cursor and allows the item cursor to react to object hotspots in various ways (scale, rotate etc.). You can adjust the parameters at the top of the script to customize the behaviour.


Instructions

  1. Add the main script to the Visionaire Studio Script editor & set the script as a definition script.
  2. Disable the default item-dragging by unchecking Allow dragging of items from inventory in the game properties and/or unchecking Items can be dragged with this command for all command buttons.
  3. Choose "Combined command" as the command type for the command button you wish to drag items with.
  4. In your actions for combining an item with an object/character/item do not use the execution type "Item dropped" but instead choose "Executed command" and select the item (combined command).


Main Script

local ItemSprite
-- SET OFFSET NEXT TO MOUSE-CURSOR:
local X_Offset = 32
local Y_Offset = -16
-- SET GENERAL SCALE AND SCALE-WOBBLE WHEN ACTIVE:
local ItemScale
local ItemScaleGeneral   = 0.75
local ItemScaleFactor    = 0.025  -- 0.0 to deactivate scale-wobble
local ItemScaleSpeed     = 0.0125 -- 0.0 to deactivate scale-wobble
-- SET ROTATION-WOBBLE WHEN ACTIVE:
local ItemRot
local ItemRotationFactor = 0.2    -- 0.0 to deactivate rotation-wobble
local ItemRotationSpeed  = 0.5    -- 0.0 to deactivate rotation-wobble
-- SET ALPHA WHEN INACTIVE AND ACTIVE:
local ItemAlpha
local ItemAlphaInactive  = 0.75
local ItemAlphaActive    = 1.0
-- SET COLOR WHEN INACTIVE AND ACTIVE:
local ItemColor
local ItemColorInactive  = 0xdddddd
local ItemColorActive    = 0xffffff
---

graphics.addDrawFunc("ItemDragCustom()",1)

function ItemDragCustom()
 
 --if game.UsedItem then
 if not game.UsedItem:isEmpty() then
  
  ItemScale = ItemScaleGeneral
  
  --
  if game.CurrentObject:isEmpty() then
   ItemScale = ItemScaleGeneral
   ItemRot   = 0.0
   ItemAlpha = ItemAlphaInactive
   ItemColor = ItemColorInactive
  else
   ItemScale = ItemScaleGeneral + (ItemScaleFactor * math.sin(getTime() * (ItemScaleSpeed) ))
   ItemRot   = ItemRotationFactor * math.sin(getTime() * (ItemRotationSpeed*0.01) )
   ItemAlpha = ItemAlphaActive
   ItemColor = ItemColorActive
  end
  --
  
  ItemSprite = graphics.loadFromFile( game.UsedItem.Sprite.Sprite:getPath() )
  ItemSprite.position = {
   x = (getCursorPos().x + X_Offset),
   y = (getCursorPos().y + Y_Offset)
  }
  ItemSprite.rotationCenter = {
   x=ItemSprite.position.x + (ItemSprite.width/2),
   y=ItemSprite.position.y+(ItemSprite.height/2)
  }
  ItemSprite.scale = ItemScale
  ItemSprite.rotation = ItemRot
  graphics.drawSprite( ItemSprite , ItemAlpha , ItemColor)
 end
 
end

game.DraggableItems = false

function Unuse(eventType)
  if eventType == eEvtMouseRightButtonUp then
    game.UsedItem = emptyObject
  end
end

registerEventHandler("mouseEvent", "Unuse")