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

NPC that trades and does a quest

ziggy46802

Active Member
Joined
Aug 19, 2012
Messages
418
Reaction score
27
Here is my NPC


Code:
local 
shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'letter'}, 2597, 8, 1,'letter')
shopModule:addBuyableItem({'parcel'}, 2595, 15, 1,'parcel')
shopModule:addBuyableItem({'label'}, 2599, 1, 1,'label')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
 
 
 
--------------------------------
------- NPC MISSION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of experience as a reward, false if you want to use items as a reward
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 1000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 5925, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2152,
-- count of the gift item
reward_count = 10, 
-- storage
storage = 1004, 
-- name of the quest
questname = "broken sign"
}
 
local npc_message ={
 
-- Proceed - message
"Please look around town and find the broken sign and fix it. Will you do this for me?",
-- if you dont have items - message
"You have not fixed the sign yet!", 
-- thanks - message
"Thank you for finding the sign and fixing it.",
-- already done - message
"Well all the other signs are okay.",
-- ready to go - message
"Please find the broken sign, fix it, and report back to me.",
-- congratulations - message
"Congratulations, you have finished the mission: Sewer Work"
 
}
 
 
if(msgcontains(msg, 'mission')) then
selfSay(npc_message[5], cid)
end
 
if(msgcontains(msg, first.questname)) then
	selfSay(npc_message[1], cid)
	talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if (getPlayerStorageValue(cid, 1004) == 3) then
		selfSay(npc_message[4], cid)
	else
		if getPlayerStorageValue(cid, 1004) == 2 then
			setPlayerStorageValue(cid, 1004, 3)
			if(useExpReward) then
				doPlayerAddExperience(cid,1000)
			else
				doPlayerAddExp(cid, 5000)
			end
			selfSay(npc_message[3], cid)
			doSendMagicEffect(getCreaturePosition(cid), 10)
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[2], cid)
		end
	end
return true
end
 
end

I keep getting the console error lua:4 attempt to index global 'npcHandler' <a nil value>
can not load script


So how do I make it so he sells and buys stuff, and also does quests and messes with storage values

- - - Updated - - -

I figured it out, here is the npc if anyonelse wants to use such a thing:
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
 
 
---------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------
------- NPC MISSION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of experience as a reward, false if you want to use items as a reward
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 1000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 5925, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2152,
-- count of the gift item
reward_count = 10, 
-- storage
storage = 1004, 
-- name of the quest
questname = "broken sign"
}
 
local npc_message ={
 
-- Proceed - message
"Please look around town and find the broken sign and fix it. Will you do this for me?",
-- if you dont have items - message
"You have not fixed the sign yet!", 
-- thanks - message
"Thank you for finding the sign and fixing it.",
-- already done - message
"Well all the other signs are okay.",
-- ready to go - message
"Please find the broken sign, fix it, and report back to me.",
-- congratulations - message
"Congratulations, you have finished the mission: Broken Sign"
 
}
 
 
if(msgcontains(msg, 'mission')) then
selfSay(npc_message[5], cid)
end
 
if(msgcontains(msg, first.questname)) then
	selfSay(npc_message[1], cid)
	talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if (getPlayerStorageValue(cid, 1004) == 3) then
		selfSay(npc_message[4], cid)
	else
		if getPlayerStorageValue(cid, 1004) == 2 then
			setPlayerStorageValue(cid, 1004, 3)
			if(useExpReward) then
				doPlayerAddExperience(cid,1000)
			else
				doPlayerAddExp(cid, 5000)
			end
			selfSay(npc_message[3], cid)
			doSendMagicEffect(getCreaturePosition(cid), 10)
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[2], cid)
		end
	end
return true
end
 
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

---------------------------------------------------------------------------------------------------------------------------------------------------------


local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'letter'}, 2597, 8, 1,'letter')
shopModule:addBuyableItem({'parcel'}, 2595, 15, 1,'parcel')
shopModule:addBuyableItem({'label'}, 2599, 1, 1,'label')

