• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Problem with a NPC of quest

JNLP

Hail Odin!
Joined
Aug 4, 2008
Messages
54
Reaction score
0
Location
Brazil
Hello guys! I tried to make a NPC to a new quest, but sadly I'm not very good in creation of NPCs and it's with error(s) that I can't fix. If someone can do it for me, I would thank and give [red]Rep+[/red] :D

NPC Script:

PHP:
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
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

function onCreatureSay(cid, type, msg)
    if msgcontains(msg, 'warrior') then
        if getPlayerVocation(cid) >= 9  then
            selfSay('Yes, you are a warrior...')
        else
            selfSay('What?! Do you want to become a {Warrior}?', cid)
        end
        talkState[talkUser] = 2
        if msgcontains(msg, 'yes') then
            selfSay('Well, if you can prove me by some {tasks} that you are worth, I can think about it...', cid)
            talkState[talkUser] =  1
        elseif msgcontains(msg, 'task') or msgcontains(msg,'tasks') or msgcontaisn(msg,'quest') then
            selfSay('Right, Here goes your first mission: My lance was stolen from here. I do not know how, but it happened. Probably it are with the {Cyclops}. Go there and try to find it. Ohh, remember that you can NOT use my lance!', cid)
            talkState[talkUser] =  0
        elseif talkState[talkUser] == 1 then
            if msgcontains(msg, 'lance') then
                if getPlayerItemCount(cid, 2414) >= 1  then
                    doPlayerRemoveItem(cid,2414,1)
                    selfSay('Good Job! Ask me for other missions when you want.', cid)
                elseif getPlayerItemCount(cid, 2414) == 0  then
                    selfSay('Come back when you get the Gungnir.',cid)
                    talkState[talkUser] = 0
                end
            end
        elseif talkstate[talkUser] == 1 then
            if msgcontains(msg, 'task') or msgcontains(msg,'mission') then
                selfSay('Yes, I have another mission for you, but first you need to do a favour to {Rob}. When you finish, talk to me again.', cid)
                talkState[talkUser] = 0
            end
        elseif talkstate[talkUser] == 1 then          
            if msgcontains(msg, 'task') or msgcontains(msg, 'mission') then
                if getPlayerStorageValue (cid,6690) <= 0 then
                    selfSay('You did not finished the mission of Rob. Come back when you have done.', cid)
                else
                    selfSay('Uhm... Looks like you really can be a {Einherjar}. I will give you one last challenge: Defeat the great sacred dragon and you will be able to fight at us side. To know his location, step in the {wooden floor},in right of my throne.',cid)
                    talkState[talkUser] = 0
                end
            elseif talkState[talkUser] == 1 then
                if msgcontains(msg, 'task') or msgcontains(msg,'mission') then
                    if getPlayerStorageValue(cid,6670) == 0 then
                        selfSay('You did not finish your mission yet',cid)
                    else
                        selfSay('Now you can pass trough the door and get your reward.',cid)
                        setPlayerStorageValue (cid,6671) = 1
                    end
                end
            end
        end
    end
    return true
end

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

And the error:

[11/02/2011 21:26:40] [Error - LuaScriptInterface::loadFile] data/npc/scripts/Odin.lua:62: unexpected symbol near '='
[11/02/2011 21:26:40] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Odin.lua
[11/02/2011 21:26:40] data/npc/scripts/Odin.lua:62: unexpected symbol near '='

I tried to edit this part, but it was pointless... <_<
 
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 
end 

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid 

