• 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 [TFS 0.X] System Online Points

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hi guys, how are you?

Im looking for a system similar to this:


Lua:
local config = {
    storage = 20000,
    pointItemId = 2160,
    pointsPerHour = 1,
    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_STATUS_CONSOLE_BLUE, string.format("You have received %d %s for being online for an hour.", config.pointsPerHour, item:getName()))
                end
                return true
            end
            player:setStorageValue(config.storage, seconds +math.ceil(interval/1000))
        end
    end
    return true
end

onlinePointsEvent:interval(10000)
onlinePointsEvent:register()

But when player log out, count system is reseted to 0. Every 1 hour player online, he get a item, allowed 4 MCs. Using OTX 2 (based on TFS 0.3.7).
 
Back
Top