eardrums
Member
- Joined
- May 27, 2010
- Messages
- 94
- Solutions
- 1
- Reaction score
- 10
Hello everyone,
so I'm working on my first quest npc and so far I've managed to get pretty far. To be honest though I find it really difficult to keep the script organized and there is a lot i still dont understand. Can someone take a look at the script for me and help me out to organize it. Writing a new one that's easier to work with. Thanks in advance!
so I'm working on my first quest npc and so far I've managed to get pretty far. To be honest though I find it really difficult to keep the script organized and there is a lot i still dont understand. Can someone take a look at the script for me and help me out to organize it. Writing a new one that's easier to work with. Thanks in advance!
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
local function greetCallback(cid)
local player = Player(cid)
if player:getStorageValue(30001) == -1 then
npcHandler:setMessage(MESSAGE_GREET, "Oh thank god I ran into you adventurer. can you help me?")
elseif player:getStorageValue(30001) == 1 then
npcHandler:setMessage(MESSAGE_GREET, "Did you activate the generator in the west control room? ")
elseif player:getStorageValue(30001) == 2 then
npcHandler:setMessage(MESSAGE_GREET, "Did you activate the generator in the west control room? ")
elseif player:getStorageValue(30001) == 3 then
npcHandler:setMessage(MESSAGE_GREET, "Did you activate the generator in the west control room? ")
elseif player:getStorageValue(30001) == 4 then
npcHandler:setMessage(MESSAGE_GREET, "Did you find out what condition they are in? ")
end
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "yes") then
local storage = player:getStorageValue(30001)
if storage == -1 and
npcHandler.topic[cid] == 0 then
npcHandler:say({
"I'm afraid we have a problem. Two people have gotten sick, and we think it's because the water from the sewers is contaminated. ...",
"The sewers provide the water source for the town well, so everyone in town is at risk. ...",
"We need your help to find the source of the contamination and stop it before it's too late. ...",
"I would go down myself, but the rats have gotten more aggressive down there lately.",
"I'm not equipped to deal with them, and I'm afraid that if I go down there alone, I'll end up getting hurt or killed. ...",
"That's why I'm asking you for help. We need someone who's brave and resourceful enough to go down into the sewers and find the source of the contamination. ...",
"Are you willing to go down into the deeper sewers and investigate the issue?"
}, cid)
npcHandler.topic[cid] = 1
return true
elseif storage == 1 then
npcHandler:say("Well, the generator is still not on, so either you're lying or you did something wrong. Either way, I'm not going to waste any more time with you. I can just find someone else to do the job.", cid)
return true
elseif storage == 2 then
npcHandler:say("Well, the generator is still not on, so either you're lying or you did something wrong. Either way, I'm not going to waste any more time with you. I can just find someone else to do the job.", cid)
return true
elseif storage == 3 then
npcHandler:say({
"Well done! You bought us sometime to find out where the contamination came form. ...",
"I need you to do me a favor before we start looking for the source. I need you to go check on the two people who got sick. ...",
"They live with Grandpa Joe. Please find out what condition they are in for me."
}, cid)
player:setStorageValue(30001, 4)
return true
elseif storage == 4 then
npcHandler:say("You are lying! Grandpa Joe told me that nobody came to help him. Get out of my sight!", cid)
return true
end
if msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
npcHandler:say({
"Thank you for agreeing to help. I know this is a dangerous task, but it's important that we find the source of the contamination and stop it. ...",
"The first thing you need to do is go to the east control room and switch off the water flow. ...",
"This is the current water supply that's being used, and I need to stop the contaminated water from flowing before other people get sick. ...",
"Once you've switched off the water flow, go to the west control room and turn on the generator. This will start the backup water supply, which is not contaminated. Good luck!"
}, cid)
player:setStorageValue(30001, 1)
npcHandler.topic[cid] = 2
end
elseif msgcontains(msg, "coming up 2") and npcHandler.topic[cid] == 2 then
player:setStorageValue(30001, 1)
npcHandler:say("still", cid)
npcHandler.topic[cid] = 0
elseif npcHandler.topic[cid] > 0 then
npcHandler:say("still", cid)
npcHandler.topic[cid] = 0
end
return true
end
local function onAddFocus(cid)
npcHandler.topic[cid] = 0
end
local function onReleaseFocus(cid)
npcHandler.topic[cid] = 0
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())