Lottery
#1
Fairly simple lottery type script, just thought I'd post it to encourage other people to publish their scripts however complicated or simple, also to help people that are just starting out. Smile

Basically the syntax for the command is
/lottery [number1] [number2] [number3]

when you execute the command it generates 3 random numbers and compares each one to your number in the same order if you get what i mean? For each number you get right, you get a cake! Anyway, heres the plugin code so you can see it for yourself, just copy and paste it in to a new lua file in your plugins folderBig Grin
Code:
local LotteryPlugin = {}
LotteryPlugin.__index = LotteryPlugin

function LotteryPlugin:new()
   local t = {}
   setmetatable(t, LotteryPlugin)
   local w = Lua__cPlugin:new()
   tolua.setpeer(w, t)
   w:tolua__set_instance(w)
   return w
end

function LotteryPlugin:Initialize()
    local Server = cRoot:Get():GetServer()
    self:SetName( "Lottery" )
    self:SetVersion( 1 )
    Log( "Initialized " .. self:GetName() .. " v." .. self:GetVersion() )
    self:BindCommand("/lottery", lottery)
    self:AddCommand("/lottery", " - Play the lottery; usage: /lottery [number 1] [number 2] [number 3]", "Lottery.lottery")

    return true

end

function LotteryPlugin:OnDisable()
    Log( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." )
end

function lottery (Split, Player)
    local Server = cRoot:Get():GetServer()    
    local number = math.random(1,10)
    local number2 = math.random(1,10)
    local number3 = math.random(1,10)
    local n = tonumber(Split[2])
    local n2 = tonumber(Split[3])
    local n3 = tonumber(Split[4])
    local won = 0
    if(n and n2 and n3) then
        if(n==number) then
            won = won + 1
        end
        if(n2==number2) then
            won = won +1
        end
        if(n3==number3) then
            won = won + 1
        end
        if(won<2) then
            Server:SendMessage("Lottery: ".. Player:GetName().. " got "..won.. " numbers right! The numbers were ".. number.. ", "..number2.. " and "..number3.. ". Prize won: "..won.." Cake!")
            else
            Server:SendMessage("Lottery: ".. Player:GetName().. " got "..won.. " numbers right! The numbers were ".. number.. ", "..number2.. " and "..number3.. ". Prize won: "..won.." Cakes!")
        end
        Player:GetInventory():AddItem( cItem( 92, won ) )
    else
        Server:SendMessage("Lottery: Please type 3 numbers after the /lottery command seperated by spaces. E.g. /lottery 1 2 3", Player)
    end
    return true
end


Plugin = LotteryPlugin:new()
cRoot:Get():GetPluginManager():AddPlugin( Plugin )

Good luck and i hope you win many cakes Wink
Reply
Thanks given by:
#2
Hello, this is a nice plugin, but I wonder if I could change the item being won? than cake, ie: iron, or diamond. or if ever better if he/she got a number the player will get item depending on how many numbers he/she got correctly and giving random item that corresponds also on how many numbers the player were correct.
Reply
Thanks given by:
#3
This script will most probably not work in current MCServer versions, it uses the old plugin architecture no longer supported.

To change the won item, search the text for 92 and replace it with E_ITEM_DIAMOND, E_ITEM_IRON or whatever item you want the players to win.
Reply
Thanks given by:




Users browsing this thread: 3 Guest(s)