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

Bug

New Member
Joined
Jan 7, 2011
Messages
111
Reaction score
1
Gettin problems with npc:
Code:
[16:19:28.650] [Error - NpcScript Interface]
[16:19:28.650] data/npc/scripts/aluguelmounts2.lua:onCreatureSay
[16:19:28.650] Description:
[16:19:28.650] data/npc/scripts/aluguelmounts2.lua:23: attempt to index global 'rent_mounts' (a nil value)
[16:19:28.650] stack traceback:
[16:19:28.650]  data/npc/scripts/aluguelmounts2.lua:23: in function 'callback'
[16:19:28.650]  data/npc/lib/npcsystem/npchandler.lua:456: in function 'onCreatureSay'
[16:19:28.650]  data/npc/scripts/aluguelmounts2.lua:9: in function <data/npc/scripts/aluguelmounts2.lua:9>

My npc scripts:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local storage = 18600;
local startTime = os.time()
 
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
	if msgcontains(msg, 'rent') then
		selfSay('Do you want to rent a horse for one day at a price of 500 gold?', cid)
	end
	if msgcontains(msg, 'yes') then
		 if not getPlayerMount(cid, 25) then 
		 if doPlayerRemoveMoney(cid, 500) then
		doPlayerAddMount(cid,25)
        setPlayerStorageValue(cid, storage, startTime)
        selfSay('I\'ll give you one of our experienced ones. Take care! Look out for low hanging branches.', cid)
		else
		selfSay('Sorry, you are too poor. I\d rent one to you for free but I\m afraid you might be desperate enough to eat the horse, sorry.', cid)
		end
		else 
		selfSay('You already have this mount.', cid)
	end
	end
end
if msgcontains(msg, 'transport') then
	selfSay('We can bring you to Thais with one of our coaches for 125 gold. Are you interested?', cid)
	end
if msgcontains(msg, 'yes') then
if doPlayerRemoveMoney(cid, 125) then
doTeleportThing(cid, newpos)
else
selfSay('You don\'t have enough money.', cid)
end
end
if msgcontains(msg, 'no') then
selfSay('You have no idea what you are missing.', cid)
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
try added 1 function name rent_mounts ,try this:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local storage = 18600;
local startTime = os.time()
 
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
	if msgcontains(msg, 'rent') then
		selfSay('Do you want to rent a horse for one day at a price of 500 gold?', cid)
	end
	if msgcontains(msg, 'yes') then
		 if not getPlayerMount(cid, 25) then 
		 if doPlayerRemoveMoney(cid, 500) then
		doPlayerAddMount(cid,25)
        setPlayerStorageValue(cid, storage, startTime)
        selfSay('I\'ll give you one of our experienced ones. Take care! Look out for low hanging branches.', cid)
		else
		selfSay('Sorry, you are too poor. I\d rent one to you for free but I\m afraid you might be desperate enough to eat the horse, sorry.', cid)
		end
		else 
			if rent_mounts[msg] then
		if getPlayerStorageValue(cid, 18600) >= os.time() then
			selfSay('You already have this mount.', cid)
             return true
		end
if msgcontains(msg, 'transport') then
	selfSay('We can bring you to Thais with one of our coaches for 125 gold. Are you interested?', cid)
	end
if msgcontains(msg, 'yes') then
if doPlayerRemoveMoney(cid, 125) then
doTeleportThing(cid, newpos)
else
selfSay('You don\'t have enough money.', cid)
end
end
if msgcontains(msg, 'no') then
selfSay('You have no idea what you are missing.', cid)
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
not working :(
Code:
[16:39:09.251] [Error - NpcScript Interface]
[16:39:09.251] data/npc/scripts/aluguelmounts2.lua:onCreatureSay
[16:39:09.251] Description:
[16:39:09.251] data/npc/scripts/aluguelmounts2.lua:30: attempt to index global 'rent_mounts' (a nil value)
[16:39:09.251] stack traceback:
[16:39:09.251]  data/npc/scripts/aluguelmounts2.lua:30: in function 'callback'
[16:39:09.251]  data/npc/lib/npcsystem/npchandler.lua:456: in function 'onCreatureSay'
[16:39:09.251]  data/npc/scripts/aluguelmounts2.lua:10: in function <data/npc/scripts/aluguelmounts2.lua:10>
 
Last edited:
Really, isnt it easier to make it work with message ?

if msgcontains(msg, 'rent') then
if getPlayerStorageValue(cid, 18600) >= os.time() then
selfSay('You already have this mount.', cid)
return true
else
selfSay('Do you want to rent a horse for one day at a price of 500 gold?', cid)
 
Back
Top