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
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local player = Player(cid)
local t = {"Venore", "Thais"}
local modalWindow = ModalWindow(333, "Travel list", "Pick your destination:")
for i = 1, #t do
modalWindow:addChoice(i, t[i])
end
modalWindow:addButton(1, "Select")
modalWindow:setDefaultEnterButton(1)
modalWindow:addButton(2, "Cancel")
modalWindow:setDefaultEscapeButton(2)
if isInArray({"travel", "sail"}, msg:lower()) then
modalWindow:sendToPlayer(player)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
local config = {
[1] = Position({x =1000, y = 1000, z = 7}), -- Venore
[2] = Position({x = 1000, y = 1000, z = 7}) -- Thais
}
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
if modalWindowId ~= 333 or buttonId == 2 then
return false
end
local player = Player(cid)
local position = config[choiceId]
if not position then
return true
end
player:teleportTo(position)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
return true
end
It's a creaturescript.What is the second script? Creaturescript?
<event type="modalwindow" name="eventName" script="scriptname.lua"/>
player:registerEvent("eventName")
NPC
creaturescriptCode: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 function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local player = Player(cid) local t = {"Venore", "Thais"} local modalWindow = ModalWindow(333, "Travel list", "Pick your destination:") for i = 1, #t do modalWindow:addChoice(i, t[i]) end modalWindow:addButton(1, "Select") modalWindow:setDefaultEnterButton(1) modalWindow:addButton(2, "Cancel") modalWindow:setDefaultEscapeButton(2) if isInArray({"travel", "sail"}, msg:lower()) then modalWindow:sendToPlayer(player) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
Code:local config = { [1] = Position({x =1000, y = 1000, z = 7}), -- Venore [2] = Position({x = 1000, y = 1000, z = 7}) -- Thais } function onModalWindow(cid, modalWindowId, buttonId, choiceId) if modalWindowId ~= 333 or buttonId == 2 then return false end local player = Player(cid) local position = config[choiceId] if position == nil then return true end player:teleportTo(position) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) return true end