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

[Request] NPC Item exchanger

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hello,

I would like to request a NPC script which will do the following.

Code:
--
It greets with: 
"Welcome traveler, you may exchange your tokens here."

And farewells with:
"Farewell traveler!"
--

It exchanges a vampire token (itemid: 9020) for items,
i.e. for a horned helmet (itemid: 2496).

--

You must have storage [B]11551[/B] or else it will say:
"Sorry, I can not talk to you."

--

Also I would like it to be easy to configure so that I could add more items.

Ofcourse I'll +REP the one who comes with a working script.

I'm using Crying Damson 0.3.6pl1

#EDIT

I got this:
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

-- CONFIG --
newitem = "Here you go, glad to be doing bussiness with you!"
noitems = "You don't have enough tokens to pay for that."

-- Yalahari Mask --

function YalahariMask(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
		
    end 
	if getPlayerStorageValue(cid, 11551) then
			if getPlayerItemCount(cid, 9020) >= 10 then
					if doPlayerRemoveItem(cid, 9020, 10) then
							selfSay(newitem, cid)
							doPlayerGiveItem(cid, 9778)
					else
							selfSay(noitems, cid)
					end
			else
					selfSay(noitems, cid)
			end
	end
end

but he won't say anything when I greet him.
 
Last edited:
Test this :P

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

function creatureSayCallback(cid, type, msg)

if(npcHandler.focus ~= cid) then
	return false
end

		playertokens = getPlayerItemCount(cid,9020)

---- example of keyword->respond

		if msgcontains(msg, 'offer') then
			selfSay('I can offer you a plate armor and plate legs for vampire lord tokens.')
		elseif msgcontains(msg, 'tokens') then
			selfSay('Vampire lord tokens are very valuable. Many treasure hunters looks for them.')

---- first item in offer

		elseif msgcontains(msg, 'plate armor') then
				if getPlayerItemCount(cid,9020) >= 5 then
                npcHandler:say('Did you bring me 5 vampire lord tokens to exchange for plate armor?', cid)
					talk_state = 1
				else
                npcHandler:say('I need 5 vampire lord tokens to exchange them to plate armor.', cid)
					talk_state = 0
				end

		elseif msgcontains(msg, 'yes') and talk_state == 1 then
			talk_state = 0
			if getPlayerItemCount(cid,9020) >= 5 then
					if doPlayerTakeItem(cid,9020,5) == 0 then
						selfSay('Here you are.')
						doPlayerAddItem(cid,2463,1)
					end
			else
                npcHandler:say('You haven\'t enough vampire lord tokens!', cid)
			end

---- /first item in offer

---- second item in offer

		elseif msgcontains(msg, 'plate legs') then
				if getPlayerItemCount(cid,9020) >= 5 then
                npcHandler:say('Did you bring me 5 vampire lord tokens to exchange for plate legs?', cid)
					talk_state = 2
				else
                npcHandler:say('I need 5 vampire lord tokens to exchange them to plate legs.', cid)
					talk_state = 0
				end

		elseif msgcontains(msg, 'yes') and talk_state == 2 then
			talk_state = 0
			if getPlayerItemCount(cid,9020) >= 5 then
					if doPlayerTakeItem(cid,9020,5) == 0 then
						selfSay('Here you are.')
						doPlayerAddItem(cid,2647,1)
					end
			else
                npcHandler:say('You haven\'t enough vampire lord tokens!', cid)
			end

---- /second item in offer

---- what happens if player say "no", if you are going to add more items, remember to change "talk_state <= 2"

		elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 2) then
			selfSay('Then not.')
			talk_state = 0
		end
	return true
end

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