Myerz
30-10-09, 01:11 PM
--[ DEFINE_VARIABLES ]--
local INITIATE_MSG = "#lotterystart"
local ENTER_MSG = "#enter"
local END_MSG = "#lotteryend"
--[[
REGISTER_ON_CHAT
]]--
function OnChat(event, pPlayer, message, type, language)
lottery = 0
--[ INTIATE_LOTTERY ]--
if (message == INITIATE_MSG) and (pPlayer:IsGm() == true) then
pPlayer:SendBroadcastMessage("Lottery has been initialized. Type #enter to enter into the lottery.")
lottery = 1
plrnumber = 0
else
pPlayer:SendAreaTriggerMessage("You cannot start the lottery")
lottery = 0
end
--[ ENTER_ LOTTERY ]--
if (message == ENTER_MSG) then
if (pPlayer:GetItemCount(80010) < 1) then
pPlayer:SendAreaTriggerMessage("You don't have enough Coins to bet!")
else
pPlayer:RemoveItem(80010, 1)
pPlayer:SendAreaTriggerMessage("Please wait until the Lottery has finished collecting.\n Your coin has been taken. Thank you!")
plrnumber = plrnumber + 1
CharDBQuery("INSERT INTO lottery (plrnumber, playername, win) VALUES ('"..plrnumber.."', '"..pPlayer:GetName().."', 0)", 0)
end
end
--[ END_LOTTERY ]--
if (message == END_MSG) then
local pid = math.random(1, plrnumber)
CharDBQuery("UPDATE `lottery` Set `win` = 1 Where `plrnumber` = '"..pid.."'", 0)
lottery = 0
plrnumber = 0
end
end
--[[
REGISTER_SERVER_HOOK
]]--
RegisterServerHook(16, "OnChat")
local INITIATE_MSG = "#lotterystart"
local ENTER_MSG = "#enter"
local END_MSG = "#lotteryend"
--[[
REGISTER_ON_CHAT
]]--
function OnChat(event, pPlayer, message, type, language)
lottery = 0
--[ INTIATE_LOTTERY ]--
if (message == INITIATE_MSG) and (pPlayer:IsGm() == true) then
pPlayer:SendBroadcastMessage("Lottery has been initialized. Type #enter to enter into the lottery.")
lottery = 1
plrnumber = 0
else
pPlayer:SendAreaTriggerMessage("You cannot start the lottery")
lottery = 0
end
--[ ENTER_ LOTTERY ]--
if (message == ENTER_MSG) then
if (pPlayer:GetItemCount(80010) < 1) then
pPlayer:SendAreaTriggerMessage("You don't have enough Coins to bet!")
else
pPlayer:RemoveItem(80010, 1)
pPlayer:SendAreaTriggerMessage("Please wait until the Lottery has finished collecting.\n Your coin has been taken. Thank you!")
plrnumber = plrnumber + 1
CharDBQuery("INSERT INTO lottery (plrnumber, playername, win) VALUES ('"..plrnumber.."', '"..pPlayer:GetName().."', 0)", 0)
end
end
--[ END_LOTTERY ]--
if (message == END_MSG) then
local pid = math.random(1, plrnumber)
CharDBQuery("UPDATE `lottery` Set `win` = 1 Where `plrnumber` = '"..pid.."'", 0)
lottery = 0
plrnumber = 0
end
end
--[[
REGISTER_SERVER_HOOK
]]--
RegisterServerHook(16, "OnChat")