• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC Change Items

merfus

Member
Joined
Dec 27, 2011
Messages
214
Reaction score
5
Location
Poland
Hello i need script for NPC who change/sell item(s) for 2 other items + 100cc

-Player must have 2 items in backpack
-If he have that 2 items ID "x" and ID "y" he talk to NPC:

Player-> Hi
NPC -> Hi
Player -> Change
NPC -> Do you want to change that ring? It will cost 100cc
Player -> Yes (Now player lost 100cc, items ID "x" and "y" and get item ID "z")

-I need 9 change of 2 items +100cc for other item in 1 script. Just like he sell 9 other items for something (every item cost with other items+100cc).

Can anyone help me?

TFS 0.3.6pl1
 
NPC XML
LUA:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NPC CHANGER" script="data/npc/scripts/echanger.lua" access="5" lookdir="2" walkinterval="25"> 
  <mana now="800" max="800" /> 
  <health now="200" max="200" /> 
  <look type="160" head="0" body="0" legs="0" feet="0" /> 
  <parameters> 
    <parameter key="message_greet" value="Hello |PLAYERNAME|. Me can make good items from items me need." /> 
  </parameters> 
</npc>

echanger.lua
LUA:
local ring = 123 <-- ring id
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(not npcHandler:isFocused(cid)) then
		return false
	end
		if msgcontains(msg, 'Change') then
			if getPlayerItemCount(cid,ring) >= 1 then
				selfSay('Do you want to change that ring? It will cost 100cc?')
				talk_state = 1
			else
				selfSay('I need a 100 Crystal coins, to give you the ring. Come back when you have them.')
				talk_state = 0
			end

			elseif msgcontains(msg, 'yes') and talk_state == 1 then
			talk_state = 0
			if getPlayerItemCount(cid, 2160) >= 100 then
			doPlayerAddItem (cid,ring)
                        selfSay('Here u are.')
			end
			else
				selfSay(havent_item)
			end


        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Every item cost with other items+100cc.')
            talk_state = 0
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
NPC XML
LUA:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NPC CHANGER" script="data/npc/scripts/echanger.lua" access="5" lookdir="2" walkinterval="25"> 
  <mana now="800" max="800" /> 
  <health now="200" max="200" /> 
  <look type="160" head="0" body="0" legs="0" feet="0" /> 
  <parameters> 
    <parameter key="message_greet" value="Hello |PLAYERNAME|. Me can make good items from items me need." /> 
  </parameters> 
</npc>

echanger.lua
LUA:
local ring = 123 <-- ring id
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(not npcHandler:isFocused(cid)) then
		return false
	end
		if msgcontains(msg, 'Change') then
			if getPlayerItemCount(cid,ring) >= 1 then
				selfSay('Do you want to change that ring? It will cost 100cc?')
				talk_state = 1
			else
				selfSay('I need a 100 Crystal coins, to give you the ring. Come back when you have them.')
				talk_state = 0
			end

			elseif msgcontains(msg, 'yes') and talk_state == 1 then
			talk_state = 0
			if getPlayerItemCount(cid, 2160) >= 100 then
			doPlayerAddItem (cid,ring)
                        selfSay('Here u are.')
			end
			else
				selfSay(havent_item)
			end


        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Every item cost with other items+100cc.')
            talk_state = 0
        end
    return true
end

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

It just sell ring for 100cc, i need script that for this Ring (Like you ID 123) you need to give for the NPC 2 ITEMS and 100cc.
Like item ID 234 and 324 + 100cc for ring ID 123. Can you do that?
 
Back
Top