• 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 Register 100 chests with different storage for the same reward.

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,470
Solutions
27
Reaction score
844
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi! I want to request the following, for TFS 1.X (if possible, don't use revscriptsys, because I use 1.2).
Ok here we go, I have a critical/dodge system running on my server, and it increases the "critical/dodge" value when using a certain itemid. The maxium value of dodge or critical you can get in a player is 100/100. This is how the action script works:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getCriticalLevel() < CRITICAL.LEVEL_MAX then
        item:remove(1)
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
        player:setCriticalLevel(player:getCriticalLevel() + 1)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your critical skill to [" .. player:getCriticalLevel() .. "/" .. CRITICAL.LEVEL_MAX .. "].")
    elseif player:getCriticalLevel() >= CRITICAL.LEVEL_MAX then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have reached the maximum of your critical skill.")
        return false
    end
    return true
end

The thing I want to do, is to hide 100 different chest for critical points, and 100 for dodge points. Thoose chests will say "You have received the warrior's blessing!" (or something like that) if you open one of them, send you magic "ghost" effect, and set you a storage to don't use it again. For that I could simple do something like
Lua:
local storage = 15670  -- Set your chest storage ID here

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) == 1 then
        player:sendCancelMessage("The chest is empty!")
        return true
    else
        player:setCriticalLevel(player:getCriticalLevel() + 1)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received the warrior/s blessing!') --Change to whatever you want to say
    end
    return true
end

But the question is, how can I set it up to work with 100 chests (100 critical points) with different storages? as neat as possible, without using revscriptsys. -----And another script for the 100 dodge points.
Thanks in advance, regards!
 
Last edited:
Solution
Using a table, put the action id on every chest starting from 20001, 20002 or you custom action ids.

