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

[HELP] Keys

I need it for a quest, like fibula quest and mad mage room, i need the npc selling a key with ID


for exemple :

Key:3660
 
here's a Simon the Beggar example:
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 thinkCallback(cid)
	local random = math.random(250)
	if random == 1 then
		npcHandler:say("Sir, Ma'am, have a gold coin to spare?")
	elseif random == 2 then
		npcHandler:say("I need help! Please help me!")
	elseif random == 3 then
		npcHandler:say("Alms! Alms for the poor!")
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
		npcHandler:say("Hello " .. getCreatureName(cid) .. ". I am a poor man. Please help me.", cid, TRUE)
		Topic[cid] = 0
		npcHandler:addFocus(cid)
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveMoney(cid, 100) == TRUE then
				npcHandler:say("Thank you very much. Can you spare 500 more gold pieces for me? I will give you a nice hint.", cid)
				Topic[cid] = 2
			else
				npcHandler:say("You haven't got enough money for me.", cid)
				Topic[cid] = 0
			end
		else
			npcHandler:say("Hmm, maybe next time.", cid)
			Topic[cid] = 0
		end
	elseif Topic[cid] == 2 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveMoney(cid, 500) == TRUE then
				npcHandler:say("That's great! I have stolen something from Dermot. You can buy it for 200 gold. Do you want to buy it?", cid)
				Topic[cid] = 3
			else
				npcHandler:say("Sorry, that's not enough.", cid)
				Topic[cid] = 0
			end
		else
			npcHandler:say("It was your decision.", cid)
			Topic[cid] = 0
		end
	elseif Topic[cid] == 3 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveMoney(cid, 200) == TRUE then
				npcHandler:say("Now you own the hot key.", cid)
				local key = doCreateItemEx(2087, 1)
				doItemSetAttribute(key, "aid", 3940)
				doPlayerAddItemEx(cid, key, 1)
			else
				npcHandler:say("Pah! I said 200 gold. You don't have so much.", cid)
			end
		else
			npcHandler:say("Ok. No problem. I'll find another buyer.", cid)
		end
		Topic[cid] = 0
	elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
		npcHandler:say("Have a nice day.", cid, TRUE)
		Topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "help") then
		npcHandler:say("I need gold. Can you spare 100 gold pieces for me?", cid)
		Topic[talkUser] = 1
	end
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a nice day.")
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
huum, i need set the action id of key, hmm thanks. and how i put it to buy in npc shop with action changed?
 
huum, i need set the action id of key, hmm thanks. and how i put it to buy in npc shop with action changed?
NPC trade window shop system (unless you modify it) doesn't support buying items that have an actionid set.
 
[06/02/2010 04:23:58] [Error - Npc interface]
[06/02/2010 04:23:58] data/npc/scripts/dermot.lua:eek:nCreatureSay
[06/02/2010 04:23:58] Description:
[06/02/2010 04:23:58] data/npc/scripts/dermot.lua:25: attempt to call global 'doSetItemActionId' (a nil value)
[06/02/2010 04:23:58] stack traceback:
[06/02/2010 04:23:58] data/npc/scripts/dermot.lua:25: in function 'callback'
[06/02/2010 04:23:58] data/npc/lib/npcsystem/npchandler.lua:383: in function 'onCreatureSay'
[06/02/2010 04:23:58] data/npc/scripts/dermot.lua:8: in function <data/npc/scripts/dermot.lua:8>

Get this error :S
 
Back
Top Bottom