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

Solved DataBase Script Question.

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
I want to change the mechanics how my task reset.
Each day globalevent changes 1 random storage value to -1.
I have been looking around in forum and seen some good examples, but not sure am i doing it correctly.

Working script here.
Code:
function onThink()
local allStorageIDs = {}
    for k, v in pairs(tasks) do
        table.insert(allStorageIDs, v.storageID)
    end
  
    local randomTask = allStorageIDs[math.random(1, #allStorageIDs)]
    local players = Game.getPlayers()
  
    db.query("UPDATE `player_storage` SET `value` = -1 WHERE `value` = -2 AND `key` = "..randomTask)
    for k, player in ipairs(players) do
        if player:getStorageValue(randomTask) == -2 then
            player:setStorageValue(randomTask, -1)
            player:sendTextMessage(BLUE, "1 random task can be redone, check back to Task Master")
        end
    end
return true
end
 
Last edited:
Code:
db.query("UPDATE `player_storage` SET `value` = -1 WHERE `value` = -2 AND `key` = " .. randomTask)
 
Code:
db.query("UPDATE `player_storage` SET `value` = -1 WHERE `value` = -2 AND `key` = " .. randomTask)
i assume, this actually changes all -2 values to -1 and only where the key is "whatever it is that point"?
I will try this.

YUP, it working perfectly.
The good thing or idk in some cases maybe bad?
Idk i like it, if player is online THEN it wont change the value.

Any Nice.
Ty Ninja :D
 
Last edited:
i assume, this actually changes all -2 values to -1 and only where the key is "whatever it is that point"?
I will try this.

YUP, it working perfectly.
The good thing or idk in some cases maybe bad?
Idk i like it, if player is online THEN it wont change the value.

Any Nice.
Ty Ninja :D
If it runs at start-up of the server, no character will be online for the change anyways, so it wouldn't matter.
 
Back
Top