# 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

```markup
<!-- Registration for the script below -->
<action itemid="2148" script="change_gold.lua" />
```

```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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stigmax.gitbook.io/tfs-guide/interface-actions/actions-scripting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
