• 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 Problem with Npc

Santi

Theres no way im stopping
Joined
Aug 29, 2010
Messages
1,975
Reaction score
152
Location
00
So the npc is supposed to repair softies or firewalker boots depending on what player chooses
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

 
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 stuff = {
[1] = {name = 'soft boots', price = 10, worn = 6530, ID = 6132, nr = 1},
[2] = {name = 'firewalker boots', price = 10, worn = 9934, ID = 9932, nr = 2}
} 

local v = doPlayerRemoveItem
local s = getPlayerItemCount
 
for i = 1, #stuff do
if (msgcontains(msg, stuff[i].name)) then
   npcHandler:say('Estas seguro que quieres reaparar tus " .. stuff[i].name .. " ?',cid)
   Topic[cid] = stuff[i].nr
elseif msgcontains(msg, 'yes') and v(cid,stuff[i].worn,1) and v(cid,2152,stuff[i].price) and Topic[cid] == stuff[i].nr then
   npcHandler:say('Aqui tienes', cid)
   doPlayerAddItem(cid,stuff[i].ID,1)
   Topic[cid] = 0
elseif msgcontains(msg, 'yes') and s(cid,2152) < stuff[i].price and Topic[cid] == stuff[i].nr then
   npcHandler:say('No dispones de suficiente dinero',cid)
   Topic[cid] = 0
elseif msgcontains(msg, 'yes') and s(cid,stuff[i].worn) < 1 and Topic[cid] == stuff[i].nr then
   npcHandler:say('No tienes unas worn " .. stuff[i].name .. " ',cid)
   Topic[cid] = 0
elseif msgcontains(msg, 'no') and Topic[cid] == stuff[i].nr then
   npcHandler:say('En otra ocasion entonces', cid)
   Topic[cid] = 0
                end
   return true
end
end

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

So, I'm having 2 problems.
The first one is this:
00:04 Admin Santi [156]: hi
00:04 Baba: Hola Admin Santi. yo reparo soft boots y firewalker boots!.
00:04 Admin Santi [156]: soft boots
00:04 Baba: Estas seguro que quieres reaparar tus " .. stuff?i?.name .. " ?

Second is that when I say firewalker boots the Npc isnt answering.

By the way, how do I make it so I can pay with gold, platinum or crystal?
Cause I put ID of gold, and I could not pay with crystals, I tried with platinums using platinums and I could but I couldn't with crystals though.

Thanks and rep+ for whoever helps!
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

local stuff = {
	[1] = {name = 'soft boots', price = 1000, worn = 6530, ID = 6132},
	[2] = {name = 'firewalker boots', price = 1000, worn = 9934, ID = 9932}
}

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] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif Topic[cid] ~= 0 then
		if msgcontains(msg, 'yes') then
			local v = stuff[Topic[cid]]
			if getPlayerItemCount(cid, v.worn) > 0 then
				if doPlayerRemoveMoney(cid, v.price) then
					doPlayerRemoveItem(cid, v.worn, 1)
					doPlayerAddItem(cid, v.ID, 1)
					npcHandler:say('Aqui tienes.', cid)
				else
					npcHandler:say('No dispones de suficiente dinero.',cid)
				end
			else
				npcHandler:say('No tienes unas worn ' .. v.name .. '.',cid)
			end
		else
			npcHandler:say('En otra ocasion entonces.', cid)
		end
		Topic[cid] = 0
	else
		for i = 1, #stuff do
			if msgcontains(msg, stuff[i].name) then
				npcHandler:say('Estas seguro que quieres reaparar tus ' .. stuff[i].name .. '?',cid)
				Topic[cid] = i
				break
			end
		end
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top