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

Lua Update points

Hookah

Member
Joined
Jan 20, 2023
Messages
57
Reaction score
8
Hello I'm wondering if anyone know how to make this script work, it seems to give the points but store is not updated with the new points. Is there any way to "reload"?
Lua:
local hundredPoints = 100
local fiftyPoints = 50
local addpoints = 50
local addpointss = 100

function onUse(player, item, fromPosition, target, toPosition)
    if item:getId() == hundredPoints then
        db.query("UPDATE znote_accounts SET points = points + "..addpointss.." WHERE account_id = ".. player:getAccountId() .."")
    elseif item:getId() == fiftyPoints then
        db.query("UPDATE znote_accounts SET points = points + "..addpoints.." WHERE account_id = ".. player:getAccountId() .."")
    end
    
    item:getPosition():sendMagicEffect(28)
    item:remove()
    player:save()
    return true
end
This is the store function
Code:
function getPoints(player)
  local points = 0
  local resultId = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `id` = " .. player:getAccountId())
  if resultId ~= false then
    points = result.getDataInt(resultId, "points")
    result.free(resultId)
  end
  return points
end

Thanks
 
You were evaluating an item id with the points amount, also you dont need to save the player at all.
Lua:
local config = {
    -- # [item id] = points
    [5988] = 50,
    [8981] = 100
}

function onUse(player, item, fromPosition, target, toPosition)

    local points = config[item:getId()]
    if not points then
        return false
    end

    db.query("UPDATE znote_accounts SET points = points + " .. points .. " WHERE account_id = " .. player:getAccountId())

    item:getPosition():sendMagicEffect(28)
    item:remove()

    return true
end
 
I have a similar problem. How can I use this for skill level changes?

I tried the same:

Lua:
db.query("UPDATE players SET skill_sword = 1 WHERE id = " .. player:getGuid())

The function works, skill level for sword in database is uploaded to 1, but once I relog the character, the value will return to the same it was before.
 
I have a similar problem. How can I use this for skill level changes?

I tried the same:

Lua:
db.query("UPDATE players SET skill_sword = 1 WHERE id = " .. player:getGuid())

The function works, skill level for sword in database is uploaded to 1, but once I relog the character, the value will return to the same it was before.
You can't update db player values while player is online.

Instead of using db update, why not use skill functions?
Lua:
player:addSkill(skillid, count)
 
You can't update db player values while player is online.

Instead of using db update, why not use skill functions?
Lua:
player:addSkill(skillid, count)
Problem is, I'm working with custom skills in my project, such as lumberjacking, mining, etc., which players will gain access to after completing a quest.

Until they “learn” those skills, skill level for them will be set as 0. Unfortunately, you cannot add skill level or tries for skills that are level 0. The easiest way to make it work would be through database editing, I guess. But, no luck so far…
 
Problem is, I'm working with custom skills in my project, such as lumberjacking, mining, etc., which players will gain access to after completing a quest.

Until they “learn” those skills, skill level for them will be set as 0. Unfortunately, you cannot add skill level or tries for skills that are level 0. The easiest way to make it work would be through database editing, I guess. But, no luck so far…
For sure you should not use database queries.
First: it does not work for online players. It will be overwritten, when they logout (server will save their skills as they are in game).
Second: database operations are very slow compared to RAM operations.

You must use player:addSkill. If it does not work for players with skill 0, you got to fix that problem in C++. It's probably related to skill gain formula that fails to calculate 'skill tries', when skill is 0.
 
For sure you should not use database queries.
First: it does not work for online players. It will be overwritten, when they logout (server will save their skills as they are in game).
Second: database operations are very slow compared to RAM operations.

You must use player:addSkill. If it does not work for players with skill 0, you got to fix that problem in C++. It's probably related to skill gain formula that fails to calculate 'skill tries', when skill is 0.
Thanks for the orientation, man. Going try this way.
 
Back
Top