• 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 working on tfs 1.4

Darekzio

New Member
Joined
Apr 26, 2024
Messages
12
Reaction score
0
hi, can someone explain why this not working? and how i can fix it


LUA:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("ModalWindow_Tutorial")
 
    local title = "Pick your favorite color!"
    local message = "You get a free tapestry in the color of your choice!"
 
    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")
 
    window:addChoice(1, "Red")
    window:addChoice(2, "Orange")
    window:addChoice(3, "Yellow")
    window:addChoice(4, "Green")
    window:addChoice(5, "Blue")
    window:addChoice(6, "Purple")
 
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
 
    window:sendToPlayer(player)
    return true
end

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}
 
    if modalWindowId == 1000 then
        if buttonId == 100 then
            player:addItem(tapestry[choiceId], 1)
        end
    end
end


the function onModalWindow doesn't work
 
the function onModalWindow doesn't work
Of course, onModalWindow is working, but you did it the wrong way. onModalWindow is for CreatureScript and not for 'action'. Alternatively, you can create a single script like in RevScript.

data/scripts.
LUA:
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    player:registerEvent("ModalWindow_Tutorial")

    local title = "Pick your favorite color!"
    local message = "You get a free tapestry in the color of your choice!"

    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")

    window:addChoice(1, "Red")
    window:addChoice(2, "Orange")
    window:addChoice(3, "Yellow")
    window:addChoice(4, "Green")
    window:addChoice(5, "Blue")
    window:addChoice(6, "Purple")

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)

    window:sendToPlayer(player)
    return true
end
testAction:id(8301) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed

local creatureevent = CreatureEvent("ModalWindow_Tutorial")

function creatureevent.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}

    if modalWindowId == 1000 then
        if buttonId == 100 then
            player:addItem(tapestry[choiceId], 1)
        end
    end
end
creatureevent:register()

If you are not familiar with RevScript, that is understandable. Let me explain how onModalWindow functions. You should separate the functions as follows: place onUse in data/actions and onModalWindow in data/creaturescript. I will demonstrate this to you.

XML:
    <action itemid="xxx" script="test.lua" />
LUA:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("ModalWindow_Tutorial")
 
    local title = "Pick your favorite color!"
    local message = "You get a free tapestry in the color of your choice!"
 
    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")
 
    window:addChoice(1, "Red")
    window:addChoice(2, "Orange")
    window:addChoice(3, "Yellow")
    window:addChoice(4, "Green")
    window:addChoice(5, "Blue")
    window:addChoice(6, "Purple")
 
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
 
    window:sendToPlayer(player)
    return true
end

XML:
<event type="modalwindow" name="test" script="test.lua"/>
LUA:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}
 
    if modalWindowId == 1000 then
        if buttonId == 100 then
            player:addItem(tapestry[choiceId], 1)
        end
    end
end

It would be good if you took a look at this tutorial
 
Last edited:
Of course, onModalWindow is working, but you did it the wrong way. onModalWindow is for CreatureScript and not for 'action'. Alternatively, you can create a single script like in RevScript.

data/scripts.
LUA:
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    player:registerEvent("ModalWindow_Tutorial")

    local title = "Pick your favorite color!"
    local message = "You get a free tapestry in the color of your choice!"

    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")

    window:addChoice(1, "Red")
    window:addChoice(2, "Orange")
    window:addChoice(3, "Yellow")
    window:addChoice(4, "Green")
    window:addChoice(5, "Blue")
    window:addChoice(6, "Purple")

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)

    window:sendToPlayer(player)
    return true
end
testAction:id(8301) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed

local creatureevent = CreatureEvent("ModalWindow_Tutorial")

function creatureevent.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}

    if modalWindowId == 1000 then
        if buttonId == 100 then
            player:addItem(tapestry[choiceId], 1)
        end
    end
end
creatureevent:register()

If you are not familiar with RevScript, that is understandable. Let me explain how onModalWindow functions. You should separate the functions as follows: place onUse in data/actions and onModalWindow in data/creaturescript. I will demonstrate this to you.

XML:
    <action itemid="xxx" script="test.lua" />
