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

TFS 1.X+ Svargrond arena reward room

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,492
Solutions
27
Reaction score
857
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi! I'm using TFS 1.4 downgraded by nekiro. I tried to create a script for svargrond wrote some local variables to define the different rewards but it's a whole mess and didn't worked. This was my attempt:
Lua:
local storage_id = PlayerStorageKeys.SvargrondArena.GreenhornChest
local presentItems = {{2114, 1}, {6570, 2}, {6574, 1}, {6569, 1}, {7377, 1}} ------ items inside the present
local backpackItems = {{7364, 100}, {7365, 100}} ------ items inside the backpack


local rewards = {
    [4028] = {reward_id = present, reward_count = 1}, ---- "present" as reward defined on local variable
    [4029] = {reward_id = backpack, reward_count = 1}, ---- "backpack" as reward defined on local variable
    [4030] = {reward_id = 7392, reward_count = 1},-- [chest uid] = {reward item id, reward item count},
    [4031] = {reward_id = 7380, reward_count = 1},
    [4032] = {reward_id = 7406, reward_count = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
---- local to add items inside the present
local present = player:addItem(1990) -- present
for i = 1, #presentItems do
present:addItem(presentItems[i][1], presentItems[i][2], presentItems[i][3], presentItems[i][4], presentItems[i][5])
end

---- local to add items inside the fur backpack
local backpack = player:addItem(7342) -- fur bp
for i = 1, #backpackItems do
backpack:addItem(presentItems[i][1], presentItems[i][2])
end

    local storage = player:getStorageValue(storage_id)
    if storage > 0 then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end

    local reward = rewards[item.uid]
    local reward_type = reward and ItemType(reward.reward_id)
    if reward_type then
        if player:addItem(reward.reward_id, reward.reward_count, false, 1, CONST_SLOT_WHEREEVER) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a " .. reward_type:getName():lower() .. ".")
            player:setStorageValue(storage_id, 1)
        else
            local weight = reward_type:getWeight()
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found an item weighing ' .. weight / 100 .. ' oz it\'s too heavy or you do not have enough room.')
        end
    end
    return true
end

The script I wrote is just giving me random rewards xD I wasn't even close. I will explain how svargrond arena chest works; as soon you finish the first challenge (Greenhorn) you should be able to pick between 5 rewards. This rewards are:
Code:
a) a present box with a piggy bank, surprise bag (blue), bar of chocolate, 10x candy, ice cream
b) a fur backpack 100 sniper arrows, and 100 onyx arrows
c) orcish maul
d) head chopper
e) blacksteel sword

You can only pick one and that's it. I tried to use tables to define what is inside the backpack and the present box but I really don't know what i'm doing. Can someone make this for me so I can see how it is supposed to be done? In advance, thanks!!

Regards :)
 
Solution
This is how I'd do it.

Didn't test.

Lua:
local storage_id = PlayerStorageKeys.SvargrondArena.GreenhornChest

local rewards = {
    [4028] = {reward = "container", containerId = 1990, containerContents = {{2114, 1}, {6570, 2}, {6574, 1}, {6569, 1}, {7377, 1}} }, ---- "present" as reward defined on local variable
    [4029] = {reward = "container", containerId = 7342, containerContents = {{7364, 100}, {7365, 100}} }, ---- "backpack" as reward defined on local variable
    [4030] = {reward = "item", itemId = 7392, amount = 1}, -- [chest uid] = {reward item id, reward item count},
    [4031] = {reward = "item", itemId = 7380, amount = 1},
    [4032] = {reward = "item", itemId = 7406, amount = 1}
}

function onUse(player, item, fromPosition, target...
This is how I'd do it.

Didn't test.

Lua:
local storage_id = PlayerStorageKeys.SvargrondArena.GreenhornChest

local rewards = {
    [4028] = {reward = "container", containerId = 1990, containerContents = {{2114, 1}, {6570, 2}, {6574, 1}, {6569, 1}, {7377, 1}} }, ---- "present" as reward defined on local variable
    [4029] = {reward = "container", containerId = 7342, containerContents = {{7364, 100}, {7365, 100}} }, ---- "backpack" as reward defined on local variable
    [4030] = {reward = "item", itemId = 7392, amount = 1}, -- [chest uid] = {reward item id, reward item count},
    [4031] = {reward = "item", itemId = 7380, amount = 1},
    [4032] = {reward = "item", itemId = 7406, amount = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    -- check storage
    if player:getStorageValue(storage_id) > 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end
    
    -- ensure reward exists in table
    local rewardIndex = rewards[item:getUniqueId()]
    if not rewardIndex then
        return true
    end
    
    -- create reward item
    local reward
    if rewardIndex.reward == "container" then
        reward = Game.createItem(rewardIndex.containerId, 1)
        for i = 1, #rewardIndex.containerContents do
            reward:addItem(rewardIndex.containerContents[i][1], rewardIndex.containerContents[i][2])
        end
    else
        reward = Game.createItem(rewardIndex.itemId, rewardIndex.amount)
    end

    -- check weight requirement
    local itemWeight = reward:getWeight()
    if itemWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found an item weighing " .. itemWeight / 100 .. " oz. It's too heavy.")
        return true
    end

    -- attempt to add item to player (check if they have inventory space)
    local success = player:addItemEx(reward, false, INDEX_WHEREEVER)
    if success ~= RETURNVALUE_NOERROR then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough room in your inventory to receive this item.")
        return true
    end
    
    -- reward successfully given, tell player and set storage
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a " .. reward:getName():lower() .. "" .. (rewardIndex.reward == "container" and ". It weighs " .. itemWeight / 100 .. " oz" or "") .. ".")
    player:setStorageValue(storage_id, 1)
    return true
end
 
Solution
Back
Top