• 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!

PHP:
<?PHP
	$lottery = $SQL->query('SELECT `lottery`.`name` FROM `lottery` ORDER BY `lottery`.`id` DESC LIMIT 1;');

	$main_content .= '<center><h1>Lottery</h1></center><center>Every 3 hours we will choose one player who will win 100k!<br />';
	
	if($lottery->rowCount())
	{
		$data = $lottery->fetch();
		$main_content .= 'Last Winner: <a href="?subtopic=characters&amp;name='.urlencode($data['name']).'">'.$data['name'].'</a> Congratulations!</center>';
	}
	else
		$main_content .= 'No winners were drawn yet.';
?>
 
Last edited:
I get this error ;p
Code:
Fatal error: Call to a member function query() on a non-object in C:\Documents and Settings\Rm\Skrivebord\Websites\xampp\htdocs\lottery.php on line 2

Can anyone help me =)?
 
I get this error ;p
Code:
Fatal error: Call to a member function query() on a non-object in C:\Documents and Settings\Rm\Skrivebord\Websites\xampp\htdocs\lottery.php on line 2

Can anyone help me =)?


Do you have `lottery` table in your database?
 

Because this is for gesiors aac.
Add above $lottery:
PHP:
    $SQL = new MySQLi('localhost', 'root', 'password', 'database');
Change rowCount() to num_rows.
Add at the bottom:
PHP:
echo $main_content;
$SQL->close();
ok.
 
Im using Gesiors Aac..
Code:
Fatal error: Call to undefined method mysqli_result::rowCount() in C:\Documents and Settings\Rm\Skrivebord\Websites\xampp\htdocs\lottery.php on line 7
 
[13/08/2009 19:44:34] Lua Script Error: [GlobalEvent Interface]
[13/08/2009 19:44:34] data/globalevents/scripts/lottery.lua:eek:nThink

[13/08/2009 19:44:34] data/globalevents/scripts/lottery.lua:13: bad argument #2 to 'random' (interval is empty)
[13/08/2009 19:44:34] stack traceback:
[13/08/2009 19:44:34] [C]: in function 'random'
[13/08/2009 19:44:34] data/globalevents/scripts/lottery.lua:13: in function <data/globalevents/scripts/lottery.lua:7>
[13/08/2009 19:44:34] [Error - GlobalEvents::think] Couldn't execute event: lottery


now what?:confused::confused:
 
[13/08/2009 19:44:34] Lua Script Error: [GlobalEvent Interface]
[13/08/2009 19:44:34] data/globalevents/scripts/lottery.lua:eek:nThink

[13/08/2009 19:44:34] data/globalevents/scripts/lottery.lua:13: bad argument #2 to 'random' (interval is empty)
[13/08/2009 19:44:34] stack traceback:
[13/08/2009 19:44:34] [C]: in function 'random'
[13/08/2009 19:44:34] data/globalevents/scripts/lottery.lua:13: in function <data/globalevents/scripts/lottery.lua:7>
[13/08/2009 19:44:34] [Error - GlobalEvents::think] Couldn't execute event: lottery


now what?:confused::confused:

If on your ots is 0 players script show errors...
 
What if there is only 1 player online? Lottery gives always reward to this player?
 
vDk, you can also modify your script a bit for a random rewards, it should be better than same reward xx times.
 
sorry but this:
PHP:
    for i, tid in ipairs(players) do
is very bad. imagine 350 players online, then everytime its a lottery, you loop 350 players... its no good. you dont really have to loop here, see if you can figure out another way

EDIT: if i understood it correct, the lottery chooses 1 random player that is online... why do you need to loop all players??

do this:

PHP:
local win_number = math.random(1, #players)
local winner = players[winner]
 
Last edited:
Then just add a check?
Lua:
if #list == 0 then return TRUE end

Im on holidays and im don't have time to write/fix scripts.
When im back i fix all errors.

@down
You must change this:
Code:
<globalevent name="lottery" interval="[B]10800[/B]" event="script" value="lottery.lua"/>

Because this is only for broadcast : P

Lua:
    lottery_hour = "3 Hours", -- Time to next lottery
 
Last edited:
btw if you change the time instead of "3 hours" to "1 hour" nothing happend ¬¬ and it stays 3 hours. please don't tell me i'm wrong because i watched for 3 hours long...!:mad:
 
I edited it a bit so you see item name on the site, also you should add it for multiworld.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
I edited it a bit so you see item name on the site, also you should add it for multiworld.

Nice idea with display item on site, script has been updated :D
I never use multiworld so i dont know how add support at this ^_^
 
Back
Top