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:


Messages In This Thread
Lottery - by Tim - 02-26-2011, 03:29 AM
RE: Lottery - by NinjaSiren - 09-29-2013, 03:19 AM
RE: Lottery - by xoft - 09-29-2013, 03:40 AM



Users browsing this thread: 1 Guest(s)