• 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 don't quite understand your problem, but shouldn't something like this work?

Lua:
function getAccountPoints(cid)
    local res = db.getResult('select `points` from `znote_accounts` where `account_id` = \''..getAccountNumberByPlayerName(getPlayerName(cid))..'\'')
    if(res:getID() == -1) then
        return false
    end
    local ret = res:getDataInt("points")
    res:free()
    return tonumber(ret)
end
 
I had just edited my post because I made some progress but regardless, using your code I got the same error
Code:
[21:29:56.111] [Error - Action Interface]
[21:29:56.117] data/actions/scripts/points.lua:onUse
[21:29:56.120] Description:
[21:29:56.123] data/lib/048-ppoints.lua:12: attempt to perform arithmetic on a boolean value
[21:29:56.128] stack traceback:
[21:29:56.134]  data/lib/048-ppoints.lua:12: in function 'doAccountAddPoints'
[21:29:56.138]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
oh well actually not the same but an error
 
Lua:
function getAccountPoints(cid)
    local res = db.getResult('SELECT `points` FROM `znote_accounts` WHERE `account_id` = \''..getAccountNumberByPlayerName(getPlayerName(cid))..'\'')
    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 `id` = '" ..getPlayerGUID(cid).. "';")
    id:free()
    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 `id` = '" ..getPlayerGUID(cid).. "';")
    id:free()
    return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) - count .."' WHERE `account_id` ='"..id.."'")
end
 
Code:
[21:53:27.367] [Error - Action Interface]
[21:53:27.370] data/actions/scripts/points.lua:onUse
[21:53:27.373] Description:
[21:53:27.374] data/lib/048-ppoints.lua:14: attempt to perform arithmetic on a boolean value
[21:53:27.381] stack traceback:
[21:53:27.382]  data/lib/048-ppoints.lua:14: in function 'doAccountAddPoints'
[21:53:27.387]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Lua:
function getAccountPoints(cid)
    local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid)))
    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 = " .. 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

are you sure that your "points" table is on "znote_accounts" and not on "accounts" table?
 
Last edited by a moderator:
Code:
[23:3:03.157] mysql_real_query(): SELECT `points` FROM `znote_accounts` WHERE account_id = loginAccount - MYSQL ERROR: Unknown column 'loginAccount' in 'where clause' (1054)

[23:3:03.167] [Error - Action Interface]
[23:3:03.169] data/actions/scripts/points.lua:onUse
[23:3:03.172] Description:
[23:3:03.174] data/lib/048-ppoints.lua:13: attempt to perform arithmetic on a boolean value
[23:3:03.182] stack traceback:
[23:3:03.184]   data/lib/048-ppoints.lua:13: in function 'doAccountAddPoints'
[23:3:03.191]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
he's trying to use the account name as the accound_id

yeah I'm sure, znote has it's own table for points management, here's the schema
SQL:
CREATE TABLE IF NOT EXISTS `znote_accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL,
  `ip` bigint(20) UNSIGNED NOT NULL,
  `created` int(10) NOT NULL,
  `points` int(10) DEFAULT 0,
  `cooldown` int(10) DEFAULT 0,
  `active` tinyint(4) NOT NULL DEFAULT '0',
  `active_email` tinyint(4) NOT NULL DEFAULT '0',
  `activekey` int(11) NOT NULL DEFAULT '0',
  `flag` varchar(20) NOT NULL,
  `secret` char(16) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;



changing the code to
Lua:
function getAccountPoints(cid)
    local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE `account_id` = '"..getAccountNumberByPlayerName(getPlayerName(cid)).."';")
    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 `account_id` ='"..getAccountNumberByPlayerName(getPlayerName(cid)).."';")
end

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

the error is:
Code:
[23:13:20.598] [Error - Action Interface]
[23:13:20.602] data/actions/scripts/points.lua:onUse
[23:13:20.604] Description:
[23:13:20.606] data/lib/048-ppoints.lua:12: attempt to perform arithmetic on a boolean value
[23:13:20.611] stack traceback:
[23:13:20.613]  data/lib/048-ppoints.lua:12: in function 'doAccountAddPoints'
[23:13:20.618]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Last edited:
Code:
[23:3:03.157] mysql_real_query(): SELECT `points` FROM `znote_accounts` WHERE account_id = loginAccount - MYSQL ERROR: Unknown column 'loginAccount' in 'where clause' (1054)

[23:3:03.167] [Error - Action Interface]
[23:3:03.169] data/actions/scripts/points.lua:onUse
[23:3:03.172] Description:
[23:3:03.174] data/lib/048-ppoints.lua:13: attempt to perform arithmetic on a boolean value
[23:3:03.182] stack traceback:
[23:3:03.184]   data/lib/048-ppoints.lua:13: in function 'doAccountAddPoints'
[23:3:03.191]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
he's trying to use the account name as the accound_id

yeah I'm sure, znote has it's own table for points management, here's the schema
SQL:
CREATE TABLE IF NOT EXISTS `znote_accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL,
  `ip` bigint(20) UNSIGNED NOT NULL,
  `created` int(10) NOT NULL,
  `points` int(10) DEFAULT 0,
  `cooldown` int(10) DEFAULT 0,
  `active` tinyint(4) NOT NULL DEFAULT '0',
  `active_email` tinyint(4) NOT NULL DEFAULT '0',
  `activekey` int(11) NOT NULL DEFAULT '0',
  `flag` varchar(20) NOT NULL,
  `secret` char(16) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;



changing the code to
Lua:
function getAccountPoints(cid)
    local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE `account_id` = '"..getAccountNumberByPlayerName(getPlayerName(cid)).."';")
    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 `account_id` ='"..getAccountNumberByPlayerName(getPlayerName(cid)).."';")
end

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

the error is:
Code:
[23:13:20.598] [Error - Action Interface]
[23:13:20.602] data/actions/scripts/points.lua:onUse
[23:13:20.604] Description:
[23:13:20.606] data/lib/048-ppoints.lua:12: attempt to perform arithmetic on a boolean value
[23:13:20.611] stack traceback:
[23:13:20.613]  data/lib/048-ppoints.lua:12: in function 'doAccountAddPoints'
[23:13:20.618]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
okay try again, I edited my last post
 
with your updated code:
Code:
[23:16:51.653] [Error - Action Interface]
[23:16:51.657] data/actions/scripts/points.lua:onUse
[23:16:51.660] Description:
[23:16:51.661] data/lib/048-ppoints.lua:13: attempt to perform arithmetic on a boolean value
[23:16:51.666] stack traceback:
[23:16:51.668]  data/lib/048-ppoints.lua:13: in function 'doAccountAddPoints'
[23:16:51.673]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
this attempt to perform arithmetic on a boolean value is driving me nuts I always get to this point
 
with your updated code:
Code:
[23:16:51.653] [Error - Action Interface]
[23:16:51.657] data/actions/scripts/points.lua:onUse
[23:16:51.660] Description:
[23:16:51.661] data/lib/048-ppoints.lua:13: attempt to perform arithmetic on a boolean value
[23:16:51.666] stack traceback:
[23:16:51.668]  data/lib/048-ppoints.lua:13: in function 'doAccountAddPoints'
[23:16:51.673]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
this attempt to perform arithmetic on a boolean value is driving me nuts I always get to this point
add some prints to know what is wrong and try again:

Lua:
function getAccountPoints(cid)
    print(getAccountNumberByPlayerName(getCreatureName(cid)))
    local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid)))
    print(res)
    if(res:getID() == -1) then
        print("false")
        return false
    end

    local ret = res:getDataInt("points")
    res:free()
    print(ret)
    return tonumber(ret)
end
 
Code:
2

false

[23:35:48.025] [Error - Action Interface]
[23:35:48.029] data/actions/scripts/points.lua:onUse
[23:35:48.031] Description:
[23:35:48.033] data/lib/048-ppoints.lua:17: attempt to perform arithmetic on a boolean value
[23:35:48.038] stack traceback:
[23:35:48.040]  data/lib/048-ppoints.lua:17: in function 'doAccountAddPoints'
[23:35:48.044]  data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
2 is indeed my account id so that's right, dunno about the false tho since the result wasn't -1
 
