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

Reward chest?

psychosisneamia

~Beginner~
Joined
Jun 7, 2012
Messages
162
Reaction score
7
Is there a way to make a chest give you rewards for example

Code:
 You received a Lottery Ticket, Return when you are level 50 for another prize!
(Level 50) ~returns~
You received a Crystal Coin, Return when you are level 100 for another prize!

You can continue adding on to it, I was just thinking this would be an awesome idea just have no idea how to code it. Any ideas? I am thinking its probably going to need storage-values if I can think of a way before anyone replies I will post my results!

Thanks in advance!
 
I got an idea for it.. I am not sure if it would work, can someone see if they can see anything that would make the script now work? I will throw it on my server tomorrow and see what it does.

Code:
function onUse(cid, item, frompos, item2, topos)

    if item.uid == 45214 then
        if getPlayerLevel(cid) <= 8 then
            doPlayerSendTextMessage(cid,22,"You need level 8 to get the first prize.")
        elseif getPlayerLevel(cid) >= 8 and getPlayerLevel(cid) < 20 then
            queststatus = getPlayerStorageValue(cid,301547)
            if queststatus == -1 then
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have found a Lottery Ticket. Return to this chest once you are level 20.")
                doPlayerSendTextMessage(cid,22,"You have found a Lottery Ticket. Return to this chest once you are level 20.")
                doPlayerAddItem(cid,5957,1)
                setPlayerStorageValue(cid,301547,1)
            else
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have already found the reward for level 8-20. Return when you are level 20!")
            end

        elseif getPlayerLevel(cid) >= 20 and getPlayerLevel(cid) < 30 then
            queststatus = getPlayerStorageValue(cid,301548)
            if queststatus == 2 then
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have already found the reward for level 20-30 Return again when you are level 50!.")
            elseif queststatus < 2 then
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have found a Crystal Coin.")
                doPlayerAddItem(cid,2160,1)
                setPlayerStorageValue(cid,301548,2)
            else
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "Even though you died you have already found the level 20-30 prize.")
            end
        end

Thanks!
 
Code:
local storage = 56200
local config = {
    [1] = {levReq = 50, rewards = {
        [1] = {2195, 1}
        }
    },
    [2] = {levReq = 100, rewards = {
        [1] = {2160, 10},
        [2] = {2159, 2}
        }
    },
    [3] = {levReq = 150, rewards = {
        [1] = {2160, 10},
        [2] = {2159, 2}
        }
    },
    [4] = {levReq = 200, rewards = {
        [1] = {2160, 10},
        [2] = {2160, 10},
        [3] = {2160, 10},
        [4] = {2159, 2}
        }
    }
}

function onUse(cid, item)
    local level = getPlayerLevel(cid)
    local quest = 1
    local text = "BUG? Ask andu on Otland"
    if getPlayerStorageValue(cid, storage) ~= nil then
        quest = getPlayerStorageValue(cid, storage) + 1
    end
    if quest > 0 and quest < #config then
        if level >= config[quest].levReq then
            text = "You gained"
            for j = 1, #config[quest].rewards do
                doPlayerAddItem(cid, config[quest].rewards[j][1], config[quest].rewards[j][2])
                text = text.. " " ..config[quest].rewards[j][2].. "x " ..getItemNameById(config[quest].rewards[j][1])
            end
            if quest < #config then
                text = ". Come back at level " ..config[(quest)].levReq.. " for next reward!"
            else
                text = ". You have took all rewards from this chest and now it is empty!"
            end
            doPlayerSetStorageValue(cid, storage, quest)
        else
            text = "Sorry but your level is too low. Come back at level " ..config[quest].levReq.. "."
        end
    else
        text = "The chest is empty!"
    end
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, text)
    return true
end
 
Last edited:
One thing I don't understand in your script andu. If a player is already level 200 will it give them the rewards for the level 50-100-200? or do you have to you the chest when you are the exact level?

Edit: I added your script to my server, and with no luck. There are no errors, however everytime someone goes to use the chest they get the message "the chest is empty"

The script of yours I used~
Code:
local storage = 56200
local config = {
    [1] = {levReq = 8, rewards = {
        [1] = {5957, 1}
        }
    },
    [2] = {levReq = 20, rewards = {
        [1] = {2160, 1}
        }
    },
    [3] = {levReq = 30, rewards = {
        [1] = {10518, 1}
        }
    },
    [4] = {levReq = 50, rewards = {
        [1] = {2527, 10}
        }
    }
}

function onUse(cid, item)
    local level = getPlayerLevel(cid)
    local quest = 1
    local text = "Error: Report this chest to a GM+"
    if getPlayerStorageValue(cid, storage) ~= nil then
        quest = getPlayerStorageValue(cid, storage) + 1
    end
    if quest > 0 and quest < #config then
        if level >= config[quest].levReq then
            text = "You gained"
            for j = 1, #config[quest].rewards do
                doPlayerAddItem(cid, config[quest].rewards[j][1], config[quest].rewards[j][2])
                text = text.. " " ..config[quest].rewards[j][2].. "x " ..getItemNameById(config[quest].rewards[j][1])
            end
            if quest < #config then
                text = ". Come back at level " ..config[(quest)].levReq.. " for your next reward!"
            else
                text = ". You have obtained all the rewards from this chest and now it is empty!"
            end
            doPlayerSetStorageValue(cid, storage, quest)
        else
            text = "Sorry but your level is too low. Come back at level " ..config[quest].levReq.. "."
        end
    else
        text = "The chest is empty!"
    end
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, text)
    return true
end
Maybe I just did something wrong?
 
change this:
Code:
if getPlayerStorageValue(cid, storage) ~= nil then
to
Code:
if getPlayerStorageValue(cid, storage) ~= -1 then

If your level is 200, and you didn't ever opened this chest you will get all rewards, for 50,100,150 and 200.

@edit
Found few bugs in messages. Here is the fixed:
Code:
local storage = 57258
local config = {
    [1] = {levReq = 50, rewards = {
        [1] = {2195, 1}
        }
    },
    [2] = {levReq = 100, rewards = {
        [1] = {2160, 10},
        [2] = {2159, 2}
        }
    },
    [3] = {levReq = 150, rewards = {
        [1] = {2160, 10},
        [2] = {2159, 2}
        }
    },
    [4] = {levReq = 200, rewards = {
        [1] = {2160, 10},
        [2] = {2160, 10},
        [3] = {2160, 10},
        [4] = {2159, 2}
        }
    }
}

function onUse(cid, item)
    local level = getPlayerLevel(cid)
    local quest = 1
    local text = "BUG? Ask andu on Otland"
    if getPlayerStorageValue(cid, storage) ~= -1 then
        quest = getPlayerStorageValue(cid, storage) + 1
    end
    if quest > 0 and quest < #config then
        if level >= config[quest].levReq then
            text = "You gained"
            for j = 1, #config[quest].rewards do
                doPlayerAddItem(cid, config[quest].rewards[j][1], config[quest].rewards[j][2])
                text = text.. " " ..config[quest].rewards[j][2].. "x " ..getItemNameById(config[quest].rewards[j][1])
            end
            if quest < #config then
                text = text.. ". Come back at level " ..config[(quest)].levReq.. " for next reward!"
            else
                text = text.. ". You have took all rewards from this chest and now it is empty!"
            end
            doPlayerSetStorageValue(cid, storage, quest)
        else
            text = "Sorry but your level is too low. Come back at level " ..config[quest].levReq.. "."
        end
    else
        text = "The chest is empty!"
    end
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, text)
    return true
end
 
Last edited:
Back
Top