• 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 Need help with 2 Npc's

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
Hi everyone, I'm very new at scripting and gave an honest shot at making two npc's.
The idea is that You start the quest with the first NPC, and then go to the Second NPC, get an item, and then return to the first NPC with the item for a reward.
I tried putting safeguards as well so that players couldn't cheat and just jump to the last part of the mission without going through the first parts

The original Script that I modded this from comes from ------- NPC MISION 2.0 by Acubens - Otland.net -

So here is the first NPC
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 MISION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of a gift for experience, false if you want to use items
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 5000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 2461, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2160,
-- count of the gift item
reward_count = 1, 
-- storage
storage1 = 60307,
storage2 = 60308,
storage3 = 60309,
-- name of the quest
questname = "Hat Retrieval Quest."
}
 
local npc_message ={
 
-- 1 Quest Starter
"I need my hat from NPC 2, can you go ask him about my {hat}?",
-- 2 checks have you spoken to NPC 2 yet
"Have you spoken with NPC 2 yet?", 
-- 3 thanks - message
"Thank You for retrieving my hat, here is your just reward.",
-- 4 already done - message
"You have already done this mission.",
-- 5 if already talked to npc 2 and item for quest completion is not in inventory
"You need to have my hat in your inventory to complete the quest.",
-- 6 congratulations - message
"Congratulations, you have finished the "..first.questname..",
-- 7 continue to second npc
"Thank you, in advance.",
-- 8 if they say no to starting the quest
"Oh, that's too bad.",
-- 9 if they ask about hat first
"Ask me about a quest",
-- 10 if player lies about talking to NPC 2, tell them what to say again
"Please ask NPC 2 about my {hat}""
 
}
 
 
-- if(msgcontains(msg, 'quest')) then
-- selfSay(npc_message[5], cid)
-- end
 
if(msgcontains(msg, 'quest')) then
	if (getPlayerStorageValue(cid,first.storage2) == 1) then -- check if quest is complete
	selfSay(npc_message[4], cid) -- if quest is complete tell player that it is
	else
		if (getPlayerStorageValue(cid,first.storage1) > 0) then -- check if quest is started
		selfSay(npc_message[1], cid) -- if not started ask them if they want to start
		talkState[talkUser] = 1
			elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then -- if they want to start say yes
			setPlayerStorageValue(cid,first.storage1,1) -- set player storage value saying that quest is started.
			selfSay(npc_message[7], cid) -- if they say yes tell player that npc is happy for starting to help them
			else
			selfSay(npc_message[8], cid) -- if no or anything else tell player quest has not started
			end
		selfSay(npc_message[2], cid) -- inquire if second npc has been talked to.
		talkState[talkUser] = 2
		elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 2) then -- players says yes they have
		if (getPlayerStorageValue(cid,first.storage3) > 0) then -- check if player is lying
			selfSay(npc_message[10], cid) -- if they are lying tell them to talk to second NPC again
	end
return true
end


	
if(msgcontains(msg, 'hat')) then
	if (getPlayerStorageValue(cid,first.storage2) == 1) then -- check if quest is complete
	selfSay(npc_message[4], cid) -- tell player quest is already complete
	else
		if (getPlayerStorageValue(cid,first.storage1) > 0) then -- check is quest is started
		selfSay(npc_message[9], cid) -- if quest is not started tell them to start it
		end
	else
		selfSay(npc_message[2], cid) -- inquire if second npc has been talked to.
		talkState[talkUser] = 3
		elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 3) then -- players says yes they have
		if (getPlayerStorageValue(cid,first.storage3) > 0) then -- check if player is lying
			selfSay(npc_message[10], cid) -- if they are lying tell them to talk to second NPC again
		else
			if(doPlayerRemoveItem(cid,first.item,first.item_count)) then -- if object is on player it will remove it
				setPlayerStorageValue(cid,first.storage2,1) -- set quest as finished
				if(useExpReward) then -- give experience if that is reward
				doPlayerAddExperience(cid,first.experience)
			else
				doPlayerAddItem(cid,first.reward,first.reward_count) -- give item if that is reward (money or object)
			end
			selfSay(npc_message[3], cid) -- tell player they did a good job
			doSendMagicEffect(getCreaturePosition(cid), 10) -- send a magic effect
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[5], cid) -- tells player that the quest item is not in their inventory to complete the quest
			end
		end
	end
return true
end

end

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

