• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

So i am working on a casino script and i need some help with the dice and npc

Angel Of Death

Rise Of Tibia ServerOwner
Joined
Mar 12, 2012
Messages
91
Reaction score
0
Alright so i need an npc that when you say hi he says would you like to roll the dice for 500 gp so you say yes he removes the gp and he says pick a number so you do so say 5 the npc then rolls the dice thats sitting on the table if the dice lands on the 5 you get 1000gp simple enough
 
This npc is done with 2 dices. Read the script and make it to 1 if you want. I made it with 2, it's too easy to win otherwise.
LUA:
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

	-- Casino --
	local winP = 25
	local cost = (getPlayerMoney(cid)/100*winP)
	local need_money = 5
	
	if(msgcontains(msg, "rules") or msgcontains(msg, "information") or msgcontains(msg, "info")) then
		selfSay("(There is 2 dices) In this betting/rolling dice game you have to get a 6 on one of the dices to win.\n Ex. I bet and roll and get 5 and 5 I will lose, but If get 6 and 5 I will win. You will always bet 25% of your total money that you have in your inventory. If you win, you will get 25% more than your bet.\n Ex. I have 100 gold coins. I have to bet 25 gold coins. If I win, I will get 125 gold coins total, else I will lose them of course. (You need to have atleast ".. need_money .." gold coins).\n Interested now?", cid)
	end
	
	if(msgcontains(msg, "roll")) then
		if(getPlayerMoney(cid) >= need_money) then
			selfSay('Are you sure that you want to roll the dice and bet {'.. math.ceil(cost) ..'} gold coins? Ask me for the {rules} if you don\'t know them.', cid)
			talkState[talkUser] = 1
		else
			selfSay('Sorry, you don\'t have enough gold. You need to have atleast '.. need_money ..' gold coins.', cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerMoney(cid) >= need_money) then
			if(doPlayerRemoveMoney(cid,cost)) then
				local diceN1 = math.random(6)
				local diceN2 = math.random(6)
				if(diceN1 == 6 or diceN2 == 6) then
					selfSay('Congratulations! You won {'.. math.ceil(cost*2) ..'} gold coins. That was '.. winP ..'% of the money you bet. You won with: '.. diceN1 ..' and '.. diceN2 ..'.', cid)
					doPlayerAddMoney(cid, math.ceil(cost*2))
					doSendMagicEffect(getCreaturePosition(cid), 12)
				else
					selfSay("Oops, you lost {".. math.ceil(cost) .."} gold coins. That was ".. winP .."% of the money you bet. Your number was: ".. diceN1 .." and ".. diceN2 ..".", cid)
					doSendMagicEffect(getCreaturePosition(cid), 2)
				end
			else
				selfSay('Sorry, you don\'t have enough gold. ['.. math.ceil(cost) ..' gold coins]', cid)
			end
		else
			selfSay('Sorry, you don\'t have enough gold. You need to have atleast '.. need_money ..' gold coins.', cid)
		end
		
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top