• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TalkAction The Numeric Lottery!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
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:
lotek.lua line 45 gave me a string error man can you fix
 
Ersiu sux :p, nice script ^^, I think I will make this with some NPC to make it more evul
 
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
 
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:
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
 
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 :)
 
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
 
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:
#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:
Back
Top