TESTED ON TFS 0.3.6PL1!
All settings in script config!
It's a numeric lottery script!
The rules are very easy!
1.Player Send's tickets by command
!ticket 1,2,3,4,5,6 (type a numbers after the commas)
Players don't have ticket buy limit.
2.Next wait to 22:00 and script auto-draw numbers and auto add to bank balance win prize (cash). : )
Prize is: All Tickets*ticketcost * 1.5 : )
Script was made by me (ersiu/azi) and please don't copy to other forums.
If you like IT - you can rep me!
In OTS FOLDER/MODS make file Lottery_System.XML and paste code:
Now execute SQL Query in PhpMyAdmin (in ots database)
And Lottery Works!
Your,
Azi/ersiu. ; )
All settings in script config!
It's a numeric lottery script!
The rules are very easy!
1.Player Send's tickets by command
!ticket 1,2,3,4,5,6 (type a numbers after the commas)
Players don't have ticket buy limit.
2.Next wait to 22:00 and script auto-draw numbers and auto add to bank balance win prize (cash). : )
Prize is: All Tickets*ticketcost * 1.5 : )
Script was made by me (ersiu/azi) and please don't copy to other forums.
If you like IT - you can rep me!
In OTS FOLDER/MODS make file Lottery_System.XML and paste code:
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Lottery System" version="2.0" author="Azi [Ersiu]" contact="http://otland.net/members/azi/" enabled="yes">
<config name="Lottery Config"><![CDATA[
config = {
types = 6, -- how many numbers you can type
range = {1,20}, -- the range is to be type numbers
cost = 1500, -- ticket cost
level = 10, -- required level to send a ticket
endDelete = false -- if no winners delete tickets? (default false - tickets play in next lottery)
}
]]></config>
<globalevent name="LotteryEnds" time="22:00" event="script"><![CDATA[
domodlib("Lottery Config")
function onTimer()
local _DRAWS = {}
local _WINERS = {}
while(true)do
local rand = math.random(config.range[1], config.range[2])
if(not isInArray(_DRAWS, rand))then table.insert(_DRAWS, rand) end
if(#_DRAWS == config.types)then break end
end
w_types = ""
for _,t in ipairs(_DRAWS) do
if(w_types=="")then w_types=t else w_types=w_types..","..t end
end
local ticket = db.getResult("SELECT `numbers`, `player_id` FROM `lotto_tickets`;")
if(ticket:getID() ~= -1) then
while(true)do
local types = ticket:getDataString("numbers")
local good = 0
for _,_type in ipairs(string.explode(types, ",")) do
if(isInArray(_DRAWS, tonumber(_type)))then good=good+1 end
end
if(good == config.types)then table.insert(_WINERS, ticket:getDataInt("player_id")) end
if not(ticket:next()) then break end
end
if(#_WINERS > 0)then
local prize = (((ticket:numRows(true)*config.cost)*1.5)/#_WINERS)
winners = ""
for _,t in ipairs(_WINERS) do
db.executeQuery("UPDATE `players` SET `balance`=balance+"..prize.." WHERE id="..t)
if(winners=="")then winners=getPlayerNameByGUID(t) else winners=winners..","..getPlayerNameByGUID(t) end
end
doBroadcastMessage("Lottery end! Winners: "..winners.."! Winners wins "..prize.." GP! Winning types: "..w_types.."! ", MESSAGE_STATUS_WARNING)
db.executeQuery("DELETE FROM `lotto_tickets`;")
else
doBroadcastMessage("Lottery end, Nobody wins lottery! Winning types: "..w_types.."! ", MESSAGE_STATUS_WARNING)
if(config.endDelete)then db.executeQuery("DELETE FROM `lotto_tickets`;") end
end
else
doBroadcastMessage("Lottery end! Nobody send ticket.", MESSAGE_STATUS_WARNING)
end
return true
end
]]></globalevent>
<talkaction words="!ticket" event="script"><![CDATA[
domodlib("Lottery Config")
function onSay(cid, words, param, channel)
local _TYPES = {}
local types = string.explode(param, ",")
if(getPlayerLevel(cid)<config.level)then doPlayerSendTextMessage(cid, 19, "You need "..config.level.." to send a ticket.") return TRUE end
for _,_type in ipairs(types) do
if(not isNumber(_type))then doPlayerSendTextMessage(cid, 19, "You can type only numbers.") return TRUE end
_type = tonumber(_type)
if(_type < config.range[1] or _type > config.range[2])then doPlayerSendTextMessage(cid, 19, "You can type numbers between "..config.range[1].."-"..config.range[2]..".") return TRUE end
if(not isInArray(_TYPES, _type))then
table.insert(_TYPES, _type)
else
doPlayerSendTextMessage(cid, 19, "Type numbers may not be repeated.")
return TRUE
end
end
if(#_TYPES < config.types or #_TYPES > config.types)then doPlayerSendTextMessage(cid, 19, "You must type "..config.types.." numbers.") return TRUE end
if(not doPlayerRemoveMoney(cid, config.cost))then doPlayerSendTextMessage(cid, 19, "You need "..config.cost.."GP to send a ticket.") return TRUE end
_t=""
for _,t in ipairs(_TYPES) do
if(_t=="")then _t=t else _t=_t..","..t end
end
doPlayerPopupFYI(cid, "Ticket Status: Sent\nTicket Cost: "..config.cost.."\nTyped Numbers:".._t)
db.executeQuery("INSERT INTO `lotto_tickets` (`player_id`, `time`, `numbers`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", '".._t.."');")
return true
end
]]></talkaction>
</mod>
Now execute SQL Query in PhpMyAdmin (in ots database)
PHP:
CREATE TABLE `lotto_tickets` (
`player_id` bigint(255) NOT NULL,
`time` int(15) NOT NULL COMMENT '\r\n',
`numbers` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
And Lottery Works!
Your,
Azi/ersiu. ; )