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

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
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

Im not sure what you want to be done, and what tfs version you use.

Here is a example for tfs 0.x, to check if a player got storage 50033 set
Lua:
local storageValue = 50033

function onUse(cid, item, fromPosition, itemEx, toPosition)

    if getPlayerStorageValue(cid, storageValue)  > 0 then
        -- do something
    end
    
    return true
end
 
OP
OP
A

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
Im not sure what you want to be done, and what tfs version you use.

Here is a example for tfs 0.x, to check if a player got storage 50033 set
Lua:
local storageValue = 50033

function onUse(cid, item, fromPosition, itemEx, toPosition)

    if getPlayerStorageValue(cid, storageValue)  > 0 then
        -- do something
    end
   
    return true
end
I want a chest that when you click it gives you an item if you have this Storage 50033, I use TFS 1.3 from OTBR
 

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
I want a chest that when you click it gives you an item if you have this Storage 50033, I use TFS 1.3 from OTBR
This should do the trick, but the player would be able to spawn as many items he wants to.
You need to describe what is supposed to happen, if you want a more "advanced" script.
Nobody will know what your intentions of the script are whitout a proper explaination

TFS 1.x
Lua:
local storageValue = 50033
local newItemId = --ADD ITEMID HERE

function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)

    local player = Player(cid)
    if player:getStorageValue(storageValue) > 0 then
        player:addItem(newItemId)
    end

    return true
end

Edit: Should the chest use a actionid or uniqueid? i mean will the be more than one chest.
 
Last edited:

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,247
Solutions
71
Reaction score
587
Location
Hell
I want a chest that when you click it gives you an item if you have this Storage 50033, I use TFS 1.3 from OTBR
Lua:
local storageValue = 50033
local reward = {2160, 10}

local a = Action()
function a.onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if player:getStorageValue(storageValue) <= 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You don\t have the storage.')
        return true
    end
    player:addItem(reward[1], reward[2])
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found an item.')
    return true
end

a:id(CHEST_ID_HERE)
a:register()
 

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
83
Location
Portugal
Lua:
local config = {
    storageKey = 50033, -- storage key required to open the chest?
    storageValue = 1, -- storage value required to open the chest?
    itemId = 2160, -- give this item
    itemCount = 5 -- give this amount
}

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

    local reward = ItemType(config.itemId)

    if p:getCapacity() > reward:getWeight(config.itemCount) then
        if p:getStorageValue(config.storageKey) == config.storageValue then
            p:addItem(config.itemId, config.itemCount)
            p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received "..reward:getArticle().." "..reward:getName()..".")
            p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." cap to receive the reward from this chest.")
    end
  
    return true
end

I guess I'm late but here's how I would do it xD

Snavy's revScript looks smoother tho I think :p
 
OP
OP
A

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
I understand you, I'll explain you better

Need Storage: 77756
Chest: 36267
36267.png
--------------------------------------------------
Reward: 36266
Reward Storage: 50033
36266.png

Message: "You find a golden symbol at the bottom of the blood-filled basin."
 

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
83
Location
Portugal
I understand you, I'll explain you better

Need Storage: 77756
Chest: 36267
View attachment 57455
--------------------------------------------------
Reward: 36266
Reward Storage: 50033
View attachment 57456

Message: "You find a golden symbol at the bottom of the blood-filled basin."

create file "basin.lua" on data/scripts/

and add this on the file:

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 p:getCapacity() > reward:getWeight(config.itemCount) then
        if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
            p:addItem(config.itemId, config.itemCount)
            p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
            p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
    end

    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()

Note: the way you described your request means players can open this chest anywhere in the map if they have the storage and they can open as many times as they want xd
 
Last edited:
OP
OP
A

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
create file "basin.lua" on data/scripts/

and add this on the file:

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 = 2160, -- give this item
    itemCount = 5 -- 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 p:getCapacity() > reward:getWeight(config.itemCount) then
        if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
            p:addItem(config.itemId, config.itemCount)
            p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
            p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
    end
 
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()

Note: the way you described your request means players can open this chest anywhere in the map if they have the storage and they can open as many times as they want xd
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 p:getCapacity() > reward:getWeight(config.itemCount) then
        if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
            p:addItem(config.itemId, config.itemCount)
            p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
            p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
    end
    
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()

I put it like this, it works for me but I can use it many times
 

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
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 p:getCapacity() > reward:getWeight(config.itemCount) then
        if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
            p:addItem(config.itemId, config.itemCount)
            p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
            p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
    end
  
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()

