guiismiti
Well-Known Member
- Joined
- May 19, 2014
- Messages
- 315
- Solutions
- 3
- Reaction score
- 68
Hello!
I am using a modal window on greet for ship travelling.
If the player is pz locked or doesn't have enough gold, the NPC needs to say it.
Problem - if I use selfSay or npcHandler:say inside the greet function, a random NPC will say those messages, and not the NPC the player is talking to.
Can anybody help, please?
I am using a modal window on greet for ship travelling.
If the player is pz locked or doesn't have enough gold, the NPC needs to say it.
Problem - if I use selfSay or npcHandler:say inside the greet function, a random NPC will say those messages, and not the NPC the player is talking to.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
local shipDestinations = {
["Ab'dendriel (130gp)"] = {
price = 130,
destinyPos = Position(32734, 31668, 6)
},
["Carlin (110gp)"] = {
price = 110,
destinyPos = Position(32387, 31820, 6)
},
["Thais (40gp)"] = {
price = 40,
destinyPos = Position(32310, 32210, 6)
},
["Venore (170gp)"] = {
price = 170,
destinyPos = Position(32954, 32022, 6)
}
}
local function greetCallback(cid)
local player = Player(cid)
if player:isPzLocked() then
npcHandler:say("You cannot travel in this condition.", cid)
return true
end
local window = ModalWindow{title = "Destinations", message = "Select a destination"}
for k, v in pairs(shipDestinations) do
window:addChoice(k)
end
window:addButton("Select", function(button, choice)
local chosenDestiny = shipDestinations[choice.text]
if not player:removeMoneyNpc(chosenDestiny.price) then
npcHandler:say("You don't have enough gold.", cid)
return true
else
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:teleportTo(chosenDestiny.destinyPos)
chosenDestiny.destinyPos:sendMagicEffect(CONST_ME_TELEPORT)
end
end)
window:setDefaultEnterButton("Select")
window:addButton("Cancel")
window:setDefaultEscapeButton("Cancel")
window:sendToPlayer(player)
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_GREET, "Welcome on board, Sir |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye. Recommend us if you were satisfied with our service.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye then.")
npcHandler:addModule(FocusModule:new())
Can anybody help, please?