Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,426
- Solutions
- 68
- Reaction score
- 1,075
I am trying to make it so when I return false in my greet callback the npc will still greet the player with the message I determine but it will not focus or release the focus of the player after doing so.
Lines 8-11 29-31 handle when the npcs shouldn't keep its focus on the player after sending the greet message. The releaseFocus doesn't work I am sure because it hasn't handled the code related to adding the player into its focus table. I want to be able to just return false on the greetCallback to make it work.
The code is probably somewhere in the following but I can't seem to figure it out.
LUA:
function greetCallback(cid)
local player = Player(cid)
if not player then return true end
local language = player:getLanguage()
local storage = player:getStorageValue(STORAGE_TUTORIAL_QUEST)
local res = greetMessages[language][storage]
if not res then
npcHandler:setMessage(MESSAGE_GREET, greetMessages[player:getLanguage()][-2].msg)
return false
end
if res.items then
for i = 1, #res.items do
player:addItem(res.items[i][1], res.items[i][2] or 1)
end
if res.giveItemMessage then
player:sendTextMessage(MESSAGE_INFO_DESCR, res.giveItemMessage)
end
end
if res.setStorage then
player:setStorageValue(res.setStorage[1], res.setStorage[2])
end
npcHandler:setMessage(MESSAGE_GREET, parseStringForKeywords(res.msg, {'|NAME|'}, {player:getName()}))
if res.noFocus then
return false
end
npcHandler:addFocus(cid)
npcHandler.topic[cid] = 1
return true
end
Lines 8-11 29-31 handle when the npcs shouldn't keep its focus on the player after sending the greet message. The releaseFocus doesn't work I am sure because it hasn't handled the code related to adding the player into its focus table. I want to be able to just return false on the greetCallback to make it work.
The code is probably somewhere in the following but I can't seem to figure it out.
LUA:
function NpcHandler:processModuleCallback(id, ...)
local ret = true
for i, module in pairs(self.modules) do
local tmpRet = true
if id == CALLBACK_CREATURE_APPEAR and module.callbackOnCreatureAppear then
tmpRet = module:callbackOnCreatureAppear(...)
elseif id == CALLBACK_CREATURE_DISAPPEAR and module.callbackOnCreatureDisappear then
tmpRet = module:callbackOnCreatureDisappear(...)
elseif id == CALLBACK_CREATURE_SAY and module.callbackOnCreatureSay then
tmpRet = module:callbackOnCreatureSay(...)
elseif id == CALLBACK_PLAYER_ENDTRADE and module.callbackOnPlayerEndTrade then
tmpRet = module:callbackOnPlayerEndTrade(...)
elseif id == CALLBACK_PLAYER_CLOSECHANNEL and module.callbackOnPlayerCloseChannel then
tmpRet = module:callbackOnPlayerCloseChannel(...)
elseif id == CALLBACK_ONBUY and module.callbackOnBuy then
tmpRet = module:callbackOnBuy(...)
elseif id == CALLBACK_ONSELL and module.callbackOnSell then
tmpRet = module:callbackOnSell(...)
elseif id == CALLBACK_ONTRADEREQUEST and module.callbackOnTradeRequest then
tmpRet = module:callbackOnTradeRequest(...)
elseif id == CALLBACK_ONADDFOCUS and module.callbackOnAddFocus then
tmpRet = module:callbackOnAddFocus(...)
elseif id == CALLBACK_ONRELEASEFOCUS and module.callbackOnReleaseFocus then
tmpRet = module:callbackOnReleaseFocus(...)
elseif id == CALLBACK_ONTHINK and module.callbackOnThink then
tmpRet = module:callbackOnThink(...)
elseif id == CALLBACK_GREET and module.callbackOnGreet then
tmpRet = module:callbackOnGreet(...)
elseif id == CALLBACK_FAREWELL and module.callbackOnFarewell then
tmpRet = module:callbackOnFarewell(...)
elseif id == CALLBACK_MESSAGE_DEFAULT and module.callbackOnMessageDefault then
tmpRet = module:callbackOnMessageDefault(...)
elseif id == CALLBACK_MODULE_RESET and module.callbackOnModuleReset then
tmpRet = module:callbackOnModuleReset(...)
end
if not tmpRet then
ret = false
break
end
end
return ret
end
LUA:
-- Greets a new player.
function NpcHandler:greet(cid)
if cid ~= 0 then
local callback = self:getCallback(CALLBACK_GREET)
if not callback or callback(cid) then
if self:processModuleCallback(CALLBACK_GREET, cid) then
local msg = self:getMessage(MESSAGE_GREET)
local player = Player(cid)
local playerName = player and player:getName() or -1
local parseInfo = { [TAG_PLAYERNAME] = playerName }
msg = self:parseMessage(msg, parseInfo)
self:say(msg, cid, true)
else
return
end
else
return
end
end
self:addFocus(cid)
end