TalkAction The Numeric Lottery!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Best answers
0
Reaction score
51
Location
Włocławek
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
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
next file - lotto/drawLots.lua
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
last lua file is - lotto/result.lua
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:

Gsp

RP
Joined
Jan 3, 2008
Messages
237
Best answers
0
Reaction score
3
lotek.lua line 45 gave me a string error man can you fix
 
OP
Azi

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Best answers
0
Reaction score
51
Location
Włocławek
#up
ok i see downline on text in function - done :)
 

Hermes

dziwki kola gramy w lola
Joined
Nov 17, 2007
Messages
1,867
Best answers
0
Reaction score
12
Location
Poland
Ersiu sux :p, nice script ^^, I think I will make this with some NPC to make it more evul
 

Raliuga

OTFusion founder
Joined
Jul 23, 2007
Messages
693
Best answers
0
Reaction score
4
Location
Mexico
Code:
Lua Script Error: [TalkAction Interface] 
data/talkactions/scripts/lotek/lotek.lua:onSay

data/talkactions/scripts/lotek/lotek.lua:13: attempt to compare nil with number
stack traceback:
data/talkactions/scripts/lotek/lotek.lua:13: in function <data/talkactions/scripts/lotek/lotek.lua:8>
hummm is something about the level and i didnt change anything xD
 

Falu Alth

New Member
Joined
Oct 18, 2008
Messages
25
Best answers
0
Reaction score
0
Location
Poland
Can i add this on other forum?With your credits...
Script is super I search script like this :p
 
OP
Azi

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Best answers
0
Reaction score
51
Location
Włocławek
Can i add this on other forum?With your credits...
yeah, sure. :)


#Raliuga
you using param with "

not:
!lotek "1,2,3,4,5,6
but:
!lotek 1,2,3,4,5,6
without ' " '. ; )
 

Raliuga

OTFusion founder
Joined
Jul 23, 2007
Messages
693
Best answers
0
Reaction score
4
Location
Mexico
yeah, sure. :)


#Raliuga
you using param with "

not:
!lotek "1,2,3,4,5,6
but:
!lotek 1,2,3,4,5,6
without ' " '. ; )
nope :/ im using it with !ticket 1,2,3,4,5,6 :O!


oh >_> i didnt read this:

*You need set in all files the config section!

srry :p


and humm... how can i make that when the player says "!ticket blablabla" his msg dont appear on the deafault channel? (BAD ENGLISH?)
 
Last edited:
OP
Azi

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Best answers
0
Reaction score
51
Location
Włocławek
#up
idk :p hehe ; )
 
Last edited:

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
nope :/ im using it with !ticket 1,2,3,4,5,6 :O!


oh >_> i didnt read this:

*You need set in all files the config section!

srry :p


and humm... how can i make that when the player says "!ticket blablabla" his msg dont appear on the deafault channel? (BAD ENGLISH?)
add return FALSE
 

elf

Sing, sing blue silver
Joined
Dec 11, 2007
Messages
3,665
Best answers
1
Reaction score
116
Location
Cracow, Poland
add return FALSE
beep- wrong! TRUE.

I didn't review whole script, but you should consider table values being bracket+quoteless if you're not using it on pairs loop.
Code:
local config = {
liczba = 666
}
instead
Code:
local config = {
["liczba"] = 666
}
 

Colandus

Advanced OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
beep- wrong! TRUE.

I didn't review whole script, but you should consider table values being bracket+quoteless if you're not using it on pairs loop.
Code:
local config = {
liczba = 666
}
instead
Code:
local config = {
["liczba"] = 666
}
It does the same thing, only difference is that without brackets and quotes it must be in variable format :p
But indeed, in this case (as it's variables) it should be quoteless :)
 

Kaorus

Unleash Dreams Staff
Joined
May 18, 2008
Messages
1,087
Best answers
0
Reaction score
8
Location
Iquique, Chile
It does the same thing, only difference is that without brackets and quotes it must be in variable format :p
But indeed, in this case (as it's variables) it should be quoteless :)
War of scripters :D
 

Victor

New Member
Joined
Feb 1, 2008
Messages
222
Best answers
0
Reaction score
1
Maybe some script to change price of ticket and one in all?
 

emocfinger

New Member
Joined
Oct 30, 2008
Messages
7
Best answers
0
Reaction score
0
Yea man , very useful
now it works with mysql.
Let me ask one thing , you can put when player do !ticked , after the money goes , give a letter or something like that.
inside the numbers like the guy use
I Tried put numbers win and player's name winner in !result
but i cant its too hard :S

Edit againnnnnnn___
The tables of result.lua are wrong they named "lotek_fate" and "lotek_reult"
 
Last edited:
OP
Azi

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Best answers
0
Reaction score
51
Location
Włocławek
#up
thx, mistaked when i translate from pl to eng. - fixed! ; )
with letter you can add:
Code:
local itemname = "letter"
local letter = doPlayerAddItem(cid, getItemIdByName(itemname), 1)
doSetItemText(uid, "You sent ticket for lotto!\n Your typed numbers: "..typ)
in ticked.lua
under:
Code:
doPlayerRemoveMoney(cid, config["cost"])
 
Last edited:
Top