Sistema de Loterias por globalevents.
Crie um arquivo .lua com o nome lottery dentro da pasta data/globalevents/scripts/loterry.lua, adicione dentro do arquivo o seguinte code:
local config = {
lottery_hour = "2 hours", -- Tempo ate a proxima loteria (Esse tempo vai aparecer somente como broadcast message)
rewards_id = {2494, 2472, 2514, 2160}, -- ID dos Itens Sorteados na Loteria
crystal_counts = 10, -- Usado somente se a rewards_id for crystal coin (ID: 2160).
website = "yes", -- Only if you have php scripts and table `lottery` in your database!
days = {
"Monday-08:00",
"Monday-13:00",
"Monday-19:30",
"Tuesday-08:00",
"Tuesday-13:00",
"Tuesday-19:30",
"Wednesday-08:00",
"Wednesday-13:00",
"Wednesday-19:30",
"Thursday-08:00",
"Thursday-13:00",
"Thursday-19:30",
"Friday-01:22",
"Friday-13:00",
"Friday-19:30",
"Saturday-21:27",
"Saturday-21:28",
"Saturday-21:29",
"Sunday-08:00",
"Sunday-13:00",
"Sunday-19:30"
}
}
local function getPlayerWorldId(cid)
if not(isPlayer(cid)) then
return false
end
local pid = getPlayerGUID(cid)
local worldPlayer = 0
local result_plr = db.getResult("SELECT * FROM `players` WHERE `id` = "..pid..";")
if(result_plr:getID() ~= -1) then
worldPlayer = tonumber(result_plr:getDataInt("world_id"))
result_plr:free()
return worldPlayer
end
return false
end
local function getOnlineParticipants()
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerAccess(pid) <= 2 and getPlayerStorageValue(pid, 281821) <= os.time() then
table.insert(players, pid)
end
end
if #players > 0 then
return players
end
return false
end
function onThink(cid, interval)
if table.find(config.days, os.date("%A-%H:%M")) then
if(getWorldCreatures(o) <= 0)then
return true
end
local query = db.query or db.executeQuery
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(random_item)
local data = os.date("%d/%m/%Y - %H:%M:%S")
local online = getOnlineParticipants()
if online then
local winner = online[math.random(1, #online)]
local world = tonumber(getPlayerWorldId(winner))
if(random_item == 2160) then
doPlayerSetStorageValue(winner, 281821, os.time() + 3600 * 24)
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. config.crystal_counts .." " .. getItemNameById(random_item) .. "s! Congratulations! (Next lottery in " .. config.lottery_hour .. ")")
else
doPlayerSetStorageValue(winner, 281821, os.time() + 3600 * 24)
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " ..getItemNameById(random_item) .. "! Congratulations! (Next lottery in " .. config.lottery_hour .. ")")
doPlayerAddItem(winner, random_item, 1)
end
if(config.website == "yes") then
query("INSERT INTO `lottery` (`name`, `item`, `world_id`, `item_name`, `date`) VALUES ('".. getCreatureName(winner).."', '".. random_item .."', '".. world .."', '".. item_name .."', '".. data .."');")
end
else
print("Ninguem OnLine pra ganhar na loteria")
end
end
return true
end
Recomendamos modificar:
- rewards_id = {2494, 2472, 2514, 2160}, -- ID dos Itens Sorteados na Loteria
Recomendo de item count apenas o 2160, outros podem bugar.
- crystal_counts = 10, -- Usado somente se a rewards_id for crystal coin (ID: 2160).
Altere pra mais ou menos o dinheiro.
- "Monday-08:00", Ajuste os dias e horários como desejado.
Em globalevents.xml, adicione:
<!-- Lottery -->
<globalevent name="lottery" interval="60000" event="script" value="lottery.lua"/>
Não mexa no code acima.
Certo, essa é a parte do servidor, agora vamos adicionar as querys necessárias no MySql:
CREATE TABLE `lottery` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`item` varchar(255) NOT NULL,
`world_id` tinyint(2) unsigned NOT NULL default '0',
`item_name` varchar(255) NOT NULL,
`date` varchar(256) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
Caso você queria adicionar uma query pra testar o site, veja:
INSERT INTO `lottery` (`id`, `name`, `item`, `world_id`, `item_name`, `date`) VALUES(NULL, 'Character', '2470', '0', 'golden legs', '22/05/2014 - 04:49:50');
Agora vamos pra parte do site, crie um arquivo .php com o nome lottery, adicione dentro do arquivo o seguinte code:
<?PHP
$main_content .= '<center><h1>Lottery</h1><h3>Lotterys held at 09:00, 14:00 and 20:30 hour, brazil time.</h3></center><br><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><tr BGCOLOR="'.$config['site']['vdarkborder'].'"><td CLASS=white><center><b>Player Name</b></center></td><td CLASS=white width=184 colspan=2><center><b>Winning Item</b></center></td><td width=50 CLASS=white><center><b>World</b></center></td><td width=100 CLASS=white><center><b>Date and Time</b></center></td></tr>';
$lottery = $SQL->query('SELECT id, name, item, world_id, item_name, date FROM lottery WHERE world_id = 0 ORDER BY id DESC;');
foreach($lottery as $result) {
$players++;
if(is_int($players / 2))
$bgcolor = $config['site']['lightborder'];
else
$bgcolor = $config['site']['darkborder'];
$main_content .= '<TR BGCOLOR='.$bgcolor.'><TD WIDTH=35%><center><a href="?subtopic=characters&name='.urlencode($result['name']).'">'.$result['name'].'</a></center></td><TD WIDTH=5%><img src=\'/item_images/'.urlencode($result['item']).'.gif\'></td><TD WIDTH=30%><center>'.$result['item_name'].'</center></td><TD WIDTH=7%><center>MegaTibia</center></td></td><TD WIDTH=30%><center>'.$result['date'].'</center></td></tr>';
}
$main_content .= '</table>';
?>
Em index.php adicione:
case "lottery";
$topic = "Lottery";
$subtopic = "lottery";
include("lottery.php");
break;
Em layouts.php adicione o code abaixo:
<a href="?subtopic=lottery">
<div id="submenu_lottery" class="Submenuitem" onmouseover="MouseOverSubmenuItem(this)" onmouseout="MouseOutSubmenuItem(this)">
<div class="LeftChain" style="background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);"></div>
<div id="ActiveSubmenuItemIcon_lottery" class="ActiveSubmenuItemIcon" style="background-image:url(<?PHP echo $layout_name; ?>/images/menu/icon-activesubmenu.gif);"></div>
<div id="ActiveSubmenuItemLabel_lottery" class="SubmenuitemLabel">Lottery</div>
<div class="RightChain" style="background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);"></div>
</div>
</a>
Pronto galera só isso, não esqueça clica em GOSTEI! Comente, participe do tópico, isso nos ajuda muito.
Créditos:
.lua - Killua e Matheus
.php - Matheus e Natanael Beckman
querys - Natanael Beckman e Matheus
Atualização 24/05/2014
- Adicionado regras pra não sorteá membro da staff(GM, GOD)
- Adicionando sistema de Storage pra não correr o risco de um player ganhar 2x no mesmo dia.