npcHandler:addModule(FocusModule:new())

You just have to put the coding for the quest first, and the coding for the shop beneath it, but it all has to be together in a certain way (sorry I dont know much about coding)
 
Try thisone instead, you hadn't "," in some places where it is needed to use them
I don't know which one of your scripts you want to use, but I've edited both of them.

LUA:
local 
shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'letter'}, 2597, 8, 1,'letter'),
shopModule:addBuyableItem({'parcel'}, 2595, 15, 1,'parcel'),
shopModule:addBuyableItem({'label'}, 2599, 1, 1,'label')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
 
 
 
--------------------------------
------- NPC MISSION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of experience as a reward, false if you want to use items as a reward
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 1000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 5925, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2152,
-- count of the gift item
reward_count = 10, 
-- storage
storage = 1004, 
-- name of the quest
questname = "broken sign"
}
 
local npc_message ={
 
-- Proceed - message
"Please look around town and find the broken sign and fix it. Will you do this for me?",
-- if you dont have items - message
"You have not fixed the sign yet!", 
-- thanks - message
"Thank you for finding the sign and fixing it.",
-- already done - message
"Well all the other signs are okay.",
-- ready to go - message
"Please find the broken sign, fix it, and report back to me.",
-- congratulations - message
"Congratulations, you have finished the mission: Sewer Work"
 
}
 
 
if(msgcontains(msg, 'mission')) then
selfSay(npc_message[5], cid)
end
 
if(msgcontains(msg, first.questname)) then
	selfSay(npc_message[1], cid)
	talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if (getPlayerStorageValue(cid, 1004) == 3) then
		selfSay(npc_message[4], cid)
	else
		if getPlayerStorageValue(cid, 1004) == 2 then
			setPlayerStorageValue(cid, 1004, 3)
			if(useExpReward) then
				doPlayerAddExperience(cid,1000)
			else
				doPlayerAddExp(cid, 5000)
			end
			selfSay(npc_message[3], cid)
			doSendMagicEffect(getCreaturePosition(cid), 10)
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[2], cid)
		end
	end
return true
end
 
end
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
 
 
---------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------
------- NPC MISSION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of experience as a reward, false if you want to use items as a reward
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 1000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 5925, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2152,
-- count of the gift item
reward_count = 10, 
-- storage
storage = 1004, 
-- name of the quest
questname = "broken sign"
}
 
local npc_message ={
 
-- Proceed - message
"Please look around town and find the broken sign and fix it. Will you do this for me?",
-- if you dont have items - message
"You have not fixed the sign yet!", 
-- thanks - message
"Thank you for finding the sign and fixing it.",
-- already done - message
"Well all the other signs are okay.",
-- ready to go - message
"Please find the broken sign, fix it, and report back to me.",
-- congratulations - message
"Congratulations, you have finished the mission: Broken Sign"
 
}
 
 
if(msgcontains(msg, 'mission')) then
selfSay(npc_message[5], cid)
end
 
if(msgcontains(msg, first.questname)) then
	selfSay(npc_message[1], cid)
	talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
	if (getPlayerStorageValue(cid, 1004) == 3) then
		selfSay(npc_message[4], cid)
	else
		if getPlayerStorageValue(cid, 1004) == 2 then
			setPlayerStorageValue(cid, 1004, 3)
			if(useExpReward) then
				doPlayerAddExperience(cid,1000)
			else
				doPlayerAddExp(cid, 5000)
			end
			selfSay(npc_message[3], cid)
			doSendMagicEffect(getCreaturePosition(cid), 10)
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[2], cid)
		end
	end
return true
end
 
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

---------------------------------------------------------------------------------------------------------------------------------------------------------


local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'letter'}, 2597, 8, 1,'letter'),
shopModule:addBuyableItem({'parcel'}, 2595, 15, 1,'parcel'),
shopModule:addBuyableItem({'label'}, 2599, 1, 1,'label')

npcHandler:addModule(FocusModule:new())

It should work, just leave a reply if it doesn't work! :)
 
Back
Top