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

Script for online time.

1268995

Member
Joined
Sep 9, 2010
Messages
422
Reaction score
13
Hello Guys.

I need (please xD) a script that every 1 hour player are online he wins a premium point on gesior (that points used to buy itens on site)

So if player stays 24h online on the server, he will win 24 points -> each hour online = 1 premium point.

Ideas?
 
Code:
[29/07/2015 22:40:23] [Error - CreatureScript Interface]
[29/07/2015 22:40:24] data/creaturescripts/scripts/addpointTimer.lua:onThink
[29/07/2015 22:40:24] Description:
[29/07/2015 22:40:24] data/creaturescripts/scripts/addpointTimer.lua:6: attempt to compare boolean with number
[29/07/2015 22:40:24] stack traceback:
[29/07/2015 22:40:24]    data/creaturescripts/scripts/addpointTimer.lua:6: in function <data/creaturescripts/scripts/addpointTimer.lua:1>

[29/07/2015 22:40:24] [Error - CreatureScript Interface]
[29/07/2015 22:40:24] data/creaturescripts/scripts/addpointTimer.lua:onThink
[29/07/2015 22:40:24] Description:
[29/07/2015 22:40:24] (luaGetCreatureStorage) Creature not found
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
 
    if getPlayerStorageValue(cid, 455577) < os.time() then
        --db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- remove this line its for testing to see if it works
    return true
end

Now i got no errors on console ;DDDDDDDD

But i dont know how to put the checkers.
Also i dont know what this part of script do:
Code:
  local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
  doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- remove this line its for testing to see if it works
 
counts time
Code:
local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
this is message to show you that script is working well
Code:
doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- remove this line its for testing to see if it works

message you can delete but counter must be there
you can edit count = 1 to amount of points to be added
Code:
time = 10
you can edit to
Code:
time = 1*60*60
Code:
        --db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
change to
Code:
        db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
before you change time = 10
1. See if you got message counting from 10 to 0 and again when it ends should start counting from 10 to 0 endless
2. See if database command adds points

#Edit
I think script will not work if you remove:
Code:
doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- remove this line its for testing to see if it works
If you want to remove message you must change:
Code:
return true
to
Code:
return remaining
 
Last edited:
counts time
Code:
local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
this is message to show you that script is working well
Code:
doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- remove this line its for testing to see if it works

message you can delete but counter must be there
you can edit count = 1 to amount of points to be added
Code:
time = 10
you can edit to
Code:
time = 1*60*60
Code:
        --db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
change to
Code:
        db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
before you change time = 10
1. See if you got message counting from 10 to 0 and again when it ends should start counting from 10 to 0 endless
2. See if database command adds points

#Edit
I think script will not work if you remove:
Code:
doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- remove this line its for testing to see if it works

Right.
1) Do not appear any message on console/to my online character about time ramaining;
2) Appear this error on console:
Code:
[29/07/2015 22:59:41] [Error - CreatureScript Interface]
[29/07/2015 22:59:41] data/creaturescripts/scripts/addpointTimer.lua:onThink
[29/07/2015 22:59:41] Description:
[29/07/2015 22:59:41] data/creaturescripts/scripts/addpointTimer.lua:7: attempt to call field 'query' (a nil value)
[29/07/2015 22:59:41] stack traceback:
[29/07/2015 22:59:41]    data/creaturescripts/scripts/addpointTimer.lua:7: in function <data/creaturescripts/scripts/addpointTimer.lua:1>

I think this erros happens when try to add points to database
 
Try this:
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
  
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end
 
Try this:
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add

    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end

Appear this error on console:
[29/07/2015 23:06:11] mysql_store_result(): UPDATE `accounts` SET `premium_points` = '105' WHERE `name` ='123456as' - MYSQL ERROR: (0)

EDIT:

I made this:
Code:
    local aid = getPlayerAccountId(cid)
    local query = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `id`= "..aid..";")

function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
    local points = 1

  
 
    if getPlayerStorageValue(cid, 455577) < os.time() then
        doAccountAddPoints(cid, points)
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end

No error appear on console, but are not adding any point.

Function doAccountAddPoints(cid, points) are this (on libs folder):

Code:
function doAccountAddPoints(cid, count)
     return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end
 
Last edited:
This should work:
Code:
function onThink(cid, interval)

    --local getAccPoints = db.storeQuery("SELECT * FROM `accounts` WHERE `name` ='"..player:getAccount().."'")
    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
   
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end
 
This should work:
Code:
function onThink(cid, interval)

    --local getAccPoints = db.storeQuery("SELECT * FROM `accounts` WHERE `name` ='"..player:getAccount().."'")
    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
 
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end

The same error appear on console:

Code:
[29/07/2015 23:30:14] [Error - CreatureScript Interface]
[29/07/2015 23:30:14] data/creaturescripts/scripts/addpointTimer.lua:onThink
[29/07/2015 23:30:14] Description:
[29/07/2015 23:30:14] data/creaturescripts/scripts/addpointTimer.lua:8: attempt to call field 'query' (a nil value)
[29/07/2015 23:30:14] stack traceback:
[29/07/2015 23:30:14]    data/creaturescripts/scripts/addpointTimer.lua:8: in function <data/creaturescripts/scripts/addpointTimer.lua:1>

As i write on my 2 last post, i maded a script and added a local query ... and no error appeared on console, but points were not being add.. Maybe the code i posted on my 2 last post can help you..
 
omg.. misstype
Code:
function onThink(cid, interval)

    --local getAccPoints = db.storeQuery("SELECT * FROM `accounts` WHERE `name` ='"..player:getAccount().."'")
    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
   
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end
 
