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

Database results

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I'm having a problem with getting results from database using LUA.
I am making a NPC which changes your name, but I don't know how I would check if the playername already exists.

Could someone make a quick example on how to get all creaturenames, and check for them to be equal to the local 'msg'?

Distro : 0.3.6pl1

Thanks in advance,
unknown666
 
LUA:
	local query = db.getResult("select id from players where name = " .. db.escapeString(NAME_TO_BE_CHECKED) .. ";")
	if query:getID() ~= -1 then --if name exists 
		print("NAME EXISTS")
	else
		print("NAME DOESN'T EXISTS")
	end
	query:free()

A function..
LUA:
function nameExists(name)
	local query = db.getResult("select id from players where name = " .. db.escapeString(NAME_TO_BE_CHECKED) .. ";")
	if query:getID() ~= -1 then --if name exists 
		return true
	else
		return false
	end
	return LUA_ERROR
end
 
try this:
Code:
local result = db.getResult("SELECT `name` FROM `players`;")
local msg = "Fallen"
if result:getID() < 0
then
    return
end
repeat
    if result:getDataString("name") == msg
    then
        npcHandler:say("Name already exists.\n")
        return false
    end
until not result:next()
result:free()
 
try this:
Code:
local result = db.getResult("SELECT `name` FROM `players`;")
local msg = "Fallen"
if result:getID() < 0
then
    return
end
repeat
    if result:getDataString("name") == msg
    then
        npcHandler:say("Name already exists.\n")
        return false
    end
until not result:next()
result:free()
Wow, enjoy table scan. actually darkhaos' function doesn't have limit either.
 
Back
Top