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

db.query, for a specific player.

Status
Not open for further replies.

Taste

Member
Joined
Apr 6, 2012
Messages
81
Reaction score
5
Hello

I need some help with db.query in LUA. I'm looking for a db.query that updates a players column when it's enabled or disabled.

For example.

table = players
column = test

/test on = If a player executes this talkaction I want that his/hers column sets to 1 (enabled)
/test off = If a player executes this talkaction I want that his/hers column sets to 0 (disabled)

Thanks in advance!
 
Maybe set it to some storage?
And then that storage sets local test to 1/0.
Lua:
db.Query('UPDATE player SET test = 1 WHERE name = '..getPlayerName(cid)..';')
 
Storages might work but I'm trying to get it to work like this. The problem is to get the player ID.

Lua:
	if tmp[1] == "on" then
	db.query('UPDATE `players` SET `test` = 1 WHERE `id` = " .. getPlayerGUID(cid) .. ";')

Lua:
	elseif tmp[1] == "off" then
	db.query('UPDATE `players` SET `test` = 0 WHERE `id` = " .. getPlayerGUID(cid) .. ";')
 
Storages might work but I'm trying to get it to work like this. The problem is to get the player ID.

Lua:
	if tmp[1] == "on" then
	db.query('UPDATE `players` SET `test` = 1 WHERE `id` = " .. getPlayerGUID(cid) .. ";')

Lua:
	elseif tmp[1] == "off" then
	db.query('UPDATE `players` SET `test` = 0 WHERE `id` = " .. getPlayerGUID(cid) .. ";')

Uh. getPlayerGUID(cid) gets the player ID?
 
Alright, haven't done much scripting.

It does not update the players test column while executing, there's no errors in the console either.
 
Alright, haven't done much scripting.

It does not update the players test column while executing, there's no errors in the console either.

Uh, ID doesn't need to be encapsed in quotation marks. So:
Lua:
 if tmp[1] == "on" then
	db.query('UPDATE `players` SET `test` = 1 WHERE `id` = ' .. getPlayerGUID(cid) .. ';')
Just replace the " with ' and it should escape the string.
 
I appreciate your help Korrex. I'll try it out later today.

Edit: It worked out just great! :)

I've come across another thing aswell, I've got some troubles reading the code.

What I seek is that when someone updates their description it sends it to the database.

Code:
db.query('UPDATE `players` SET `TestDescription` = [COLOR="#FF0000"][B]What should I write here? [/B][/COLOR]WHERE `id` = ' .. getPlayerGUID(cid) .. ';')

Lua:
	elseif isInArray({"desc", "description", "d"}, tmp[1]) then
		local d = param:gsub(tmp[1]..(tmp[2] and " " or ""), "")

		if not(d) or d:len() == 0 then
			return doPlayerSendCancel(cid, "You need to specify a description.")
		end

		if d:len() > 50 then
			return doPlayerSendCancel(cid, "The description is too long. (Max.: 50 letters)")
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Description was set to: ")
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, d)
		doPlayerSetDescription(cid, d)
 
Last edited:
db.query('UPDATE `players` SET `TestDescription` = "' .. d .. '" WHERE `id` = ' .. getPlayerGUID(cid) .. ';')
 
Status
Not open for further replies.
Back
Top