function onCreatureSay(cid, type, msg) 
    if msgcontains(msg, 'warrior') then 
        if getPlayerVocation(cid) >= 9  then 
            selfSay('Yes, you are a warrior...') 
        else 
            selfSay('What?! Do you want to become a {Warrior}?', cid) 
        end 
        talkState[talkUser] = 2 
        if msgcontains(msg, 'yes') then 
            selfSay('Well, if you can prove me by some {tasks} that you are worth, I can think about it...', cid) 
            talkState[talkUser] =  1 
        elseif msgcontains(msg, 'task') or msgcontains(msg,'tasks') or msgcontaisn(msg,'quest') then 
            selfSay('Right, Here goes your first mission: My lance was stolen from here. I do not know how, but it happened. Probably it are with the {Cyclops}. Go there and try to find it. Ohh, remember that you can NOT use my lance!', cid) 
            talkState[talkUser] =  0 
        elseif talkState[talkUser] == 1 then 
            if msgcontains(msg, 'lance') then 
                if getPlayerItemCount(cid, 2414) >= 1  then 
                    doPlayerRemoveItem(cid,2414,1) 
                    selfSay('Good Job! Ask me for other missions when you want.', cid) 
                elseif getPlayerItemCount(cid, 2414) == 0  then 
                    selfSay('Come back when you get the Gungnir.',cid) 
                    talkState[talkUser] = 0 
                end 
            end 
        elseif talkstate[talkUser] == 1 then 
            if msgcontains(msg, 'task') or msgcontains(msg,'mission') then 
                selfSay('Yes, I have another mission for you, but first you need to do a favour to {Rob}. When you finish, talk to me again.', cid) 
                talkState[talkUser] = 0 
            end 
        elseif talkstate[talkUser] == 1 then           
            if msgcontains(msg, 'task') or msgcontains(msg, 'mission') then 
                if getPlayerStorageValue(cid,6690) <= 0 then 
                    selfSay('You did not finished the mission of Rob. Come back when you have done.', cid) 
                else 
                    selfSay('Uhm... Looks like you really can be a {Einherjar}. I will give you one last challenge: Defeat the great sacred dragon and you will be able to fight at us side. To know his location, step in the {wooden floor},in right of my throne.',cid) 
                    talkState[talkUser] = 0 
                end 
            elseif talkState[talkUser] == 1 then 
                if msgcontains(msg, 'task') or msgcontains(msg,'mission') then 
                    if getPlayerStorageValue(cid,6670) == 0 then 
                        selfSay('You did not finish your mission yet',cid) 
                    else 
                        selfSay('Now you can pass trough the door and get your reward.',cid) 
                        setPlayerStorageValue(cid,6671, 1) 
                    end 
                end 
            end 
        end 
    end 
    return true 
end 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
The npc is crashing the server! ;S

Edit:

I could'nt see well, but if I'm not mistaken the problem is in the line 3.
 
Last edited:
The npc is crashing the server! ;S

Edit:

I could'nt see well, but if I'm not mistaken the problem is in the line 3.

No! here I think I fixed it: read the commented part of the script
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 --[HERE]
function onThink()                    npcHandler:onThink()                    end 

