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

Lua quest npc

sharpy

New Member
Joined
Jan 4, 2010
Messages
77
Reaction score
0
alright so heres the script im trying to make (keep in mind im not good at all at scripting)
ive edited this script from another npc script and i keep getting all kinds of different errors
i need this npc to give you and item with a unique id when you say quest and also need him to give a reward for bringing him back 5x of an item (item with uid is small axe (2559) and uid (10102) and the item to bring him is ancient rune (2348)) if someone could help me out with this i would appreciate it very much.

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

	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		selfSay('Do you want to help me by doing me a favor?', cid)
		talkState[talkUser] = 1
		end
	end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		doPlayerAddItem(cid, 2559, 1, 10102)
		selfSay('Here take this axe and bring me back five ancient runes.', cid)
		talkState[talkUser] = 0
		end
	end
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		end
	end
	elseif(msgcontains(msg, 'anchient runes') then
		selfSay('Do you have five anchient runes for me?', cid)
		talkState[talkUser] = 2
		end
	end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser]== 2) then
		if(getPlayerItemCount(cid, 2348) >= 5) then
			doPlayerRemoveItem(cid, 2348, 5)
			selfSay('thank you for helping me here is your reward.', cid)
			doPlayerAddItem(cid, 2160, 1)
		elseif(getplayerItemCount(cid, 2348) < 5) then
			selfsay('You do not have enough ancient runes.', cid)
			talkState[talkuser] = 0
			end
		end
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
This:
Lua:
doPlayerAddItem(cid, 2559, 1, 10102)
Should be:
Lua:
setItemAttribute(doPlayerAddItem(cid,2559,1), 'uid', 10102)

And this:
Lua:
elseif(getplayerItemCount(cid, 2348) < 5) then
Should be
Lua:
elseif(getPlayerItemCount(cid, 2348) < 5) then
 
alright i changed those lines in my script and im getting and error <eof> expected near line 23??? or something like that i think the problem may be i have too many end's in the script also i think it needs a storage id in there so that this quest can only be done once

(update)
removed all ends from syntax's and script is partly working however i gave the wrong info the script needs an action id not a unique id can this be done by changing the line
Lua:
setItemAttribute(doPlayerAddItem(cid,2559,1), 'uid', 10102)
to this instead?
Lua:
setItemAttribute(doPlayerAddItem(cid,2559,1), 'aid', 10102)

(update)
function for both of these lines is not working i get this error
attempt to call global 'setItemAttribute' (a nil value)
stack traceback:
data/npc/scripts/quest.lua:22: in function 'callback'
Data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/quest.lua:8: in function <data/npc/scripts/quest.lua:8>

this script is giving me the item but not setting the values for either an action id or unique id
 
Last edited:
My bad
Its:
doItemSetAttribute
Instead of
setItemAttribute

Lua:
doItemSetAttribute(doPlayerAddItem(cid,2559,1), 'aid', 10102)
 
TY this worked however im getting an error at the last of the script when you say yes to having ancient runes but you do not have the ammount the npc says nothing at all
here is the script now
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

	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		selfSay('Do you want to help me by doing me a favor?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		doItemSetAttribute(doPlayerAddItem(cid,2559,1), 'uid', 10102)
		selfSay('Here take this axe and bring me back five ancient runes.', cid)
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	elseif(msgcontains(msg, 'ancient runes')) then
		selfSay('Do you have five anchient runes for me?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser]== 2) then
		if(getPlayerItemCount(cid, 2348) >= 5) then
			doPlayerRemoveItem(cid, 2348, 5)
			selfSay('thank you for helping me here is your reward.', cid)
			doPlayerAddItem(cid, 2160, 1)
		elseif(getPlayerItemCount(cid, 2348) < 5) then
			selfsay('You do not have enough ancient runes.', cid)
			talkState[talkuser] = 0

		end
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Havnt found any major errors or anything, but try this:
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
 
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		selfSay('Do you want to help me by doing me a favor?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		doItemSetAttribute(doPlayerAddItem(cid,2559,1), 'uid', 10102)
		selfSay('Here take this axe and bring me back five ancient runes.', cid)
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	elseif(msgcontains(msg, 'ancient runes')) then
		selfSay('Do you have five anchient runes for me?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser]== 2) then
		if doPlayerRemoveItem(cid,2348,5) then
		   selfSay('thank you for helping me here is your reward.', cid)
		   doPlayerAddItem(cid,2160,1)
		   talkState[talkUser] = 0
                else
                     selfSay('You do not have enough ancient runes', cid)
                     talkState[talkUser] = 0
                end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top