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

phern

alysiaots.com
Joined
Nov 2, 2008
Messages
195
Reaction score
2
Location
Poland
Hello, I tried to set NPC greetings to be different if player has certain storage, but I couldnt find the solution <_<
For example, if NPC greets player for the first time, it says "hello xxx, i got {task} foe you", and if player arleady took the task, it says "are you {done} yet?"

I would be really gratefull if someone could give me idea how to make it.

Thank you in advance.
 
Lua:
function greetCallback(cid)
	if getPlayerStorageValue(cid, XXXXX) == Y then
		npcHandler:setMessage(MESSAGE_GREET, "xDd")
	elseif getPlayerStorageValue(cid, YYYY) == Z then
		npcHandler:setMessage(MESSAGE_GREET, "xP :P")
	else
		npcHandler:setMessage(MESSAGE_GREET, "xdd")
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
Well, I did what you told me, but it still says "13:27 Kalahan: Welcome, Test Two! I have been expecting you."

code:
Code:
  local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions 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 

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

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if (not npcHandler:isFocused(cid)) then
        return false
   end
        

function greetCallback(cid)
	if getPlayerStorageValue(cid, 60452) == -1 then
		npcHandler:setMessage(MESSAGE_GREET, "xDd")
	elseif getPlayerStorageValue(cid, 60452) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "xP :P")
	else
		npcHandler:setMessage(MESSAGE_GREET, "xdd")
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)

      
       if(msgcontains(msg, 'yes')) and getPlayerStorageValue(cid, 60452) == -1 then


local msgs={ 
            "Thank you, kid. I am really tired, and I feel that there is not much time for me left, but still- I have to eat something. There are many rabbits nearby, but I am too old to hunt them. I still got some savings, so if you bring me 5 pieces of {meat} and I will reward you.", 
            
            "Ohh my poor hip...",  
            } 
      doNPCTalkALot(msgs,9000) --if the 2750 is ommited, it uses 3000 always 
doPlayerSetStorageValue(cid,60452, 1)





---------------------------------------------------------
elseif msgcontains(msg, 'meat') or msgcontains(msg, 'yes') or msgcontains(msg, 'help') and getPlayerStorageValue(cid, 60452) == 1 then
if(doPlayerRemoveItem(cid, 2666, 5) == TRUE) then

setPlayerStorageValue(cid,60452,2)
doPlayerAddExperience(cid,1000)
doPlayerAddItem(cid, 2152, 10)
doPlayerSendTextMessage(cid, 22, "1000 exp gained.")

selfSay('Thank you my dear. I really appreciate it. Here is 1000 gold coins. I really hope, that gods saw your good deed and rewarded you aswell. You can bring me as many food as you can, I will reward you each time.', cid)
else
selfSay('Please bring me some food. I am starving.', cid)
          
 
end
end

        ------------------------------------------------ confirm no ------------------------------------------------
       
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end




npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It shouldn't be inside message callback, try:
Code:
  local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions 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 

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

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if (not npcHandler:isFocused(cid)) then
        return false
   end
      
       if(msgcontains(msg, 'yes')) and getPlayerStorageValue(cid, 60452) == -1 then


local msgs={ 
            "Thank you, kid. I am really tired, and I feel that there is not much time for me left, but still- I have to eat something. There are many rabbits nearby, but I am too old to hunt them. I still got some savings, so if you bring me 5 pieces of {meat} and I will reward you.", 
            
            "Ohh my poor hip...",  
            } 
      doNPCTalkALot(msgs,9000) --if the 2750 is ommited, it uses 3000 always 
doPlayerSetStorageValue(cid,60452, 1)





---------------------------------------------------------
elseif msgcontains(msg, 'meat') or msgcontains(msg, 'yes') or msgcontains(msg, 'help') and getPlayerStorageValue(cid, 60452) == 1 then
if(doPlayerRemoveItem(cid, 2666, 5) == TRUE) then

setPlayerStorageValue(cid,60452,2)
doPlayerAddExperience(cid,1000)
doPlayerAddItem(cid, 2152, 10)
doPlayerSendTextMessage(cid, 22, "1000 exp gained.")

selfSay('Thank you my dear. I really appreciate it. Here is 1000 gold coins. I really hope, that gods saw your good deed and rewarded you aswell. You can bring me as many food as you can, I will reward you each time.', cid)
else
selfSay('Please bring me some food. I am starving.', cid)
          
 
end
end

        ------------------------------------------------ confirm no ------------------------------------------------
       
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

function greetCallback(cid)
	if getPlayerStorageValue(cid, 60452) == -1 then
		npcHandler:setMessage(MESSAGE_GREET, "xDd")
	elseif getPlayerStorageValue(cid, 60452) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "xP :P")
	else
		npcHandler:setMessage(MESSAGE_GREET, "xdd")
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top