• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent Lottery System!

vDk

Member
Joined
Jul 22, 2007
Messages
795
Reaction score
14
Location
Poland, Kraków
Hello,
This is my lottery script :thumbup:

For TFS 0.3.5 (MOD)
mods/lottery.xml
Code:
<mod name="Lottery System" version="1.5" author="vDk" contact="[email protected]" enabled="yes">
	<config name="lottery_config"><![CDATA[
		config = {
			lottery_hour = "3 Hours", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
			rewards_id = {2494, 2472, 2514, 2160}, -- Rewards ID
			crystal_counts = 10, -- Used only if on rewards_id is crystal coin (ID: 2160).
			website = "yes" -- Only if you have php scripts and table `lottery` in your database!
		}
	]]></config>
	<globalevent name="lottery" interval="10800" event="script"><![CDATA[
		domodlib('lottery_config')
	function onThink(interval, lastExecution)
	if(getWorldCreatures(0) == 0)then
		return true
	end
		local list = {}
		for i, tid in ipairs(getPlayersOnline()) do
		list[i] = tid
	end
	
		local winner = list[math.random(1, #list)]
		local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
	
	if(random_item == 2160) then
		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
		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
		db.executeQuery("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
	end
	return true
	end 
	]]></globalevent>
</mod>

For TFS 0.3.4pl2:
data/globalevents/lottery.lua

Lua:
-- by vDk
local config = {
    lottery_hour = "3 Hours", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
    rewards_id = {2494, 2472, 2514, 2160}, -- Rewards ID
    crystal_counts = 10, -- Used only if on rewards_id is crystal coin (ID: 2160).
    website = "yes" -- Only if you have php scripts and table `lottery` in your database!
    }
function onThink(interval, lastExecution)
	if(getWorldCreatures(0) == 0)then
		return true
	end
 
    local list = {}
    for i, tid in ipairs(getPlayersOnline()) do
		list[i] = tid
	end

	local winner = list[math.random(1, #list)]
	local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
	
	if(random_item == 2160) then
		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
		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
		db.executeQuery("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
	end
	return true
end

data/globalevents/globalevents.xml:

Code:
<globalevent name="lottery" interval="10800" event="script" value="lottery.lua"/>
If you want lottery system on your acc maker:

lottery.php

PHP:
<?PHP
$lottery = $SQL->query('SELECT id, name, item FROM lottery ORDER BY id DESC LIMIT 1;');
foreach($lottery as $result) {
$main_content .= '<center><h1>Lottery</h1></center>
<center>Every X hours we will choose one player who will win random item!<br/>
Last Winner: <a href="?subtopic=characters&name='.urlencode($result['name']).'">'.$result['name'].'</a> Item: <i>'.$result['item'].'</i> Congratulations!</center>';
}
?>
Open index.php and add:

PHP:
      case "lottery";
          $topic = "Lottery System";
          $subtopic = "lottery";
          include("lottery.php");
      break;
DB:

Code:
CREATE TABLE `lottery` (
   `id` int(11) NOT NULL auto_increment,
   `name` varchar(255) NOT NULL,
   `item` varchar(255) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

Code:
INSERT INTO `lottery`(`id`, `name`, `item`) VALUES (NULL , 'Nobody', 'nothing');

Do you like this script? REP++ me today! :D
Special thanks to Chojrak for help!
 
Last edited:
Pretty cool, haven't seen this before.
Hope it works! :wub:
 
Do you have lottery table in your database? for me and others work perfectly, post link to your website

P.S do you set
Code:
website = 1
in script config?
 
@2up
for me too, but if someone won lottery then site isn't blank :).

Try this:
Code:
<?PHP
	$lottery = $SQL->query('SELECT id, name FROM lottery ORDER BY id DESC LIMIT 1;');
	$data = mysql_fetch_array($lottery);

	$main_content .= '<center><h1>Lottery</h1></center>
		<center>Every 3 hours we will choose one player who will win 100k!<br/>
		Last Winner: <a href="?subtopic=characters&name='.urlencode($data['name']).'">'.$data['name'].'</a>  Congratulations!</center>';
?>
 
Try this:
Code:
<?PHP
	$lottery = $SQL->query('SELECT id, name FROM lottery ORDER BY id DESC LIMIT 1;');
	$data = mysql_fetch_array($lottery);

	$main_content .= '<center><h1>Lottery</h1></center>
		<center>Every 3 hours we will choose one player who will win 100k!<br/>
		Last Winner: <a href="?subtopic=characters&name='.urlencode($data['name']).'">'.$data['name'].'</a>  Congratulations!</center>';
?>

Hmm, this show errors... :thumbup:
The best solution is add manualy "first" winner, example:
Code:
INSERT INTO `lottery`(`id`, `name`) VALUES (NULL , 'Nobody');
 
can someone edit it to when you've won the lottery you'll get a item like; a winning ticket like you get in RL tibia :p
Repp++ for the one who edit that for me :wub:

( if need, i use TFS 0.3.5 )
 
Last edited:
looks nice, but how does it works???


Every x hours (default 3) script get random player from online list and give him prize :wub:

P.S small script update (untested because im on turkey now and i can't check, so please raport any errors)
 
Last edited:
Back
Top