Last edited:
Lua:
function getAccountPoints(cid)
    local resultId = db.getResult("SELECT `points` FROM `znote_accounts` WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid)))
    if resultId ~= false then
        local ret = result.getDataInt(resultId, "points")
        result:free(resultId)
        return tonumber(ret)
    end
    return -1
end

based on this

if it doesn't work, try changing the old script from:

if(res:getID() == -1) then

to:
if res == false then
 
Code:
[1:10:26.982] [Error - Action Interface]
[1:10:26.986] data/actions/scripts/points.lua:onUse
[1:10:26.988] Description:
[1:10:26.991] data/lib/048-ppoints.lua:12: attempt to perform arithmetic on a nil value
[1:10:26.998] stack traceback:
[1:10:27.001]   data/lib/048-ppoints.lua:12: in function 'doAccountAddPoints'
[1:10:27.005]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
Lua:
function getAccountPoints(cid)
    local res = db.getResult("SELECT `points` FROM `znote_accounts` WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid)))
    print(res)
    if res == -1 then
        print("result is -1")
        return false
    end

    local ret = res:getDataInt("points")
    res:free()
    print(ret)
    return tonumber(ret)
end
 
Last edited by a moderator:
dunno why but nothing was printed, the error now mentions getaccountpoints too
Code:
[1:48:27.686] [Error - Action Interface]
[1:48:27.689] data/actions/scripts/points.lua:onUse
[1:48:27.692] Description:
[1:48:27.694] data/lib/048-ppoints.lua:3: attempt to concatenate local 'res' (a table value)
[1:48:27.700] stack traceback:
[1:48:27.702]   data/lib/048-ppoints.lua:3: in function 'getAccountPoints'
[1:48:27.707]   data/lib/048-ppoints.lua:16: in function 'doAccountAddPoints'
[1:48:27.712]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
 
dunno why but nothing was printed, the error now mentions getaccountpoints too
Code:
[1:48:27.686] [Error - Action Interface]
[1:48:27.689] data/actions/scripts/points.lua:onUse
[1:48:27.692] Description:
[1:48:27.694] data/lib/048-ppoints.lua:3: attempt to concatenate local 'res' (a table value)
[1:48:27.700] stack traceback:
[1:48:27.702]   data/lib/048-ppoints.lua:3: in function 'getAccountPoints'
[1:48:27.707]   data/lib/048-ppoints.lua:16: in function 'doAccountAddPoints'
[1:48:27.712]   data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>
try again, i was kinda sleepy lol
 
Code:
[2:3:55.782] [Error - Action Interface]
[2:3:55.786] data/actions/scripts/points.lua:onUse
[2:3:55.788] Description:
[2:3:55.790] data/lib/004-database.lua:60: [Result:getDataInt] Result not set!
[2:3:55.794] stack traceback:
[2:3:55.796]    [C]: in function 'error'
[2:3:55.799]    data/lib/004-database.lua:60: in function 'getDataInt'
[2:3:55.803]    data/lib/048-ppoints.lua:9: in function 'getAccountPoints'
[2:3:55.807]    data/lib/048-ppoints.lua:16: in function 'doAccountAddPoints'
[2:3:55.811]    data/actions/scripts/points.lua:8: in function <data/actions/scripts/points.lua:5>

there's also this simbol I cannot paste, here's an image
1592715995168.png
 
Lua:
function getAccountPoints(cid)
    local resultId = db.getResult("SELECT `points` FROM `znote_accounts` WHERE id = " .. getAccountNumberByPlayerName(getCreatureName(cid)))
    if resultId ~= false then
        local ret = result.getDataInt(resultId, "points")
        print(ret)
        result:free(resultId)
        return tonumber(ret)
    end
    print("end")
    return -1
end
what does this prints?
 
Back
Top