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

[TFS 1.0] Travel NPC using modalWindow

Rith

New Member
Joined
Jun 14, 2007
Messages
176
Reaction score
0
Is it possible to use modalWindow in npc script? Anyone want share small example?
 
No, not really. At least not in the Cipsoft Tibia client. The only window is the FYI window which displays some text with an OK button. But it should be relatively easy to set up in OTClient.

You could also try dll-injection to build your own GUI in the Cipsoft Tibia client. But I believe that's pretty complicated.

I'm very sorry about the misinformation.
 
Last edited:
NPC
Code:
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())
creaturescript
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 not position then
        return true
    end

    player:teleportTo(position)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Last edited:
How to name and declare the creaturescript file? So far i was only content developer and i'll need 101 guide how to set up the script ;D
 
creaturescripts.xml
Code:
<event type="modalwindow" name="eventName" script="scriptname.lua"/>
login.lua
Code:
player:registerEvent("eventName")
 
I can't get this to work. the window pops up, but when I click OK it doesn't teleport me.

Do you need Open Tibia Client for this?
 
NPC
Code:
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())
creaturescript
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


-hugs-
 
Back
Top