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

[EACH 1HOUR ONLINE] REWARD - PREMIUM POINTS TFS 1.2

Zak.Tibiam

New Member
Joined
Mar 25, 2012
Messages
150
Reaction score
3
hello people would like to know if anyone could help with a script that every 1 hour online in the player wins 1 server premium points on your account.

use tfs 1.2


Thank you
 
Creaturescripts

Code:
function onLogin(player)

addEvent(addPremiumPoint, 60 * 60 * 1000)

return true
end


function addPremiumPoint(player)
    db.executeQuery("UPDATE `players` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getId() .. " LIMIT 1');")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
    addEvent(addPremiumPoint, 60 * 60 * 1000)
end
 
Creaturescripts

Code:
function onLogin(player)

addEvent(addPremiumPoint, 60 * 60 * 1000)

return true
end


function addPremiumPoint(player)
    db.executeQuery("UPDATE `players` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getId() .. " LIMIT 1');")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
    addEvent(addPremiumPoint, 60 * 60 * 1000)
end
Creaturescripts

Code:
function onLogin(player)

addEvent(addPremiumPoint, 60 * 60 * 1000)

return true
end


function addPremiumPoint(player)
    db.executeQuery("UPDATE `players` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getId() .. " LIMIT 1');")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
    addEvent(addPremiumPoint, 60 * 60 * 1000)
end
@Itutorial my friend the points have to go to the accounts table no players would look like?

Code:
function onLogin(player)

addEvent(addPremiumPoint, 60 * 60 * 1000)

return true
end


function addPremiumPoint(player)
    db.executeQuery("UPDATE `accounts` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getId() .. " LIMIT 1');")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
    addEvent(addPremiumPoint, 60 * 60 * 1000)
end
 
There is no function db.executeQuery not in lua at least.

I don't know if this will work tho.
Code:
local event = nil
local timeOnline = 60 * 60 * 1000

function addPremiumPoint(cid)
    local player = Player(cid)
    if player then
        db.query("UPDATE `accounts` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getGuid() .. " LIMIT 1');")
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
        event = addEvent(addPremiumPoint, timeOnline, cid)
    end
end

function onLogin(player)
    if not event then
        event = addEvent(addPremiumPoint, timeOnline, player:getId())
    end
    return true
end
 
There is no function db.executeQuery not in lua at least.

I don't know if this will work tho.
Code:
local event = nil
local timeOnline = 60 * 60 * 1000

function addPremiumPoint(cid)
    local player = Player(cid)
    if player then
        db.query("UPDATE `accounts` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getGuid() .. " LIMIT 1');")
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
        event = addEvent(addPremiumPoint, timeOnline, cid)
    end
end

function onLogin(player)
    if not event then
        event = addEvent(addPremiumPoint, timeOnline, player:getId())
    end
    return true
end
once the first player logged in, no one else will get the addEvent as you don't bind the player with the event table
better saying event will never turn to false / nil again as it's always beeing re adressed.
Code:
event = {}; event[cid] = addEvent(....)
 
once the first player logged in, no one else will get the addEvent as you don't bind the player with the event table
better saying event will never turn to false / nil again as it's always beeing re adressed.
Code:
event = {}; event[cid] = addEvent(....)
Good to know, thank you :)
 
once the first player logged in, no one else will get the addEvent as you don't bind the player with the event table
better saying event will never turn to false / nil again as it's always beeing re adressed.
Code:
event = {}; event[cid] = addEvent(....)
But isn't using addEvent a bad idea here o.o, what if the player logout in the middle, it would just bug an error later on
 
But isn't using addEvent a bad idea here o.o, what if the player logout in the middle, it would just bug an error later on
That is why the id is passed instead of player as @Evil Hero pointed out the event is now a table and cid is the index of the table, we don't want the player log out and log in multiple times stacking up the events this is why we want the return value of the addevent.
 
So I will re-write it with the above in mind.
Again I have no idea if this will work :p
Code:
local event = {}
local timeOnline = 60 * 60 * 1000

function addPremiumPoint(cid)
    local player = Player(cid)
    if player then
        db.query("UPDATE `accounts` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getGuid() .. " LIMIT 1');")
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.")
        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

Edited, see @Evil Hero's suggestion below :)
 
function addPremiumPoint(cid) local player = Player(cid) if player then db.query("UPDATE `accounts` SET `premium_points` = premium_points + 1 WHERE `id`= " .. player:getGuid() .. " LIMIT 1');") player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been online for an hour and have earned 1 premium point.") event[cid] = addEvent(addPremiumPoint, timeOnline, cid) return end event[cid] = {} end
Code:
event[cid] = {}
should rather be
Code:
event[cid] = nil
in order for the gc to pick it up and clear memory.
 
Back
Top