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

Lua [Help] This chest system does not work :(

exanime

I´m learning Lua
Joined
Oct 24, 2011
Messages
40
Reaction score
3
Location
Bogota, Colombia
I have this chest system, all chest in one but no work on my TFS 1.0 Help me please
No have error in console, however, I did a chest with uid but This chest open and I do not get nothing :C

help me please!

Code:
local t = {
[6001] = {8001,"magic sword",2400,1},
[6002] = {8001,"demon armor",2494,1},
[6003] = {8001,"stonecutter axe",2431,1},
[6004] = {8001,"annihilation bear",2326,1},
[6005] = {8002,"emerald sword",8930,1},
[6006] = {8002,"obsidian truncheon",8928,1},
[6007] = {8002,"hellforged axe",8924,1},
[6008] = {8002,"royal crossbow",8851,1},
[6009] = {8002,"warsinger bow",8854,1},
[6010] = {8002,"spellbook of dark mysteries",8918,1},
[6011] = {8002,"master archers armor",8888,1},
[6012] = {8002,"fireborn giant armor",8881,1},
[6013] = {8002,"robe of the underworld",8890,1},
[6014] = {8003,"demon legs",2495,1},
[6015] = {8003,"rainbow shield",8905,1},
[6016] = {8003,"spellbook of dark mysteries",8918,1},
[6017] = {8003,"royal crossbow",8851,1},
[6018] = {8004,"royal crossbow",8851,1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local v = t[item.uid]
if player:getStorageValue(cid,v[1]) == -1 and player:getFreeCapacity(cid) >= (itemType:getWeight(v[3])) then
player:setStorageValue(cid,v[1],1)
player:addItem(cid,v[3], v[4])
player:sendTextMessage(cid,MESSAGE_INFO_DESCR, "You have found a " .. v[2] .. "!")
elseif player:getStorageValue(cid,v[1]) == 1 then
player:sendTextMessage(cid,MESSAGE_INFO_DESCR, "It is empty")
elseif player:getFreeCapacity(cid) < (itemType:getWeight(v[3])) then
player:sendTextMessage(cid,MESSAGE_INFO_DESCR, "You need  " .. itemType:getWeight(v[3]) .. " capacity in order to get the item")
end
return TRUE
end

Code:
<action uniqueid="6001-6017" script="Customquest/all.lua"/>
 
If the chest is opening, with no errors in console, most likely the script is not loading at all.

Reload actions.xml and see if there is any errors when loading the script.

You can also put a print into the script, and check console if it prints into console when using the chest.
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print(1)
    local v = t[item.uid]
 
I tried "print(1)" on all code, however, do not run the code "no print (1)" under the main function, above the function prints the code "1"

I do not understand why it does not work

D:
Helpme please
this system is very funcionally, all quest in one, if there are many gifts , many files!
 
I modified the Code, not work :C

Code:
local t = {
[6001] = {8001,"magic sword",2400,1},
[6002] = {8001,"demon armor",2494,1},
[6003] = {8001,"stonecutter axe",2431,1},
[6004] = {8001,"annihilation bear",2326,1},
[6005] = {8002,"emerald sword",8930,1},
[6006] = {8002,"obsidian truncheon",8928,1},
[6007] = {8002,"hellforged axe",8924,1},
[6008] = {8002,"royal crossbow",8851,1},
[6009] = {8002,"warsinger bow",8854,1},
[6010] = {8002,"spellbook of dark mysteries",8918,1},
[6011] = {8002,"master archers armor",8888,1},
[6012] = {8002,"fireborn giant armor",8881,1},
[6013] = {8002,"robe of the underworld",8890,1},
[6014] = {8003,"demon legs",2495,1},
[6015] = {8003,"rainbow shield",8905,1},
[6016] = {8003,"spellbook of dark mysteries",8918,1},
[6017] = {8003,"royal crossbow",8851,1},
[6018] = {8004,"royal crossbow",8851,1}
--uid =  {v[1], v[2],           v[3],v[4]}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
print("Work")
local v = t[item.uid]

if player:getStorageValue(cid,v[1]) >= 1 then
player:sendTextMessage(cid,MESSAGE_INFO_DESCR, "It is empty")
end
if player:getStorageValue(cid,v[1]) <= -1 and player:getFreeCapacity(cid) >= (itemType:getWeight(v[3])) then
player:setStorageValue(cid,v[1],1)
player:addItem(cid,v[3], v[4])
player:sendTextMessage(cid,MESSAGE_INFO_DESCR, "You have found a " .. v[2] .. "!")
else
player:sendTextMessage(cid,MESSAGE_INFO_DESCR, "You need  " .. itemType:getWeight(v[3]) .. " capacity in order to get the item")
end
return TRUE
end
 
Code:
local t = {
    [6001] = {8001,"magic sword",2400,1},
    [6002] = {8001,"demon armor",2494,1},
    [6003] = {8001,"stonecutter axe",2431,1},
    [6004] = {8001,"annihilation bear",2326,1},
    [6005] = {8002,"emerald sword",8930,1},
    [6006] = {8002,"obsidian truncheon",8928,1},
    [6007] = {8002,"hellforged axe",8924,1},
    [6008] = {8002,"royal crossbow",8851,1},
    [6009] = {8002,"warsinger bow",8854,1},
    [6010] = {8002,"spellbook of dark mysteries",8918,1},
    [6011] = {8002,"master archers armor",8888,1},
    [6012] = {8002,"fireborn giant armor",8881,1},
    [6013] = {8002,"robe of the underworld",8890,1},
    [6014] = {8003,"demon legs",2495,1},
    [6015] = {8003,"rainbow shield",8905,1},
    [6016] = {8003,"spellbook of dark mysteries",8918,1},
    [6017] = {8003,"royal crossbow",8851,1},
    [6018] = {8004,"royal crossbow",8851,1}
--  [ActionID] = {Storage, Name, ID, Count}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local v = t[item.actionid]
    local itemType = ItemType(v[3])
    local storage, weight = player:getStorageValue(v[1]), itemType:getWeight()
    if storage == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty")
    elseif storage == -1 and player:getCapacity() < weight then
        player:setStorageValue(v[1], 1)
        player:addItem(v[3], v[4])
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a " .. v[2] .. "!")
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You need " .. weight .. " capacity in order to get ".. itemType:getArticle() .." ".. v[2] ..".")
    end
return true
end

Code:
<action fromaid="6001" toaid="6018" script="test.lua"/>
you were using cid in everything for your script even though this is 1.2, you don't need cid anymore since you have player userdata (player:Method())
player is the object you're doing something to so you don't need to use cid again unless you make your own function to turn it into a userdata

edit: also use actionids for this (6001-6018)
 
@Up

:D
Thank you learned a little more today
Thank you for your explanation
Code:
local t = {
    {storage = 8001, items = {
            [6001] = {2400},
            [6002] = {2494},
            [6003] = {2431},
            [6004] = {2326}
        }
    },
    {storage = 8002, items = {
            [6005] = {8930},
            [6006] = {8928},
            [6007] = {8924},
            [6008] = {8851},
            [6009] = {8854},
            [6010] = {8918},
            [6011] = {8888},
            [6012] = {8881},
            [6013] = {8890}
        }
    },
    {storage = 8003, items = {
            [6014] = {2495},
            [6015] = {8905},
            [6016] = {8918},
            [6017] = {8851}
        }
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for _, v in pairs(t) do
        local val = v.items[item.actionid]
        if val then
            print(n)
           local itemType        = ItemType(val[1])
           local st1             = v.storage
           local storage, weight = player:getStorageValue(st1), itemType:getWeight()
           if storage == 1 then
               player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty")
           elseif storage == -1 and player:getCapacity() < weight then
               player:setStorageValue(st1, 1)
               player:addItem(val[1], val[2] or 1)
               player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a " .. val[2] .. "!")
           else
              local art, name = val[2] or itemType:getArticle(), (val[2] and val[2] > 1) and itemType:getPluralName() or itemType:getName()
               player:sendTextMessage(MESSAGE_INFO_DESCR, "You need " .. weight .. " capacity in order to get ".. art .." ".. name ..".")
           end
           break
       end
    end
    return true
end
you can simplify the table by doing it this way
in items table you put [action id] = {item id, count} (you don't need to use count unless you want more than 1 item)
if you want to use a count you can define it but it uses 1 as default withplayer:addItem(val[1], val[2] or 1) if you haven't defined the count
+ you don't have to manually input the item names since you can just get the name from id and put it in the text message

edit: updated script
 
Last edited:
Back
Top