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

Npc sells key

galsegal90

New Member
Joined
Aug 21, 2007
Messages
130
Reaction score
3
Hey.. Please someone help me with script of NPC who sells a key with action ID.. I've tried myself for hours and got sick of it..

thanks for helpers!

It doesnt matter if its in trade or talk..

btw i'm using 0.1.1 New horizon
client 8.6



PROBLEM SOLVES!
thanks to old post of: Cykotitan!!!
 
Last edited:
Actually it doesnt matter :)


btw.. here's my script

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

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

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if(msgcontains(msg, 'key') or msgcontains(msg, 'pier')) then
selfSay('Do you want to buy a key to the pier for 10 gold? ', cid)
talkState[talkUser] = 1
end
if(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(doPlayerRemoveMoney(cid, 10) == TRUE) then
doPlayerAddItem(cid, 2089, 1)
doSetItemActionId(2091, 2089)
selfSay('Here you are.', cid)
else
selfSay('Sorry, you don\'t have enough gold.', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end

return true
end

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


I get the key without the action ID!

and here the errors I get in console everytime I buy the key:

[30/04/2011 14:42:42] [Error - Npc interface]
[30/04/2011 14:42:42] data/npc/scripts/pierkey.lua:eek:nCreatureSay
[30/04/2011 14:42:42] Description:
[30/04/2011 14:42:43] data/npc/scripts/pierkey.lua:25: attempt to call global 'doSetItemActionId' (a nil value)
[30/04/2011 14:42:43] stack traceback:
[30/04/2011 14:42:43] data/npc/scripts/pierkey.lua:25: in function 'callback'
[30/04/2011 14:42:43] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[30/04/2011 14:42:43] data/npc/scripts/pierkey.lua:8: in function <data/npc/scripts/pierkey.lua:8>
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)	 npcHandlernCreatureAppear(cid)	 end
function onCreatureDisappear(cid)	 npcHandlernCreatureDisappear(cid)	 end
function onCreatureSay(cid, type, msg)	 npcHandlernCreatureSay(cid, type, msg)	 end
function onThink()	 npcHandlernThink()	 end

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

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(msgcontains(msg, 'key') or msgcontains(msg, 'pier')) then
		selfSay('Do you want to buy a key to the pier for 10 gold? ', cid)
		talkState[talkUser] = 1
	end
	if(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 10) == TRUE) then
			key = doPlayerAddItem(cid, 2089, 1)
			doSetItemActionId(key, 2091)
			selfSay('Here you are.', cid)
		else
		selfSay('Sorry, you don\'t have enough gold.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

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 f
	if not npcHandler:isFocused(cid) then
		if msgcontains(msg, 'hello') or msgcontains(msg, 'hi') then
			local a = getPlayerVocation(cid)
			if a == 1 or a == 5 then
				npcHandler:say('It\'s good to see somebody who has chosen the path of wisdom. What do you want?', cid)
			elseif a == 2 or a == 6 then
				npcHandler:say('Hail, friend of nature! How may I help you?', cid)
			elseif a == 3 or a == 7 then
				npcHandler:say('Neither strong enough to be a knight nor wise enough to be a real mage. You like it easy, don\'t you? Why are you disturbing me?', cid)
			else
				npcHandler:say('Another creature who believes thinks physical strength is more important than wisdom! Why are you disturbing me?', cid)
			end
			npcHandler:addFocus(cid)
		else
			return false
		end
	elseif msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
		npcHandler:say('Farewell, '..getCreatureName(cid)..'!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 1 and msgcontains(msg, 'yes') then
		npcHandler:say('Before we start I must ask you for a small donation of 1000 gold coins. Are you willing to pay 1000 gold coins for the test?', cid)
		f = 2
	elseif t[cid] == 1 and msgcontains(msg, 'no') then
		npcHandler:say('Then leave, unworthy worm!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 1 then
		npcHandler:say('You\'re not worthy if you cannot make up your mind. Leave!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 2 and msgcontains(msg, 'yes') then
		if doPlayerRemoveMoney(cid, 1000) then
			npcHandler:say('All right then. Here comes the first question. What was the name of Dago\'s favourite pet?', cid)
			f = 3
		else
			npcHandler:say('You don\'t even have the money to make a donation? Then go!', cid)
			npcHandler:releaseFocus(cid)
		end
	elseif t[cid] == 2 and msgcontains(msg, 'no') then
		npcHandler:say('You\'re not worthy then. Now leave!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 2 then
		npcHandler:say('You\'re not worthy if you cannot make up your mind. Leave!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 3 and msgcontains(msg, 'redips') then
		npcHandler:say('Perhaps you knew him after all. Tell me - how many fingers did he have when he died?', cid)
		f = 4
	elseif t[cid] == 3 then
		npcHandler:say('You are wrong. Get lost!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 4 and (msgcontains(msg, '7') or msgcontains(msg, 'seven')) then
		npcHandler:say('Also true. But can you also tell me the colour of the deamons in which master specialized?', cid)
		f = 5
	elseif t[cid] == 4 then
		npcHandler:say('You are wrong. Get lost!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 5 and msgcontains(msg, 'black') then
		npcHandler:say('It seems you are worthy after all. Do you want the key to the crypt?', cid)
		f = 6
	elseif t[cid] == 5 then
		npcHandler:say('You are wrong. Get lost!', cid)
		npcHandler:releaseFocus(cid)
	elseif t[cid] == 6 and msgcontains(msg, 'yes') then
		npcHandler:say('Here you are.', cid)
		doItemSetAttribute(doPlayerAddItem(cid, 2089, 1), 'aid', 3142)
	elseif t[cid] == 6 then
		npcHandler:say('It is always a wise decision to leave the dead alone.', cid)
	elseif msgcontains(msg, 'job') then
		npcHandler:say('Once I was the master of all mages, but now I only protect this crypt.', cid)
	elseif msgcontains(msg, 'name') then
		npcHandler:say('I am Skjaar the Mage, master of all spells.', cid)
	elseif msgcontains(msg, 'door') then
		npcHandler:say('This door seals a crypt.', cid)
	elseif msgcontains(msg, 'crypt') then
		npcHandler:say('Here lies my master. Only his closest followers may enter.', cid)
	elseif msgcontains(msg, 'help') then
		npcHandler:say('I\'m not here to help anybody. I only protect my master\'s crypt.', cid)
	elseif msgcontains(msg, 'mountain') then
		npcHandler:say('Hundreds of years my master\'s castle stood on the top of this mountain. Now there is a volcano.', cid)
	elseif msgcontains(msg, 'volcano') then
		npcHandler:say('I can still feel the magical energy in the volcano.', cid)
	elseif msgcontains(msg, 'castle') then
		npcHandler:say('The castle was destroyed when my master tried to summon a nameless creature. All that is left is this volcano.', cid)
	elseif msgcontains(msg, 'time') then
		npcHandler:say('To those who have lived for a thousand years time holds no more terror.', cid)
	elseif msgcontains(msg, 'master') then
		npcHandler:say('If you are one of his followers, you need not ask about him, for you will know. And if you aren\'t, you are not worthy anyway!', cid)
	elseif msgcontains(msg, 'key') then
		npcHandler:say('I will give the key to the crypt only to the closest followers of my master. Would you like me to test you?', cid)
		f = 1
	elseif msgcontains(msg, 'fuck') or msgcontains(msg, 'idiot') or msgcontains(msg, 'asshole') then
		npcHandler:say('Take this for your words!', cid)
		local h = getCreatureHealth(cid)
		if h ~= 1 then
			doCreatureAddHealth(cid, -(h - 1))
		end
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
		npcHandler:releaseFocus(cid)
	end
	t[cid] = f or nil
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, 'Run away, unworthy |PLAYERNAME|!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Back
Top