I put it like this, it works for me but I can use it many times
This should fix it, he forgot to check if you had new storage set
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 p:getCapacity() > reward:getWeight(config.itemCount) then
        if p:getStorageValue(config.needStorageKey) == config.needStorageValue and p:getStorageValue(config.giveStorageKey) ~= config.giveStorageValue then
            p:addItem(config.itemId, config.itemCount)
            p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
            p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
    end
   
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()
 

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
83
Location
Portugal
I put it like this, it works for me but I can use it many times

Yeah that's what I said in my last post... xD

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 p:getCapacity() > reward:getWeight(config.itemCount) then
            if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
                p:addItem(config.itemId, config.itemCount)
                p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
                p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
                p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
            else
                return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
            end
        else
            return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is emtpy.")
    end
    
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()
 
OP
OP
A

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
Yeah that's what I said in my last post... xD

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) == 0 then
        if p:getCapacity() > reward:getWeight(config.itemCount) then
            if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
                p:addItem(config.itemId, config.itemCount)
                p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
                p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
                p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
            else
                return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
            end
        else
            return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is emtpy.")
    end
   
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()
now it just doesn't give it to you hahaha
 

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
83
Location
Portugal
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 p:getCapacity() > reward:getWeight(config.itemCount) then
            if p:getStorageValue(config.needStorageKey) == config.needStorageValue then
                p:addItem(config.itemId, config.itemCount)
                p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You find "..reward:getArticle().." "..reward:getName().." at the bottom of the blood-filled basin.")
                p:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
                p:setStorageValue(config.giveStorageKey, config.giveStorageValue)
            else
                return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
            end
        else
            return p:sendTextMessage(MESSAGE_STATUS_WARNING, "You need at least "..reward:getWeight(config.itemCount).." capacity to open this chest.")
        end
    else
        return p:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is emtpy.")
    end
    
    return true
end

a:id(36267) -- carefull this means all items with this id can be opened, no matter where they are (i would use action id instead for this)
a:register()
 
Solution

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,247
Solutions
71
Reaction score
587
Location
Hell
Improved readability
Lua:
local config = {
    STORAGE_PERMISSION    = 77756, -- storage key required to open the chest?
    STORAGE_CHEST_OPENED  = 50033, -- storage key 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 reward = ItemType(config.itemId)
    if player:getStorageValue(config.STORAGE_CHEST_OPENED) > 0 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
    
    if player:getStorageValue(config.STORAGE_PERMISSION) <= 0 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        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, 1)
    return true
end
a:id(36267)
a:register()
 
OP
OP
A

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
Improved readability
Lua:
local config = {
    STORAGE_PERMISSION    = 77756, -- storage key required to open the chest?
    STORAGE_CHEST_OPENED  = 50033, -- storage key 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 reward = ItemType(config.itemId)
    if player:getStorageValue(config.STORAGE_CHEST_OPENED) > 0 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
   
    if player:getStorageValue(config.STORAGE_PERMISSION) <= 0 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        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, 1)
    return true
end
a:id(36267)
a:register()
Lua:
local config = {
    STORAGE_PERMISSION    = 50039, -- storage key required to open the chest?
    STORAGE_CHEST_OPENED  = 50039, -- storage key given after chest opened?

    itemId     = 36282, -- give this item
    itemCount  = 1      -- give this amount
}

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, "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
    
    if player:getStorageValue(config.STORAGE_PERMISSION) <= 3 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        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, 1)
    return true
end
a:id(36292)
a:register()

it doesn't work for me with this bag
bag.png
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,247
Solutions
71
Reaction score
587
Location
Hell
Lua:
local config = {
    STORAGE_PERMISSION    = 50039, -- storage key required to open the chest?
    STORAGE_CHEST_OPENED  = 50039, -- storage key given after chest opened?

    itemId     = 36282, -- give this item
    itemCount  = 1      -- give this amount
}

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, "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
  
    if player:getStorageValue(config.STORAGE_PERMISSION) <= 3 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You don't have permission to open this.")
        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, 1)
    return true
end
a:id(36292)
a:register()

it doesn't work for me with this bag
View attachment 57478
if you wanna use actionid
replace
Lua:
a:id(36292) -- use item id
with
Lua:
a:aid(36292) -- use actionid
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,247
Solutions
71
Reaction score
587
Location
Hell
15:28 You don't have permission to open this.

I have storage 50039, 1 and I want it from 50039, 3
Permissions should be given when value of 50039 is 3 ?
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
 
Top