• 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!

RevScripts [TFS 1.5] Chest script

Lokinho23

Member
Joined
Jan 15, 2025
Messages
21
Reaction score
8
The script it doesnt work
Players receive rewards based on their vocation.
Players of vocation 4 and 8 must choose between sword, axe, or club before opening the chest.
Rewards are given inside a backpack.
The script prevents duplicate rewards and ensures inventory space.
The !choose command allows players to select a weapon before claiming the


LUA:
local actionId = 2945
local storageKey = 14021 + actionId
local weaponStorageKey = storageKey + 1
local backpackId = 1990

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getActionId() ~= actionId then
        return false
    end

    if player:getStorageValue(storageKey) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The chest is empty.")
        return true
    end

    local vocationId = player:getVocation():getId()
    local rewardItems = {}

    if vocationId == 1 or vocationId == 2 or vocationId == 5 or vocationId == 6 then
        table.insert(rewardItems, 12774)
    elseif vocationId == 3 or vocationId == 7 then
        table.insert(rewardItems, 12806)
        table.insert(rewardItems, 12807)
    elseif vocationId == 4 or vocationId == 8 then
        local chosenWeapon = player:getStorageValue(weaponStorageKey)
        if chosenWeapon == -1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Use !choose sword, axe, or club before opening the chest.")
            return true
        else
            table.insert(rewardItems, chosenWeapon)
        end
    end

    local backpack = player:addItem(backpackId, 1, true)
    if not backpack then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Your inventory is full. Make space and try again.")
        return true
    end

    for _, itemId in ipairs(rewardItems) do
        backpack:addItem(itemId, 1)
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received your reward!")
    player:setStorageValue(storageKey, 1)

    return true
end

function onSay(player, words, param)
    local weaponRewards = {
        sword = 12794,
        axe = 12808,
        club = 12805
    }
    
    local chosenWeapon = weaponRewards[param:lower()]
    if chosenWeapon then
        player:setStorageValue(weaponStorageKey, chosenWeapon)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have chosen " .. param .. " as your weapon.")
        return true
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Invalid choice. Use !choose sword, axe, or club.")
        return false
    end
end

local chooseCommand = TalkAction("!choose")
chooseCommand.onSay = onSay
chooseCommand:register()
 
Solution
Can someone do the script or tell me how to do it
I think it can help you.
consists of two scripts, one of this script with the onUse function that will open the modal window with the settings inside the other script with modalWindow function.

This script was infinity giving itens: remember to put storage value after give the item.

Edit:
I used UniqueId: 2336 for tests. You can edit as you want.
LUA:
weaponChest:uid(2336)
The script it doesnt work
You asked GPT and explained everything completely wrong, and GPT turned the script completely wrong. You didn't read compat.lua or lucascript.cpp, nor even the Otland wiki, where everything is explained about what you wanted.

You just need to click the object, a modal window will appear, and you will select the item by vocation, right?

Or do you just want to use a command that shows the modal window to choose the reward item? I believe Xiniki already has it ready to use... just grab it and adapt it.
 
Can someone do the script or tell me how to do it
Install modal windows first or ensure they work in your distro in nekiro there is 1 line of code commented preventing modal windows from being used start there then ensure other things like modal window helpers or things u may use
 
Can someone do the script or tell me how to do it
I think it can help you.
consists of two scripts, one of this script with the onUse function that will open the modal window with the settings inside the other script with modalWindow function.

This script was infinity giving itens: remember to put storage value after give the item.

Edit:
I used UniqueId: 2336 for tests. You can edit as you want.
LUA:
weaponChest:uid(2336)
 

Attachments

Solution

Similar threads

Replies
4
Views
256
Replies
10
Views
769
Back
Top