kimokimo
Kimo
So as the title says this is a lottery game with just 3 simple commands.
This is the the items table you can easily edit.
How to use it:
First you need to say (/lottery start) to open it for players to join and you can wait as you want then when you see there is enough players joined the lottery with this another command
(/lottery check) then you can roll the lottery and pick the winner with (/lottery roll). that's it
also you can broadcast how many players joined with this command (/lottery bc).
This is the command for players to join they just type (/lotteryjoin donation)
Also if you want it to broadcast automaticly when the lottery is on use this :
Code:
function getLotteryPlayers()
local players = {}
for _, zid in pairs(getPlayersOnline()) do
if getCreatureStorage(zid, 1300) == 1 then
table.insert(players, zid)
end
end
return players
end
local itemRewards = {
{7697, 1},
{11255, 1},
{6433, 1},
{8903, 1},
{7289, 1},
{9777, 1},
{11118, 1},
{2157, 500},
{8821, 1},
{8858, 1},
{2352, 1},
{11307, 1},
{11308, 1},
{2453, 1},
{2184, 1},
{11323, 1},
{9776, 1},
{9778, 1},
{2270, 1},
{2294, 1}
}
function onSay(cid, words, param, channel)
local t = string.explode(param, ",")
local players = getLotteryPlayers()
if (t[1] == 'open') then
setGlobalStorageValue(1300, 1)
doBroadcastMessage("".. getCreatureName(cid) .." has opened donation lottery to participate say (/lotteryjoin donation) for 100gn.", MESSAGE_EVENT_ADVANCE)
elseif (t[1] == 'roll') then
local storage = getGlobalStorageValue(1300)
if storage == 1 then
local players = getLotteryPlayers()
local list = {}
for i, tid in ipairs(players) do
list[i] = tid
end
local winner = list[math.random(1, #list)]
local prize = math.random(1, #itemRewards)
doBroadcastMessage('['.. getCreatureName(cid) ..'] has drawn the donation lottery and the winner is ['.. getCreatureName(winner) ..'] he got ['.. itemRewards[prize][2] ..'x: '.. getItemNameById(itemRewards[prize][1]) ..'] - Congratulations!', MESSAGE_EVENT_ADVANCE)
local wonitem = doPlayerAddItem(winner, itemRewards[prize][1], itemRewards[prize][2])
doItemSetAttribute(wonitem, "description", "Won in donation lottery by:[".. getCreatureName(winner) .."]")
setGlobalStorageValue(1300, 0)
for _, bid in pairs(getPlayersOnline()) do
if getCreatureStorage(bid, 1300) == 1 then
doPlayerSetStorageValue(bid, 1300, 0)
end
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Lottery is not open yet start it first.")
end
elseif (t[1] == 'check') then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "[".. #players .."] in lottery")
elseif (t[1] == 'bc') then
doBroadcastMessage("There are ".. #players .." players joined donation lottery so far to join say (/lotteryjoin donation)!", MESSAGE_EVENT_ORANGE)
end
return true
end
Code:
local itemRewards = {
{7697, 1},
{11255, 1},
{6433, 1},
{8903, 1},
{7289, 1},
{9777, 1},
{11118, 1},
{2157, 500},
{8821, 1},
{8858, 1},
{2352, 1},
{11307, 1},
{11308, 1},
{2453, 1},
{2184, 1},
{11323, 1},
{9776, 1},
{9778, 1},
{2270, 1},
{2294, 1}
}
How to use it:
First you need to say (/lottery start) to open it for players to join and you can wait as you want then when you see there is enough players joined the lottery with this another command
(/lottery check) then you can roll the lottery and pick the winner with (/lottery roll). that's it
also you can broadcast how many players joined with this command (/lottery bc).
This is the command for players to join they just type (/lotteryjoin donation)
Code:
function onSay(cid, words, param, channel)
local t = string.explode(param, ",")
if getPlayerAccess(cid) > 3 then
doPlayerSendTextMessage(cid,19,"Staff can't join lottery")
return true
end
local storage = getGlobalStorageValue(1300)
if storage < 1 then
doPlayerSendTextMessage(cid,19,"No lottery is open atm")
return true
end
if (t[1] == 'donation') then
if getCreatureStorage(cid, 1300) < 1 then
if doPlayerRemoveItem(cid, 2157, 100) then
doPlayerSetStorageValue(cid, 1300, 1)
doPlayerSendTextMessage(cid,19,"You have joined the donation lottery for 100gn now wait for a staff member to roll the lottery (DONT LOG OUT)")
else
doPlayerSendTextMessage(cid,19,"You don't have enough gold nuggets you need 100")
end
else
doPlayerSendTextMessage(cid,19,"You have already joined the lottery")
end
end
return true
end
Also if you want it to broadcast automaticly when the lottery is on use this :
Code:
function getLotteryPlayers()
local players = {}
for _, zid in pairs(getPlayersOnline()) do
if getCreatureStorage(zid, 1300) == 1 then
table.insert(players, zid)
end
end
return players
end
[/SIZE]
function onThink(interval, lastExecution)
local players = getLotteryPlayers()
if getStorage(1300) == 1 then
doBroadcastMessage("There are ".. #players .." players joined donation lottery so far to join say (/lotteryjoin donation)!", MESSAGE_EVENT_ORANGE)
end
return true
end