• 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 how to get accountId using lua

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
48
Hello, I have this code
Lua:
function getAccountPoints(cid)
local id = db.getResult("SELECT `account_id` FROM `players` WHERE `name` = '" ..getPlayerName(cid).. "';")
print("id: " ..id.. "")
local res = db.getResult('select `points` from `znote_accounts` where `account_id` = \''..id..'\'')
if(res:getID() == -1) then
return false
end
local ret = res:getDataInt("points")
res:free()
return tonumber(ret)
end

function doAccountAddPoints(cid, count)
local id = db.getResult("SELECT `account_id` FROM `players` WHERE `name` = '" ..getPlayerName(cid).. "';")
print("id: " ..id.. "")
return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) + count .."' WHERE `account_id` ='"..id.."'")
end

function doAccountRemovePoints(cid, count)
local id = db.getResult("SELECT `account_id` FROM `players` WHERE `name` = '" ..getPlayerName(cid).. "';")
print("id: " ..id.. "")
return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) - count .."' WHERE `account_id` ='"..id.."'")
end

I want to get the ammount of points a player checking on his account id and the add/remove points from him. The thing is I think I'm getting a field or idk an object or something like that, I need the integer value of account id. I'm getting this error on console
Code:
[21:26:50.095] [Error - Action Interface]
[21:26:50.099] data/actions/scripts/points.lua:onUse
[21:26:50.103] Description:
[21:26:50.105] data/lib/048-ppoints.lua:15: attempt to concatenate local 'id' (a table value)
[21:26:50.110] stack traceback:
[21:26:50.113]  data/lib/048-ppoints.lua:15: in function 'doAccountAddPoints'
[21:26:50.119]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Last edited:
I mean I got help from another forum as well and he said this script was working for him, problem is I did everything here and it still doesn't work I'm losing it. I deleted everything and added again, restarted the server, reloaded actions, checked my database and what not
lib
Lua:
function getAccountPoints(cid)
    local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")
    if(res:getID() ~= -1) then
        repeat
              return res:getDataInt("points")
          until not(res:next())
        res:free()
    end
end

function doAccountAddPoints(cid, count)
    return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) + count .."' WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")
end

function doAccountRemovePoints(cid, count)
    return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) - count .."' WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")
end

points.lua
Lua:
local cfg = {
amount = 1
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

if getPlayerLevel(cid) > 8 then
doAccountAddPoints(cid, cfg.amount)
doCreatureSay(cid, "Parabéns! Você recebeu 1 Premium Points! ", TALKTYPE_ORANGE_1)
doSendMagicEffect(getCreaturePosition(cid), 28)
doRemoveItem(item.uid,1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "RELOGUE PARA SALVAR. SEUS PONTOS ESTÃO DISPONIVEIS NO SITE")
else
doPlayerSendCancel(cid,"Você precisa de level 8 para usar este item.")
end
return TRUE
end

actions.xml
XML:
<action itemid="12597" event="script" value="points.lua"/>

oh shit I actually made it work editing the second line of my lib file to
Lua:
local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE `account_id` = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")

who should I give the best answer to? I really appreciate the help you guys gave me
 
Back
Top