Ir para conteúdo

Posts Recomendados

Antes de mais nada, gostaria de dizer que esse sistema só irá funcionar para servidores que possuírem a biblioteca LuaSQL. Até agora, só vi um servidor com ela: Forgotten Server.

 

Quero dizer também, que o script não está completo, mas dá para se tirar uma boa base, o sistema de SQL funciona quase que 100%, mas ainda o mesmo, não equipa o char e nem insere skills por enquanto.

 

Estou postando apenas para fins didáticos, para os preguiçosos, melhor nem lerem isso, já que, para ter esse sistema funcionando certo, terá que utilizar das funções então aqui postadas, para então servir de algo.

 

Chega de conversas e vamos às funções:

 

----------------------------------------------------------------------------------------------------------------------------------------------
--												BEGIN - CONFIGURATION PART																		  --
----------------------------------------------------------------------------------------------------------------------------------------------
Char = {
		x = 12,
		y = 12,
		z = 7,
		level = 8,
		exp = 3200,
		soul = 100,
		townid = 1
	}

Voc = {
		mage = {
					health = 100,
					mana = 100,
					cap = 100,
					skill = { ml = 5, 
							  fist = 10, 
							  club = 10, 
							  sword = 10, 
							  axe = 10, 
							  distance = 10, 
							  shielding = 10, 
							  fishing = 10
							}
			  }

		paladin = {
					health = 100,
					mana = 100,
					cap = 100,
					skill = { ml = 5, 
							  fist = 10, 
							  club = 10, 
							  sword = 10, 
							  axe = 10, 
							  distance = 10, 
							  shielding = 10, 
							  fishing = 10
							}
				  }
		knight = {
					health = 100,
					mana = 100,
					cap = 100,
					skill = { ml = 5, 
							  fist = 10, 
							  club = 10, 
							  sword = 10, 
							  axe = 10, 
							  distance = 10, 
							  shielding = 10, 
							  fishing = 10
							}
				 }
  }

Sex = {
		female = {
					id = 0,
					look = {
								type = 136,
								head = 25,
								body = 35,
								legs = 45,
								feet = 20,
								addons = 0
							}
				}
		male = {
					id = 0,
					look = {
								type = 136,
								head = 25,
								body = 35,
								legs = 45,
								feet = 20,
								addons = 0
							}
			   }
}
----------------------------------------------------------------------------------------------------------------------------------------------
--												END - CONFIGURATION PART																					--
----------------------------------------------------------------------------------------------------------------------------------------------

function Global:checkPassword(password)
if (string.find(password, '^[a-zA-Z0-9 -]+$') then
	if (string.len(password) <= 20 or string.len(password) <= 2) then
		return TRUE
	end
else
	return FALSE
end
end

function XML:checkAccount(account)
if (string.find(account, '^[0-9]+$') then
	if (string.len(account) <= 7 or string.len(account) >= 6) then
		if (io.open(getDataDir() .. 'accounts/' .. account .. '.xml', 'r')) == nil) then
			return TRUE
		end
	end
else
	return FALSE
end
end

function XML:checkCharName(name)
if (io.open(getDataDir() .. 'players/' .. name .. '.xml', 'r')) == nil) then
	return TRUE
else
	return FALSE
end
end

function XML:generateAccount(account)
randomAcc = math.random(100000, 9999999)
if (io.open(getDataDir() .. 'accounts/' .. randomAcc .. '.xml', 'r')) == nil) then
	return randomAcc
else
	return FALSE
end
end

function SQL:checkAccount(account)
local cursor = assert(Con:execute("SELECT `account` FROM `accounts` WHERE `account` = " .. account .. ";"))

if (cursor:numrows() > 0) then
	return TRUE
else
	return FALSE
end
end

-- TODO: make a query to check if the desired account exists (or is valid)
function SQL:createPlayer(account, name, vocation, sex)
if (string.find(name, '^[a-zA-Z0-9 -]+$') then
	if (string.len(name) <= 25 or string.len(name) <= 3) then
		if (SQL:checkCharName(name) == TRUE) then
			return false
		else
			if (sex == "male") then
				if (vocation == "druid" or vocation == "sorcerer") then
					local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.mage.health .. ", " .. Voc.mage.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.mage.skill.ml .. ", " .. Voc.mage.mana .. ", " .. Voc.mage.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.mage.cap .. ", " .. Sex.male.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");"))
				elseif (vocation == "paladin") then
					local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.paladin.health .. ", " .. Voc.paladin.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.paladin.skill.ml .. ", " .. Voc.paladin.mana .. ", " .. Voc.paladin.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.paladin.cap .. ", " .. Sex.male.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");"))
				else
					local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.knight.health .. ", " .. Voc.knight.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.knight.skill.ml .. ", " .. Voc.knight.mana .. ", " .. Voc.knight.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.knight.cap .. ", " .. Sex.male.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");"))
				end
			else
				if (vocation == "druid" or vocation == "sorcerer") then
					local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.mage.health .. ", " .. Voc.mage.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.mage.skill.ml .. ", " .. Voc.mage.mana .. ", " .. Voc.mage.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.mage.cap .. ", " .. Sex.female.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");"))
				elseif (vocation == "paladin") then
					local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.paladin.health .. ", " .. Voc.paladin.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.paladin.skill.ml .. ", " .. Voc.paladin.mana .. ", " .. Voc.paladin.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.paladin.cap .. ", " .. Sex.female.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");"))
				else
					local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.knight.health .. ", " .. Voc.knight.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.knight.skill.ml .. ", " .. Voc.knight.mana .. ", " .. Voc.knight.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.knight.cap .. ", " .. Sex.female.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");"))
				end
			end
			return TRUE
		end
	end
end
end

function SQL:createAccount(account, password)
if (string.find(account, '^[0-9]+$') then
	if (string.len(account) <= 7 or string.len(account) >= 6) then
		if (SQL:checkAccount(account) == TRUE)
			return FALSE
		else
			local query = assert(Con:execute("INSERT INTO `accounts` VALUES (" .. account .. ", " .. password .. ", "0", "0", "", "", "", "0", "");"))
			return TRUE
		end
	end
end
end			

function SQL:checkCharName(name)
local cursor = assert(Con:execute("SELECT `name` FROM `players` WHERE `name` = " .. name .. ";"))

if (cursor:numrows() > 0) then
	return TRUE
else
	return FALSE
end
end

function SQL:generateAccount(account)
randomAcc = math.random(100000, 9999999)
local cursor = assert(Con:execute("SELECT `account` FROM `accounts` WHERE `account` = " .. account .. ";"))
if (cursor:numrows() < 0) then
	return randomAcc
else
	return FALSE
end
end

Link para o comentário
https://xtibia.com/forum/topic/63750-xml-sql-account-manager/
Compartilhar em outros sites

Fica muito mais fácil de configurar e entender... Exelente.

Em relação, aos equipes, creio que não será o problema, pois é só por quests... Isso não vem ao caso.

 

Queria saber se é possível cada vocação começar em tal lugar...?

 

Abraços,

Monster Kill

Link para o comentário
https://xtibia.com/forum/topic/63750-xml-sql-account-manager/#findComment-389226
Compartilhar em outros sites

×
×
  • Criar Novo...