omg.. misstype
Code:
function onThink(cid, interval)

    --local getAccPoints = db.storeQuery("SELECT * FROM `accounts` WHERE `name` ='"..player:getAccount().."'")
    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
  
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    doPlayerSendDefaultCancel(cid, "Time before adding point: "..remaining..".") -- if you remove this line change return true to return remaining
    return true -- return remaining
end

Error on console:

Code:
[29/07/2015 23:37:41] mysql_store_result(): UPDATE `accounts` SET `premium_points` = `premium_points` + 1 WHERE `id` = 1607361; - MYSQL ERROR:  (0)
 
creaturescripts/creaturescripts.xml
Code:
<event type="think" name="addpointTimer" script="addpointTimer.lua" />

creaturescripts/addpointTimer.lua
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
   
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = `" .. getPlayerAccount(cid) .. "`;")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    return remaining
end

creaturescripts/scripts/login.lua
Code:
local time = 10 -- time to add points set to 1*60*60 after you test it
            registerCreatureEvent(cid, "addpointTimer")
            setPlayerStorageValue(cid, 455577, os.time() + time)
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Every 1 hour online you will earn 1 point to sms shop.")
 
creaturescripts/creaturescripts.xml
Code:
<event type="think" name="addpointTimer" script="addpointTimer.lua" />

creaturescripts/addpointTimer.lua
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
  
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = `" .. getPlayerAccount(cid) .. "`;")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    return remaining
end

creaturescripts/scripts/login.lua
Code:
local time = 10 -- time to add points set to 1*60*60 after you test it
            registerCreatureEvent(cid, "addpointTimer")
            setPlayerStorageValue(cid, 455577, os.time() + time)
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Every 1 hour online you will earn 1 point to sms shop.")

Error on console:
Code:
[29/07/2015 23:45:15] mysql_real_query(): UPDATE `accounts` SET `premium_points` = `premium_points` + 1 WHERE `id` = `12345as`; - MYSQL ERROR: Unknown column '12345as' in 'where clause' (1054)

12345as = player account

If you think the code are right, i think the problem is something missing in my 050-function.lua inside libs folder... what u think?
 
No its about query command
This must work:
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
   
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    return remaining
end
 
No its about query command
This must work:
Code:
function onThink(cid, interval)

    local time = 10 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add
  
    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    return remaining
end

Ye, i was changing db.query to db.executeQuery and u posted again :p

Now the code WORKS!
But is adding only 1 point, the code are not adding more points when time restarts.

I maded this to the code:
Code:
function onThink(cid, interval)

  local time = 1*60*60 -- time to add points change to 1*60*60 after you test it
  local count = 1 -- how many points to add
   
  if getPlayerStorageValue(cid, 455577) < os.time() then
  db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
  setPlayerStorageValue(cid, 455577, os.time() + time)
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"Point added!")
  end
  local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
  return remaining
end

I mean, i added
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"Point added!")

And appear "Point Added" only 1 time...
 
Ops, i change
local time = 1*60*60 -- time to add points change to 1*60*60 after you test it
to
local time = 10 -- time to add points change to 1*60*60 after you test it

And points are being added after 10 seconds and added again and again..

I think it workss!!

EDIT:

The script i have is the final script buddy?
 
Last edited:
test it and if works change time = 5 to time = 1*60*60 in login.lua and addpointtimer.lua

creaturescripts/creaturescripts.xml
Code:
<event type="think" name="addpointTimer" script="addpointTimer.lua" />

creaturescripts/addpointTimer.lua
Code:
function onThink(cid, interval)

    local time = 5 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add

    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Point added!")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    return remaining
end

creaturescripts/scripts/login.lua
Code:
local time = 5 -- time to add points set to 1*60*60 after you test it
    registerCreatureEvent(cid, "addpointTimer")
    setPlayerStorageValue(cid, 455577, os.time() + time)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Every 1 hour online you will earn 1 point to sms shop.")

so db.executeQuery works right?
 
Last edited:
test it and if works change time = 5 to time = 1*60*60 in login.lua and addpointtimer.lua

creaturescripts/creaturescripts.xml
Code:
<event type="think" name="addpointTimer" script="addpointTimer.lua" />

creaturescripts/addpointTimer.lua
Code:
function onThink(cid, interval)

    local time = 5 -- time to add points change to 1*60*60 after you test it
    local count = 1 -- how many points to add

    if getPlayerStorageValue(cid, 455577) < os.time() then
        db.storeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. count .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Point added!")
        setPlayerStorageValue(cid, 455577, os.time() + time)
    end
    local remaining = math.ceil(getPlayerStorageValue(cid, 455577) - os.time())
    return remaining
end

creaturescripts/scripts/login.lua
Code:
local time = 5 -- time to add points set to 1*60*60 after you test it
    registerCreatureEvent(cid, "addpointTimer")
    setPlayerStorageValue(cid, 455577, os.time() + time)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Every 1 hour online you will earn 1 point to sms shop.")

#edit
again did executeQuery instead of storeQuery :p

Ye, time = 5 are adding 1 point to shop after 5 seconds !!!

I have questions:

1) 1*60*60 = 1 hour?
2) If player log out and then log in, the 1 hour count will be restarted?
3) There is a possibility of player make a bug? (i cant think how this script can bug, since its perfect, but as u are a godlike programmer, maybe u can see a ocult bug that players can abuse in future).
 
Last edited:
1 yes
2 yes
3 i dont see bugs

If player dies also will restart the time?

Well, then i think the script are done and PERFECT!!!

Thank you VERY MUCH man.
@WibbenZ , see? Shadow Dan maded even u saying "u wrong, change that and that" XD

Thanks dan, any problem i talk to u.. If my ot gives me some money i will not forget ur help :p
 
Back
Top