I Made this script only for TFS 0.3b2!
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)
2.Next GM must draw lot a winning numbers
/lot (!!Use only once time, because tickeds from before this lot's are deleted!!)
3.To player look win or lose must use
!result [if player win, player take money from rate and him ticked's are delete from database! (
To win the player must have all the numbers drawn, such as, but not necessarily one after another)]
Price is: All Tickets*ticketcost * 2 : )
Script was made by me (ersiu/azi) and please don't copy to other forums.!
*You need set in all files the config section!
You need make in data/talkactions/scripts new folder "lotto", there are scripts for lottery
first file
lotto/ticket.lua
next file - lotto/drawLots.lua
last lua file is - lotto/result.lua
Ok, all lua files made, now edit talkactions.xml and ADD:
Now Go to you phpMyAdmin and use SQL filed in your OTS Database and put and execute this code:
And Lottery Works!
Your,
Azi/ersiu. ; )
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)
2.Next GM must draw lot a winning numbers
/lot (!!Use only once time, because tickeds from before this lot's are deleted!!)
3.To player look win or lose must use
!result [if player win, player take money from rate and him ticked's are delete from database! (
To win the player must have all the numbers drawn, such as, but not necessarily one after another)]
Price is: All Tickets*ticketcost * 2 : )
Script was made by me (ersiu/azi) and please don't copy to other forums.!
*You need set in all files the config section!
You need make in data/talkactions/scripts new folder "lotto", there are scripts for lottery
first file
lotto/ticket.lua
Code:
config = {
["numberOfNumbers"] = 6, -- how many numbers you can type
["numbers"] = {1,20}, -- the range is to be type numbers
["cost"] = 15000, -- ticket cost
["level"] = 50 -- required level to send a ticket
}
function onSay(cid, words, param)
local types = {}
local err=0
local typ = ""
local nbrs = string.explode(param, ",")
if(getPlayerLevel(cid) >= config["level"])then
if(getPlayerMoney(cid) >= config["cost"])then
if(#nbrs >= config["numberOfNumbers"])then
for i=1, config["numberOfNumbers"] do
if(tonumber(nbrs[i]) >= config["numbers"][1] and tonumber(nbrs[i]) <= config["numbers"][2] and err ~= 4)then
if(isInArray(types, tonumber(nbrs[i])) == TRUE)then
err = 5
elseif(err ~= 5)then
table.insert(types, tonumber(nbrs[i]))
err = 0
end
else
err = 4
end
end
else
err = 3
end
else
err = 2
end
else
err = 1
end
if(err == 1)then
doPlayerSendTextMessage(cid, 19, "You need "..config["level"].." level to play.")
elseif(err == 2)then
doPlayerSendTextMessage(cid, 19, "You need pay "..config["cost"].." gp to play.")
elseif(err == 3)then
doPlayerSendTextMessage(cid, 19, "You need to type "..config["numberOfNumbers"].." numbers (!ticked x,x,x,x,x,x).")
elseif(err == 4)then
doPlayerSendTextMessage(cid, 19, "The rage of type numbers must be "..config["numbers"][1].." between "..config["numbers"][2]..".")
elseif(err == 5)then
doPlayerSendTextMessage(cid, 19, "Type numbers may not be repeated.")
else
for i=1,(config["numberOfNumbers"])-1 do
typ = typ..""..types[i]..","
end
typ = typ..""..types[config["numberOfNumbers"]]
doPlayerRemoveMoney(cid, config["cost"])
doPlayerSendTextMessage(cid, 19, "Ticked Sent! Cost: "..config["cost"].." gp.\nNumber Types: "..typ..".")
db.executeQuery("INSERT INTO `lotto_fate` (`player_id`, `time`, `numbers`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", '"..typ.."');")
end
end
Code:
config = {
["numberOfNumbers"] = 6, -- how many numbers you can type
["numbers"] = {1,20}, -- the range is to be type numbers
["cost"] = 1500
}
function drawLots(config)
numbers = {}
for a=-5, config["numberOfNumbers"] do
rand = math.random(config["numbers"][1],config["numbers"][2])
for x=1,50 do
if(isInArray(numbers, rand) == FALSE)then
table.insert(numbers, rand)
x=10
end
end
end
return numbers
end
function onSay(cid, words, param)
local numbers = drawLots(config)
local lot = ""
for i=1,(config["numberOfNumbers"])-1 do
lot = lot..""..numbers[i]..","
end
lot = lot..""..numbers[config["numberOfNumbers"]]
db.executeQuery("DELETE FROM `lotto_fate` WHERE `time` <= (SELECT `time` FROM `lotto_result` ORDER BY `time` DESC LIMIT 1);")
db.executeQuery("DELETE FROM `lotto_result`;")
local rows = db.getResult("SELECT `player_id` FROM `lotto_fate`;")
if(rows:getID() ~= -1) then
local rate = ((rows:numRows(true)*config["cost"])*2)
db.executeQuery("INSERT INTO `lotto_result` (`time`, `numbers`, `rate`) VALUES (" .. os.time() .. ", '"..lot.."', "..rate..");")
doBroadcastMessage("The Draw lot of our lottery!!\nWinning Numbers: "..lot..".\n Price is "..rate.." gp!\nCongratulations to the winners!", MESSAGE_STATUS_WARNING)
else
doPlayerSendCancel(cid, "Anybody sent ticket.")
end
end
Code:
function onSay(cid, words, param)
local fate = db.getResult("SELECT `numbers` FROM `lotto_fate` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
local result = db.getResult("SELECT `rate`,`numbers` FROM `lotto_result`;")
local numbers = {}
local results = {}
local win = 0
results = string.explode(result:getDataString("numbers"), ",")
local traf = 0
if(fate:getID() ~= -1) then
while(true) do
numbers = string.explode(fate:getDataString("numbers"), ",")
traf=0
for i=1, #numbers do
if(isInArray(results, numbers[i]) == TRUE)then
traf=traf+1
end
if(traf == 6)then
win = 1
end
end
if not(fate:next()) or win==1 then
break
end
end
fate:free()
if(win == 0)then
doPlayerSendTextMessage(cid, 19, "You lose!")
else
doPlayerPopupFYI(cid, "Congratulations, You win "..result:getDataInt("rate").." gp!")
doPlayerAddMoney(cid, result:getDataInt("rate"))
db.executeQuery("DELETE FROM `lotto_fate` WHERE `player_id`=".. getPlayerGUID(cid) ..";")
end
else
doPlayerSendCancel(cid, "You don\'t send a tickets or take the prize earlier")
end
end
Ok, all lua files made, now edit talkactions.xml and ADD:
Code:
<talkaction log="yes" access="0" words="!ticked" script="lotto/ticket.lua"/>
<talkaction log="yes" access="0" words="!result" script="lotto/result.lua"/>
<talkaction log="yes" access="5" words="/lot" script="lotto/drawLots.lua"/>
Now Go to you phpMyAdmin and use SQL filed in your OTS Database and put and execute this code:
PHP:
CREATE TABLE `lotto_fate` (
`player_id` bigint(255) NOT NULL,
`time` int(15) NOT NULL COMMENT '\r\n',
`numbers` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `lotto_result` (
`time` int(15) NOT NULL,
`numbers` text NOT NULL,
`rate` bigint(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
And Lottery Works!
Your,
Azi/ersiu. ; )
Last edited: