Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[NPC] Exchanger

Experienced Elementalist
Joined
Jul 29, 2012
Messages
240
Reaction score
25
I saw many people requesting this so here you are

add in data/npc
Exchanger.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Exchanger" script="ex.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="138" head="57" body="59" legs="40" feet="76" addons="0"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. Do you want to exchange THEITEM for THEPRIZE?!"/> 
		<parameter key="message_farewell" value="Cya later!"/>
	</parameters>
</npc>

in scripts /data/npc/scripts make ex.lua
Code:
--Script by Amiroslo
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local t = {}
 
local item = 9020 -- The item that he should have
local count = 1 -- how many of it he should have
 
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, 'change') then
		selfSay('are you sure you want to change '.. count ..' of '.. getItemNameById(item) ..' for THEPRIZE?', cid)--Change THEPRIZE to prize name
		t[cid] = 1
	elseif t[cid] == 1 then
		npcHandler:releaseFocus(cid)
		t[cid] = nil
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, item, count) then
			   doPlayerAddItem(cid, ITEMID) --Change ITEMID to the prize
				selfSay('you have recieved THEPRIZE', cid) --Change THEPRIZE to prize name
			else
				selfSay('you don\'t have '.. count ..' of '.. getItemNameById(item) ..' to recieve your prize!', cid)
				end
			end
		end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Tested on 0.3.6pl1

Rep++ if helped you
 
Back
Top