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())