• 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 Clickable item if you have a certain storage value

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
Hello, can you help me with a script of a chest or a coal basin by clicking on an item only if you have this storage 50033
 
Solution
now it just doesn't give it to you hahaha


Lua:
local config = {
    needStorageKey = 77756, -- storage key required to open the chest?
    needStorageValue = 1, -- storage value required to open the chest?
    giveStorageKey = 50033, -- storage key given after chest opened?
    giveStorageValue = 1, -- storage value given after chest opened?
    itemId = 36266, -- give this item
    itemCount = 1 -- give this amount
}

local a = Action()

function a.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local p = player
    if not p then
        return false
    end

    local reward = ItemType(config.itemId)

    if player:getStorageValue(config.giveStorageKey) ~= config.giveStorageValue then
        if...
I don't think I understand what you are saying.

The following line is only going to allow you if you have 4+
Lua:
if player:getStorageValue(config.STORAGE_PERMISSION) <= 3 then
if you want it to allow when you have 3 then change
Lua:
<= 3
to
Lua:
< 3
with this storage you can open the chest "50039, 1"
When you open it, it gives you the items and this storage "50039, 3" and you can't open the chest anymore

check npc
line 12 and 35

Lua:
    if msgcontains(msg, "mission") and player:getStorageValue(Storage.Kilmaresh.Twelve.Boss) == 3 then
        if player:getStorageValue(Storage.Kilmaresh.Twelve.Boss) == 3 then
            npcHandler:say({"Could you help me with some more work?"}, cid)-- needs review, this is not the speech of the global
            npcHandler.topic[cid] = 5
            npcHandler.topic[cid] = 5
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 5 and player:getStorageValue(Storage.Kilmaresh.Twelve.Boss) == 3 then
        if player:getStorageValue(Storage.Kilmaresh.Twelve.Boss) == 3 then
            npcHandler:say({"Kill 300 members of the Fafnar cult, help me find Ivory Lyre and help me find an animal to stone."}, cid)-- needs review, this is not the speech of the global
            player:setStorageValue(Storage.Kilmaresh.Twelve.Boss, 4)
            player:setStorageValue(Storage.Kilmaresh.Thirteen.Fafnar, 1)
            player:setStorageValue(Storage.Kilmaresh.Thirteen.Lyre, 1)
            player:setStorageValue(Storage.Kilmaresh.Thirteen.Presente, 1)
            npcHandler.topic[cid] = 6
        else
            npcHandler:say({"Sorry."}, cid)
            npcHandler.topic[cid] = 0
        end
    end
    if msgcontains(msg, "report") and player:getStorageValue(Storage.Kilmaresh.Thirteen.Fafnar) == 300 then
        if player:getStorageValue(Storage.Kilmaresh.Thirteen.Fafnar) == 300 then
            npcHandler:say({"Have you finished killing the 300 members of Fafnar's cult?"}, cid)-- needs review, this is not the speech of the global
            npcHandler.topic[cid] = 7
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 7 and player:getStorageValue(Storage.Kilmaresh.Thirteen.Fafnar) == 300 then
        if player:getStorageValue(Storage.Kilmaresh.Thirteen.Fafnar) == 300 then
            npcHandler:say({"Thanks. You killed the 300 members of the Fafnar cult."}, cid)-- needs review, this is not the speech of the global
            player:setStorageValue(Storage.Kilmaresh.Thirteen.Fafnar, 301)
            npcHandler.topic[cid] = 8
        else
            npcHandler:say({"Sorry."}, cid)
            npcHandler.topic[cid] = 0
        end
    end
    if msgcontains(msg, "report") and player:getStorageValue(Storage.Kilmaresh.Thirteen.Lyre) == 3 then
        if player:getStorageValue(Storage.Kilmaresh.Thirteen.Lyre) == 3 then
            npcHandler:say({"Did you manage to find Lyre?"}, cid)-- needs review, this is not the speech of the global
            npcHandler.topic[cid] = 9
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 9 and player:getStorageValue(Storage.Kilmaresh.Thirteen.Lyre) == 3 then
        if player:getStorageValue(Storage.Kilmaresh.Thirteen.Lyre) == 3 and player:getItemById(36282, 1) then
            player:removeItem(36282, 1)
            npcHandler:say({"Thanks. I was looking for Lyre for a long time."}, cid)-- needs review, this is not the speech of the global
            player:setStorageValue(Storage.Kilmaresh.Thirteen.Lyre, 4)
        else
            npcHandler:say({"Sorry."}, cid)
            npcHandler.topic[cid] = 0
        end
    end
 
Last edited:
Since both STORAGE_CHEST_OPENED and STORAGE_PERMISSION seem to be using the same key 50039, I removed one of them.

Assuming players have to complete some other task and get atleast storage value 1 before using this chest:
Lua:
local config = {
    STORAGE_CHEST_OPENED  = 50039,

    itemId     = 36282,
    itemCount  = 1
}

local a = Action()
function a.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local reward = ItemType(config.itemId)
    if player:getStorageValue(config.STORAGE_CHEST_OPENED) < 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You haven't completed task ABC.")
        return true
    end

    if player:getStorageValue(config.STORAGE_CHEST_OPENED) >= 3 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is emtpy.")
        return true
    end

    if player:getCapacity() < reward:getWeight(config.itemCount) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
        return true
    end

    player:addItem(config.itemId, config.itemCount)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)

    player:setStorageValue(config.STORAGE_CHEST_OPENED, 3)
    return true
end

a:aid(36292)
a:register()
 
Back
Top