• 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 (Action) Help with this script please (TFS 1.2)

Newani

New Member
Joined
Sep 11, 2024
Messages
20
Reaction score
2
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ICE)
    setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ICE)
    setCombatParam(combat, COMBAT_PARAM_CREATEITEM, 22381)
    return true
end

    if(os.time() - getPlayerStorageValue(cid, 202223)) < 100 then
       doPlayerSendCancel(cid, "You are exausted.")
       doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    return TRUE
end
 setPlayerStorageValue(cid, 202223, os.time())
    doCreatureSay(cid, "Release Recollection!", TALKTYPE_ORANGE_1)
    return TRUE
end
 
Solution
You have some code lines without scope of your function.


For better introduction go to actions/actions.xml and define path to lua file where your action will be defined

XML:
<action itemid="x" script="your_file.lua" />

x- id of an item which will be usable (item which you want to use)
your_file - file where code will be stored


Fill your config as you want and it will spawn item on top of clicked one. Adding item to player's backpack requires other functions
LUA:
local config = {
    storage         = 202223,
    cooldown        = 2, -- seconds
    newItemId       = 22381,
    effectSuccess   = CONST_ME_ICE,
    effectFail      = CONST_ME_POFF,
    consumeUsedItem = false
}

function onUse(player, item, fromPosition, target...
Not working. I need the script correctly. The way the "return true" statement is placed, and everything around it, is probably incorrect, or I'm not sure if it should be replaced.
The function should be designed so that when a certain object on the ground is used, it should create another object, in this case, the item ID: 22381.
 

Attachments

You have some code lines without scope of your function.


For better introduction go to actions/actions.xml and define path to lua file where your action will be defined

XML:
<action itemid="x" script="your_file.lua" />

x- id of an item which will be usable (item which you want to use)
your_file - file where code will be stored


Fill your config as you want and it will spawn item on top of clicked one. Adding item to player's backpack requires other functions
LUA:
local config = {
    storage         = 202223,
    cooldown        = 2, -- seconds
    newItemId       = 22381,
    effectSuccess   = CONST_ME_ICE,
    effectFail      = CONST_ME_POFF,
    consumeUsedItem = false
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local now = os.time()
    local lastUse = player:getStorageValue(config.storage)

    if lastUse ~= -1 and (now - lastUse) < config.cooldown then
        player:sendCancelMessage("You are exhausted.")
        player:getPosition():sendMagicEffect(config.effectFail)
        return true
    end

    player:setStorageValue(config.storage, now)
    Game.createItem(config.newItemId, 1, toPosition)
    toPosition:sendMagicEffect(config.effectSuccess)
    player:say("Release Recollection!", TALKTYPE_MONSTER_SAY)

    if config.consumeUsedItem then
        item:remove(1)
    end

    return true
end
 
Last edited:
Solution
Back
Top