function guild_patron(GuildID, action, RoleID, skill) local LIP = require("LIP") local config = LIP.load("server_config\\lua\\lua_config.ini") env = assert(require("luasql.mysql").mysql()) local pass = "" if config.lua_sql.pass ~= nil then pass = config.lua_sql.pass end con = assert(env:connect( config.lua_sql.db, config.lua_sql.user, pass, config.lua_sql.host, config.lua_sql.port )) local protector_level = 0 for level in rows(con, string.format("SELECT `Level` FROM guild_patron_level WHERE GuildID = %s", GuildID)) do protector_level = level end local skill_learned = 0 if action == 1 then sql = "SELECT `Level` FROM guild_patron_level WHERE GuildID = '%s'" local level_exists = 0 for level in rows(con, sql:format(GuildID)) do level_exists = level end if level_exists == 0 then sql = "INSERT INTO guild_patron_level VALUES ('%s', 1)" con:execute(sql:format(GuildID)) else sql = "Update guild_patron_level set `Level` = `Level`+1 where GuildID = '%s'" con:execute(sql:format(GuildID)) end elseif action == 2 then sql = "SELECT Skill FROM guild_patron WHERE RoleID = '%s' AND Skill = '%s' " for learned_skill in rows(con, sql:format(RoleID, skill)) do skill_learned = learned_skill end elseif action == 3 then sql = "INSERT INTO `guild_patron` VALUES ('%s', '%s', '%s')" con:execute(sql:format(GuildID, RoleID, skill)) end return protector_level, skill_learned end