• 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!

Lottery system (help) !

since you won't post the script, i'll have to guess that your libs (primarily 000-constant.lua) are outdated
 
since you won't post the script, i'll have to guess that your libs (primarily 000-constant.lua) are outdated

troll, anyway i removed he's char he made a new char i guess it will work now but i'm trying to add a lottery system wich has some errors and i'm kinda stuck on the npc error lotternpc.jpg

Lua:
-- Credits for inspiration and ideas to Azi, <a href="http://forum.otsmedia.eu/archive/index.php/thread-876.html" target="_blank">http://forum.otsmedia.eu/archive/ind...hread-876.html</a>
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)
	npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
	npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)
	npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
	npcHandler:onThink()
end
function creatureSayCallback(cid, type, msg)
	if(not(npcHandler:isFocused(cid))) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if(msgcontains(msg, "lottery")) then
		npcHandler:say("Welcome to our {lottery}. The lottery is a chance to get rich really quick! All you need to do is to {buy} a {ticket}, state four numbers from 1 to " .. lotteryConfig.maxNumber .. " and wait for the draw.", cid)
	elseif(msgcontains(msg, "buy") or msgcontains(msg, "ticket")) then
		npcHandler:say("Do you want to buy a ticket for a lottery?", cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, "yes")) then
		if(talkState[talkUser] == 1) then
			if(db.getResult("SELECT * FROM `lottery` WHERE `player_id` = " .. getPlayerGUID(cid) .. ""):getID() < 1) then
				npcHandler:say("Please state four numbers from 1 to " .. lotteryConfig.maxNumber .. ". You can always state random numbers saying 'random'. Remember you cannot state two exact numbers.", cid)
				talkState[talkUser] = 2
			else
				npcHandler:say("You've already bought a ticket for this lottery.", cid)
				talkState[talkUser] = 0
			end
		end
	elseif(msgcontains(msg, "no")) then
		if(talkState[talkUser] > 0) then
			npcHandler:say("Then no.", cid)
			talkState[talkUser] = 0
		end
	elseif(talkState[talkUser] == 2) then
		local numbers = {}
		if(string.lower(msg) == "random") then
			repeat
				randomNumber = math.random(1, lotteryConfig.maxNumber)
				if(not(isInArray(numbers, randomNumber))) then
					table.insert(numbers, randomNumber)
				end
			until table.maxn(numbers) == lotteryConfig.numbersCount
		else
			if(string.explode(msg, ", ")) then
				if(table.maxn(string.explode(msg, ", ")) == lotteryConfig.numbersCount) then
					for i = 1, lotteryConfig.numbersCount do
						if(tonumber(string.explode(msg, ", ")[i]) < 1 or tonumber(string.explode(msg, ", ")[i]) > lotteryConfig.maxNumber or isInArray(numbers, string.explode(msg, ", ")[i])) then
							npcHandler:say("The combination of numbers is wrong.", cid)
							talkState[talkUser] = 0
							return true
						end
						table.insert(numbers, string.explode(msg, ", ")[i])
					end
				else
					npcHandler:say("You must state atleast " .. lotteryConfig.numbersCount .. " numbers.", cid)
					return true
				end
			else
				npcHandler:say("You can state numbers only.", cid)
				return true
			end
		end
		local output = ""
		for i = 1, lotteryConfig.numbersCount do
			if(i ~= lotteryConfig.numbersCount) then
				output = output .. numbers[i] .. ", "
			else
				output = output .. numbers[i]
			end
		end
		if(getPlayerMoney(cid) < lotteryConfig.ticketPrice) then
			npcHandler:say("You don't have enought money.", cid)
			talkState[talkUser] = 0
		else
			db.executeQuery("INSERT INTO `lottery` (`player_id`, `numbers`) VALUES (" .. getPlayerGUID(cid) .. ", '" .. tostring(output) .. "')")
			npcHandler:say("Your numbers are " .. output .. ". I wish you good luck and big winnings!", cid)
			talkState[talkUser] = 0
			doPlayerRemoveMoney(cid, lotteryConfig.ticketPrice)
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


http://otland.net/f82/teckmans-lottery-system-139287/
 
Last edited:
Well, the error you have is saying that lotteryConfig does not exist.
So, from the link I show, you need to add that table.
 
