• 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 not working

  • Thread starter Deleted member 49793
  • Start date
D

Deleted member 49793

Guest
Hmm didnt work, I edited a bit of it but just wording and items at top someone mind taking a look?

When i say dont work i mean i try and spawn an npc with that script it doesnt let me, npc is fine but wont let me spawn it due to the script

Code:
local t = {
--      ['name of the item'] = {tokenID, token count, final item[, item count[, inside = { {itemid, count}, itemid, ... } ]] },
	['20 Crystal Coins'] = {6527, 1, 2160, 20},
	['Wyvern Fang (T5)'] = {6527, 1, 7408},
	['Great Axe (T5)'] = {6527, 1, 2415},
	['Boots of haste (T5)'] = {6527, 1, 2195},
	['Yalahari Armor (T5)'] = {6527, 1, 9776},
	['Yalahari Mask (T5)'] = {6527, 1, 9778},
	['Yalahari Legs (T5)'] = {6527, 1, 9777},
	['Great Shield (T5)'] = {6527, 1, 2523},
	['Hailstorm Rod (T5)'] = {6527, 1, 2183},
	['Soft Boots'] = {6527, 1, 2640},
	['Glowing Shard'] = {6527, 1, 11390},
	['2 Death Rings'] = {6527, 1, 1988, inside = {6300, 6300}},
	['Expert Donation Backpack'] = {6527, 4, 10518, inside = {2640, 11389, 11389, 11389, 11389, 11389, {2160, 10}}}}}}},
}
local checkCapacity = true
 
local cachedList = 'You can exchange donation coins for the following items: '
for k in pairs(t) do
	cachedList = cachedList .. '{' .. k .. '}, '
end
cachedList = cachedList:gsub(', $', '.')
 
local Topic = {}
 
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 greetCallback(cid)
	Topic[cid] = nil
	return true
end
 
function creatureSayCallback(cid, _type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'list') or msgcontains(msg, 'trade') or msgcontains(msg, 'change') then
		npcHandler:say(cachedList, cid)
	elseif Topic[cid] then
		if msgcontains(msg, 'yes') then
			local k = t[Topic[cid]]
			if getPlayerItemCount(cid, k[1]) >= k[2] then
				local v = doCreateItemEx(k[3], k[4] or 1)
				if k.inside and isContainer(v) then
					for _, p in ipairs(k.inside) do
						if type(p) == 'table' then
							doAddContainerItem(v, p[1], p[2] or 1)
						else
							doAddContainerItem(v, p, 1)
						end
					end
				end
				if doPlayerAddItemEx(cid, v, not checkCapacity) == 1 or not checkCapacity then
					npcHandler:say('Thank you for you donating! Every bit helps towards making this the #1 Unique RPG Server!', cid)
					doPlayerRemoveItem(cid, k[1], k[2])
				else
					npcHandler:say('You don\'t have enough capacity.', cid)
				end
			else
				npcHandler:say('You don\'t have enough donation coins, message Moistgiraffe to donate for more.', cid)
			end
		else
			npcHandler:say('Too bad maybe next time.', cid)
		end
		Topic[cid] = nil
		return true
	end
 
	for k, v in pairs(t) do
		if msgcontains(msg, k) then
			if type(v) == 'string' then
				npcHandler:say(v, cid)
				Topic[cid] = nil
			else
				npcHandler:say(('Would you like to trade ' .. (v[2] > 1 and v[2] or getItemInfo(v[1]).article) .. ' ' .. (v[2] > 2 and getItemInfo(v[1]).plural or getItemInfo(v[1]).name) .. ' for ' .. (k:find('%d') and '' or v[4] and v[4] > 1 and getItemInfo(v[3]).stackable and v[4] or getItemInfo(v[3]).article) .. ' ' .. k .. '?'):gsub('  ', ' '), cid)
				Topic[cid] = k
			end
			break
		end
	end
 
	return true
end
 
