• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua [OnUse] TFS1.4.2

srunobantana

Active Member
Joined
Oct 24, 2021
Messages
55
Reaction score
34
Could someone please help me create an 'OnUse' that does not require getting close? I would like to use Minato's kunai from a distance, but currently it can only be used if the character walks up to the 'OnUse'.
LUA:
local configKunai = {
    itemId = 37441,
    effect = CONST_ME_BLOCKHIT,
    textKunai = "Hiraishin no Jutsu",
    textColor = 205,
    actionId = 50000
}

HIRAISHIN_KUNAIS = HIRAISHIN_KUNAIS or {}

local function createKunaiAtPosition(player, pos)
    local playerId = player:getId()

    if HIRAISHIN_KUNAIS[playerId] then
        local oldKunai = HIRAISHIN_KUNAIS[playerId]
        if oldKunai:getId() > 0 then
            oldKunai:remove()
        end
    end

    local kunai = Game.createItem(configKunai.itemId, 1, pos)
    if not kunai then
        player:sendCancelMessage("Não foi possível criar a kunai.")
        pos:sendMagicEffect(CONST_ME_POFF)
        return
    end

    kunai:setActionId(configKunai.actionId)
    kunai:setAttribute("description", "Kunai marcada por " .. player:getName())
    HIRAISHIN_KUNAIS[playerId] = kunai

    pos:sendMagicEffect(configKunai.effect)
    Game.sendAnimatedText(configKunai.textKunai, pos, configKunai.textColor)

    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Kunai marcada criada neste local!")
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local markPosition = toPosition or fromPosition
    createKunaiAtPosition(player, markPosition)

    markPosition:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end


 
cant you simply use "allowFarUse(true)"?

Edit:
in actions.xml
example:
<action itemid="2264" script="custom/test.lua" allowfaruse="1" />

add "allowfaruse="1" behind the declaration of the script and keep your script just like it is.

Tested and works in TFS 1.4.2.
 
Last edited:

Similar threads

Back
Top