LUA:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("ModalWindow_Tutorial")
 
    local title = "Pick your favorite color!"
    local message = "You get a free tapestry in the color of your choice!"
 
    local window = ModalWindow(1000, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")
 
    window:addChoice(1, "Red")
    window:addChoice(2, "Orange")
    window:addChoice(3, "Yellow")
    window:addChoice(4, "Green")
    window:addChoice(5, "Blue")
    window:addChoice(6, "Purple")
 
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
 
    window:sendToPlayer(player)
    return true
end

XML:
<event type="modalwindow" name="test" script="test.lua"/>
LUA:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}
 
    if modalWindowId == 1000 then
        if buttonId == 100 then
            player:addItem(tapestry[choiceId], 1)
        end
    end
end

It would be good if you took a look at this tutorial
Still not working, after choosen red or other thing i do not receive anything
 
I have problems too, I can't do it that way, I have to do it this way
I found a way to do it, but when I do a lot of rescripts, it doesn't work for me, it only works this way with the ids 1000, 1001 and 2000

The way is this:

Code:
local mainMenuConfig = {
    modalWindow = {
        id = 2000,
        title = "Main Menu",
        message = "Choose an item to craft:",
        eventText = "ModalWindow_MainMenu",
        buttons = {
            {text = "Select", defaultEnterButton = true},
            {text = "Back", defaultEscapeButton = true},
        },
        options = {
            {name = "Iron bar", levelRequired = 1},
            {name = "Bad quality red iron bar", levelRequired = 80},
            {name = "Red iron bar", levelRequired = 150},
            {name = "Adamantium bar", levelRequired = 200},
        }
    }
}

The other way the screen opens too, but the buttons or any action don't work. I need help too maybe is a problem for tfs 1.4 and 1.4.2
 
I have problems too, I can't do it that way, I have to do it this way
I found a way to do it, but when I do a lot of rescripts, it doesn't work for me, it only works this way with the ids 1000, 1001 and 2000

The way is this:

Code:
local mainMenuConfig = {
    modalWindow = {
        id = 2000,
        title = "Main Menu",
        message = "Choose an item to craft:",
        eventText = "ModalWindow_MainMenu",
        buttons = {
            {text = "Select", defaultEnterButton = true},
            {text = "Back", defaultEscapeButton = true},
        },
        options = {
            {name = "Iron bar", levelRequired = 1},
            {name = "Bad quality red iron bar", levelRequired = 80},
            {name = "Red iron bar", levelRequired = 150},
            {name = "Adamantium bar", levelRequired = 200},
        }
    }
}

The other way the screen opens too, but the buttons or any action don't work. I need help too maybe is a problem for tfs 1.4 and 1.4.2
every modal window needs to have a unique id.

If you have 4 scripts creating modal windows with id 2000, only 1 of them would work properly.
The other one's might appear to work, but incorrectly, or not work at all.

So solution here is to make sure all your modal windows have unique id.
1000, 1001, 1002, 1003, 1004..
 
I found the problem in event conflicts event Text = "ModalWindow_MainMenu", I had repeated it in several scripts... xDI
This is where they are registered and identified.

Artificial Intelligence Racing GIF by Roborace
 
I found the problem in event conflicts event Text = "ModalWindow_MainMenu", I had repeated it in several scripts... xDI
This is where they are registered and identified.

Artificial Intelligence Racing GIF by Roborace

The modal window event is registered to the player, triggering it for them.
If you have 4 scripts that register 4 different modal window events, all 4 of those events are still going to trigger every time a modal window is created / used.

The only way to separate the logic of the modal windows is with their id.
(so technically you could just have 1 modal window event that controls the logic for all of your modal windows. 🤷‍♂️)
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId == 1000 then

But yeah, if you're registering and deregistering the events immediately, maybe you won't run into the issue?
Cuz only 1 event would be registered at a time.. so the modal window id would basically never be used?

idk lmao. xD

Kind of depends on the situation I guess.

gg on fixing the issue anyway. lol
 
Last edited by a moderator:
The modal window event is registered to the player, triggering it for them.
If you have 4 scripts that register 4 different modal window events, all 4 of those events are still going to trigger every time a modal window is created / used.

The only way to separate the logic of the modal windows is with their id.
(so technically you could just have 1 modal window event that controls the logic for all of your modal windows. 🤷‍♂️)
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId == 1000 then

But yeah, if you're registering and deregistering the events immediately, maybe you won't run into the issue?
Cuz only 1 event would be registered at a time.. so the modal window id would basically never be used?

idk lmao. xD

Kind of depends on the situation I guess.

gg on fixing the issue anyway. lol
Yes, need have to study the modal, because sometimes it does weird things, well, as long as you can adapt to it, it's the best xD
 
Back
Top