please, i really need this and the zombie thing since i'm updating the map tomorrow :/

lottery
since you won't post the script, i'll have to guess that your libs (primarily 000-constant.lua) are outdated

troll, anyway i removed he's char he made a new char i guess it will work now but i'm trying to add a lottery system wich has some errors and i'm kinda stuck on the npc error View attachment 12036

Lua:
-- Credits for inspiration and ideas to Azi, <a href="http://forum.otsmedia.eu/archive/index.php/thread-876.html" target="_blank">http://forum.otsmedia.eu/archive/ind...hread-876.html</a>
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)
	npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
	npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)
	npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
	npcHandler:onThink()
end
function creatureSayCallback(cid, type, msg)
	if(not(npcHandler:isFocused(cid))) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if(msgcontains(msg, "lottery")) then
		npcHandler:say("Welcome to our {lottery}. The lottery is a chance to get rich really quick! All you need to do is to {buy} a {ticket}, state four numbers from 1 to " .. lotteryConfig.maxNumber .. " and wait for the draw.", cid)
	elseif(msgcontains(msg, "buy") or msgcontains(msg, "ticket")) then
		npcHandler:say("Do you want to buy a ticket for a lottery?", cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, "yes")) then
		if(talkState[talkUser] == 1) then
			if(db.getResult("SELECT * FROM `lottery` WHERE `player_id` = " .. getPlayerGUID(cid) .. ""):getID() < 1) then
				npcHandler:say("Please state four numbers from 1 to " .. lotteryConfig.maxNumber .. ". You can always state random numbers saying 'random'. Remember you cannot state two exact numbers.", cid)
				talkState[talkUser] = 2
			else
				npcHandler:say("You've already bought a ticket for this lottery.", cid)
				talkState[talkUser] = 0
			end
		end
	elseif(msgcontains(msg, "no")) then
		if(talkState[talkUser] > 0) then
			npcHandler:say("Then no.", cid)
			talkState[talkUser] = 0
		end
	elseif(talkState[talkUser] == 2) then
		local numbers = {}
		if(string.lower(msg) == "random") then
			repeat
				randomNumber = math.random(1, lotteryConfig.maxNumber)
				if(not(isInArray(numbers, randomNumber))) then
					table.insert(numbers, randomNumber)
				end
			until table.maxn(numbers) == lotteryConfig.numbersCount
		else
			if(string.explode(msg, ", ")) then
				if(table.maxn(string.explode(msg, ", ")) == lotteryConfig.numbersCount) then
					for i = 1, lotteryConfig.numbersCount do
						if(tonumber(string.explode(msg, ", ")[i]) < 1 or tonumber(string.explode(msg, ", ")[i]) > lotteryConfig.maxNumber or isInArray(numbers, string.explode(msg, ", ")[i])) then
							npcHandler:say("The combination of numbers is wrong.", cid)
							talkState[talkUser] = 0
							return true
						end
						table.insert(numbers, string.explode(msg, ", ")[i])
					end
				else
					npcHandler:say("You must state atleast " .. lotteryConfig.numbersCount .. " numbers.", cid)
					return true
				end
			else
				npcHandler:say("You can state numbers only.", cid)
				return true
			end
		end
		local output = ""
		for i = 1, lotteryConfig.numbersCount do
			if(i ~= lotteryConfig.numbersCount) then
				output = output .. numbers[i] .. ", "
			else
				output = output .. numbers[i]
			end
		end
		if(getPlayerMoney(cid) < lotteryConfig.ticketPrice) then
			npcHandler:say("You don't have enought money.", cid)
			talkState[talkUser] = 0
		else
			db.executeQuery("INSERT INTO `lottery` (`player_id`, `numbers`) VALUES (" .. getPlayerGUID(cid) .. ", '" .. tostring(output) .. "')")
			npcHandler:say("Your numbers are " .. output .. ". I wish you good luck and big winnings!", cid)
			talkState[talkUser] = 0
			doPlayerRemoveMoney(cid, lotteryConfig.ticketPrice)
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


http://otland.net/f82/teckmans-lottery-system-139287/


Solved the Zombie event but i really need help with the lottery system
 
Last edited:
Back
Top