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

Solved Problems executing DB.Query in LUA!

Rayeko

Programmer
Joined
Apr 9, 2008
Messages
185
Reaction score
3
Hi

Well, I wonder how to make this to work:
Its a function I made. Basically its about knowing in-game the points the player have. I know how to add points ingame. But, doing a function to get the points.. Its a chaos. I can't make it work.

This is the part of the function I have so far:
Code:
function getPoints(cid)
	return db.executeQuery("SELECT points FROM players WHERE name='" .. getPlayerName(cid) .. "'")
end

The value "points" in the DB, is an INT value, I also tried using "tonumber()" but still I get the same error. This is the error I get:
Code:
[Error - TalkAction Interface] 
data/talkactions/scripts/stats/points.lua:onSay
Description: 
data/talkactions/scripts/stats/pointst.lua:3: attempt to concatenate a nil value
stack traceback:
data/talkactions/scripts/stats/points.lua:3: in function <data/talkactions/scripts/stats/points.lua:1>

And the script of the "points.lua" file is:
Code:
function onSay(cid,words,param)

	doPlayerPopupFYI(cid, "You have "..getPoints(cid).." points")				
	
return TRUE
end

Also, I would like to know how to do the same but with a text value. For example, how to retrieve the player's email from their account in the DB. Its almost the same but without using INT values, is text. I have this portion of the function (that is almost the same):
Code:
function getPlayerEmail(cid)
	return db.executeQuery("SELECT email FROM `accounts` WHERE (`accno` = '" .. getPlayerAccount(cid) .. "')")
end

Thanks for any kind of help!
 
Last edited:
Code:
function getPoints(cid)
	return db.getResult("SELECT points FROM players WHERE name= '" .. getPlayerName(cid) .. "' LIMIT 1;"):getDataInt("points")
end

function onSay(cid, words, param)
	doPlayerPopupFYI(cid, "You have " .. getPoints(cid) .. " points")
	return true
end
Code:
function getPlayerEmail(cid)
	return db.getResult("SELECT email FROM accounts WHERE name = '" .. getPlayerAccount(cid) .. "' LIMIT 1;"):getDataString("email")
end
 
Are you talking about premium points? If so, I believe your query should look like this:
Code:
function getPoints(cid)
	return db.executeQuery("SELECT premium_points FROM accounts WHERE id='" .. getAccountIdByName(" .. getPlayerName(cid) .. ") .. "'")
end
 
Back
Top