Autor: vDk oraz klekSu. klik

Licencja: Rób co chcesz byle by nie zmieniać autora

Skrypt losuje z pośród podanych ID itemów gracza który otrzymuje jedna z nich loteria może się odbywać w co określony czas.

Część LUA

Przechodzimy do katalogu data/lib/function.lua tak doklejamy:

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

Kolejnym krokiem jest data/globalevents/scripts/ i utworzenie tam pliku lottery.lua a jego zawartość to:

lottery.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 

Teraz przechodzimy do data/globalevents/globalevents.xml i tam doklejamy jedna linijkę:

<globalevent name="lottery" interval="10800" event="script" value="lottery.lua"/>

Gdzie 10800 to liczba sekund co ile bedzie losowanie. Jeśli zmienisz np na 6 godzin nie zapomnij zmienić tego wyżej w skrypcie! lottery_hour = “x Hours”!

Część PHP

W naszym acc makerze tworzymy plik lottery.php

lottery.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 />';
}
?>

Nie zapomnij dodać też tego do index.php:

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

Oraz dodaj odpowiednie rzeczy do layouta!

Część SQL

Po pierwsze dodaj:

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 ;
 
 
===== ORAZ =====
 
INSERT INTO `lottery` (`id`, `name`, `item`, `world_id`) VALUES
(NULL, 'Nobody', 'nothing', 0);

No i gotowe! Brawo!

otspub/lottery_system_v2_by_vdk_and_kleksu.txt · Last modified: 2010/04/28 19:08 by kielb
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
 otosowy pasek