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

Lua [NPC] Script, change item to items. HELP!

Adi69

Active Member
Joined
Mar 14, 2008
Messages
161
Reaction score
35
Location
Poland
Hello OTlanders!

I tried do this NPC script and something I will not go ...
Could you do for me a script in which npc, will change dirty cape (ID:2237) to cape (ID: 2654) and give to player leather legs(ID: 2649) like it:

Player: Hi
NPC: Oh welcome... Are You from wrecked ship? Probably, was it terrible, yep?
Player: Yes
NPC: Your clothes look like rags. Is it wet? You should be shivering. I willl search some clothes for you. What have we got here...? It will be good for you. Would you like it?
Player: Yes
(and npc change dirty cape to cape, and give to player leather legs)
NPC: Here you are


Very Thanks in advence!
This script is very important for me! REP++
 
You don't need any parameters in the XML file.

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)
	if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
		npcHandler:say(getPlayerSex(cid) == 0 and "Well hello there lovely lady! How may I help you today?" or "Well hello sir, how may I help you today?", cid)
		Topic[cid] = 0
		npcHandler:addFocus(cid)
	elseif msgcontains(msg, "cape") and npcHandler:isFocused(cid) then
		npcHandler:say("I can give you a new {cape} in exchange for a dirty one.", cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "yes") then
			if doPlayerRemoveItem(cid, 2237, 1) then
				npcHandler:say("Here you are.", cid)
				doPlayerAddItem(cid, 2654, 1)
                                doPlayerAddItem(cid, 2649, 1)
				doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
				Topic[cid] = 0
			else
				npcHandler:say("You do not have a dirt cape to exchange.", cid)
				Topic[cid] = 0
			end
		elseif msgcontains(msg, "no") then
			npcHandler:say("Okay then.", cid)
			Topic[cid] = 0
		end
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHander:isFocused(cid) then
		npcHandler:say("Good bye.", cid, TRUE)
		Topic[cid] = nil
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "job") then
		npcHandler:say("I can give you a new {cape} in exchange for a dirty one.", cid)
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
 
Last edited:
Back
Top