function creatureSayCallback(cid, type, msg) 
    if(not npcHandler:isFocused(cid)) then 
        return false 
    end 
	if msgcontains(msg, 'warrior') then 
        if getPlayerVocation(cid) >= 9  then 
            selfSay('Yes, you are a warrior...') 
        else 
            selfSay('What?! Do you want to become a {Warrior}?', cid) 
        end 
        talkState[talkUser] = 2 
        if msgcontains(msg, 'yes') then 
            selfSay('Well, if you can prove me by some {tasks} that you are worth, I can think about it...', cid) 
            talkState[talkUser] =  1 
        elseif msgcontains(msg, 'task') or msgcontains(msg,'tasks') or msgcontaisn(msg,'quest') then 
            selfSay('Right, Here goes your first mission: My lance was stolen from here. I do not know how, but it happened. Probably it are with the {Cyclops}. Go there and try to find it. Ohh, remember that you can NOT use my lance!', cid) 
            talkState[talkUser] =  0 
        elseif talkState[talkUser] == 1 then 
            if msgcontains(msg, 'lance') then 
                if getPlayerItemCount(cid, 2414) >= 1  then 
                    doPlayerRemoveItem(cid,2414,1) 
                    selfSay('Good Job! Ask me for other missions when you want.', cid) 
                elseif getPlayerItemCount(cid, 2414) == 0  then 
                    selfSay('Come back when you get the Gungnir.',cid) 
                    talkState[talkUser] = 0 
                end 
            end 
        elseif talkstate[talkUser] == 1 then 
            if msgcontains(msg, 'task') or msgcontains(msg,'mission') then 
                selfSay('Yes, I have another mission for you, but first you need to do a favour to {Rob}. When you finish, talk to me again.', cid) 
                talkState[talkUser] = 0 
            end 
        elseif talkstate[talkUser] == 1 then           
            if msgcontains(msg, 'task') or msgcontains(msg, 'mission') then 
                if getPlayerStorageValue(cid,6690) <= 0 then 
                    selfSay('You did not finished the mission of Rob. Come back when you have done.', cid) 
                else 
                    selfSay('Uhm... Looks like you really can be a {Einherjar}. I will give you one last challenge: Defeat the great sacred dragon and you will be able to fight at us side. To know his location, step in the {wooden floor},in right of my throne.',cid) 
                    talkState[talkUser] = 0 
                end 
            elseif talkState[talkUser] == 1 then 
                if msgcontains(msg, 'task') or msgcontains(msg,'mission') then 
                    if getPlayerStorageValue(cid,6670) == 0 then 
                        selfSay('You did not finish your mission yet',cid) 
                    else 
                        selfSay('Now you can pass trough the door and get your reward.',cid) 
                        setPlayerStorageValue(cid,6671, 1) 
                    end 
                end 
            end 
        end 
    end 
    return true 
end 

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid 

--[[function onCreatureSay(cid, type, msg) <<< This function is already in use. [Look up]
    if msgcontains(msg, 'warrior') then 
        if getPlayerVocation(cid) >= 9  then 
            selfSay('Yes, you are a warrior...') 
        else 
            selfSay('What?! Do you want to become a {Warrior}?', cid) 
        end 
        talkState[talkUser] = 2 
        if msgcontains(msg, 'yes') then 
            selfSay('Well, if you can prove me by some {tasks} that you are worth, I can think about it...', cid) 
            talkState[talkUser] =  1 
        elseif msgcontains(msg, 'task') or msgcontains(msg,'tasks') or msgcontaisn(msg,'quest') then 
            selfSay('Right, Here goes your first mission: My lance was stolen from here. I do not know how, but it happened. Probably it are with the {Cyclops}. Go there and try to find it. Ohh, remember that you can NOT use my lance!', cid) 
            talkState[talkUser] =  0 
        elseif talkState[talkUser] == 1 then 
            if msgcontains(msg, 'lance') then 
                if getPlayerItemCount(cid, 2414) >= 1  then 
                    doPlayerRemoveItem(cid,2414,1) 
                    selfSay('Good Job! Ask me for other missions when you want.', cid) 
                elseif getPlayerItemCount(cid, 2414) == 0  then 
                    selfSay('Come back when you get the Gungnir.',cid) 
                    talkState[talkUser] = 0 
                end 
            end 
        elseif talkstate[talkUser] == 1 then 
            if msgcontains(msg, 'task') or msgcontains(msg,'mission') then 
                selfSay('Yes, I have another mission for you, but first you need to do a favour to {Rob}. When you finish, talk to me again.', cid) 
                talkState[talkUser] = 0 
            end 
        elseif talkstate[talkUser] == 1 then           
            if msgcontains(msg, 'task') or msgcontains(msg, 'mission') then 
                if getPlayerStorageValue(cid,6690) <= 0 then 
                    selfSay('You did not finished the mission of Rob. Come back when you have done.', cid) 
                else 
                    selfSay('Uhm... Looks like you really can be a {Einherjar}. I will give you one last challenge: Defeat the great sacred dragon and you will be able to fight at us side. To know his location, step in the {wooden floor},in right of my throne.',cid) 
                    talkState[talkUser] = 0 
                end 
            elseif talkState[talkUser] == 1 then 
                if msgcontains(msg, 'task') or msgcontains(msg,'mission') then 
                    if getPlayerStorageValue(cid,6670) == 0 then 
                        selfSay('You did not finish your mission yet',cid) 
                    else 
                        selfSay('Now you can pass trough the door and get your reward.',cid) 
                        setPlayerStorageValue(cid,6671, 1) 
                    end 
                end 
            end 
        end 
    end 
    return true 
end ]]

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
Ok, I will test. The problem was with that function?

