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

Lua Custom scripting

BarJuice

Zyloria Owner
Joined
Mar 28, 2008
Messages
118
Reaction score
1
Location
South Carolina
I wont post the exact script i use for my server, but i figured a tutorial was in order for the same type of script that i needed.

Global values in global.lua are always resetted when server is started back up. I didnt know where i could store a value at so i decided to use sql lua scripting to access my data base and set and get values in it to make my script work.

First things first.
Create a table in your database called server_storage and give it to fields (key,value) both int, length is your choice.

Next.
To access the values using lua you would need to write this
Code:
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
bla = 1000 --the storage key your looking up
local cur = assert(con:execute("SELECT `key`, `value` FROM `server_storage` WHERE `key` = '" .. bla .. "';"))
local row = cur:fetch({}, "a")
cur:close()
owner = row.value

To set new values:
Due to my scripting abilities i didnt know how to change an sql field but i did know how to delete and create, if anyone knows and can help out would they please let me know how to change the field. To set new values you need to write this:
Code:
value = 1000
 assert(con:execute("DELETE FROM `server_storage` WHERE `key` = " .. bla .. ";"))
assert(con:execute("INSERT INTO `server_storage` (`key`, `value`) VALUES (" .. bla .. ", " .. value .. ");"))

Not a great tutorial, but im sure it will teach someone something :)
 
Last edited:
I wont post the exact script i use for my server, but i figured a tutorial was in order for the same type of script that i needed.

Global values in global.lua are always resetted when server is started back up. I didnt know where i could store a value at so i decided to use sql lua scripting to access my data base and set and get values in it to make my script work.

First things first.
Create a table in your database called server_storage and give it to fields (key,value) both int, length is your choice.

Next.
To access the values using lua you would need to write this
Code:
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
bla = 1000 --the storage key your looking up
local cur = assert(con:execute("SELECT `key`, `value` FROM `server_storage` WHERE `key` = '" .. bla .. "';"))
local row = cur:fetch({}, "a")
cur:close()
owner = row.value

To set new values:
Due to my scripting abilities i didnt know how to change an sql field but i did know how to delete and create, if anyone knows and can help out would they please let me know how to change the field. To set new values you need to write this:
Code:
value = 1000
 assert(con:execute("DELETE FROM `server_storage` WHERE `key` = " .. bla .. ";"))
assert(con:execute("INSERT INTO `server_storage` (`key`, `value`) VALUES (" .. bla .. ", " .. value .. ");"))

Not a great tutorial, but im sure it will teach someone something :)

The SQL Command to 'Update' Something is

Code:
"UPDATE `table` SET `fieldname`='NEWVALUE' WHERE `table`='CONDITION'"

Enjoy
 
Back
Top