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

Revscripts Tournament Coins

tutbarao

New Member
Joined
Feb 18, 2011
Messages
25
Reaction score
0
I didn't find it anywhere. Please Help

I am using the latest version of Otservbr, and I am looking to use the tournament coins but I don't know how to do it, I would like to make the players win "X" tournament coins every "X" time.
 
I didn't find it anywhere. Please Help

I am using the latest version of Otservbr, and I am looking to use the tournament coins but I don't know how to do it, I would like to make the players win "X" tournament coins every "X" time.


Code:
local config = {
    storage = 20000,
    pointItemId = 24774, -- Item ID, in this case is TibiaCoin just create a new one for Tournament.
    pointsPerHour = 1, -- 1 Point Per hour
    checkDuplicateIps = false
}

local onlinePointsEvent = GlobalEvent("GainPointPerHour")

function onlinePointsEvent.onThink(interval)
    local players = Game.getPlayers()
    if #players == 0 then
        return true
    end

    local checkIp = {}
    for _, player in pairs(players) do
        local ip = player:getIp()
        if ip ~= 0 and (not config.checkDuplicateIps or not checkIp[ip]) then
            checkIp[ip] = true
            local seconds = math.max(0, player:getStorageValue(config.storage))
            if seconds >= 3600 then
                player:setStorageValue(config.storage, 0)
                local item = player:addItem(config.pointItemId, config.pointsPerHour)
                if item then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You received 1 Tournament coin because you play for 1 hour.")
                end
                return true
            end
            player:setStorageValue(config.storage, seconds +math.ceil(interval/1000))
        end
    end
    return true
end

onlinePointsEvent:interval(10000)
onlinePointsEvent:register()

Creating an item when you use it it will update your db.Table to 1 tournament coin:

Code:
local tournamentCoin = Action()

function tournamentCoin.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local tournamentCoins = 1
  db.query("UPDATE `accounts` SET `tournamentBalance` = `tournamentBalance` + '" .. tournamentCoins .. "' WHERE `id` = '" .. player:getAccountId() .. "';")
  player:sendTextMessage(MESSAGE_INFO_DESCR, "You received "..tournamentCoins.." Tournament Coins.")
  item:remove(1)
  return true
end

tournamentCoin:id(24275) --- Item ID
tournamentCoin:register()

Add on your db this sql:
Code:
ALTER TABLE `accounts` ADD `tournamentBalance` BIGINT UNSIGNED NOT NULL DEFAULT '0',
 
Back
Top