• 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:
action
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

tag
XML:
<action itemid="12597" event="script" value="points.lua"/>
 
You can do:
addPlayerPoints(cid, 5)
addPlayerPoints(cid, -5) -- takes away points.

Lua:
function getPlayerPoints(cid)
    local resultr, ret = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `account_id` = "..getPlayerAccountId(cid)..";")
    ret = result.getDataInt(resultr, "points")
    result.free(resultr)
    return ret
end

function addPlayerPoints(cid, points)
    db.query("UPDATE `znote_account` SET `points` = `points` + "..points.." WHERE `account_id` = "..getPlayerAccountId(cid)..";")
end


Lua:
local points = 1

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLevel(cid) > 8 then
        addPlayerPoints(cid, points)
        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
 
Code:
[2:49:15.525] [Error - Action Interface]
[2:49:15.529] data/actions/scripts/points.lua:onUse
[2:49:15.532] Description:
[2:49:15.533] data/actions/scripts/points.lua:8: attempt to call global 'doAccountAddPoints' (a nil value)
[2:49:15.540] stack traceback:
[2:49:15.542]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Thats not even the same code you posted.
Post automatically merged:

Change the function with this
Lua:
function getPlayerPoints(cid)
    local resultr, ret = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `account_id` = "..getPlayerAccountId(cid)..";")
    ret = result.getDataInt(resultr, "points")
    result.free(resultr)
    return ret
end

function addPlayerPoints(cid, points)
    db.query("UPDATE `znote_account` SET `points` = `points` + "..points.." WHERE `account_id` = "..getPlayerAccountId(cid)..";")
end

and post the actual code your using.
 
what? of course it is
I removed the "removepoints" chunk of code and left like you mentioned, and even tried this one you just posted
Code:
[2:53:21.429] [Error - Action Interface]
[2:53:21.433] data/actions/scripts/points.lua:onUse
[2:53:21.435] Description:
[2:53:21.437] data/actions/scripts/points.lua:8: attempt to call global 'doAccountAddPoints' (a nil value)
[2:53:21.443] stack traceback:
[2:53:21.445]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Your error
Code:
data/actions/scripts/points.lua:8: attempt to call global 'doAccountAddPoints' (a nil value)

Line 8 of the code you posted
Lua:
       doRemoveItem(item.uid,1)
 
I think this error is because he couldn't call the global variable when trying to take away the item or somethiung, I swear I'm using exactly what you said

Lib:
Lua:
function getPlayerPoints(cid)
    local resultr, ret = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `account_id` = "..getPlayerAccountId(cid)..";")
    ret = result.getDataInt(resultr, "points")
    result.free(resultr)
    return ret
end

function addPlayerPoints(cid, points)
    db.query("UPDATE `znote_account` SET `points` = `points` + "..points.." WHERE `account_id` = "..getPlayerAccountId(cid)..";")
end

Points.lua (action)
Lua:
local points = 1

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLevel(cid) > 8 then
        addPlayerPoints(cid, points)
        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
 
Code:
[3:8:57.381] [Error - Action Interface]
[3:8:57.385] data/actions/scripts/points.lua:onUse
[3:8:57.388] Description:
[3:8:57.391] data/actions/scripts/points.lua:8: attempt to call global 'doAccountAddPoints' (a nil value)
[3:8:57.397] stack traceback:
[3:8:57.399]    data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>

ovh n entra.png

I'm using the codes I mentioned before, this are the error and the print
 
It looks like you haven't closed your server for 30 minutes. I can't really help you at this point because its not making sense. The only way I can help now if I have your server or teamviewer....or get your actions folder and your lib/global files.
 
honestly I have no idea either, this code used to work perfectly when I was using gesior but when I switched to znote I thought a simple query change would adapt the script but honestly this is cursed. I "think" the "easiest" way to fix is figure a way to fix this data/lib/048-ppoints.lua:12: attempt to perform arithmetic on a boolean value on one of the versions of the code we talked before. it's simply not converting currectly getting data in a weird format
 
Lua:
function getAccountPoints(cid)
local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE `account_id` = "..getPlayerAccountId(cid)..";")
print(ret)
if(res:getID() == -1) then
return false
end
local ret = res:getDataInt("points")
res:free()
return tonumber(ret)
end

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

function doAccountRemovePoints(cid, count)
return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) - count .."' WHERE id = " ..getPlayerAccountId(cid)..";")
end
this print isn't printing anything


error
Code:
[3:23:11.047] [Error - Action Interface]
[3:23:11.051] data/actions/scripts/points.lua:onUse
[3:23:11.053] Description:
[3:23:11.055] data/lib/048-ppoints.lua:13: attempt to perform arithmetic on a boolean value
[3:23:11.061] stack traceback:
[3:23:11.064]   data/lib/048-ppoints.lua:13: in function 'doAccountAddPoints'
[3:23:11.069]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
That should be changed with this:
Lua:
function getPlayerPoints(cid)
    local resultr, ret = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `account_id` = "..getPlayerAccountId(cid)..";")
    ret = result.getDataInt(resultr, "points")
    result.free(resultr)
    return ret
end

function addPlayerPoints(cid, points)
    db.query("UPDATE `znote_account` SET `points` = `points` + "..points.." WHERE `account_id` = "..getPlayerAccountId(cid)..";")
end
 
Code:
[3:43:17.940] [Error - Action Interface]
[3:43:17.944] data/actions/scripts/points.lua:onUse
[3:43:17.948] Description:
[3:43:17.950] data/actions/scripts/points.lua:8: attempt to call global 'doAccountAddPoints' (a nil value)
[3:43:17.954] stack traceback:
[3:43:17.956]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Your server isn't restarting or something man. You aren't doing something right. Everything should be working if you did it how I said it.
 
Back
Top