Scripting

Script Structure

onUse(player, item, fromPosition, target, toPosition, isHotkey)

Parameters:

  • player: Player who is using the item.

  • item: Item which is being clicked on by the player.

  • fromPosition: Position of where the item is clicked from.

  • target: The item/creature the item is used on (use with, like a fishing rod). If the item does not have the use with flag, target is equal to item.

  • toPosition: Position of where the target is located.

  • isHotkey: True if the item was used from hotkeys, otherwise false.

Return Value:

  • true: Will allow the usage of the item, no message will be sent.

  • false: Will not use the item, player will be sent a cancel message containing the words "You cannot use this object."

Example

<!-- Registration for the script below -->
<action itemid="2148" script="change_gold.lua" />
-- data/actions/scripts/change_gold.lua
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getName() == "Delusion" then
        item:transform(2160)
        return true
    end
    return false -- Anybody who is not me will not be able to use the item!
end

Last updated