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

[Support] Communicate with SQL via LUA script?

Michael Orsino

Premium User
Premium User
Support Team
Joined
Nov 15, 2007
Messages
854
Solutions
10
Reaction score
389
Location
Santiago, Chile (Australian)
I would like to know how to communicate with my database in a lua script.
For example, I would like to execute this quire in a lua NPC script.

Code:
UPDATE  `databaseone`.`players` SET  `maglevel` =  '0' WHERE  `players`.`id` =1 LIMIT 1 ;

Thanks for any help
 
Code:
db.executeQuery("UPDATE `databaseone`.`players` SET  `maglevel` = '0' WHERE `players`.`id` = 1 LIMIT 1;")
 
As I am using this inside a NPC script, I was hoping the NPC could identify the player it is speaking to and execute the query for that character, I worded that poorly so this example should help:

Code:
db.executeQuery("UPDATE `databaseone`.`players` SET  `maglevel` = '0' WHERE `players`.[COLOR="Red"]`name` = (getPlayerName(cid))[/COLOR] LIMIT 1;")

This does not work, as it just queries for the character "(getPlayerName(cid))" which of course does not exist.
Any ideas?
 
Code:
db.executeQuery("UPDATE `databaseone`.`players` SET `maglevel` = 0 WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
 
For some reason my script refuses to work! I'll post it here, but I have no expectation that anyone will actually read through it and find the error(s).
I am certain there are better ways of doing this, and I have tried many other ways but they have not worked either and this is what I have come to - and it wont work either.

Basic idea of the script:
When you say 'yes'
change promotion level to 2
kill the player
set the character back to level 8 stats

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)        end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)        end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                npcHandler:onThink()                end

function ascension(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

if getPlayerLevel(cid) >= 150 and getPlayerPromotionLevel(cid) == 2  then
	npcHandler:say('LET THE GODS SACRIFICE THIS SOUL SO THAT HE MAY BE REBORN!', cid)
		doCreatureAddHealth(cid, -(getCreatureHealth(cid))) --kills the player

db.executeQuery("UPDATE `empire`.`players` SET  `experience` = '4200' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 

1;")
db.executeQuery("UPDATE `empire`.`players` SET  `level` = '8' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
db.executeQuery("UPDATE `empire`.`players` SET  `healthmax` = '185' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 

1;")
db.executeQuery("UPDATE `empire`.`players` SET  `maglevel` = '10' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
db.executeQuery("UPDATE `empire`.`players` SET  `health` = '185' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
db.executeQuery("UPDATE `empire`.`players` SET  `mana` = '35' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
db.executeQuery("UPDATE `empire`.`players` SET  `manamax` = '35' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
db.executeQuery("UPDATE `empire`.`players` SET  `manaspent` = '0' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")
db.executeQuery("UPDATE `empire`.`players` SET  `cap` = '385' WHERE `players`.`name` = '" .. getPlayerName(cid) .. "' LIMIT 1;")

	doTeleportThing(cid, {x=1018, y=1023, z=7})
	doPlayerPopupFYI(cid, 'You have Ascended! Your level has been sacrificed in return for this godly status.')
	doPlayerSetPromotionLevel(cid, 2)
else
npcHandler:say('You need level 150 and first Promotion to ascend!', cid)
	end
end

keywordHandler:addKeyword({'ascension'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "The process of {ascend}

ing is a very spiritual practice where by your level is sacrificed, along with your life in order to be reborn a new soul with a 

higher understanding of your chosen vocation, be it magic, combat or a mixture of both."})

local node1 = keywordHandler:addKeyword({'ascend'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you really 

want to ascend? There is no turning back once you say {yes}. Please think about this before you do.'})
    node1:addChildKeyword({'yes'}, ascension, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'This is your choice, if you 

ever change your mind, do not hesitate to return.', reset = true})
npcHandler:addModule(FocusModule:new())
 
Back
Top