Aleada
Unknown Member
- Joined
- Mar 14, 2013
- Messages
- 231
- Reaction score
- 7
Heya everyone, I'm trying to make NPC's that interact differently based on certain attributes.
This is the code I have so far:
Lt. Evan (FULL):
Carpenter Todd (Important parts):
But I'm guessing the "return false" is what is messing it up.. if the storage is >= 1 then if you go to the next NPC and try to talk to them, it's like it's stuck on that piece of code.. for exmaple:
I'm not really sure how to fix it though :/ I mean, everything works fine until you go to another NPC
Anyone got any ideas?
This is the code I have so far:
Lt. Evan (FULL):
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local storage = 20004
local config = {time_check = 0, delay = 30, message = "LONG LIVE THE KING!"}
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()
if config["time_check"] < os.time() and math.random(3) == 3 then
config["time_check"] = (os.time() + config["delay"])
Npc():say(config["message"], TALKTYPE_YELL)
end
npcHandler:onThink()
end
local function greetCallback(cid)
local player = Player(cid)
if player:getStorageValue(storage) >= 1 then
npcHandler:setMessage(MESSAGE_GREET, "Thank you for helping me kill those rats. The carpenter needs your help. He is located in the middle of the town, just west of here.")
else
npcHandler:setMessage(MESSAGE_GREET, "Have you obtained all 15 pieces of cheese yet?")
end
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
elseif msgcontains(msg, "althea") then
npcHandler:say("This used to be the beautiful land of Althea, but lately things have changed. The dark mage has returned and is opening {portals} to other realms daily.", cid)
npcHandler.topic[cid] = 1
elseif msgcontains(msg, "portal") and npcHandler.topic[cid] == 1 then
npcHandler:say("These portals are entries for fowl creatures who terrorize the land and the people of Althea. The king\'s men are struggling to solve the mystery of closing the portals to bring an end to the terror of the dark mage. The {king} requires your assistance.", cid)
npcHandler.topic[cid] = 2
elseif msgcontains(msg, "king") and npcHandler.topic[cid] == 2 then
npcHandler:say("The king has summoned you, but he will only accept you after you\'ve achieved level 8. I could possibly help you by giving you a {mission}.", cid)
elseif msgcontains(msg, "mission") and getPlayerStorageValue(cid, storage) < 0 then
npcHandler:say("Below the city, in the sewers, is overrun by rats. Kill as many as you can while gathering 15 cheese. Report back to me after you have gathered all of the cheese.", cid)
setPlayerStorageValue(cid, storage, 0)
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "yes") and getPlayerStorageValue(cid, storage) == 0 then
if getPlayerItemCount(cid, 2696) >= 15 then
doPlayerRemoveItem(cid, 2696, 15)
npcHandler:say("Thank you for acquiring this cheese. Here, take this reward for your bravery. The carpenter has a mission ready for you. You should go talk to him.", cid)
doPlayerAddItem(cid,2148,25)
doPlayerAddExp(cid, 100)
setPlayerStorageValue(cid, storage, 1)
else
npcHandler:say("I\'m sorry, but it seems that you have not acquired all of the required cheese. Please, come back when you have all 15 pieces.", cid)
end
elseif msgcontains(msg, "mission") and getPlayerStorageValue(cid, storage) >= 1 then
npcHandler:say("You have done all that I need, thank you again!", cid)
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "help") then
if getPlayerLevel(cid) >= 8 then
npcHandler:say("You must talk to the king as soon as possible, he is waiting for you!", cid)
else
npcHandler:say("The king is waiting for you, but first... you must achieve level 8. There are many {missions} just ask around!", cid)
npcHandler.topic[cid] = 0
end
end
return true
end
local function onAddFocus(cid)
end
local function onReleaseFocus(cid)
if getPlayerStorageValue(cid, storage) < 0 then
npcHandler:say("Just ask me for a mission.", cid)
elseif getPlayerStorageValue(cid, storage) == 0 then
npcHandler:say("Report back to me after you have obtained 15 pieces of cheese.", cid)
elseif getPlayerStorageValue(cid, storage) == 1 then
npcHandler:say("Don't forget about the carpenter!", cid)
elseif getPlayerStorageValue(cid, storage) > 1 then
npcHandler:say("Thank you again!", cid)
end
return true
end
npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Carpenter Todd (Important parts):
Code:
~~~~~~~~
local function greetCallback(cid)
if getPlayerStorageValue(cid, storage) >= 6 then
npcHandler:say("I can't thank you enough for helping me. I heard the farmer needs help though...", cid)
return false
elseif getPlayerStorageValue(cid, storage) == 2 then
npcHandler:setMessage(MESSAGE_GREET, "Have you obtained 10 pieces of wood yet?")
elseif getPlayerStorageValue(cid, storage) == 3 then
npcHandler:setMessage(MESSAGE_GREET, "Thank you again for getting the wood, I have another {mission} for you.")
elseif getPlayerStorageValue(cid, storage) == 4 then
npcHandler:say("Please, go place the traps in the correct places!", cid)
return false
elseif getPlayerStorageValue(cid, storage) == 5 then
npcHandler:setMessage(MESSAGE_GREET, "Have you placed all of the traps in the correct spot yet?")
end
return true
end
local function onAddFocus(cid)
end
local function onReleaseFocus(cid)
if getPlayerStorageValue(cid, storage) <= 0 then
npcHandler:say("After you help Lt. Evan, I'll need your help.", cid)
elseif getPlayerStorageValue(cid, storage) == 1 then
npcHandler:say("Just ask me for a mission when you're ready.", cid)
elseif getPlayerStorageValue(cid, storage) == 2 then
npcHandler:say("Report back to me after you have obtained all of the wood.", cid)
elseif getPlayerStorageValue(cid, storage) == 3 then
npcHandler:say("Just ask me if you would like another mission.", cid)
elseif getPlayerStorageValue(cid, storage) == 4 then
npcHandler:say("Report back to me after you have successfully set the traps.", cid)
elseif getPlayerStorageValue(cid, storage) == 5 then
npcHandler:say("If you want your reward, just let me know.", cid)
elseif getPlayerStorageValue(cid, storage) == 6 then
npcHandler:say("Don't forget about the farmer south of town.", cid)
end
return true
end
~~~~~~~~~
But I'm guessing the "return false" is what is messing it up.. if the storage is >= 1 then if you go to the next NPC and try to talk to them, it's like it's stuck on that piece of code.. for exmaple:
Code:
15:20 Justin [8]: hi
15:20 Lt. Evan: Thank you for helping me kill those rats. The carpenter needs your help. He is located in the middle of the town, just west of here.
15:20 Justin [8]: hi
15:20 Carpenter Todd: Thank you for helping me kill those rats. The carpenter needs your help. He is located in the middle of the town, just west of here.
Anyone got any ideas?
Last edited: