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

Receive reward every time play unlock bestiary.

endziu2222

Active Member
Joined
Nov 2, 2010
Messages
167
Solutions
1
Reaction score
44
~I was trying to make something worked but it did not succeeded. So I am here to ask for you to help me out. I am trying to give player reward any time player receives message in the server log example: 10:04 You unlocked details for the creature 'Rat' But I would like it to work for all monsters instead of only rat. Code I have you can find bellow: I am using Canary based server/revscipt
Lua:
-- Define the array of prizes with their descriptions
local prizeData = {
    [942] = {id = 22771, description = "Tibia coins scroll"},
}

-- Function to reward players when they unlock creature details
function onCreatureDetailsUnlocked(player, message)
    if message:match("You unlocked details for the creature") then
        -- Randomly select one of the prize IDs from the table keys
        local prizeKeys = {}
        for key, _ in pairs(prizeData) do
            table.insert(prizeKeys, key)
        end
        local selectedPrizeId = prizeKeys[math.random(#prizeKeys)]
       
        -- Check if the selected prize ID exists in the prizeData table
        if prizeData[selectedPrizeId] then
            local prize = prizeData[selectedPrizeId]
           
            -- Give the player the selected prize item
            local prizeItemId = prize.id
            player:addItem(prizeItemId, 1) -- Adjust quantity as needed
           
            -- Broadcast the message with the prize description
            Game.broadcastMessage("[bestiary SYSTEM] Congratulations! " .. player:getName() .. " won " .. prize.description .. " in the bestiary.", MESSAGE_EVENT_ADVANCE)
        else
            print("Error: Prize ID not found in prizeData.")
        end
    end
end

-- Register the function to capture log messages
function onRecvCreatureDetailsUnlocked(player, message)
    if player and type(message) == "string" then
        onCreatureDetailsUnlocked(player, message)
    end
end

-- Register the function to be called when a player logs in
function onPlayerLogin(player)
    if player then
        player:registerEvent("RecvCreatureDetailsUnlocked")
    end
end

-- Register the login event
for _, player in ipairs(Game.getPlayers()) do
    onPlayerLogin(player)
end
 
Last edited:
Back
Top