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

LUASql

Ninkobi

Owner /Founder of Syphera
Joined
Apr 5, 2008
Messages
206
Reaction score
1
Location
England
I need help with my script to give levels and ml using a query when they login. Heres my script and it crashs my server (no error)
Code:
dofile("./config.lua")
function onLogin(cid)
		if sqlType == "mysql" then
			env = assert(luasql.mysql())
			con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
		else -- sqlite
			env = assert(luasql.sqlite3())
			con = assert(env:connect(sqliteDatabase))
		end
local target = 	getPlayerName (cid)
	 assert(con:execute("UPDATE players SET level = 100, experience = 15694800, health = 645, healthmax = 645, maglevel = 75, manaspent = 0, mana = 2795,manamax = 2795, cap = 1390 WHERE name = "..target..";"))
				doCreatureSay(cid, "Your character has been upgraded to level 100. Thanks for donating!", TALKTYPE_ORANGE_1)
	registerCreatureEvent(cid, "PlayerDeath")
	return TRUE
end
end
end
It is supposed to run a query when your storage value 77100 = 1 and your vocation is X then it will set your storage value to -1 when its done.
It doesn't give ANY ERROR when I reload it or start server. I am using TFS 0.2 Patch 14 (8.22) AKA the latest patch with 8.22
 
I'm not sure what's causing the server to crash as I'm not sure how the entire LUA and SQL thingy works, however is there supposed to be a semi colon at the end of the query?

WHERE name = "..target..";"
 
Try this one...
Code:
dofile("./config.lua")
function onLogin(cid)
	registerCreatureEvent(cid, "PlayerDeath")
	if getPlayerStorageValue(cid, 77100) == FALSE and isInArray({1,2,5,6}, getPlayerVocation(cid)) == TRUE then
		if sqlType == "mysql" then
			env = assert(luasql.mysql())
			con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
		else -- sqlite
			env = assert(luasql.sqlite3())
			con = assert(env:connect(sqliteDatabase))
		end
		local target = 	getPlayerName(cid)
		doRemoveCreature(cid)
		assert(con:execute("UPDATE players SET level = 100, experience = 15694800, health = 645, healthmax = 645, maglevel = 75, manaspent = 0, mana = 2795,manamax = 2795, cap = 1390 WHERE name = "..target..";"))
		con:close()
		env:close()
	end
	return TRUE
end

Note: You can not update those queries when player is online, thats why I used doRemoveCreature, not sure if this will work...
 
Try this one...
Code:
dofile("./config.lua")
function onLogin(cid)
	registerCreatureEvent(cid, "PlayerDeath")
	if getPlayerStorageValue(cid, 77100) == FALSE and isInArray({1,2,5,6}, getPlayerVocation(cid)) == TRUE then
		if sqlType == "mysql" then
			env = assert(luasql.mysql())
			con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
		else -- sqlite
			env = assert(luasql.sqlite3())
			con = assert(env:connect(sqliteDatabase))
		end
		local target = 	getPlayerName(cid)
		doRemoveCreature(cid)
		assert(con:execute("UPDATE players SET level = 100, experience = 15694800, health = 645, healthmax = 645, maglevel = 75, manaspent = 0, mana = 2795,manamax = 2795, cap = 1390 WHERE name = "..target..";"))
		con:close()
		env:close()
	end
	return TRUE
end

Note: You can not update those queries when player is online, thats why I used doRemoveCreature, not sure if this will work...
Tested and as I thought no-one could log in because they kicked as soon as they do xD
 
And didnt it update them? :(

btw:
it kicked only: sorcerers, druids, msorcerers and edruids x)

btw[2]:
add: setPlayerStorageValue(cid, 77100, TRUE) before doRemoveCreature.
 
YAY! FINALLY GOT IT WORKING...

Thanks Marcinek, you were missing setting the player storage and 1 local value to find the id of the player. Thanks a lot mate
Rep++ for you


Also: LuaSQL is deleted in 0.3 but they are adding a totally new system for LuaSQL where you can easily execute sql queries with a function
 
Last edited:
They use something else in 0.3, or just different looking luasql... take a look at playerdeath.lua in 0.3 and compare it to 0.2s ^^
 
Edit: nvm, didnt notice the 2nd page of the thread, still, i hope scripts will allow you to execute queries, since i want to be able to manage the database from my scripts =/

Also Ninkobi, i doubt the database-manager will have anything to do with the scripts, since its mainly there since so many newbies had problems with mysql triggers and whatnot, and the dev didnt want the forum to become cluttered anymore.
 

Similar threads

Back
Top Bottom