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

NPC Error

druidbacu

New Member
Joined
Sep 15, 2011
Messages
60
Solutions
1
Reaction score
1
Please help me.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

hmage        = 22385

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
function creatureSayCallback(cid, type, msg)
 
    if (not npcHandler:isFocused(cid)) then
        return false
    end
 
  if msgcontains (msg, "mage") and getPlayerSex(cid) == 1 then
    npcHandler:say("I can give you {male Hat Addon}", cid)
	Topic[talkUser] = 0

  elseif msgcontains (msg, "male hat addon") and getPlayerSex(cid) == 1 and getPlayerStorageValue(cid, hmage) == -1 then
    npcHandler:say("You need 1 x ferumbras' hat to unlock Hat Addon.", cid)
	Topic[talkUser] = 1	
  elseif msgcontains(msg, "yes") and getPlayerStorageValue(cid, hmage) < 1 and Topic[talkUser] == 1 and getPlayerItemCount(cid,5903) >= 1 then
    npcHandler:say("Ah, right! The mage rod! Here you go.", cid)
	Topic[talkUser] = 0
	doPlayerRemoveItem(cid,5903,1)
    doSendMagicEffect(getCreaturePosition(cid), 13)
	setPlayerStorageValue(cid,hmage,1)
	if getPlayerSex(cid) == 1 then 
    doPlayerAddOutfit(cid, 129, 1)
	elseif getPlayerSex(cid) == 0 then
    doPlayerAddOutfit(cid, 137, 2)
	else
	npcHandler:say("You do not have required materials", cid)
	end
	end
	return true
end

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

Log:


Code:
[10:28:01.068] [Error - NpcScript Interface] 
[10:28:01.068] data/npc/scripts/Thomas.lua:onCreatureSay
[10:28:01.068] Description: 
[10:28:01.068] data/npc/scripts/Thomas.lua:27: attempt to index global 'Topic' (a nil value)
[10:28:01.068] stack traceback:
[10:28:01.068] 	data/npc/scripts/Thomas.lua:27: in function 'callback'
[10:28:01.068] 	data/npc/lib/npcsystem/npchandler.lua:385: in function 'onCreatureSay'
[10:28:01.068] 	data/npc/scripts/Thomas.lua:8: in function <data/npc/scripts/Thomas.lua:8>
 
Last edited:
Try this:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
hmage        = 22385
 
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
function creatureSayCallback(cid, type, msg)
 
    if (not npcHandler:isFocused(cid)) then
        return false
    end
 
	if msgcontains(msg, "mage") and getPlayerSex(cid) == 1 then
		npcHandler:say("I can give you {male Hat Addon}", cid)
		Topic[talkUser] = 0
 
	elseif msgcontains(msg, "male hat addon") then
		if getPlayerSex(cid) ~= 1 then sem_msg = "You are not MALE" end
		if getPlayerStorageValue(cid, hmage) > -1 then sem_msg = "You allready have this addon" end
		if not(sem_msg ~= nil) then
			npcHandler:say("You need 1 x ferumbras' hat to unlock Hat Addon.", cid)
			Topic[talkUser] = 1	
		else 
			npcHandler:say(sem_msg, cid)
		end
	
	elseif msgcontains(msg, "yes") then
		if Topic[talkUser] == 1 then
			if getPlayerItemCount(cid,5903) < 1 then sem_2_msg = "You don't have ferumbras hat!" end
			if sem_2_msg == nil then
				npcHandler:say("Ah, right! The mage rod! Here you go.", cid)
				Topic[talkUser] = 0
				doPlayerRemoveItem(cid,5903,1)
				doSendMagicEffect(getCreaturePosition(cid), 13)
				setPlayerStorageValue(cid,hmage,1)
					if getPlayerSex(cid) == 1 then 
						doPlayerAddOutfit(cid, 129, 1)
					elseif getPlayerSex(cid) == 0 then
						doPlayerAddOutfit(cid, 137, 2)
					end
			else
			npcHandler:say(sem_2_msg, cid)
			end	
		end
	end
	
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

- - - Updated - - -

sryy;

try this, this will work :

Lua:
-- start shit
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
--returns how many msgs he have said already
function cancelNPCTalk(events)
  local ret=1
  for aux=1,table.getn(events) do
     if events[aux].done==FALSE then
        stopEvent(events[aux].event)
     else
        ret=ret+1
     end
  end
  events=nil
  return(ret)
end
 
function doCreatureSayWithDelay(cid,text,type,delay,e)
   if delay<=0 then
      doCreatureSay(cid,text,type)
   else
      local func=function(pars)
                    doCreatureSay(pars.cid,pars.text,pars.type)
                    pars.e.done=TRUE
                 end
      e.done=FALSE
      e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
   end
end

function doNPCTalkALot(msgs,interval)
  local e={}
  local ret={}
  if interval==nil then interval=3000 end --3 seconds is default time between messages
  for aux=1,table.getn(msgs) do
      e[aux]={}
      doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux])
      table.insert(ret,e[aux])
  end
  return(ret)
end
--end shit :P
 
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end      
-- zmienne lokalne
   local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local namee = getPlayerName(cid)
 
	local mage_outfit_storage = 22385
	if msgcontains(msg, "mage") and getPlayerSex(cid) == 1 then
		npcHandler:say("I can give you {male Hat Addon}", cid)
		talkState[talkUser] = 0
	end
	
	if msgcontains(msg, "male hat addon") then
		if getPlayerSex(cid) ~= 1 then sem_msg = "You are not MALE" end
		if getPlayerStorageValue(cid, mage_outfit_storage) > -1 then sem_msg = "You allready have this addon" end
		if not(sem_msg ~= nil) then
			talkState[talkUser] = 1	
			npcHandler:say("You need 1 x ferumbras' hat to unlock Hat Addon. Do you have this one? {yes}", cid)
		else 
			npcHandler:say(sem_msg, cid)
		end
	end
	
	if msgcontains(msg, "yes") then
		if talkState[talkUser] == 1 then
			if getPlayerItemCount(cid,5903) < 1 then sem_2_msg = "You don't have ferumbras hat!" end
			if sem_2_msg == nil then
				npcHandler:say("Ah, right! The mage rod! Here you go.", cid)
				talkState[talkUser] = 0
				doPlayerRemoveItem(cid,5903,1)
				doSendMagicEffect(getCreaturePosition(cid), 13)
				setPlayerStorageValue(cid,mage_outfit_storage,1)
					if getPlayerSex(cid) == 1 then 
						doPlayerAddOutfit(cid, 129, 1)
					elseif getPlayerSex(cid) == 0 then
						doPlayerAddOutfit(cid, 137, 2)
					end
			else
			npcHandler:say(sem_2_msg, cid)
			end	
		else 
			npcHandler:say("Error msg:  your talkstate is: "..talkState[talkUser].."", cid)
		end
	end
	
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top