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

[Support] NPC

Joined
Jul 25, 2007
Messages
382
Reaction score
38
Alright, this is my first attempt at writing a NPC, just been doing actions. And ,well, Just getting a host of errors and when I fixed them all the script wasn't correct anymore. So, if someone could edit this to be proper, I'd really appreciate it, will learn off it.

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

function creatureSayCallback(cid, type, msg)
        if(not npcHandler:isFocused(cid)) then
                return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	local target_level = 25
	local item_cloth = 5913
	local item_reward = 2152

	if talkSate[talkUser] == 1 then
		if getPlayerStorageValue(cid, 1003) == 1 then
			npcHandler:say("Sorry mate, gotta get back to work, no time to chat")
			npcHandler:say("Might have some more work for you in the future though.")
			talkState[talkUser] = 0
		elseif getPlayerStorageValue(cid, 1002) == 1 then
			npcHandler:say("Welcome back, have any luck?")
			if msgcontains(msg, "yes") then
				if doPlayerRemoveItem(cid, item_cloth, 1) == true then
				npcHandler:say("HAH, sent those bandits to their grave eh?")
				npcHandler:say("Nice work there, here, take this for a job well done")
				doPlayerAddItem(cid, item_reward, 5)
				doPlayerSetStorageValue(cid, 1003, 1)
				talkState[talkUser] = 0
		elseif getPlayerStorageValue(cid, 1001) == 1 then
			npcHandler:say("Come for work have ya'?")
			if msgcontains("yes") or msgcontains("ya") then
				npcHandler:say("Hah, great, was hoping you'd say that")
				if getPlayerLevel(cid) < target_level then
					npcHandler:say("Hrmm, you may need to train up a bit more first")
				else npcHandler:say("Well, to the point then.")
					npcHandler:say("Lately these damned bandits have been jumping travelers,")
					npcHandler:say("specifically traders, I need you to.. take care of them so to speak.")
					npcHandler:say("Just bring me back a piece of their cloth as a soveniour.")
					npcHandler:say("Good luck!")
					talkState[talkUser] = 0
					doPlayerSetStorageValue(cid, 1002, 1)			
		elseif msgcontains(msg, "job") or msgcontains(msg, "work") or msgcontains(msg, "quest") then
			npcHandler:say("Hah! I am a proud guard of CITY")
			if msgcontains(msg, "do") or msgcontains("details") or msgcontains("guard")
				npcHandler:say("WHAT DO I DO? I protect these walls inside and out! From preventing muggings to slaying treturous beasts.")
				npcHandler:say("Why just recently I saved Jin over there from getting robbed blind")
				if msgcontains(msg, "Jin") then
					npcHandler:say("Great fellow he is, carves the finest damn arrows this side the Eastern Sea too.")
					npcHandler:say("You know what, I've taken a liking to ya lad.")
					npcHandler:say("I may have some work for ya, if yer' interested of course")
					doPlayerSetStorageValue(cid, 1001, 1)
					talkState[talkUser] = 0
				end
			end
		end
	end
return TRUE
end
 
its so bugedS tho
Code:
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
	local target_level = 25
	local item_cloth = 5913
	local item_reward = 2152
	if talkSate[talkUser] == 1 then
		if getPlayerStorageValue(cid, 1003) == 1 then
			npcHandler:say("Sorry mate, gotta get back to work, no time to chat\nMight have some more work for you in the future though.")
			talkState[talkUser] = 0
		elseif getPlayerStorageValue(cid, 1002) == 1 then
			npcHandler:say("Welcome back, have any luck?")
			if msgcontains(msg, "yes") then
				if doPlayerRemoveItem(cid, item_cloth, 1) == true then
					npcHandler:say("HAH, sent those bandits to their grave eh?\nNice work there, here, take this for a job well done")
					doPlayerAddItem(cid, item_reward, 5)
					doPlayerSetStorageValue(cid, 1003, 1)
					talkState[talkUser] = 0
				end
			end
		elseif getPlayerStorageValue(cid, 1001) == 1 then
			npcHandler:say("Come for work have ya\'?")
			if msgcontains("yes") or msgcontains("ya") then
				npcHandler:say("Hah, great, was hoping you'd say that")
				if getPlayerLevel(cid) < target_level then
					npcHandler:say("Hrmm, you may need to train up a bit more first")
				else
					npcHandler:say("Well, to the point then.\nLately these damned bandits have been jumping travelers,\nspecifically traders, I need you to.. take care of them so to speak.\nJust bring me back a piece of their cloth as a soveniour.\nGood luck!")
					talkState[talkUser] = 0
					doPlayerSetStorageValue(cid, 1002, 1)       
				end
			elseif msgcontains(msg, "job") or msgcontains(msg, "work") or msgcontains(msg, "quest") then
				npcHandler:say("Hah! I am a proud guard of CITY")
				if msgcontains(msg, "do") or msgcontains("details") or msgcontains("guard")
					npcHandler:say("WHAT DO I DO? I protect these walls inside and out! From preventing muggings to slaying tretrous beasts.\nWhy just recently I saved Jin over there from getting robbed blind")
					if msgcontains(msg, "Jin") then
						npcHandler:say("Great fellow he is, carves the finest damn arrows this side the Eastern Sea too.\nYou know what, I've taken a liking to ya lad.\nI may have some work for ya, if yer' interested of course")
						doPlayerSetStorageValue(cid, 1001, 1)
						talkState[talkUser] = 0
					end
				end
			end
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Really appreciate it, can actually get him summoned now.

