• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[SQL][Lua] Check information in table sql players

Armed

New Member
Joined
Nov 4, 2008
Messages
9
Reaction score
0
Hi,
i have question, how i can check in TFS [1.2+] what players have in table players.

Code:
local accid = getAccountNumberByPlayerName(getPlayerName(cid))
local data = db.storeQuery("SELECT `lang` FROM `players` WHERE `id` ='"..accid.."';")
local lang = data.getDataInt(data, "lang")

This is have error:
Code:
 attempt to index local 'data' (a boolean value)

im new in this language and i have problem. Do you have any tutorials or tips how i can check this information?

Sorry for my english.
 
Solution
Post the script if you're making changes along whole error.
Did you copy whole code that myAac has posted?

You gotta have a language column in your accounts table.
Run this in your DB:
PHP:
ALTER TABLE accounts
ADD lang INT(16);

Then you're gotta update a table and copy data from players:
PHP:
UPDATE accounts
  SET lang = (
    SELECT lang
    FROM players
    WHERE account_id = id);

Then lua will be:
LUA:
local player = Player(cid)
local accid = player:getAccountId()
local data = db.storeQuery("SELECT `lang` FROM `accounts` WHERE `id` ="..accid)
local lang = result.getNumber(data, "lang")
Okey, thx i dont have error now, but my if dosent work:
Code:
if lang == 1 then
    keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'Mozemy wymienic {change} monet dla ciebie. Dostep do konta uzyskasz {bank account}.'})
else
    keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
end
Now i have lang = 1 in mysql but NPC says only "else" options.
 
I edit npc code lua:
Code:
local accid = getAccountNumberByPlayerName(getPlayerName(cid))
local data = db.storeQuery("SELECT `lang` FROM `players` WHERE `id` ='"..accid.."';")
local lang = result.getNumber(data, "lang")
print(lang)
if lang == 1 then
    keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'Mozemy wymienic {change} monet dla ciebie. Dostep do konta uzyskasz {bank account}.'})
else
    keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
end
[code]
this is all my code
 
Your're searching for players with account_id but comparing with player id, your database structure is kinda bad if you assign a different language for each player instead of each account.
 
Its better when you save lang in accounts table.

And you can check it like this:
Code:
local player = Player(cid)
local accid = player:getAccountId()
local data = db.storeQuery("SELECT `lang` FROM `accounts` WHERE `id` ='"..accid.."';")
local lang = result.getNumber(data, "lang")
 
Okey but i have error:
Code:
 attempt to index local 'player' (a nil value)
stack traceback:
This is new for me that is why i have problem with this ;/
 
Post the script if you're making changes along whole error.
Did you copy whole code that myAac has posted?

You gotta have a language column in your accounts table.
Run this in your DB:
PHP:
ALTER TABLE accounts
ADD lang INT(16);

Then you're gotta update a table and copy data from players:
PHP:
UPDATE accounts
  SET lang = (
    SELECT lang
    FROM players
    WHERE account_id = id);

Then lua will be:
LUA:
local player = Player(cid)
local accid = player:getAccountId()
local data = db.storeQuery("SELECT `lang` FROM `accounts` WHERE `id` ="..accid)
local lang = result.getNumber(data, "lang")
 
Last edited:
Solution
I know how add column to base, i copy MyAac code to file:
Code:
local player = Player(cid)
local accid = player:getAccountId()
local data = db.storeQuery("SELECT `lang` FROM `accounts` WHERE `id` ='"..accid.."';")
local lang = result.getNumber(data, "lang")
if lang == 1 then
    keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'Mozemy wymienic {change} monet dla ciebie. Dostep do konta uzyskasz {bank account}.'})
else
    keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
end
And i have error:
Code:
[LIST=1]
[*] attempt to index local 'player' (a nil value)
[*]stack traceback
[/LIST]
 
8. Removing Solved Content:
- If you solved your problem, post the solution, do not remove the content in your posts. Instead write the solution you found. This can help other users with the same problem.
- Threads with removed content are useless and are seen as spam.
- If you were able to solve the issue yourself, post the solution and report your own post so a moderator can tag it as the "Best Answer".
Rules for the Support board
 
Back
Top