Edit:

Almost there xD

[15/02/2011 10:20:55] [Error - Npc interface]
[15/02/2011 10:20:55] data/npc/scripts/Odin.lua: onCreatureSay
[15/02/2011 10:20:55] Description:
[15/02/2011 10:20:55] data/npc/scripts/Odin.lua:21: table index is nil
[15/02/2011 10:20:55] stack traceback:
[15/02/2011 10:20:55] data/npc/scripts/Odin.lua:21: in function 'callback'
[15/02/2011 10:20:55] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[15/02/2011 10:20:55] data/npc/scripts/Odin.lua:8: in function <data/npc/scripts/Odin.lua:8>
 
Last edited:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local v = {}

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
	elseif msgcontains(msg, 'warrior') then
		if getPlayerVocation(cid) > 8 then
			selfSay('Yes, you are a warrior...')
			v[cid] = 0
		else
			selfSay('What?! Do you want to become a {Warrior}?', cid)
			v[cid] = 1
		end
	elseif v[cid] == 1 and msgcontains(msg, 'yes') then
		selfSay('Well, if you can prove me by some {tasks} that you are worth, I can think about it...', cid)
		doCreatureSetStorage(cid, 6650, 0)
		v[cid] = 0
	elseif (msgcontains(msg, 'task') or msgcontains(msg,'quest') or msgcontains(msg, 'mission')) or (msgcontains(msg, 'lance') and getCreatureStorage(cid, 6650) == 1) then
		local k = getCreatureStorage(cid, 6650)
		if k == -1 then
			selfSay('You have to become a {warrior} first.', cid)
		elseif k == 0 then
			selfSay('Right, Here goes your first mission: My lance was stolen from here. I do not know how, but it happened. Probably it are with the {Cyclops}. Go there and try to find it. Ohh, remember that you can NOT use my lance!', cid)
			doCreatureSetStorage(cid, 6650, 1)
		elseif k == 1 then
			if doPlayerRemoveItem(cid, 2414, 1) then
				selfSay('Good job! Ask me for other missions when you want.', cid)
				doCreatureSetStorage(cid, 6650, 2)
			else
				selfSay('Come back when you get the Gungnir.', cid)
			end
		elseif k == 2 then
			selfSay('Yes, I have another mission for you, but first you need to do a favour to {Rob}. When you finish, talk to me again.', cid)
			doCreatureSetStorage(cid, 6650, 3)
		elseif k == 3 then
			if getPlayerStorageValue(cid, 6690) == -1 then
				selfSay('You haven\'t finished the mission of Rob. Come back when you are done.', cid)
			else
				selfSay('Uhm... Looks like you really can be a {Einherjar}. I will give you one last challenge: Defeat the great sacred dragon and you will be able to fight at our side. To find out his location, step on the {wooden floor}, right of my throne.', cid)
				doCreatureSetStorage(cid, 6650, 4)
			end
		elseif k == 4 then
			if getPlayerStorageValue(cid, 6670) == -1 then
				selfSay('You haven\'t finished your mission yet.', cid)
			else
				selfSay('You may now pass through the door and get your reward.', cid)
				doCreatureSetStorage(cid, 6650, 5)
				doCreatureSetStorage(cid, 6671, 1)
			end
		end
		v[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
It can be optimized more (altough you probably won't care about it), you can try merging the storages and only use 1 key.
 
I'll test it, thanks.

Edit:

It was having an error in the first line, but I replace it with another and now works.

It can be optimized more (altough you probably won't care about it), you can try merging the storages and only use 1 key.

Yeah, I'll do that. It's more simple than write "getCreatureStorage..." every hour! Thanks for the suggestion and for fix the script. Rep+! :)
 
Last edited:
Back
Top