npcHandler:setMessage(MESSAGE_GREET, "Hello, I can redeem your donation coins for donation items. Just ask me about my {list} of items.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())
 
Why are you making so many threads of this same thing? I answered the other thread...
 
Try this :thumbup::
Lua:
local t = {
--      ['name of the item'] = {tokenID, token count, final item[, item count[, inside = { {itemid, count}, itemid, ... } ]] },
	['20 Crystal Coins'] = {6527, 1, 2160, 20},
	['Wyvern Fang (T5)'] = {6527, 1, 7408},
	['Great Axe (T5)'] = {6527, 1, 2415},
	['Boots of haste (T5)'] = {6527, 1, 2195},
	['Yalahari Armor (T5)'] = {6527, 1, 9776},
	['Yalahari Mask (T5)'] = {6527, 1, 9778},
	['Yalahari Legs (T5)'] = {6527, 1, 9777},
	['Great Shield (T5)'] = {6527, 1, 2523},
	['Hailstorm Rod (T5)'] = {6527, 1, 2183},
	['Soft Boots'] = {6527, 1, 2640},
	['Glowing Shard'] = {6527, 1, 11390},
	['2 Death Rings'] = {6527, 1, 1988, inside = {6300, 6300}},
	['Expert Donation Backpack'] = {6527, 4, 10518, inside = {2640, 11389, 11389, 11389, 11389, 11389, {2160, 10}}},
}
local checkCapacity = true
 
local cachedList = 'You can exchange donation coins for the following items: '
for k in pairs(t) do
	cachedList = cachedList .. '{' .. k .. '}, '
end
cachedList = cachedList:gsub(', $', '.')
 
local Topic = {}
 
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 greetCallback(cid)
	Topic[cid] = nil
	return true
end
 
function creatureSayCallback(cid, _type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'list') or msgcontains(msg, 'trade') or msgcontains(msg, 'change') then
		npcHandler:say(cachedList, cid)
	elseif Topic[cid] then
		if msgcontains(msg, 'yes') then
			local k = t[Topic[cid]]
			if getPlayerItemCount(cid, k[1]) >= k[2] then
				local v = doCreateItemEx(k[3], k[4] or 1)
				if k.inside and isContainer(v) then
					for _, p in ipairs(k.inside) do
						if type(p) == 'table' then
							doAddContainerItem(v, p[1], p[2] or 1)
						else
							doAddContainerItem(v, p, 1)
						end
					end
				end
				if doPlayerAddItemEx(cid, v, not checkCapacity) == 1 or not checkCapacity then
					npcHandler:say('Thank you for you donating! Every bit helps towards making this the #1 Unique RPG Server!', cid)
					doPlayerRemoveItem(cid, k[1], k[2])
				else
					npcHandler:say('You don\'t have enough capacity.', cid)
				end
			else
				npcHandler:say('You don\'t have enough donation coins, message Moistgiraffe to donate for more.', cid)
			end
		else
			npcHandler:say('Too bad maybe next time.', cid)
		end
		Topic[cid] = nil
		return true
	end
 
	for k, v in pairs(t) do
		if msgcontains(msg, k) then
			if type(v) == 'string' then
				npcHandler:say(v, cid)
				Topic[cid] = nil
			else
				npcHandler:say(('Would you like to trade ' .. (v[2] > 1 and v[2] or getItemInfo(v[1]).article) .. ' ' .. (v[2] > 2 and getItemInfo(v[1]).plural or getItemInfo(v[1]).name) .. ' for ' .. (k:find('%d') and '' or v[4] and v[4] > 1 and getItemInfo(v[3]).stackable and v[4] or getItemInfo(v[3]).article) .. ' ' .. k .. '?'):gsub('  ', ' '), cid)
				Topic[cid] = k
			end
			break
		end
	end
 
	return true
end
 
npcHandler:setMessage(MESSAGE_GREET, "Hello, I can redeem your donation coins for donation items. Just ask me about my {list} of items.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top