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

Easy Npc Script!

  • Thread starter Thread starter Deleted member 49793
  • Start date Start date
D

Deleted member 49793

Guest
Hey guys pretty easy npc script but cant quite figure it out... Basicly Id like it to have tables at the top so its easy to adjust if thats fine :) Basicly the script will...

You can trade id **** for item ****

The script will be used to trade in donation coins for donation items
Also i need one example of a trade for 1 donation coin just use id **** and trade it for a backpack with a few items inside.

Thank you :)

Words for Npc:
Hello I can redeem your donation coins for donation items just ask me about my LIST of items.

If player says List he will reply some words that trigger other things such as, Donation Weapon will make npc say

Would you like to trade in 1 donation coin for a Donation Weapon?

Yes ---

Takes coin and gives player Weapon :)

Pretty easy

Rep++ For whoever helps thanks!
 
LUA:
local t = {
--      ['name of the item'] = {tokenID, token count, final item[, item count[, inside = { {itemid, count}, itemid, ... } ]] },
	['50 snowballs'] = {9020, 1, 2111, 50},
	['Donation Weapon'] = {9020, 3, 8931},
	['backpack with a few items inside'] = {9020, 2, 1988, inside = {2392, 2466, {2160, 5}}},
}
local checkCapacity = true

local cachedList = 'You can exchange tokens 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 your tokens!', 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 tokens.', cid)
			end
		else
			npcHandler:say('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())
Note that these are just examples.
 
Hmm didnt work, I edited a bit of it but just wording and items at top 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())
 
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}}}}
}

You had too many " } "
 
In case you still didn't manage to get it fixed, try:
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