• 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 with this NPC pls

Stewie

Family Guy # ;3
Joined
May 3, 2010
Messages
786
Reaction score
12
Location
TV
Hi,i got a problem with this NPC,im say Demon Oak or Infested Area,after i say Yes,and NPC say nothing,im using tfs 0.4 rev 3884

LUA:
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 (not npcHandler:isFocused(cid)) then
        return false
    end
 
 	if msgcontains(msg, "infested area") or msgcontains(msg, "demon oak") then
       npcHandler:say('How do you know? Did you go into the infested area?', cid)
       talk_state = 1
       elseif msgcontains(msg, 'yes') and talk_state == 1 then
        if getPlayerStorageValue(cid, 35735) == 1 then
                   	npcHandler:say('I have searched for dareful heroes like you. ...', cid)
                   	npcHandler:say('Take this axe and bring that damn demon oak down, report back to me when you are done. The world depends on you now, kid. ...', cid)
                    	npcHandler:say('Good luck, I mean it.', cid)
                   	doPlayerSetStorageValue(cid, 35738, 1)
                   	DoPlayerAddItem(cid, 8293, 1)
                   	talk_state = 0
                end
            else
                npcHandler:say('I won\'t discuss any further with you for now.', cid)
                talk_state = 0
            end
 	if getPlayerStorageValue(cid, 35735) == 1 and msgcontains(msg, "infested area") or msgcontains(msg, "demon oak") then
                npcHandler:say('Did you really defeat it?', cid)
                talk_state = 2
        elseif msgcontains(msg, 'yes') and talk_state == 2 then
            if getPlayerStorageValue(cid, 35700) == 1 then
              npcHandler:say('You chopped down the demon oak?!? Unbelievable!! Let\'s hope it doesn\'t come back. As long as evil is still existent in the soil of the plains, it won\'t be over. Still, the demons suffered a setback, that\'s for sure. ...', cid)
              npcHandler:say('For your brave action, I tell you a secret which has been kept for many many years. There is an old house south of the location where you found the demon oak. There should be a grave with the name \'Yesim Adeit\' somewhere close by. ...', cid)
              npcHandler:say('It belongs to a Daramian nobleman named \'Teme Saiyid\'. I knew him well and he told me -almost augured- that someone will come who is worthy to obtain his treasure. I\'m sure this \'someone\' is you. Good luck in finding it!', cid)
		doPlayerSetStorageValue(cid, 35700, 2)
                talk_state = 0
            else
                npcHandler:say('Have you entered the infested area yet?', cid)
                talk_state = 0
            end
 
        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 3) then
            npcHandler:say('Bye.', cid)
            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())
 
Last edited:
Create a file ondata/npc called Oldrak.xml and paste:
PHP:
<npc name="Oldrak" script="data/npc/scripts/oldrak.lua" walkinterval="2000" floorchange="0" access="3">
    <health now="150" max="150"/>
    <look type="57" head="115" body="113" legs="31" feet="38" addons="3"/>
    <parameters>
        <parameter key="message_greet" value="Hello, |PLAYERNAME|!" />
        <parameter key="message_needmoremoney" value="Try again when you have more money."/>
        <parameter key="message_decline" value="Why would you tease me like that?"/>
    </parameters>
</npc>
Go to data/npc/scripts and create a file called oldrak.lua and paste:

PHP:
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 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, "hallowed axe") then
		selfSay("Do you want to buy a Hallowed Axe for " .. HALLOWEDAXE_PRICE .. " gold coins?", cid)
		talkState[talkUser] = 1
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
		if getPlayerItemCount(cid, 2386) >= 1 and getPlayerMoney(cid) >= HALLOWEDAXE_PRICE then
			if doPlayerRemoveMoney(cid, HALLOWEDAXE_PRICE) then
				selfSay("Here you are. You can now defeat the demon oak with this axe.", cid)
				doPlayerRemoveItem(cid, 2386, 1)
				doPlayerAddItem(cid, 8293, 1)
				talkState[talkUser] = 0
			end
		else
			selfSay("I need an axe and " .. HALLOWEDAXE_PRICE.. " gold coins to make you a {hallowed axe}.", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, "demon oak") then
		selfSay("Did you defeat the demon oak?", cid)
		talkState[talkUser] = 2
	elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
		if getCreatureStorage(cid, storages.done) == 1 then
			selfSay("Good job!", cid)
			doCreatureSetStorage(cid, storages.done, 2)
			talkState[talkUser] = 0
		else
			selfSay("Go defeat the demon oak first.", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, "no") and (talkState[talkUser] >= 1 and talkState[talkUser] <= 3) then
		selfSay("Ok thanks.", cid)
		talkState[talkUser] = 0
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

