RA
erro

Loteria ? Erro chatinho!

Por raynerjr, 19 de jun. de 2015 em Scripts

resolvido
7
1.3k
raynerjrR
19 de junho de 2015 às 19:06

- Olá estou com um pequeno problema no sistema de loteria.


Ele entrega o item para jogador, faz tudo certo.


Mais não esta adicionando na tabela da database, que seria lottery, e da um pequeno erro, onde não parece na página de Loteria do meu site os ganhadores!



Alguém sabe por que? Vi vários com o mesmo problema!


SkyLighS
19 de junho de 2015 às 19:09

poste seu sistema de lotéria, e também tente trocar de sistema.

raynerjrR
20 de junho de 2015 às 09:06

Sistema de Loteria:

 

local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
local list = {}
for i, tid in ipairs(players) do
list[i] = tid
end
local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(random_item)
local world = tonumber(getPlayerWorldId(winner))
if(random_item == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
else
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
doPlayerAddItem(winner, random_item, 1)
end
if(config.website == "yes") then
db.executeQuery("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
return TRUE
end

 


@up

BrunoB
23 de junho de 2015 às 08:49
Melhor resposta

@@raynerjr

 

Tente assim:

 

local config = {
	lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
	rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
	crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
	website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
	local players = getPlayersOnline()
	if #players > 0 then
		local list = {}
		for i, tid in ipairs(players) do
			list[i] = tid
		end
		local winner = list[math.random(1, #list)]
		local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
		local item_name = getItemNameById(random_item)
		local world = tonumber(getPlayerWorldId(winner))
		if(random_item == 2160) then
			doPlayerAddItem(winner, random_item, config.crystal_counts)
			doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
		else
			doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
			doPlayerAddItem(winner, random_item, 1)
		end
		if(config.website == "yes") then
			db.query("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
		end
	end
	return true
end

Editado Junho 23 por Bruno Minervino

VodkartV
23 de junho de 2015 às 08:56

e qual o erro?? vc usa sqlite ou mysql??

 

ele tinha um bug, se n tivesse nenhum online da erro...

 

 

local config = {
lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
if #getPlayersOnline() > 0 then
local players = getPlayersOnline()
local winner, r_item = players[math.random(1, #players)], config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(r_item)
doPlayerAddItem(winner, r_item, isItemStackable(r_item) and 100 or 1)
doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '..(isItemStackable(r_item) and 100 or 1)..' '.. item_name ..'(s)! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
if(config.website == "yes") then
db.query("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
end
return true
end

Editado Junho 23 por Vodkart

raynerjrR
23 de junho de 2015 às 12:32

@@raynerjr

 

Tente assim:

 

 

local config = {
	lottery_hour = "3 Hours", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
	rewards_id = {2494, 2472, 2514, 2493, 2470, 2195, 2173, 2160, 2520}, -- Rewards ID
	crystal_counts = 100, -- used only if on rewards_id you have crystal coins (ID: 2160).
	website = "yes" -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
	local players = getPlayersOnline()
	if #players > 0 then
		local list = {}
		for i, tid in ipairs(players) do
			list[i] = tid
		end
		local winner = list[math.random(1, #list)]
		local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
		local item_name = getItemNameById(random_item)
		local world = tonumber(getPlayerWorldId(winner))
		if(random_item == 2160) then
			doPlayerAddItem(winner, random_item, config.crystal_counts)
			doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
		else
			doBroadcastMessage('[Baiak Rock Lottery] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
			doPlayerAddItem(winner, random_item, 1)
		end
		if(config.website == "yes") then
			db.query("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
		end
	end
	return true
end

 

 

 

Sistema do @Bruno Minervino deu certinho.

Já o do @Vodkart deu erro.

Mais obrigado pela atenção os dois.

 

Rep+

Resolvido

BrunoB
23 de junho de 2015 às 19:53

Tópico movido para a seção de dúvidas e pedidos resolvidos.