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

Sql or Lua usage

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
311
Solutions
27
Reaction score
154
Location
Brazil
GitHub
Mateuso8
Hello,

I'm developing a system of daily tasks, which will reset whenever the server starts. In my onStartup I have the following code:
Lua:
    local resultId = db.storeQuery("SELECT * FROM `player_storage` WHERE `key` = "..DAILY_TRASH_STATUS.." AND `value` = 2") --Get all rows with Status = 2
    if resultId ~= false then
        repeat
            local playerId = result.getDataInt(resultId, "player_id") --Get playerId
            --Player(playerId):setStorageValue(DAILY_TRASH_SHOULD_RESET, 1)
            db.query("UPDATE `player_storage` SET `value` = 1 WHERE `player_id` = " .. playerId .." AND `key` = "..DAILY_TRASH_SHOULD_RESET)
        until not result.next(resultId)
        result.free(resultId)
    end
Can i use playerId as cid, in line 5?
To reset player task, i have onLogin check a storage value, if 1 then reset. I set this storage to 1 in line 6. If my first question is Yes the answer, what form should I use? Why?

Thanks for helping.
 
Solution
Either one is fine, startup would be my opinion honestly that way you do the important operations on server load when it can't affect player latency (even though technically you're saving nanoseconds). Another reason is that visually & mentally it's more concise and you know it's all being done at once.
Well the easiest attempt which does not involve db access can be done through storage values yes.
This could be achieved by saving a timestamp once the player has done all daily quests and then match that timestamp with the time when the player login again.
If you however want to stick with onStartup then there is no other way of doing it as you are doing right now.
This example would work like, if a player login after 12am it resets his dailies:
Lua:
function onLogin(player)
    local dateTable = os.date("*t", os.time())
    local lastLoginTable = os.date("*t", player:getStorageValue(DAILY_TRASH_STATUS))
    local storageStatus = player:getStorageValue(DAILY_TRASH_STATUS)
    if storageStatus < 1 or dateTable.year > lastLoginTable.year or dateTable.month > lastLoginTable.month or dateTable.day > lastLoginTable.day then
        player:setStorageValue(DAILY_TRASH_STATUS, 1)
    end
    return true
end
and this is the way you have to set it once his daily task is done:
Lua:
player:setStorageValue(DAILY_TRASH_STATUS, os.time())
so it can evaluate the timestamps on login.
 
Well the easiest attempt which does not involve db access can be done through storage values yes.
This could be achieved by saving a timestamp once the player has done all daily quests and then match that timestamp with the time when the player login again.
If you however want to stick with onStartup then there is no other way of doing it as you are doing right now.
This example would work like, if a player login after 12am it resets his dailies:
Lua:
function onLogin(player)
    local dateTable = os.date("*t", os.time())
    local lastLoginTable = os.date("*t", player:getStorageValue(DAILY_TRASH_STATUS))
    local storageStatus = player:getStorageValue(DAILY_TRASH_STATUS)
    if storageStatus < 1 or dateTable.year > lastLoginTable.year or dateTable.month > lastLoginTable.month or dateTable.day > lastLoginTable.day then
        player:setStorageValue(DAILY_TRASH_STATUS, 1)
    end
    return true
end
and this is the way you have to set it once his daily task is done:
Lua:
player:setStorageValue(DAILY_TRASH_STATUS, os.time())
so it can evaluate the timestamps on login.
Thanks for answering.
Im doing:
1 - Quest_Status >= 2(done status) in server startup, reset dailys.
2 - os.time() >= Quest_Cooldown(get os.time() value when picking up task) and Quest_Status == 1(doing task) onLogin, reset because wait time get 0 and player don't finished the task.
3 - os.time() >= Quest_Cooldown(get os.time() value when picking up task) and Quest_Status == 2(task done) on NPC that give the task, if player ask for a new task, can pickup.
I think will remove item 1. But should i use setStorageValue or change directly in database?
 
Last edited:
Hello,

I'm developing a system of daily tasks, which will reset whenever the server starts. In my onStartup I have the following code:
Lua:
    local resultId = db.storeQuery("SELECT * FROM `player_storage` WHERE `key` = "..DAILY_TRASH_STATUS.." AND `value` = 2") --Get all rows with Status = 2
    if resultId ~= false then
        repeat
            local playerId = result.getDataInt(resultId, "player_id") --Get playerId
            --Player(playerId):setStorageValue(DAILY_TRASH_SHOULD_RESET, 1)
            db.query("UPDATE `player_storage` SET `value` = 1 WHERE `player_id` = " .. playerId .." AND `key` = "..DAILY_TRASH_SHOULD_RESET)
        until not result.next(resultId)
        result.free(resultId)
    end
Can i use playerId as cid, in line 5?
To reset player task, i have onLogin check a storage value, if 1 then reset. I set this storage to 1 in line 6. If my first question is Yes the answer, what form should I use? Why?

Thanks for helping.
bump
Still in doubt, the system is fully ready, should I use line 5 or line 6 to change the value of storage? And why?
 
Either one is fine, startup would be my opinion honestly that way you do the important operations on server load when it can't affect player latency (even though technically you're saving nanoseconds). Another reason is that visually & mentally it's more concise and you know it's all being done at once.
 
Solution
Back
Top