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

Coins for being online

zerghel

Tsuni
Joined
Jul 1, 2008
Messages
299
Reaction score
9
Hi.
i got this script to give 1 coin every hour online (creaturescript)
but it need an "account, ip check" or something cause i allow multiclienting from same account
for 3 characters they get 3 coins every hour to their account
hope u can helpme with this
thx in advance
Lua:
local event = {}
local timeOnline = 60 * 60 * 1000

function addPremiumPoint(cid)
    local player = Player(cid)
    if player then
        db.query("UPDATE accounts SET coins = coins + 1 WHERE id = '" ..player:getAccountId().. "';")
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have been online for an hour and have earned 1 Store coin.")
        event[cid] = addEvent(addPremiumPoint, timeOnline, cid)
        return
    end
    event[cid] = nil
end

function onLogin(player)
    local cid = player:getId()
    if not event[cid] then
        event[cid] = addEvent(addPremiumPoint, timeOnline, cid)
    end
    return true
end
 
Solution
Lua:
local timeOnline = 60 * 60 * 1000
local pointPlayers = {}

function addPremiumPoint(PID, playerIP)
    local player = Player(PID)
    if player then
        db.query("UPDATE accounts SET coins = coins + 1 WHERE id = '" ..player:getAccountId().. "';")
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have been online for an hour and have earned 1 Store coin.")
        addEvent(addPremiumPoint, 60 * 60 * 1000, PID, playerIP)
        return true
    else
        pointPlayers[playerIP] = nil
    end
end

function onLogin(player)
    local PID = player:getId()
    local playerIP = player:getIp()
  
    if not pointPlayers[player:getIp()]  then
        pointPlayers[playerIP] = true
        addEvent(addPremiumPoint, 60 * 60 * 1000, PID...
Here is a modified version I made for the thread: GlobalEvent - System Online Points (https://otland.net/threads/system-online-points.250371/)

With this script you can verify the IP of the player and the Account, can be activated or deactivated in config.
The event is updated every 10 seconds by default, to avoid a bit of overload on the server, although you shouldn't worry too much about it if you have very few players, I can't tell you how it works with 1000 or more players.

The time is being saved in a storage, so if you disconnect at minute 59, when you connect this counter it will resume to continue counting the time online

data/scripts/filename.lua
Lua:
local config = {
    storage = 20000,
    pointsPerHour = 1, -- gain points
    checkDuplicateIps = false,
    checkDuplicateAcc = false,
    checkInterval = 10 -- seconds
}

local onlinePointsEvent = GlobalEvent("GainPointPerHour")

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

    local checkIp, checkAcc = {}, {}
    for _, player in pairs(players) do
        local ip, accountId = player:getIp(), player:getAccountId()
        if ip ~= 0 and (not config.checkDuplicateIps or not checkIp[ip]) and (not config.checkDuplicateAcc or not checkAcc[accountId]) then
            checkIp[ip], checkAcc[accountId] = true, true
            local seconds = math.max(0, player:getStorageValue(config.storage))
            if seconds >= 3600 then
                player:setStorageValue(config.storage, math.max(0, seconds -3600))
                db.query(string.format("UPDATE accounts SET coins = coins +%d WHERE id = '%d';", config.pointsPerHour, accountId))
                player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have been online for an hour and have earned 1 Store coin.")
                return true
            end
            player:setStorageValue(config.storage, seconds +config.checkInterval)
        end
    end
    return true
end

onlinePointsEvent:interval(config.checkInterval * 1000)
onlinePointsEvent:register()
 
Here is a modified version I made for the thread: GlobalEvent - System Online Points (https://otland.net/threads/system-online-points.250371/)

With this script you can verify the IP of the player and the Account, can be activated or deactivated in config.
The event is updated every 10 seconds by default, to avoid a bit of overload on the server, although you shouldn't worry too much about it if you have very few players, I can't tell you how it works with 1000 or more players.

The time is being saved in a storage, so if you disconnect at minute 59, when you connect this counter it will resume to continue counting the time online

data/scripts/filename.lua
Lua:
local config = {
    storage = 20000,
    pointsPerHour = 1, -- gain points
    checkDuplicateIps = false,
    checkDuplicateAcc = false,
    checkInterval = 10 -- seconds
}

local onlinePointsEvent = GlobalEvent("GainPointPerHour")

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

    local checkIp, checkAcc = {}, {}
    for _, player in pairs(players) do
        local ip, accountId = player:getIp(), player:getAccountId()
        if ip ~= 0 and (not config.checkDuplicateIps or not checkIp[ip]) and (not config.checkDuplicateAcc or not checkAcc[accountId]) then
            checkIp[ip], checkAcc[accountId] = true, true
            local seconds = math.max(0, player:getStorageValue(config.storage))
            if seconds >= 3600 then
                player:setStorageValue(config.storage, math.max(0, seconds -3600))
                db.query(string.format("UPDATE accounts SET coins = coins +%d WHERE id = '%d';", config.pointsPerHour, accountId))
                player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have been online for an hour and have earned 1 Store coin.")
                return true
            end
            player:setStorageValue(config.storage, seconds +config.checkInterval)
        end
    end
    return true
end

onlinePointsEvent:interval(config.checkInterval * 1000)
onlinePointsEvent:register()
Thank you very much my friend, 100% perfect !!!

@Sarah Wesker I called you in private to ask you one more question, if i can help, thank you.
 
Back
Top