rep if i helped
 
After:
LUA:
NpcSystem.parseParameters(npcHandler)
Paste:
LUA:
local talk_state = {}

And its doPlayerAddItem, not DoPlayerAddItem
In line 28, I havn't checked if there are any more errors apart from that.
 
Try this I've made some changes to your script.
Edit: Fixed!
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
-- 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 greetCallback(cid)
        talkState[cid] = 0
        return true
end
function doDelaySay(delay, msg, cid)
	return addEvent(npcHandler:say, delay*1000, msg, cid)
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 (not npcHandler:isFocused(cid)) then
        return false
    end
 
 	if msgcontains(msg, "infested area") or msgcontains(msg, "demon oak") then
		npcHandler:say('How do you know? Did you go into the infested area?', cid)
		talkState[cid] = 1
    elseif msgcontains(msg, 'yes') and talkState[cid] == 1 then
        if getPlayerStorageValue(cid, 35735) == 1 then
            npcHandler:say('I have searched for dareful heroes like you. ...', cid)
            doDelaySay(4, 'Take this axe and bring that damn demon oak down, report back to me when you are done. The world depends on you now, kid. ...', cid)
			doDelaySay(6, 'Good luck, I mean it.', cid)
            doPlayerSetStorageValue(cid, 35738, 1)
            doPlayerAddItem(cid, 8293, 1)
            talkState[cid] = 0
        else
            npcHandler:say('I won\'t discuss any further with you for now.', cid)
			talkState[cid] = 0
        end
 	elseif getPlayerStorageValue(cid, 35735) == 1 and msgcontains(msg, "infested area") or msgcontains(msg, "demon oak") then
        npcHandler:say('Did you really defeat it?', cid)
        talkState[cid] = 2
    elseif msgcontains(msg, 'yes') and talkState[cid] == 2 then
        if getPlayerStorageValue(cid, 35700) == 1 then
            npcHandler:say('You chopped down the demon oak?!? Unbelievable!! Let\'s hope it doesn\'t come back. As long as evil is still existent in the soil of the plains, it won\'t be over. Still, the demons suffered a setback, that\'s for sure. ...', cid)
            doDelaySay(7, 'For your brave action, I tell you a secret which has been kept for many many years. There is an old house south of the location where you found the demon oak. There should be a grave with the name \'Yesim Adeit\' somewhere close by. ...', cid)
            doDelaySay(14, 'It belongs to a Daramian nobleman named \'Teme Saiyid\'. I knew him well and he told me -almost augured- that someone will come who is worthy to obtain his treasure. I\'m sure this \'someone\' is you. Good luck in finding it!', cid)
			doPlayerSetStorageValue(cid, 35700, 2)
            talkState[cid] = 0
        else
            npcHandler:say('Have you entered the infested area yet?', cid)
            talkState[cid] = 0
        end
	elseif msgcontains(msg, 'no') and (talkState[cid] >= 1 and talkState[cid] <= 3) then
            npcHandler:say('Bye.', cid)
            talkState[cid] = 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_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

After:
LUA:
NpcSystem.parseParameters(npcHandler)
Paste:
LUA:
local talk_state = {}

And its doPlayerAddItem, not DoPlayerAddItem
In line 28, I havn't checked if there are any more errors apart from that.
There were various mistake in which also the npc would have spamed the whole screen, so I made a small delay for it. ;p
 
Last edited:
@Shinmaru

Error

Code:
[23/02/2011 18:39:44] [Error - Npc interface] 
[23/02/2011 18:39:44] (Unknown script file)
[23/02/2011 18:39:44] Description: 
[23/02/2011 18:39:44] attempt to call a nil value
[23/02/2011 18:39:44] stack traceback:
 
Back
Top