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

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
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"/>
If you want lottery system on your acc maker:

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 />';
}
?>
Open index.php and add:

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

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:
What kind of checks, hm? And the lottery.lua isn't mine.
 
Last edited by a moderator:
// by vDk, klekSu
Fatal error: Call to a member function query() on a non-object in D:\xampp\htdocs\lottery.php on line 3
 
Did you add tables to database?

Code:
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 ;

Code:
INSERT INTO `lottery` (`id`, `name`, `item`, `world_id`) VALUES
(NULL, 'Nobody', 'nothing', 0);
 
Last edited by a moderator:
[03/09/2009 10:31:56] Lua Script Error: [GlobalEvent Interface]
[03/09/2009 10:31:56] data/globalevents/scripts/lottery.lua:eek:nThink

[03/09/2009 10:31:56] data/globalevents/scripts/lottery.lua:17: attempt to call global 'getPlayerWorldId' (a nil value)
[03/09/2009 10:31:56] stack traceback:
[03/09/2009 10:31:56] data/globalevents/scripts/lottery.lua:17: in function <data/globalevents/scripts/lottery.lua:8>
[03/09/2009 10:31:56] [Error - GlobalEvents::eek:nThink] Couldn't execute event: lottery

why i get this error in my console
 
Because you did not paste the getPlayerWorldId function in functions.lua.
 
Last edited by a moderator:
Back
Top