• 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 Total noob needs help with reward quest action script

xomuz

New Member
Joined
Jan 19, 2024
Messages
8
Reaction score
3
Can somebody explain me this. I’m coming from TFS 0.4, and now in TFS 1.4.2 I don’t even know how to create a simple reward quest ike where clicking on a body gives you an item.
I tried using RME as usual by setting the Action ID to 2000, then a Unique ID, and adding items to the Contents, but it just doesn’t work.

Switching to scripts, I looked at the default Annihilator script 'quests.lua', and I noticed that storage values are different. Back in TFS 0.4, you would normally use storage values between 1000 and 65535, but now it looks like storage is tied directly to the item ID itself?
player:setStorageValue(item.uid, 1)

But what if I want to use the same item in multiple quests?
How should it look now in RME and in actions.xml?
 
Can somebody explain me this. I’m coming from TFS 0.4, and now in TFS 1.4.2 I don’t even know how to create a simple reward quest ike where clicking on a body gives you an item.
I tried using RME as usual by setting the Action ID to 2000, then a Unique ID, and adding items to the Contents, but it just doesn’t work.

Switching to scripts, I looked at the default Annihilator script 'quests.lua', and I noticed that storage values are different. Back in TFS 0.4, you would normally use storage values between 1000 and 65535, but now it looks like storage is tied directly to the item ID itself?
player:setStorageValue(item.uid, 1)

But what if I want to use the same item in multiple quests?
How should it look now in RME and in actions.xml?
you can use,
Insert Action 2000 into the trunk or corpse, save it on data/scripts
Code:
local STORAGE = 1234
local DURATION = 24 * 60 * 60

local Actscript = Action()
function Actscript.onUse(player, item)
    if player:getStorageValue(STORAGE) > os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "MESSAGE")
        return true
    end
  
    player:setStorageValue(STORAGE, os.time() + DURATION)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "MESSAGE")
    player:addItem(2148)
    -- item:remove(1) < remove item?
    return true
end

Actscript:uid(29670)  -- uid of the corpse or chest
Actscript:register()
 
you can use,
Insert Action 2000 into the trunk or corpse, save it on data/scripts
Code:
local STORAGE = 1234
local DURATION = 24 * 60 * 60

local Actscript = Action()
function Actscript.onUse(player, item)
    if player:getStorageValue(STORAGE) > os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "MESSAGE")
        return true
    end
 
    player:setStorageValue(STORAGE, os.time() + DURATION)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "MESSAGE")
    player:addItem(2148)
    -- item:remove(1) < remove item?
    return true
end

Actscript:uid(29670)  -- uid of the corpse or chest
Actscript:register()
it looks a bit weird and with duration

I would prefer to modify this original script from Annihilator Rewards but instead to get just one reward, let’s say 2400.
Can somebody explain why it sets storage two times? player:setStorageValue(PlayerStorageKeys.annihilatorReward, 1) and player:setStorageValue(item.uid, 1)
LUA:
local annihilatorReward = {1990, 2400, 2431, 2494}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid <= 1250 or item.uid >= 30000 then
        return false
    end

    local itemType = ItemType(item.uid)
    if itemType:getId() == 0 then
        return false
    end

    local itemWeight = itemType:getWeight()
    local playerCap = player:getFreeCapacity()
    if table.contains(annihilatorReward, item.uid) then
        if player:getStorageValue(PlayerStorageKeys.annihilatorReward) == -1 then
            if playerCap >= itemWeight then
                if item.uid == 1990 then
                    player:addItem(1990, 1):addItem(2326, 1)
                else
                    player:addItem(item.uid, 1)
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found a ' .. itemType:getName() .. '.')
                player:setStorageValue(PlayerStorageKeys.annihilatorReward, 1)
                player:addAchievement("Annihilator")
            else
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        end
    elseif player:getStorageValue(item.uid) == -1 then
        if playerCap >= itemWeight then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found a ' .. itemType:getName() .. '.')
            player:addItem(item.uid, 1)
            player:setStorageValue(item.uid, 1)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
    end
    return true
end
 
Back
Top