• 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.X+ ModalWindow not executing functions

jakub742

Member
Joined
May 1, 2010
Messages
144
Solutions
2
Reaction score
20
Location
Slovakia
Hi, Im using Nekiro's latest tfs 7.72 downgrade and im trying out modal windows. I have ModalWindowHelper i tried several code examples that i could find here but it just wont works.

Modal window will show up but when i click on the button nothing happens. Tested with otclientv8 and otclient. There is no error in server log either.
I dont know where is the problem. If i use just a simple print or send message to a player in button function nothing happens.

I tried basic example from ModalWindowHelper lib, also this Help with modalwindow and buy premium by modal window, tried the tapestry modal buy, nothing works.
 
Last edited:
Solution
Yes i get the modal window buttons options everything as u just nothing happened.
function onWaypointsModal(player, modalWindowId, buttonId, choiceId) wont be executed tried to print text at first line of the function and nothing.

Today i also tried pulling the latest 772 branch, uncommented code in game.cpp compiled tried everything again from scratch just with the modals but same thing. Im desperate no errors i cant figure out how it works for u and not for me lul :D
Try uncoment also this in protocolgame.cpp :
C++:
case 0xF9: parseModalWindowAnswer(msg); break;
If that's doesn't help you, im sure you done something wrong then xD
I'm pretty sure that you guys still need to add the source code part responsible for modal windows, back to tfs in order for it to work, a lib file alone will not make it work as both of you noticed
 
I'm pretty sure that you guys still need to add the source code part responsible for modal windows, back to tfs in order for it to work, a lib file alone will not make it work as both of you noticed
I was checking the sources and there are parts of code that contains modal window and event for creaturescript.

creatureevent.cpp
1650898383087.png
Also function
void CreatureEvent::executeModalWindow(Player* player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId)
Modal functions also in game.cpp

Idk what else do i need. The downgrade repo is here
 
show
Lua:
playerAnswerModalWindow
in game.cpp

C:
void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice)
{
    Player* player = getPlayerByID(playerId);
    if (!player) {
        return;
    }
    if (!player->hasModalWindowOpen(modalWindowId)) {
        return;
    }
    player->onModalWindowHandled(modalWindowId);
    // offline training, hard-coded
    /*if (modalWindowId == std::numeric_limits<uint32_t>::max()) {
        if (button == offlineTrainingWindow.defaultEnterButton) {
            if (choice == SKILL_SWORD || choice == SKILL_AXE || choice == SKILL_CLUB || choice == SKILL_DISTANCE || choice == SKILL_MAGLEVEL) {
                BedItem* bedItem = player->getBedItem();
                if (bedItem && bedItem->sleep(player)) {
                    player->setOfflineTrainingSkill(choice);
                    return;
                }
            }
        } else {
            player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Offline training aborted.");
        }
        player->setBedItem(nullptr);
    } else {
        for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
            creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
        }
    }
    */
    for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
        creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
    }
}
 
C:
void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice)
{
    Player* player = getPlayerByID(playerId);
    if (!player) {
        return;
    }
    if (!player->hasModalWindowOpen(modalWindowId)) {
        return;
    }
    player->onModalWindowHandled(modalWindowId);
    // offline training, hard-coded
    /*if (modalWindowId == std::numeric_limits<uint32_t>::max()) {
        if (button == offlineTrainingWindow.defaultEnterButton) {
            if (choice == SKILL_SWORD || choice == SKILL_AXE || choice == SKILL_CLUB || choice == SKILL_DISTANCE || choice == SKILL_MAGLEVEL) {
                BedItem* bedItem = player->getBedItem();
                if (bedItem && bedItem->sleep(player)) {
                    player->setOfflineTrainingSkill(choice);
                    return;
                }
            }
        } else {
            player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Offline training aborted.");
        }
        player->setBedItem(nullptr);
    } else {
        for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
            creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
        }
    }
    */
    for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
        creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
    }
}
I just uncommented and compiled. I'm not sure if that's a fix but now it's working for me :p
 
Modal windows are supported since tibia 8.4 or something like that, on 7.7 protocol they were not available on cip client.
If you want to use them you have to do what @dewral did.
alright thanks im using otclient so its fine.
Post automatically merged:

I just uncommented and compiled. I'm not sure if that's a fix but now it's working for me :p
just did the same. But its not working for me 😭

