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

Solved Problem with NPC when adding multiple trade offers

lycefur

New Member
Joined
Jul 13, 2010
Messages
99
Reaction score
2
I need help again. It seems I failed in editing NPC script sent to me in my other thread by Sonical. Base script worked with 1 item but I want the NPC to sell many different items for 'niebieski krysztal' - id 10584 as cash.

The thing is that when I am buying the first offer from this npc (winged helmet) everything is working properly:
14:49 Handlarz: Welcome, GOD Leviathan! I have been expecting you.
14:49 GOD Leviathan [396]: winged helmet
14:49 Handlarz: Czy chcesz kupic winged helmet za 25 niebieskich krysztalow?
14:49 GOD Leviathan [396]: yes
14:49 Handlarz: Prosze, oto Twoj przedmiot.
Here he deletes 25 niebieski krysztal from my bp and adds winged helmet to my bp. All is OK. The problems start when I want to buy second, third and etc offered items:
14:53 Handlarz: Welcome, GOD Leviathan! I have been expecting you.
14:53 GOD Leviathan [396]: yalahari mask
14:53 Handlarz: Czy chcesz kupic yalahari mask za 35 niebieskich krysztalow?
14:53 GOD Leviathan [396]: yes
14:53 Handlarz: Prosze, oto Twoj przedmiot.
As you can see it is everything OK in the chat window, he asks me for correct value (35 niebieski krysztal) and he says "yalahari mask" but he deletes my 25 niebieski krysztal instead of 35 and he gives me winged helmet instead of yalahari mask. Same with yalahari armor and leg piece.

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
		--CONFIG
	local itemi = 2474 --winged helmet
	local cash = 10584 --item id of "cash"
	local count = 25 
		local itemi2 = 9778 --yalahari mask
		local count2 = 35 
			local itemi3 = 9776 --yalahari armor
			local count3 = 35 
				local itemi4 = 9777 --yalahari leg piece
				local count4 = 35 
						local itemi5 = 8710 
						local count5 = 5 
								local itemi6 = 8710 
								local count6 = 5 
									local itemi7 = 8710 
									local count7 = 5 
											local itemi8 = 8710 
											local count8 = 5 
	--CONFIG END
 
									if(msgcontains(msg, 'winged helmet')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi).." za "..count.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 1
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
							if doPlayerRemoveItem(cid, cash, count) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
							
									if(msgcontains(msg, 'yalahari mask')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi2).." za "..count2.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 1
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
							if doPlayerRemoveItem(cid, cash, count2) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi2, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
												
									if(msgcontains(msg, 'yalahari armor')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi3).." za "..count3.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 1
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
							if doPlayerRemoveItem(cid, cash, count3) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi3, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
													
									if(msgcontains(msg, 'yalahari leg piece')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi4).." za "..count4.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 1
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
							if doPlayerRemoveItem(cid, cash, count4) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi4, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
													

	return TRUE
end

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

Sorry for my nubishness and halp plz. I give rep fo sho.
 
Last edited:
You couldn't use same talkstate many times ^_^
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
		--CONFIG
	local itemi = 2474 --winged helmet
	local cash = 10584 --item id of "cash"
	local count = 25 
		local itemi2 = 9778 --yalahari mask
		local count2 = 35 
			local itemi3 = 9776 --yalahari armor
			local count3 = 35 
				local itemi4 = 9777 --yalahari leg piece
				local count4 = 35 
						local itemi5 = 8710 
						local count5 = 5 
								local itemi6 = 8710 
								local count6 = 5 
									local itemi7 = 8710 
									local count7 = 5 
											local itemi8 = 8710 
											local count8 = 5 
	--CONFIG END
 
									if(msgcontains(msg, 'winged helmet')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi).." za "..count.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 1
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
							if doPlayerRemoveItem(cid, cash, count) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
							
									if(msgcontains(msg, 'yalahari mask')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi2).." za "..count2.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 2
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
							if doPlayerRemoveItem(cid, cash, count2) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi2, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
												
									if(msgcontains(msg, 'yalahari armor')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi3).." za "..count3.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 3
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
							if doPlayerRemoveItem(cid, cash, count3) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi3, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
													
									if(msgcontains(msg, 'yalahari leg piece')) then
							npcHandler:say("Czy chcesz kupic "..getItemNameById(itemi4).." za "..count4.." niebieskich krysztalow?", cid)
							talkState[talkUser] = 4
							elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 4) then
							if doPlayerRemoveItem(cid, cash, count4) == true then
							npcHandler:say("Prosze, oto Twoj przedmiot.", cid)
							doPlayerAddItem(cid, itemi4, 1)
							talkState[talkUser] = 0
							else
							npcHandler:say("Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.", cid)
							talkState[talkUser] = 0
							end
							elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
							npcHandler:say("Nie to nie.", cid)
							talkState[talkUser] = 0
							end
													

	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
l2tables
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local cash = 10584 --item id of 'cash'
local t = {
	['winged helmet'] = {2474, 25},
	['yalahari mask'] = {9778, 35},
	['yalahari armor'] = {9976, 35},
	['yalahari leg piece'] = {9777, 35},
	['cockroach leg'] = {8710, 5},
}

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 greetCallback(cid)
	Topic[cid] = nil
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif not Topic[cid] then
		for txt, v in pairs(t) do
			if msgcontains(msg, txt) then
				Topic[cid] = txt
				npcHandler:say('Czy chcesz kupic ' .. txt .. ' za ' .. count .. ' niebieskich krysztalow?', cid)
				return true
			end
		end
	else
		if msgcontains(msg, 'yes') then
			local v = t[Topic[cid]]
			if doPlayerRemoveItem(cid, cash, v[2]) then
				npcHandler:say('Prosze, oto Twoj przedmiot.', cid)
				doPlayerAddItem(cid, v[1], 1)
			else
				npcHandler:say('Nie masz przy sobie odpowiedniej ilosci niebieskich krysztalow.', cid)
			end
		else
			npcHandler:say('Nie to nie.', cid)
		end
		Topic[cid] = nil
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top