• 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!

Solved NPC error

70011983

Ners
Joined
Nov 21, 2011
Messages
354
Solutions
1
Reaction score
56
Location
Croatia
Could someone see what's wrong?
I was editing the things,and I'm not a pro :p Still learning:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}
 
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)
	local n
	if not npcHandler:isFocused(cid) then
		if msgcontains(msg, 'hello') or msgcontains(msg, 'hi') then
			npcHandler:say('G...greetings.', cid)
			npcHandler:addFocus(cid)
		else
			return false
		end
	elseif msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
		npcHandler:say('Exactly! Get away!', cid)
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'book') and getPlayerPartner(cid) > 0 then
		npcHandler:say('So, it\'s probably the Ralk\'s book, isn\'t it?', cid)
		n = 1
	elseif Topic[cid] == 1 and msgcontains(msg, 'yes') then
		npcHandler:say('So, true, I can read it for you, but not for free. Interested in it?', cid)
		n = 2
	elseif Topic[cid] == 2 and msgcontains(msg, 'yes') then
		npcHandler:say('Okey then, but are you sure? I will have to take the book then..the reading will destroy it, proceed?', cid)
		n = 3
	elseif Topic[cid] == 3 and msgcontains(msg, 'yes') then
		npcHandler:say('So, it will cost you about 20 gold ingots, are you interested? Not cheap, but it\'s a hard job.', cid)
		n = 4
	elseif Topic[cid] == 4 and msgcontains(msg, 'yes') then
		if doPlayerRemoveMoney(cid, 20000000) then
	    if doPlayerRemoveItem(cid, 6124, 1) then
			npcHandler:say('So, let me see..mm..mmahm.... Now, It says about a wizard called Ralk, that hes defending the Merge realm. This could be a joke too, Says it\'s below the Dream Realm. That\'s all, the other pages are rotten, hope it helped you a little..', cid)
			npcHandler:say('Damn, I bet <hicks> your cheating spouse took all of your money <hicks> from you. You\'re as poor as a church mouse. <hicks>', cid)
		end
	end
	return true
end
 
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye ...")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye ...took bad for you..")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Code:
[27/03/2013 11:22:05] [Error - LuaScriptInterface::loadFile] data/npc/scripts/book.lua:48: 'end' expected (to close 'function' at line 12) near '<eof>'
[27/03/2013 11:22:05] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/book.lua
[27/03/2013 11:22:05] data/npc/scripts/book.lua:48: 'end' expected (to close 'function' at line 12) near '<eof>'
Giving rep :p
 
Every if should have one end, also end the function with end.
Best way to check if you did this all correctly is by using tabs. As you can see, every if has now an end on the same vertical line.
Not exactly sure what you were trying to make, but best is to also use "else" so a player knows whats wrong.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}
 
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
		if msgcontains(msg, 'hello') or msgcontains(msg, 'hi') then
			npcHandler:say('G...greetings.', cid)
			npcHandler:addFocus(cid)
		else
			return false
		end
	end

	if msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
		npcHandler:say('Exactly! Get away!', cid)
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'book') and getPlayerPartner(cid) > 0 then
		npcHandler:say('So, it\'s probably the Ralk\'s book, isn\'t it?', cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 and msgcontains(msg, 'yes') then
		npcHandler:say('So, true, I can read it for you, but not for free. Interested in it?', cid)
		Topic[cid] = 2
	elseif Topic[cid] == 2 and msgcontains(msg, 'yes') then
		npcHandler:say('Okey then, but are you sure? I will have to take the book then..the reading will destroy it, proceed?', cid)
		Topic[cid] = 3
	elseif Topic[cid] == 3 and msgcontains(msg, 'yes') then
		npcHandler:say('So, it will cost you about 20 gold ingots, are you interested? Not cheap, but it\'s a hard job.', cid)
		Topic[cid] = 4
	elseif Topic[cid] == 4 and msgcontains(msg, 'yes') then
	    	if getPlayerItemCount(cid, 6124) >= 1 then
		        if doPlayerRemoveMoney(cid, 20000000) then
                                doPlayerRemoveItem(cid, 6124, 1)
				npcHandler:say('So, let me see..mm..mmahm.... Now, It says about a wizard called Ralk, that hes defending the Merge realm. This could be a joke too, Says it\'s below the Dream Realm. That\'s all, the other pages are rotten, hope it helped you a little..', cid)
				npcHandler:say('Damn, I bet <hicks> your cheating spouse took all of your money <hicks> from you. You\'re as poor as a church mouse. <hicks>', cid)
			else
				npcHandler:say('You don\'t have enough money.', cid)
			end
		else
			npcHandler:say('You don\'t have this book.', cid)
		end
	end
	return true
end
 
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye ...")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye ...took bad for you..")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
Um..no errors now,thx but, he isn't answering me when I say "book" I wanted it to be like this:

Code:
PLAYER: Hi
NPC: G...greetings.
PLAYER: book
NPC: So, it's probably the Ralk's book, isn't it?
PLAYER: yes
NPC: So, true, I can read it for you, but not for free. Interested in it?
PLAYER: yes
NPC: Okey then, but are you sure? I will have to take the book then..the reading will destroy it, proceed?
PLAYER: yes
NPC: So, it will cost you about 20 gold ingots, are you interested? Not cheap, but it's a hard job.
PLAYER: yes
<After saying "yes", the NPC takes away the book and 20 gold ingots, and it says the next text message \/>
NPC: So, let me see..mm..mmahm.... Now, It says about a wizard called Ralk, that hes defending the Merge realm. This could be a joke too, Says it's below the Dream Realm. That's all, the other pages are rotten, hope it helped you a little..
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}
 
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
		if msgcontains(msg, 'hello') or msgcontains(msg, 'hi') then
			npcHandler:say('G...greetings.', cid)
			npcHandler:addFocus(cid)
		else
			return false
		end
	end
 
	if msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
		npcHandler:say('Exactly! Get away!', cid)
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'book') then
		npcHandler:say('So, it\'s probably the Ralk\'s book, isn\'t it?', cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 and msgcontains(msg, 'yes') then
		npcHandler:say('So, true, I can read it for you, but not for free. Interested in it?', cid)
		Topic[cid] = 2
	elseif Topic[cid] == 2 and msgcontains(msg, 'yes') then
		npcHandler:say('Okey then, but are you sure? I will have to take the book then..the reading will destroy it, proceed?', cid)
		Topic[cid] = 3
	elseif Topic[cid] == 3 and msgcontains(msg, 'yes') then
		npcHandler:say('So, it will cost you about 20 gold ingots, are you interested? Not cheap, but it\'s a hard job.', cid)
		Topic[cid] = 4
	elseif Topic[cid] == 4 and msgcontains(msg, 'yes') then
	    	if getPlayerItemCount(cid, 6124) >= 1 then
		        if doPlayerRemoveMoney(cid, 20000000) then
                                doPlayerRemoveItem(cid, 6124, 1)
				npcHandler:say('So, let me see..mm..mmahm.... Now, It says about a wizard called Ralk, that hes defending the Merge realm. This could be a joke too, Says it\'s below the Dream Realm. That\'s all, the other pages are rotten, hope it helped you a little..', cid)
				npcHandler:say('Damn, I bet <hicks> your cheating spouse took all of your money <hicks> from you. You\'re as poor as a church mouse. <hicks>', cid)
			else
				npcHandler:say('You don\'t have enough money.', cid)
			end
		else
			npcHandler:say('You don\'t have this book.', cid)
		end
	end
	return true
end
 
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye ...")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye ...took bad for you..")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Thanks again :p Can't rep you anymore, when will I be able to rep again the same person?
1 more thing, if it's not too hard, how I make it so you can do this action, just once,so you click it, and that's it, you can't anymore..?
Code:
function onUse(cid, item, frompos, item2, topos)
 
	       if doPlayerRemoveItem(cid, 2403, 1) then
        doPlayerAddItem(cid, 7488, 1)
                        doSendMagicEffect(getPlayerPosition(cid), 37) 	
        doCreatureSay(cid, "The knife broke apart when it touched the frozen body, but it wasn't useless...", TALKTYPE_ORANGE_1, cid)
	else
        doCreatureSay(cid, "It's too freezy for you, get a knife and then come back..", TALKTYPE_ORANGE_1, cid)
	end
end
 
You can add storage.
Lua:
if(getPlayerStorageValue(cid, 9105) == -1) then
	-- 
	setPlayerStorageValue(cid, 9105, 1)
 
It should look like this?
Code:
function onUse(cid, item, frompos, item2, topos)
 
 if(getPlayerStorageValue(cid, 9105) == -1) then
	-- 
	setPlayerStorageValue(cid, 9105, 1)
        if doPlayerAddItem(cid, 2403, 1) then
            doSendMagicEffect(getPlayerPosition(cid), 34) 	
            doCreatureSay(cid, "You have searched in the bone pile, luckily, there was a knife inside.", TALKTYPE_ORANGE_1, cid)
	end
end
?

BTW,the Storage, I can use the same for multiple actions? So you call all of them use just once?
 
Lua:
setPlayerStorageValue(cid, 9105, 1)
Use this on the place where after that happens a player shouldn't be able to use it again.
So under the doCreatureSay for example.

Once a storage value is added, it doesn't matter from which script you check it, it is stored in the database, so it's the same for all scripts.
So for other scripts use a different storage.
 
I keep getting this error:
Code:
[27/03/2013 14:51:26] [Error - LuaScriptInterface::loadFile] data/actions/scripts/knife.lua:11: 'end' expected (to close 'function' at line 1) near '<eof>'
[27/03/2013 14:51:26] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/knife.lua)
[27/03/2013 14:51:26] data/actions/scripts/knife.lua:11: 'end' expected (to close 'function' at line 1) near '<eof>'

This is how it looks like:
Code:
function onUse(cid, item, frompos, item2, topos)
 
if(getPlayerStorageValue(cid, 9105) == -1) then
        if doPlayerAddItem(cid, 2403, 1) then
            doSendMagicEffect(getPlayerPosition(cid), 34) 	
            doCreatureSay(cid, "You have searched in the bone pile, luckily, there was a knife inside.", TALKTYPE_ORANGE_1, cid)
	setPlayerStorageValue(cid, 9105, 1)
	end
end
 
Every if should have an end, but every function too, so in total it should have 3 ends. With function onUse it's also always good to use return true (above the last end for example) so people don't get the "You cannot use this object" message.
 
Back
Top