and here is the second NPC - most of the talking parts are copy pasted from the first Npc, and I just edited the few lines that I needed to change for the story to work
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 MISION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of a gift for experience, false if you want to use items
useExpReward = true,
-- The experience that will get the player at the end of the mission
experience = 5000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 2461, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2160,
-- count of the gift item
reward_count = 1, 
-- storage
storage1 = 60307,
storage2 = 60308,
storage3 = 60309,
-- name of the quest
questname = "Hat Retrieval Quest."
}
 
local npc_message ={
 
-- 1 Quest Starter
"I need my hat from NPC 2, can you go ask him about my {hat}?",
-- 2 checks have you spoken to NPC 2 yet
"I borrowed his hat.. does he want it back so soon?", 
-- 3 thanks - message
"Thank You for retrieving my hat, here is your just reward.",
-- 4 already done - message
"I know nothing about a stupid hat.",
-- 5 if already talked to npc 2 and item for quest completion is not in inventory
"You need to have my hat in your inventory to complete the quest.",
-- 6 congratulations - message
"Congratulations, you have finished the "..first.questname..",
-- 7 continue to second npc
"Thank you, in advance.",
-- 8 if they say no to starting the quest
"Oh, that's too bad.",
-- 9 if they ask about hat first
"I already gave you the stupid hat! Go give it to that mangy #@$@## &@!@%^!",
-- 10 if player lies about talking to NPC 2, tell them what to say again
"Here's his hat.. and tell him his {hat} sucks!""
 
}
 
 
--if(msgcontains(msg, 'quest')) then
--selfSay(npc_message[5], cid)
--end
 
if(msgcontains(msg, 'hat')) then
	if (getPlayerStorageValue(cid,first.storage1) > 0) then -- inquire if first npc has been talked to.
	selfSay(npc_message[4], cid) -- tell player quest is not started
	else
		if (getPlayerStorageValue(cid,first.storage3) == 1) then -- check is quest with NPC 2 is started
		selfSay(npc_message[9], cid) -- if quest is started tell them to go back to NPC 1
	else
		selfSay(npc_message[2], cid) -- tell player he has the hat
		talkState[talkUser] = 1
		elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then -- if player says yes then
		if (getPlayerStorageValue(cid,first.storage3) > 0) then
			setPlayerStorageValue(cid,first.storage3,1) -- set storage value to completed
			doPlayerAddItem(cid,first.item,first.item_count) -- give hat
			selfSay(npc_message[10], cid) -- tell player they have received the item and to return to npc 1
			end
		else
			selfSay(npc_message[8], cid)
			end
	end
return true
end

end

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

I don't actually know what the 'return true' value means or does..
If someone can help me fix it or troubleshoot through this it would be great.
Thanks in advance!

Also this is the Original script I modded it from... if it gives some perspective!
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 MISION  2.0 --------
------ by Acubens - Otland.net -
--------------------------------
 
 
local first = {
-- Place true if you want to use the system of a gift for experience, false if you want to use items
useExpReward = false,
-- The experience that will get the player at the end of the mission
experience = 5000,
-- Id of the item that will be asking for the NPC to complete the mission
item = 2668, 
-- Count of the item required
item_count = 1,  
-- id of the gift that going to obtain the player at finish the mission 
reward = 2160,
-- count of the gift item
reward_count = 1, 
-- storage
storage = 60307, 
-- name of the quest
questname = "Acubens Quest"
}
 
local npc_message ={
 
-- Procced - message
"I need some item to complete this mission, procced?",
-- if you dont have items - message
"You dont have any items to this mission.", 
-- thanks - message
"Thank You for Help me, {take it}.",
-- already done - message
"You have already done this mision.",
-- ready to go - message
"The Mission {"..first.questname.."} is, really serius, i need your help to complete it, if you help me then i will  give some items to you..",
-- congratulations - message
"Congratulations, you have finished the "..first.questname..""
 
}
 
 
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,first.storage) > 0) then
		selfSay(npc_message[4], cid)
	else
		if(doPlayerRemoveItem(cid,first.item,first.item_count)) then
			setPlayerStorageValue(cid,first.storage,1)
			if(useExpReward) then
				doPlayerAddExperience(cid,first.experience)
			else
				doPlayerAddItem(cid,first.reward,first.reward_count)
			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())

- - - Updated - - -

Any suggestions?

- - - Updated - - -

any suggestions?
 
Last edited by a moderator:
Hmmm This script Would be useful in my server too. And it seems to be Almost Done, in my Opinion. Can anyone Touch it up? I would like this NPC as well :D
 
Back
Top