• 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+ Action script

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,306
Reaction score
129
Hello guys i getting this error on quest while player clicks chest


Lua:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/pradziaquests.lua:onUse
data/actions/scripts/quests/pradziaquests.lua:34: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/quests/pradziaquests.lua:34: in function <data/actions/scripts/quests/pradziaquests.lua:28>



how its set upd

actions.xml
Lua:
<action fromuid="3000" touid="3023" script="quests/pradziaquests.lua" /> <!--  newbie quests -->

script

Lua:
local chests = {
    [3000] = {itemid = 2169, count = 1}, -- time ring
    [3001] = {itemid = 2168, count = 1}, -- life ring
    [3002] = {itemid = 2165, count = 1}, -- stealth ring
    [3003] = {itemid = 3966, count = 1}, -- banana staff
    [3004] = {itemid = 2428, count = 1}, -- orchich axe
    [3005] = {itemid = 2383, count = 1}, -- spike sword
    [3006] = {itemid = 7620, count = 100}, -- mana potion
    [3007] = {itemid = 7618, count = 100}, -- health potion
    [3008] = {itemid = 2182, count = 1}, -- snakebit rod
    [3009] = {itemid = 2190, count = 1}, -- vortex wand
    [3010] = {itemid = 2389, count = 1}, -- spear
    [3011] = {itemid = 2410, count = 100}, -- throwing knife
    [3012] = {itemid = 2513, count = 1}, -- battle shield
    [3013] = {itemid = 2457, count = 1}, -- steel helmet
    [3014] = {itemid = 2478, count = 1}, -- brass legs
    [3015] = {itemid = 3940, count = 1}, -- comoflouge backpack
    [3016] = {itemid = 2789, count = 66}, -- brown mushrooms
    [3017] = {itemid = 2420, count = 1}, -- machete
    [3018] = {itemid = 2186, count = 1}, -- noonlight rod
    [3019] = {itemid = 2191, count = 1}, -- wand of dragon breath
    [3020] = {itemid = 2399, count = 100}, -- throwing stars
    [3021] = {itemid = 2553, count = 1}, -- pick
    [3022] = {itemid = 2160, count = 2}, -- crystal coin
    [3023] = {itemid = 2521, count = 1}, -- dark shield
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid < 2999 or item.uid >= 3024 then
        return false
    end

    if chests[item.uid] then
        if player:getStorageValue(Storage.pradziaquests) == 1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
            return true
        end

        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
            local itemWeight = itemType:getWeight()
            local playerCap = player:getFreeCapacity()
            if playerCap >= itemWeight then
                local article = itemType:getArticle()
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
                player:addItem(chest.itemid, chest.count)
                player:setStorageValue(Storage.pradziaquests, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
            end
        end
    end

    return true
end



can anyone help me out please ?
 
This script reads:
Code:
if player:getStorageValue(Storage.pradziaquests) == 1 then
and writes:
Code:
player:setStorageValue(Storage.pradziaquests, 1)
value to storage with key Storage.pradziaquests. Table Storage is not defined in this script. It should be probably somewhere in data/lib. In case of otservbr-global it's in file data/lib/core/storages.lua but there is no pradziaquests key in otservbr.
You can add it to table in storages.lua or replace Storage.pradziaquests with some value in your Lua script, like:
Code:
if player:getStorageValue(123890123) == 1 then
(..)
player:setStorageValue(123890123, 1)
 
This script reads:
Code:
if player:getStorageValue(Storage.pradziaquests) == 1 then
and writes:
Code:
player:setStorageValue(Storage.pradziaquests, 1)
value to storage with key Storage.pradziaquests. Table Storage is not defined in this script. It should be probably somewhere in data/lib. In case of otservbr-global it's in file data/lib/core/storages.lua but there is no pradziaquests key in otservbr.
You can add it to table in storages.lua or replace Storage.pradziaquests with some value in your Lua script, like:
Code:
if player:getStorageValue(123890123) == 1 then
(..)
player:setStorageValue(123890123, 1)
im using tfs 1,3 and i want every chest uniqID 3000 - 2023 can be taken, and player gets 23 storages means in total within 23 chests clicked.

Exploring what you told now :) thanks alot
 
@Lbtg
3000-3023 gives 24 boxes.

1. Use storage key 1000000. Player can pick item only one item from 24 boxes. Pick from one box, block all 24 boxes for player.
Code:
if player:getStorageValue(1000000) == 1 then
(..)
player:setStorageValue(1000000, 1)

2. Use storage key 1000000. Player can pick 24 items from 24 boxes, but in any combination. Pick 1 item from every box OR 24x same item from one box OR 11 items from box nr 1 and 13 items from box nr 2.
Code:
if player:getStorageValue(1000000) < 24 then
(..)
player:setStorageValue(1000000, math.max(player:getStorageValue(1000000), 0) + 1)
(not used storage has value -1, we use math.max to convert values below 0 to 0, to make calculation '< 24 times' work fine, stop after 24 picks, not 25)

3. Use storages 1003000 - 1003023. Player can pick one item from each box. Probably what you wanted.
Code:
if player:getStorageValue(1000000 + item.uid) == 1 then
(..)
player:setStorageValue(1000000 + item.uid, 1)
 
Here I have changed the variable Storage.pradziaquests to a constant and this should work

Lua:
local chests = {
    [3000] = {itemid = 2169, count = 1}, -- time ring
    [3001] = {itemid = 2168, count = 1}, -- life ring
    [3002] = {itemid = 2165, count = 1}, -- stealth ring
    [3003] = {itemid = 3966, count = 1}, -- banana staff
    [3004] = {itemid = 2428, count = 1}, -- orchich axe
    [3005] = {itemid = 2383, count = 1}, -- spike sword
    [3006] = {itemid = 7620, count = 100}, -- mana potion
    [3007] = {itemid = 7618, count = 100}, -- health potion
    [3008] = {itemid = 2182, count = 1}, -- snakebit rod
    [3009] = {itemid = 2190, count = 1}, -- vortex wand
    [3010] = {itemid = 2389, count = 1}, -- spear
    [3011] = {itemid = 2410, count = 100}, -- throwing knife
    [3012] = {itemid = 2513, count = 1}, -- battle shield
    [3013] = {itemid = 2457, count = 1}, -- steel helmet
    [3014] = {itemid = 2478, count = 1}, -- brass legs
    [3015] = {itemid = 3940, count = 1}, -- comoflouge backpack
    [3016] = {itemid = 2789, count = 66}, -- brown mushrooms
    [3017] = {itemid = 2420, count = 1}, -- machete
    [3018] = {itemid = 2186, count = 1}, -- noonlight rod
    [3019] = {itemid = 2191, count = 1}, -- wand of dragon breath
    [3020] = {itemid = 2399, count = 100}, -- throwing stars
    [3021] = {itemid = 2553, count = 1}, -- pick
    [3022] = {itemid = 2160, count = 2}, -- crystal coin
    [3023] = {itemid = 2521, count = 1}, -- dark shield
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid < 2999 or item.uid >= 3024 then
        return true
    end

    local chest = chests[item.uid]
    if not chest then
        return true
    end

    if player:getStorageValue(655350) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
        return true
    end

    local itemType = ItemType(chest.itemid)
    if itemType then
        local itemWeight = itemType:getWeight()
        local playerCap = player:getFreeCapacity()
        if playerCap >= itemWeight then
            local article = itemType:getArticle()
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
            player:addItem(chest.itemid, chest.count)
            player:setStorageValue(655350, 1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
        end
    end

    return true
end
 
Back
Top