• 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

gameover99097

Banned User
Joined
Nov 19, 2010
Messages
270
Reaction score
4
Elo , bawię się i bawię i nie mogę tego ogarnąć ; d
Słabo znam lua więc tak chce zrobić npc Yaman (djin) ktory funkcjonuje jak na rl.

Code:
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 wing(cid, message, keywords, parameters, node)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if getPlayerItemCount(cid, 2195) >= 1 then
		doPlayerRemoveItem(cid, 2195, 1) 
		doPlayerAddItem(cid, 5891, 1)
		selfSay('Here is your item!', cid)
		return true
	else
		selfSay('You don\'t have all items or cash!', cid)
	end
end
     
function flask(cid, message, keywords, parameters, node)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if getPlayerItemCount(cid, 2475) >= 4 then
		doPlayerRemoveItem(cid, 2475, 4)
		doPlayerAddItem(cid, 5885, 1)
		selfSay('Here is your item!', cid)
		return true
	else
		selfSay('You don\'t have these items!', cid)
	end
end	
     
function sulphur(cid, message, keywords, parameters, node)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if getPlayerItemCount(cid, 2392) >= 3 then 
		doPlayerRemoveItem(cid, 2392, 3)
		doPlayerAddItem(cid, 5904, 1)
		selfSay('Here is your item!', cid)
		return true
	else
		selfSay('You don\'t have these items!', cid)
	end
end
     
function spirit(cid, message, keywords, parameters, node)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if getPlayerItemCount(cid, 2498) >= 2 then
		doPlayerRemoveItem(cid, 2498, 2)
		doPlayerAddItem(cid, 5884, 1)
		selfSay('Here is your item!', cid)
		return true
	else
		selfSay('You don\'t have these items!', cid)
	end   
end
     
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I can make Warrior's Sweat, Magic Sulphur, Enchanted chicken wings and Fighting spirit!"})
local node1 = keywordHandler:addKeyword('sweat'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to trade 4x Warrior helmets for a Warrior\'s sweat?'})
	node1:addChildKeyword({'yes'}, flask, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})
     
local node2 = keywordHandler:addKeyword({'sulphur'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to trade 3x Fire swords for a Magic sulphur?'})
	node2:addChildKeyword({'yes'}, sulphur, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})

local node3 = keywordHandler:addKeyword({'wing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to trade a Boots of haste for an Enchanted chicken wing?'})
	node3:addChildKeyword({'yes'}, wing, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})
     
local node4 = keywordHandler:addKeyword({'spirit'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to trade 2x Royal helmets for a Fighting spirit?'})
	node4:addChildKeyword({'yes'}, spirit, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node4:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})
npcHandler:addModule(FocusModule:new())

Npc nie odpowiada wgl nawet na "hi"
 
Nie jestem specjalistą, ale chyba brakuje Ci:
Code:
npcHandler:addModule(FocusModule:new())
 
Wgl czemu robisz to w taki sposób? Nie lepiej już zrobić np.:

item = 'You do not have the required items.'
done = 'Here you are.'

Code:
elseif msgcontains(msg, 'warrior\'s sweat') then
				if getPlayerItemCount(cid,2475) >= 1 and getPlayerItemCount(cid,2475) >= 1 and getPlayerItemCount(cid,2475) >= 1 and getPlayerItemCount(cid,2475) >= 1 then
					selfSay('Did you bring me 4 warrior helmets?', cid)
					talk_state = 4
				else
					selfSay('I need {4 warrior helmet\'s}, to give you the warrior\'s sweat. Come back when you have them.', cid)
					talk_state = 0
				end
		elseif msgcontains(msg, 'yes') and talk_state == 4 then
			talk_state = 0
			if getPlayerItemCount(cid,2475) >= 4 then
					if doPlayerRemoveItem(cid,2475,1) == TRUE and doPlayerRemoveItem(cid,2475,1) == TRUE and doPlayerRemoveItem(cid,2475,1) == TRUE and doPlayerRemoveItem(cid,2475,1) == TRUE then
						doPlayerAddItem(cid,5885,1)
						selfSay(done, cid)
					end
				else
				selfSay(item, cid)
				end
 
Code:
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
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	local keywords = {
	["sweat"]	= {1, "Do you want to trade 4x Warrior helmets for a Warrior\'s sweat?"},
	["sulphur"]	= {2, "Do you want to trade 3x Fire swords for a Magic sulphur?'"},
	["wing"]	= {3, "Do you want to trade 3x Fire swords for a Magic sulphur?"},
	["spirit"]	= {4, "Do you want to trade 2x Royal helmets for a Fighting spirit?"},
	["help"]	= {5, "I can make Warrior's Sweat, Magic Sulphur, Enchanted chicken wings and Fighting spirit!"}
	}
	local items = {
	[1] = {2195, 1, 5891, 1},
	[2] = {2475, 1, 5885, 1},
	[3] = {2392, 3, 5904, 1},
	[4] = {2498, 2, 5884, 1}
	}
	for k, v in pairs(keywords) do	
		if msgcontains(msg:lower(), k) then
			selfSay(v[2], cid)
			talk_state = v[1]
			break
		end
	end
	if msgcontains(msg, 'yes') and ( talk_state > 0 and talk_state < 5) then
		local id = talk_state
		if getPlayerItemCount(cid, items[id][1]) >= items[id][2] then
			doPlayerRemoveItem(cid, items[id][1], items[id][2]) 
			doPlayerAddItem(cid, items[id][3], items[id][4])
			selfSay('Here is your item!', cid)
			return true
		else
			selfSay('You don\'t have all items or cash!', cid)
		end
		talk_state = 666
	elseif msgcontains(msg, 'no') and ( talk_state > 0 and talk_state < 5) then
		selfSay('Alright then. Come back when you got the neccessary items.', cid)
		talk_state = 666
	end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Powinno działać. Dzięki Kamilu
 
Last edited:
Back
Top