klekSu
Stroke my ego.
- Joined
- Nov 4, 2008
- Messages
- 1,285
- Reaction score
- 18
CREDITS GOES TO vDk, me (item name show and multiworld), and special thanks to masteuszx. You can find main thread here.
So i'll show you the second version for multiworld with item show on page.
Here we start.
data/lib/function.lua
data/globalevents/lottery.lua
data/globalevents/globalevents.xml:
If you want lottery system on your acc maker:
lottery.php
Open index.php and add:
DB:
If you feel like, rep me
So i'll show you the second version for multiworld with item show on page.
Here we start.
data/lib/function.lua
Lua:
-- by masteuszx
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()
else
return false
end
return worldPlayer
end
data/globalevents/lottery.lua
Lua:
-- by vDk, klekSu
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, 2160}, -- Rewards ID
crystal_counts = 10, -- 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('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
else
doBroadcastMessage('[LOTTERY SYSTEM] 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
data/globalevents/globalevents.xml:
XML:
<globalevent name="lottery" interval="10800" event="script" value="lottery.lua"/>
lottery.php
PHP:
// by vDk, klekSu
<?PHP
$lottery = $SQL->query('SELECT id, name, item, world_id FROM lottery WHERE world_id = 0 ORDER BY id DESC LIMIT 1;');
foreach($lottery as $result) {
$main_content .= '<center><h1>Lottery</h1></center>
<table width="100%"><tr><td><center>Every X hours we will choose one player who will win random item!<br/><br />
Last Winner on World0: <a href="?subtopic=characters&name='.urlencode($result['name']).'">'.$result['name'].'</a> won <i>'.$result['item'].'</i> Congratulations!<br /><br />';
}
$lottery2 = $SQL->query('SELECT id, name, item, world_id FROM lottery WHERE world_id = 1 ORDER BY id DESC LIMIT 1;');
foreach($lottery2 as $result) {
$main_content .= 'Last Winner on World1: <a href="?subtopic=characters&name='.urlencode($result['name']).'">'.$result['name'].'</a> won <i>'.$result['item'].'</i> Congratulations!</center></td></tr>';
$main_content .= '</table><br />';
}
?>
PHP:
case "lottery";
$topic = "Lottery System";
$subtopic = "lottery";
include("lottery.php");
break;
SQL:
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',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
SQL:
INSERT INTO `lottery` (`id`, `name`, `item`, `world_id`) VALUES
(NULL, 'Nobody', 'nothing', 0);
If you feel like, rep me
Last edited by a moderator: