• 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 Give X premium points per hour

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
870
Solutions
2
Reaction score
49
Using tfs 1.2

im trying to make so every hour players would get x premium points but probably doing something hella dumb :D
Lua:
local config = {
    storage = 20000,
    pointsAddPerHour = 5,
    pointsPerHour = 1,
    checkDuplicateIps = false
}


function 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 premium_points = db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. config.pointsAddPerHour .. " WHERE `id` = " .. config.pointsPerHour)
                if premium_points then
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("You have received %s premium points for being online for an hour.", config.pointsAddPerHour))
                end
                return true
            end
            player:setStorageValue(config.storage, seconds +math.ceil(interval/1000))
        end
    end
    return true
end
 
Last edited:
Problem may be the ID in your query at the end. Try this code, i cannot do myself sorry. Also check my comment incase you want it to work like that instead. Was just something I would consider an improvement, instead of possibiliy people exploiting being afk with 1000 accs. Good luck. Any errors post them with good detail.

Lua:
local config = {
    storage = 20000,
    pointsAddPerHour = 5,
    pointsPerHour = 1,
    checkDuplicateIps = false
}


function onThink(interval)
    local players = Game.getPlayers() -- To only reward players which are online, change Game.getPlayers() to getOnlinePlayers()
    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 premium_points = db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. config.pointsAddPerHour .. " WHERE `id` = " .. player:getGuid() .. ";")
                if premium_points then
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("You have received %s premium points for being online for an hour.", config.pointsAddPerHour))
                end
                return true
            end
            player:setStorageValue(config.storage, seconds +math.ceil(interval/1000))
        end
    end
    return true
end
 
Back
Top