But, when I try to talk to him I get this:
[Error - Npc interface]
data/npc/scripts/tak_guard_quest.lua:onCreatureSay
Description:
data/npc/scripts/tak_guard_quest.lua:18: attempt to index global 'talkSate' (a nil value)
stack traceback:
data/npc/scripts/tak_guard_quest.lua:18: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/tak_guard_quest.lua:7: in function <data/npc/scripts/tak_guard_quest.lua:7>
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local target_level = 25
local item_cloth = 5913
local item_reward = 2152

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 greetCallback(cid)
	Topic[cid] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "yes") or msgcontains(msg, "ya") then
			npcHandler:say("Hah, great, was hoping you'd say that!", cid)
			if getPlayerLevel(cid) < target_level then
				npcHandler:say("Hrmm, you may need to train up a bit more first", cid)
			else
				npcHandler:say("Well, to the point then.\nLately these damned bandits have been jumping travelers,\nspecifically traders, I need you to.. take care of them so to speak.\nJust bring me back a piece of their cloth as a soveniour.\nGood luck!", cid) 
				doPlayerSetStorageValue(cid, 1001, 2)
			end
		else
			-- Player said something else than expected
		end
		Topic[cid] = 0
	elseif Topic[cid] == 2 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveItem(cid, item_cloth, 1) then
				npcHandler:say("HAH, sent those bandits to their grave eh?\nNice work there, here, take this for a job well done!", cid)
				doPlayerAddItem(cid, item_reward, 5)
				doPlayerSetStorageValue(cid, 1001, 3)
			else
				-- Player doesn't have thr required item
			end
		else
			-- Player said something else than expected
		end
		Topic[cid] = 0
	elseif msgcontains(msg, "job") or msgcontains(msg, "work") or msgcontains(msg, "quest") then
		local v = getPlayerStorageValue(cid, 1001)
		if v < 1 then
			npcHandler:say("Hah! I am a proud {guard} of the CITY.", cid)
			Topic[cid] = 0
		elseif v == 1 then
			npcHandler:say("Come for work have ya'?", cid)
			Topic[cid] = 1
		elseif v == 2 then
			npcHandler:say("Welcome back, have any luck?", cid)
			Topic[cid] = 2
		elseif v == 3 then
			npcHandler:say("Sorry mate, gotta get back to work, no time to chat\nMight have some more work for you in the future though.", cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, "do") or msgcontains(msg, "details") or msgcontains(msg, "guard") then
		npcHandler:say("WHAT DO I DO? I protect these walls inside and out! From preventing muggings to slaying treacherous beasts.\nWhy just recently I saved {Jin} over there from getting robbed blind.", cid)
		Topic[cid] = 0
	elseif msgcontains(msg, "jin") then
		if getPlayerStorageValue(cid, 1001) < 1 then
			npcHandler:say("Great fellow he is, carves the finest damn arrows this side the Eastern Sea too.\nYou know what, I've taken a liking to ya lad.\nI may have some {work} for ya, if yer' interested of course.", cid)
			doPlayerSetStorageValue(cid, 1001, 1)
		else
			npcHandler:say("Great fellow he is, carves the finest damn arrows this side the Eastern Sea too.", cid)
		end
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Still getting errors with yours Cryo:

[Error - Npc interface]
data/npc/scripts/tak_guard_quest.lua:onCreatureSay
Description:
data/npc/lib/npc.lua:54: attempt to index local 'keyword' (a nil value)
stack traceback:
data/npc/lib/npc.lua:54: in function 'msgcontains'
data/npc/scripts/tak_guard_quest.lua:64: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/tak_guard_quest.lua:12: in function <data/npc/scripts/tak_guard_quest.lua:12>

[Error - Npc interface]
data/npc/scripts/tak_guard_quest.lua:onCreatureSay
Description:
data/npc/lib/npc.lua:54: attempt to index local 'keyword' (a nil value)
stack traceback:
data/npc/lib/npc.lua:54: in function 'msgcontains'
data/npc/scripts/tak_guard_quest.lua:64: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/tak_guard_quest.lua:12: in function <data/npc/scripts/tak_guard_quest.lua:12>

[Error - Npc interface]
data/npc/scripts/tak_guard_quest.lua:onCreatureSay
Description:
data/npc/lib/npc.lua:54: attempt to index local 'keyword' (a nil value)
stack traceback:
data/npc/lib/npc.lua:54: in function 'msgcontains'
data/npc/scripts/tak_guard_quest.lua:64: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/tak_guard_quest.lua:12: in function <data/npc/scripts/tak_guard_quest.lua:12>
 
Back
Top