Code:
void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice)
{
    Player* player = getPlayerByID(playerId);
    if (!player) {
        return;
    }
    if (!player->hasModalWindowOpen(modalWindowId)) {
        return;
    }
    player->onModalWindowHandled(modalWindowId);
    // offline training, hard-coded
    if (modalWindowId == std::numeric_limits<uint32_t>::max()) {
        if (button == offlineTrainingWindow.defaultEnterButton) {
            if (choice == SKILL_SWORD || choice == SKILL_AXE || choice == SKILL_CLUB || choice == SKILL_DISTANCE || choice == SKILL_MAGLEVEL) {
                BedItem* bedItem = player->getBedItem();
                if (bedItem && bedItem->sleep(player)) {
                    player->setOfflineTrainingSkill(choice);
                    return;
                }
            }
        } else {
            player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Offline training aborted.");
        }
        player->setBedItem(nullptr);
    } else {
        for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
            creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
        }
    }
    
    for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
        creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
    }
}
Post automatically merged:

I tried adding
Code:
 player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Executing playerAnswerModalWindow");
after Player* player = getPlayerByID(playerId); to test if the function actually gets executed and no output or error message followed so after i click on button in ModalWindow nothing happens. Function wont be executed. Idk why 😫
 
Last edited:
alright thanks im using otclient so its fine.
Post automatically merged:


just did the same. But its not working for me 😭

Code:
void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice)
{
    Player* player = getPlayerByID(playerId);
    if (!player) {
        return;
    }
    if (!player->hasModalWindowOpen(modalWindowId)) {
        return;
    }
    player->onModalWindowHandled(modalWindowId);
    // offline training, hard-coded
    if (modalWindowId == std::numeric_limits<uint32_t>::max()) {
        if (button == offlineTrainingWindow.defaultEnterButton) {
            if (choice == SKILL_SWORD || choice == SKILL_AXE || choice == SKILL_CLUB || choice == SKILL_DISTANCE || choice == SKILL_MAGLEVEL) {
                BedItem* bedItem = player->getBedItem();
                if (bedItem && bedItem->sleep(player)) {
                    player->setOfflineTrainingSkill(choice);
                    return;
                }
            }
        } else {
            player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Offline training aborted.");
        }
        player->setBedItem(nullptr);
    } else {
        for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
            creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
        }
    }
   
    for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) {
        creatureEvent->executeModalWindow(player, modalWindowId, button, choice);
    }
}
Post automatically merged:

I tried adding
Code:
 player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Executing playerAnswerModalWindow");
after Player* player = getPlayerByID(playerId); to test if the function actually gets executed and no output or error message followed so after i click on button in ModalWindow nothing happens. Function wont be executed. Idk why 😫

Try using this script - MoveEvent - [TFS 1.X] Waypoints like in Diablo (https://otland.net/threads/tfs-1-x-waypoints-like-in-diablo.263655/)
 
Yes, im using tfs 772 nekiro's
For me it's working good as you can see here
ezgif-4-027d582810.gif

Are you sure you registered everything right?
 
Yes, im using tfs 772 nekiro's
For me it's working good as you can see here
ezgif-4-027d582810.gif

Are you sure you registered everything right?
Yes i get the modal window buttons options everything as u just nothing happened.
function onWaypointsModal(player, modalWindowId, buttonId, choiceId) wont be executed tried to print text at first line of the function and nothing.

Today i also tried pulling the latest 772 branch, uncommented code in game.cpp compiled tried everything again from scratch just with the modals but same thing. Im desperate no errors i cant figure out how it works for u and not for me lul :D
 
Yes i get the modal window buttons options everything as u just nothing happened.
function onWaypointsModal(player, modalWindowId, buttonId, choiceId) wont be executed tried to print text at first line of the function and nothing.

Today i also tried pulling the latest 772 branch, uncommented code in game.cpp compiled tried everything again from scratch just with the modals but same thing. Im desperate no errors i cant figure out how it works for u and not for me lul :D
Try uncoment also this in protocolgame.cpp :
C++:
case 0xF9: parseModalWindowAnswer(msg); break;
If that's doesn't help you, im sure you done something wrong then xD
 
Solution
Try uncoment also this in protocolgame.cpp :
C++:
case 0xF9: parseModalWindowAnswer(msg); break;
If that's doesn't help you, im sure you done something wrong then xD
I uncommented what u said there was compilation error, because of that i found out that function
Code:
void ProtocolGame::parseModalWindowAnswer(NetworkMessage& msg)
was commented out so i uncommented the function recompiled and now its working. Thanks for the help mate ;) I really appreciate it
 
Back
Top