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

[Help] My gambling npc ;(

furstwin

New Member
Joined
Aug 9, 2007
Messages
486
Reaction score
1
Location
Sweden
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end
	local count = 5
	local chanse = math.random(1, 6)
        player_gold = getPlayerItemCount(cid,2148)
        player_plat = getPlayerItemCount(cid,2152)*100
        player_crys = getPlayerItemCount(cid,2160)*10000
        player_money = player_gold + player_plat + player_crys
---------------------------------------------------------------------------
        if msgcontains(msg, 'play') or msgcontains(msg, 'roll') then
            selfSay('How much do you want to play?.')
                talk_state = 1
            end
------------------------------------------------ confirm yes ------------------------------------------------
         if param ~= "" and talk_state == 1 then
         SelfSay('Do you want to bet ' ..param.. ' to win ' ..param.. '*count?')
	end
      talk_state = 2

	elseif msgcontains(msg, 'yes') and talk_state == 2 then
	 if chanse < 6 then
           doPlayerAddMoney(cid, param * count)		            	         
            end
     talk_state = 0
end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Error:
Code:
Something about an 'end' close to the function at line 31~~

Could anyone fix it?(A)
 
Try this byt im not sure that this script work

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end
	local count = 5
	local chanse = math.random(1, 6)
        player_gold = getPlayerItemCount(cid,2148)
        player_plat = getPlayerItemCount(cid,2152)*100
        player_crys = getPlayerItemCount(cid,2160)*10000
        player_money = player_gold + player_plat + player_crys
---------------------------------------------------------------------------
        if msgcontains(msg, 'play') or msgcontains(msg, 'roll') then
            selfSay('How much do you want to play?.')
                talk_state = 1
            end
------------------------------------------------ confirm yes ------------------------------------------------
         if param ~= "" and talk_state == 1 then
         SelfSay('Do you want to bet ' ..param.. ' to win ' ..param.. '*count?')
	end
      talk_state = 2

	elseif msgcontains(msg, 'yes') and talk_state == 2 then
	 if chanse < 6 then
           doPlayerAddMoney(cid, param * count)		            	         
            end
     talk_state = 0
end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
        end
    end

npcHandler:addModule(FocusModule:new())
 
You need to use getNumber(msg) function, not a param oO

Here is getNumber(str) made by idk who, place it in your global.lua and in you NPC do like this:
Code:
n = getNumber(msg)
    if n ~= 0 then
       selfSay(".......")
    else
        selfSay("How much do you want to bet?") 
    end
Code:
function getNumber(txt)
	x = string.gsub(txt,"%a","")
	x = tonumber(x)
	if x ~= nill and x > 0 then
		return x
	else
	return 0
	end
end
 
Back
Top