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