• 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 Can someone put these 2 scripts into 1?

Onizuka

Member
Joined
Jul 5, 2008
Messages
2,291
Reaction score
14
i need these 2 scripts put into 1. if possible :P thanks ;x

LUA:
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

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

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
		if msgcontains(msg, 'offer') then
		selfSay('You can here change some items for {warrior sweat}, {magic sulphur}, {enchanted chicken wing}, {fighting spirit}.', cid)

elseif msgcontains(msg, 'spider silk yarn') then
				if getPlayerItemCount(cid,5879) >= 10 then
					selfSay('Did you bring me 10 giant spider silks?', cid)
					talk_state = 4
				else
					selfSay('I need {10 giant spider silks}, to give you spider silk yarn. 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,5879) >= 10 then
					if doPlayerRemoveItem(cid,5879,10) == TRUE then
						doPlayerAddItem(cid,5886,1)
						selfSay(done, cid)
					end
				else
				selfSay(item, cid)
				end

		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 the 4 warrior helmets?', cid)
				talk_state = 10
			else
				selfSay('I need a {4 warrior helmet\'s}, to give you the warrior sweat. Come back when you have them.', cid)
				talk_state = 0
			end
		elseif msgcontains(msg, 'yes') and talk_state == 10 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

elseif msgcontains(msg, 'magic sulphur') then
if getPlayerItemCount(cid,2392) >= 1 and getPlayerItemCount(cid,2392) >= 1 and getPlayerItemCount(cid,2392) >= 1 then
selfSay('Did you bring me 3 fire swords?', cid)
talk_state = 5
else
selfSay('I need {3 fire sword\'s}, to give you the magic sulpher. Come back when you have them.', cid)
talk_state = 0
end

		elseif msgcontains(msg, 'yes') and talk_state == 5 then
			talk_state = 0
			if getPlayerItemCount(cid,2392) >= 3 then
					if doPlayerRemoveItem(cid,2392,1) == TRUE and doPlayerRemoveItem(cid,2392,1) == TRUE and doPlayerRemoveItem(cid,2392,1) == TRUE then
						doPlayerAddItem(cid,5904,1)
										selfSay(done, cid)
				end
			else
				selfSay(item, cid)
			end

		elseif msgcontains(msg, 'enchanted chicken wing') then
			if getPlayerItemCount(cid,2195) >= 1 then
				selfSay('Did you bring me boots of haste?', cid)
				talk_state = 6
			else
				selfSay('I need {boots of haste}, to give you the enchanted chicken wing. Come back when you have them.', cid)
				talk_state = 0
			end

		elseif msgcontains(msg, 'yes') and talk_state == 6 then
			talk_state = 0
			if getPlayerItemCount(cid,2195) >= 1 then
					if doPlayerRemoveItem(cid,2195,1) == TRUE then
						doPlayerAddItem(cid,5891,1)
										selfSay(done, cid)
					end
			else
				selfSay(item, cid)
			end

		elseif msgcontains(msg, 'fighting spirit') then
			if getPlayerItemCount(cid,2498) >= 1 and getPlayerItemCount(cid,2498) >= 1 then
				selfSay('Did you bring me the 2 Royal Helmets?', cid)
				talk_state = 10
			else
				selfSay('I need a {2 Royal Helmet\'s}, to give you the Fighting Spirit. Come back when you have them.', cid)
				talk_state = 0
			end
		elseif msgcontains(msg, 'yes') and talk_state == 10 then
			talk_state = 0
			if getPlayerItemCount(cid,2498) >= 2 then
					if doPlayerRemoveItem(cid,2498,1) == TRUE and doPlayerRemoveItem(cid,2498,1) == TRUE then
						doPlayerAddItem(cid,5884,1)
										selfSay(done, cid)
					end

			else
				selfSay(item, cid)
			end

        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('So Leave, LEAVE ME NOW!')
            talk_state = 0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

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

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local hasItems = {}
local amuletStatus = 12000
local items = {
	[1] = {8264, 1},
	[1] = {8263, 1},
	[1] = {8262, 1},
	[1] = {8265, 1}
}
local wait = {
	storage = 12001,
	_time = 24 * 3600
}

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
	if(msgcontains(msg, 'amulet') and getCreatureStorage(cid, amuletStatus) <= 0) then
		selfSay('Do you want me to forge all the amulet pieces?', cid)
		talkState[talkUser] = 3
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
		hasItems[talkUser] = true
		for _, data in ipairs(items) do
			if(getPlayerItemCount(cid, data[1]) < data[2]) then
				hasItems[talkUser] = false
			end
		end
		if(hasItems[talkUser]) then
			for _, data in ipairs(items) do
				doPlayerRemoveItem(cid, data[1], data[2])
			end
			exhaustion.set(cid, wait.storage, wait._time)
			doCreatureSetStorage(cid, amuletStatus, 2)
			selfSay('Great, come back in 24 hours and ill have the amulet forged.', cid)
		else
			selfSay('You don\'t have required items.', cid)
		end
		hasItems[talkUser] = nil
		talkState[talkUser] = nil
	elseif(msgcontains(msg, 'amulet') and getCreatureStorage(cid, amuletStatus) == 2) then
		if(not exhaustion.get(cid, wait.storage)) then
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
			doCreatureSetStorage(cid, amuletStatus, 3)
			doPlayerAddItem(cid, 8266, 1)
			selfSay('Just in time! Your amulet is forged and ready.', cid)
		else
			selfSay('I need more time.', cid)
		end
	end

	return true
end

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

local Topic = {}
local amuletStatus = 12000
local items = {
	[1] = {8264, 1},
	[2] = {8263, 1},
	[3] = {8262, 1},
	[4] = {8265, 1}
}
local wait = {
	storage = 12001,
	time = 24 * 3600
}

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

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

function greetCallback(cid)
	Topic[cid] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, 'offer') then
		selfSay('You can here change some items for {warrior sweat}, {magic sulphur}, {enchanted chicken wing}, {fighting spirit}.', cid)
		Topic[cid] = 0
	elseif msgcontains(msg, 'spider silk yarn') then
		if getPlayerItemCount(cid,5879) >= 10 then
			selfSay('Did you bring me 10 giant spider silks?', cid)
			Topic[cid] = 1
		else
			selfSay('I need {10 giant spider silks}, to give you spider silk yarn. Come back when you have them.', cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
		Topic[cid] = 0
		if doPlayerRemoveItem(cid,5879,10) then
			doPlayerAddItem(cid,5886,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'warrior\'s sweat') then
		if getPlayerItemCount(cid,2475) >= 1 then
			selfSay('Did you bring me the 4 warrior helmets?', cid)
			Topic[cid] = 2
		else
			selfSay('I need a {4 warrior helmet\'s}, to give you the warrior sweat. Come back when you have them.', cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
		Topic[cid] = 0
		if doPlayerRemoveItem(cid,2475,4) then
			doPlayerAddItem(cid,5885,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'magic sulphur') then
		if getPlayerItemCount(cid,2392) >= 3 then
			selfSay('Did you bring me 3 fire swords?', cid)
			Topic[cid] = 3
		else
			selfSay('I need {3 fire sword\'s}, to give you the magic sulpher. Come back when you have them.', cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 3 then
		Topic[cid] = 0
		if doPlayerRemoveItem(cid,2392,3) then
			doPlayerAddItem(cid,5904,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'enchanted chicken wing') then
		if getPlayerItemCount(cid,2195) >= 1 then
			selfSay('Did you bring me boots of haste?', cid)
			Topic[cid] = 4
		else
			selfSay('I need {boots of haste}, to give you the enchanted chicken wing. Come back when you have them.', cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 4 then
		Topic[cid] = 0
		if doPlayerRemoveItem(cid,2195,1) then
			doPlayerAddItem(cid,5891,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'fighting spirit') then
		if getPlayerItemCount(cid,2498) >= 2 then
			selfSay('Did you bring me the 2 Royal Helmets?', cid)
			Topic[cid] = 5
		else
			selfSay('I need a {2 Royal Helmet\'s}, to give you the Fighting Spirit. Come back when you have them.', cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 5 then
		Topic[cid] = 0
		if doPlayerRemoveItem(cid,2498,2) then
			doPlayerAddItem(cid,5884,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'no') and (Topic[cid] >= 1 and Topic[cid] <= 5) then
		selfSay('So Leave, LEAVE ME NOW!')
		Topic[cid] = 0
	elseif msgcontains(msg, 'amulet') then
		local v = getCreatureStorage(cid, amuletStatus)
		if v < 1 then
			selfSay('Do you want me to forge all the amulet pieces?', cid)
			Topic[cid] = 6
		elseif v == 1 then
			if not exhaustion.get(cid, wait.storage) then
				doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
				doCreatureSetStorage(cid, amuletStatus, 2)
				doPlayerAddItem(cid, 8266, 1)
				selfSay('Just in time! Your amulet is forged and ready.', cid)
			else
				selfSay('I need more time.', cid)
			end
			Topic[cid] = 0
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 6 then
		for _, v in ipairs(items) do
			if getPlayerItemCount(cid, v[1]) < v[2] then
				selfSay('You don\'t have required items.', cid)
				return true
			end
		end
		for _, v in ipairs(items) do
			doPlayerRemoveItem(cid, v[1], v[2])
		end
		exhaustion.set(cid, wait.storage, wait.time)
		doCreatureSetStorage(cid, amuletStatus, 1)
		selfSay('Great, come back in 24 hours and I\'ll have the amulet forged.', cid)
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
LUA:
[5:28:57.289] [Error - NpcScript Interface]
[5:28:57.289] data/npc/scripts/A Sweaty Cyclops.lua:onCreatureSay
[5:28:57.289] Description:
[5:28:57.289] data/npc/scripts/A Sweaty Cyclops.lua:137: attempt to index global 'hasItems' (a nil value)
[5:28:57.289] stack traceback:
[5:28:57.289]   data/npc/scripts/A Sweaty Cyclops.lua:137: in function 'callback'
[5:28:57.289]   data/npc/lib/npcsystem/npchandler.lua:385: in function 'onCreatureSay'
[5:28:57.289]   data/npc/scripts/A Sweaty Cyclops.lua:20: in function <data/npc/scripts/A Sweaty Cyclops.lua:20>
 
Back
Top