Lua:
local chests = {
    [20001] = {storage = 20001, criticalLevel = 1},
    [20002] = {storage = 20002, criticalLevel = 1},
    [20003] = {storage = 20003, criticalLevel = 1},
    [20004] = {storage = 20004, criticalLevel = 1},
    [20005] = {storage = 20005, criticalLevel = 1},
    [20006] = {storage = 20006, criticalLevel = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chestSelected = chests[item.actionid]
    if(chestSelected) then
        if player:getStorageValue(chestSelected.storage) == -1 then
            player:setCriticalLevel(player:getCriticalLevel() + chestSelected.criticalLevel)...
Using a table, put the action id on every chest starting from 20001, 20002 or you custom action ids.

Lua:
local chests = {
    [20001] = {storage = 20001, criticalLevel = 1},
    [20002] = {storage = 20002, criticalLevel = 1},
    [20003] = {storage = 20003, criticalLevel = 1},
    [20004] = {storage = 20004, criticalLevel = 1},
    [20005] = {storage = 20005, criticalLevel = 1},
    [20006] = {storage = 20006, criticalLevel = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chestSelected = chests[item.actionid]
    if(chestSelected) then
        if player:getStorageValue(chestSelected.storage) == -1 then
            player:setCriticalLevel(player:getCriticalLevel() + chestSelected.criticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received the warrior/s blessing!') --Change to whatever you want to say
            player:setStorageValue(chestSelected.storage, 1)
            fromPosition:sendMagicEffect(CONST_ME_YALAHARIGHOST)
        else
            player:sendCancelMessage("The chest is empty!")

        end
    end
    return true
end
 
Last edited:
Solution
Using a table, put the action id on every chest starting from 20001, 20002 or you custom action ids.

Lua:
local chests = {
    [20001] = {storage = 20001, criticalLevel = 1},
    [20002] = {storage = 20002, criticalLevel = 1},
    [20003] = {storage = 20003, criticalLevel = 1},
    [20004] = {storage = 20004, criticalLevel = 1},
    [20005] = {storage = 20005, criticalLevel = 1},
    [20006] = {storage = 20006, criticalLevel = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chestSelected = chests[item.actionid]
    if(chestSelected) then
        if player:getStorageValue(chestSelected.storage) == -1 then
            player:setCriticalLevel(player:getCriticalLevel() + chestSelected.criticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received the warrior/s blessing!') --Change to whatever you want to say
            player:setStorageValue(chestSelected.storage, 1)
            fromPosition:sendMagicEffect(CONST_ME_YALAHARIGHOST)
        else
            player:sendCancelMessage("The chest is empty!")

        end
    end
    return true
end

Thanks a lot!, did some minor changes but this works perfectly
Lua:
local chests = {
    [27101] = {storage = 27101, criticalLevel = 1},
    [27102] = {storage = 27102, criticalLevel = 1},
    [27103] = {storage = 27103, criticalLevel = 1},
    [27104] = {storage = 27104, criticalLevel = 1},
    [27105] = {storage = 27105, criticalLevel = 1},
    [27106] = {storage = 27106, criticalLevel = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chestSelected = chests[item.actionid]
    if(chestSelected) then
        if player:getStorageValue(chestSelected.storage) == -1 and player:getCriticalLevel() < CRITICAL.LEVEL_MAX then
            player:setCriticalLevel(player:getCriticalLevel() + chestSelected.criticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received the warrior blessing!') --Change to whatever you want to say
            player:setStorageValue(chestSelected.storage, 1)
            fromPosition:sendMagicEffect(CONST_ME_YALAHARIGHOST)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"The chest is empty!")

        end
    end
    return true
end

by the way you can use the same action ID for all the 100 chests, only unique ids can't be repeated, action ids can :D
Then change local chestSelected = chests[item.actionid] to local chestSelected = chests[item.uniqueid] and register
XML:
<action actionid="27101" script="ralke/systembook.lua" />
instead of
XML:
<action fromaid="27101" toaid="27106" script="ralke/criticalchest.lua" />
And set 1 aid, multiple uids on RME??

any particular reason on why you'd want to use different storages?
Hmm I just thought that setting a storage value is the best way to make a player don't get the reward from the same chest two times.
Lua:
if player:getStorageValue(chestSelected.storage) == -1
But if there's another way to do this please let me know :)
Ralke said:
how can I set it up to work with 100 chests (100 critical points) with different storages? as neat as possible

Here is a explaining video, to clarify what is needed.
 
Thanks a lot!, did some minor changes but this works perfectly
Lua:
local chests = {
    [27101] = {storage = 27101, criticalLevel = 1},
    [27102] = {storage = 27102, criticalLevel = 1},
    [27103] = {storage = 27103, criticalLevel = 1},
    [27104] = {storage = 27104, criticalLevel = 1},
    [27105] = {storage = 27105, criticalLevel = 1},
    [27106] = {storage = 27106, criticalLevel = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chestSelected = chests[item.actionid]
    if(chestSelected) then
        if player:getStorageValue(chestSelected.storage) == -1 and player:getCriticalLevel() < CRITICAL.LEVEL_MAX then
            player:setCriticalLevel(player:getCriticalLevel() + chestSelected.criticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received the warrior blessing!') --Change to whatever you want to say
            player:setStorageValue(chestSelected.storage, 1)
            fromPosition:sendMagicEffect(CONST_ME_YALAHARIGHOST)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"The chest is empty!")

        end
    end
    return true
end


Then change local chestSelected = chests[item.actionid] to local chestSelected = chests[item.uniqueid] and register
XML:
<action actionid="27101" script="ralke/systembook.lua" />
instead of
XML:
<action fromaid="27101" toaid="27106" script="ralke/criticalchest.lua" />
And set 1 aid, multiple uids on RME??


Hmm I just thought that setting a storage value is the best way to make a player don't get the reward from the same chest two times.
Lua:
if player:getStorageValue(chestSelected.storage) == -1
But if there's another way to do this please let me know :)


Here is a explaining video, to clarify what is needed.

i like the mapping :D
 
Ty @Levi999x 😁 You can find an old released version here (<- click) if you wish to take a look.
It is quite changed since that release, but that specific city (the one in the video) isn't under major changes
Here you go.

Can't get easier.

Put the same ActionId on every chest.
Put 1 UniqueId on every chest. (UniqueId and storage are combined into 1 number.)

(I setup the critical for you, but couldn't do dodge, since you never gave us the functions for it.)

Lua:
local actionId = 27100
local chests = {
    [27101] = "critical", -- [uniqueId] = "type"
    [27102] = "critical",
    [27103] = "critical",
    [27104] = "dodge",
    [27105] = "dodge",
    [27106] = "dodge"
}

local criticalAndDodgeChests = Action()

function disappearingLootChest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local uniqueId = item:getUniqueId()
    local chestSelected = chests[uniqueId]
    if chestSelected then
        if player:getStorageValue(uniqueId) ~= -1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"The chest is empty!")
            return true
        end
       
        -- critical
        if chestSelected == "critical" then
            if player:getCriticalLevel() >= CRITICAL.LEVEL_MAX then
                player:sendTextMessage(MESSAGE_STATUS_WARNING, "Unable to use chest. You have already reached the maximum critical skill.")
                return false
            end
            local newCriticalLevel = player:getCriticalLevel() + 1
            player:setCriticalLevel(newCriticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your critical skill to [" .. newCriticalLevel .. "/" .. CRITICAL.LEVEL_MAX .. "].")
            player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
       
        -- dodge
        elseif chestSelected == "dodge" then
            -- give dodge stuff..
           
           
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "Error in table. Please contact gamemaster.") -- dodge or critical is mispelled in your table.
            return true
        end
       
        -- gives chest storage, so can't be used again
        player:setStorageValue(uniqueId, 1)
    end
    return true
end

criticalAndDodgeChests:aid(actionId)
criticalAndDodgeChests:register()
 
Here you go.

Can't get easier.

Put the same ActionId on every chest.
Put 1 UniqueId on every chest. (UniqueId and storage are combined into 1 number.)

(I setup the critical for you, but couldn't do dodge, since you never gave us the functions for it.)

Lua:
local actionId = 27100
local chests = {
    [27101] = "critical", -- [uniqueId] = "type"
    [27102] = "critical",
    [27103] = "critical",
    [27104] = "dodge",
    [27105] = "dodge",
    [27106] = "dodge"
}

local criticalAndDodgeChests = Action()

function disappearingLootChest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local uniqueId = item:getUniqueId()
    local chestSelected = chests[uniqueId]
    if chestSelected then
        if player:getStorageValue(uniqueId) ~= -1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"The chest is empty!")
            return true
        end
   
        -- critical
        if chestSelected == "critical" then
            if player:getCriticalLevel() >= CRITICAL.LEVEL_MAX then
                player:sendTextMessage(MESSAGE_STATUS_WARNING, "Unable to use chest. You have already reached the maximum critical skill.")
                return false
            end
            local newCriticalLevel = player:getCriticalLevel() + 1
            player:setCriticalLevel(newCriticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your critical skill to [" .. newCriticalLevel .. "/" .. CRITICAL.LEVEL_MAX .. "].")
            player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
   
        -- dodge
        elseif chestSelected == "dodge" then
            -- give dodge stuff..
       
       
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "Error in table. Please contact gamemaster.") -- dodge or critical is mispelled in your table.
            return true
        end
   
        -- gives chest storage, so can't be used again
        player:setStorageValue(uniqueId, 1)
    end
    return true
end

criticalAndDodgeChests:aid(actionId)
criticalAndDodgeChests:register()
@Xikini you're amazing, thanks again! Sorry for the delay, tested and working perfectly. This is the script outcome:
Lua:
local chests = {
    [27101] = "critical", -- [uniqueId] = "type"
    [27102] = "critical",
    [27103] = "critical",
    [27104] = "dodge",
    [27105] = "dodge",
    [27106] = "dodge"
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local uniqueId = item:getUniqueId()
    local chestSelected = chests[uniqueId]
    if chestSelected then
        if player:getStorageValue(uniqueId) ~= -1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"The chest is empty!")
            return true
        end
   
        -- critical
        if chestSelected == "critical" then
            if player:getCriticalLevel() >= CRITICAL.LEVEL_MAX then
                player:sendTextMessage(MESSAGE_STATUS_WARNING, "Unable to use chest. You have already reached the maximum critical skill.")
                return false
            end
            local newCriticalLevel = player:getCriticalLevel() + 1
            player:setCriticalLevel(newCriticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your critical skill to [" .. newCriticalLevel .. "/" .. CRITICAL.LEVEL_MAX .. "].")
            player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
   
        -- dodge
        elseif chestSelected == "dodge" then
            if player:getDodgeLevel() >= DODGE.LEVEL_MAX then
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "Unable to use chest. You have already reached the maximum dodge skill.")
            return false
            end
            local newDodgeLevel = player:getDodgeLevel() + 1
            player:setDodgeLevel(newDodgeLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your dodge skill to [" .. newDodgeLevel .. "/" .. DODGE.LEVEL_MAX .. "].")
            player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
            -- give dodge stuff..
                 
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "Error in table. Please contact gamemaster.") -- dodge or critical is mispelled in your table.
            return true
        end
   
        -- gives chest storage, so can't be used again
        player:setStorageValue(uniqueId, 1)
    end
    return true
end

Levi999x said:
@Levi999x I attached on the previous post
Anyways here it is
 
Back
Top