• 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 Trying to get the greeting right for NPC

XiolenceOT

New Member
Joined
Jun 5, 2023
Messages
42
Reaction score
4
Literally everything works perfect, until the end when the quest is complete and the next part starts where the storage is 2977 is set to 1. When you greet him for that part he just says welcome back, instead of the "Did you rest well?" line. Is there a better way to do it then check both storages?
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)
    local storageValue = player:getStorageValue(2976)
	local storageValue2977 = player:getStorageValue(2977)

    if storageValue < 1 then
        npcHandler:setMessage(MESSAGE_GREET, "Good evening, " .. player:getName() .. ". Care to help me with my {research}?")
        npcHandler.topic[cid] = 0
    elseif storageValue == 1 then
        npcHandler:setMessage(MESSAGE_GREET, "Did you find the {tower}?")
        npcHandler.topic[cid] = 1
    elseif storageValue == 3 then
        npcHandler:setMessage(MESSAGE_GREET, "Did you manage to find a way inside yet?")
        npcHandler.topic[cid] = 3
    elseif storageValue == 4 then
        npcHandler:setMessage(MESSAGE_GREET, "I'm waiting for you to bring me the book.")
        npcHandler.topic[cid] = 0
	elseif storageValue == 2 then
		npcHandler:setMessage(MESSAGE_GREET, "Did you find the tower?")
        npcHandler.topic[cid] = 2
    elseif storageValue == 5 then
        npcHandler:setMessage(MESSAGE_GREET, "Covered in blood I see, did you find the book?")
        npcHandler.topic[cid] = 5
    elseif storageValue == 6 and storageValue2977 == -1 then
        npcHandler:setMessage(MESSAGE_GREET, "Did you rest well? We have more work ahead of us, " .. player:getName() .. ". Are you ready to continue?")
        npcHandler.topic[cid] = 6
		elseif storageValue2977 == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Let's not get lazy now, " .. player:getName() .. ". Go speak to Davin!")
        npcHandler.topic[cid] = 7
		
		
    else
        npcHandler:setMessage(MESSAGE_GREET, "Welcome back!")
        npcHandler.topic[cid] = 0
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local storageValue = player:getStorageValue(2976)

    if msgcontains(msg, "yes") then
        if storageValue == 2 then
            npcHandler:say("Well done! That's a strong step forward. If you're up for it, you should look around the tower and see if you can find a way in. I read in a book that thieves broke in on the east side of the tower once, something about a short wall or something. Maybe it's still there. If you manage to get inside, see if you can find a book labeled 'The Claire Massacre'. Be careful, " .. player:getName() .. ".", cid)
            player:setStorageValue(2976, 3)
        elseif storageValue == 3 then
            npcHandler:say("Did you manage to find a way inside yet? Check the east walls for a way in.", cid)
        elseif storageValue == 5 then
            if player:getItemCount(1971) > 0 then
                player:removeItem(1971, 1)
			player:addOutfit(666)
            player:addOutfit(667)
                player:addExperience(1000000)
                player:setStorageValue(2976, 6)
                npcHandler:say("Maybe we should take a break. Speak to me again after you rest up a little. Great work today!", cid)
            else
                npcHandler:say("You don't have the book with you. Keep looking for it!", cid)
            end
        elseif storageValue == 6 then
            npcHandler:say("Great! I read the book thoroughly. It mentions a mansion the Claire family resided in. It also mentions the 'great family war' that took place, but the rest of the pages were torn out. I'll need you to go there and locate the other book so I can decipher more about the history of the Claire family. Talk to Davin, he stays low on the mountains to the east. Seek him out and tell him I sent you.", cid)
            player:setStorageValue(2977, 1)
        end
    elseif msgcontains(msg, "research") and storageValue == -1 then
        npcHandler:say("Great! I knew someone would be interested. I'm trying to uncover what happened here. I need you to see if you can find the location of the tower I read about when I was a kid. Look for the tower and come back to me once you've found it.", cid)
        player:setStorageValue(2976, 1)
    elseif msgcontains(msg, "no") then
        npcHandler:say("Alright, I'm here whenever you're ready...", cid)
    elseif storageValue == 2 and (msgcontains(msg, "tower") or msgcontains(msg, "yes")) then
        npcHandler:say("Well done! That's a strong step forward. If you're up for it, you should look around the tower and see if you can find a way in. I read in a book that thieves broke in on the east side of the tower once, something about a short wall or something. Maybe it's still there. If you manage to get inside, see if you can find a book labeled 'The Claire Massacre'. Be careful, " .. player:getName() .. ".", cid)
        player:setStorageValue(2976, 3)
    elseif storageValue == 3 and (msgcontains(msg, "no") or msgcontains(msg, "wall")) then
        npcHandler:say("Maybe you should check the east walls for a way in.", cid)
    elseif storageValue == 4 then
        npcHandler:say("I'm waiting for you to bring me the book, " .. player:getName() .. "..", cid)
    elseif storageValue == 5 and (msgcontains(msg, "book") or msgcontains(msg, "yes")) then
        if player:getItemCount(1971) > 0 then
            player:removeItem(1971, 1)
            player:addExperience(1000000)
	        player:addOutfit(666)
            player:addOutfit(667)
            player:setStorageValue(2976, 6)
            npcHandler:say("Maybe we should take a break. Speak to me again after you rest up a little. Great work today!", cid)
        else
            npcHandler:say("You don't have the book with you. Keep looking for it!", cid)
        end
    end

    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I could just fix it.. but it's better if you learn how to fix it yourself, when you can't figure out why something isn't working.

use print()

In this case, you'd want to print(storageValue) and print(storageValue2977)

Then you should see why it's not getting to where you want it to be.

Lua:
local function greetCallback(cid)
    local player = Player(cid)
    local storageValue = player:getStorageValue(2976)
    local storageValue2977 = player:getStorageValue(2977)

    print(storageValue)
    print(storageValue1977)

-- rest of code
    return true
end
 
I could just fix it.. but it's better if you learn how to fix it yourself, when you can't figure out why something isn't working.

use print()

In this case, you'd want to print(storageValue) and print(storageValue2977)

Then you should see why it's not getting to where you want it to be.

Lua:
local function greetCallback(cid)
    local player = Player(cid)
    local storageValue = player:getStorageValue(2976)
    local storageValue2977 = player:getStorageValue(2977)

    print(storageValue)
    print(storageValue1977)

-- rest of code
    return true
end

thank you :) I forgot about the prints
 
Back
Top