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

[How-to] Modal Windows

Sometimes I have to put so many text on the window so It misses some words because it doesn't update the size to fits them all. Is there any way to change or solve this?
 
Last edited:
how to make it so that an item is required to get the tapestrys?

You can adjust the rules in the creature script by checking to make sure they have the required item before giving them a tapestry:

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}
    local requiredItem = 2157 -- id for gold nuggets
    local requiredCount = 10

    if modalWindowId == 1000 then
        if buttonId == 100 then
            if player:getItemCount(requiredItem) >= requiredCount then
                player:addItem(tapestry[choiceId], 1)
            else
                player:sendCancelMessage('Sorry, you need 10 gold nuggets to buy this tapestry.')
            end
        end
    end
end

If you wanted to make a different required item for each tapestry it would a nice idea to make a table and then use loops to make it shorter and easier to edit.

--------------------------------------------------------------------------

Sometimes I have to put so many text on the window so It misses some words because it doesn't update the size to fits them all. Is there any way to change or solve this?

You can make the screen longer by making the message longer:

Code:
local message = "----------------------------------- You get a free tapestry in the color of your choice! --------------------------------"
local window = ModalWindow(1000, title, message)
 
one more question how to make an npc pop up a model window

You can use it as a function:
Code:
local function sendModalWindowToPlayer(player)
   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)
end

Then in your NPC Script wherever you want to use it you can just use the function for the window:
Code:
sendModalWindowToPlayer(player)
 
i tried to loop it like this dont seem to do anything tho

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
  player:unregisterEvent("Supply")
  local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}
  local requiredItem = 2157 -- id for gold nuggets
  local requiredCount = 10

  if modalWindowId == 1000 then
  if buttonId == 100 then
  if player:getItemCount(requiredItem) >= requiredCount then
  player:addItem(tapestry[choiceId], 1)
         player:removeItem(2157, 10)
  else
  player:sendCancelMessage('Sorry, you need 10 gold nuggets to buy this tapestry.')
  end
   elseif modalWindowId == 1000 then
         if buttonId == 100 then
         if choiceId == 2 then
         if player:getItemCount(requiredItem) >= requiredCount then
  player:addItem(tapestry[choiceId], 2)
         player:removeItem(2157, 30)
  else
  player:sendCancelMessage('Sorry, you need 10 gold nuggets to buy this tapestry.')
  end
  end
  end
end
 
i tried to loop it like this dont seem to do anything tho

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
  player:unregisterEvent("Supply")
  local tapestry = {1869, 1866, 1863, 1860, 1872, 1857}
  local requiredItem = 2157 -- id for gold nuggets
  local requiredCount = 10

  if modalWindowId == 1000 then
  if buttonId == 100 then
  if player:getItemCount(requiredItem) >= requiredCount then
  player:addItem(tapestry[choiceId], 1)
         player:removeItem(2157, 10)
  else
  player:sendCancelMessage('Sorry, you need 10 gold nuggets to buy this tapestry.')
  end
   elseif modalWindowId == 1000 then
         if buttonId == 100 then
         if choiceId == 2 then
         if player:getItemCount(requiredItem) >= requiredCount then
  player:addItem(tapestry[choiceId], 2)
         player:removeItem(2157, 30)
  else
  player:sendCancelMessage('Sorry, you need 10 gold nuggets to buy this tapestry.')
  end
  end
  end
end

Sorry I shouldn't have said loop, actually I meant we can re-structure the table so that it's more dynamic now and we're able to keep our code short and neat!

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestries = {
        {tapestryId = 1869, requiredItemId = 2157, requiredItemCount = 55},
        {tapestryId = 1866, requiredItemId = 2160, requiredItemCount = 88},
        {tapestryId = 1863, requiredItemId = 2152, requiredItemCount = 4},
        {tapestryId = 1860, requiredItemId = 2148, requiredItemCount = 15},
        {tapestryId = 1872, requiredItemId = 2157, requiredItemCount = 5},
        {tapestryId = 1857, requiredItemId = 2157, requiredItemCount = 11}
    }

    if modalWindowId == 1000 then
        if buttonId == 100 then
            local selection = tapestries[choiceId]
            if not selection then
                return player:sendCancelMessage('[ERROR]: Sorry, your selection was not found.')
            end
            if player:getItemCount(selection.requiredItemId) >= selection.requiredItemCount then
                player:addItem(selection.tapestryId, 1)
            else
                player:sendCancelMessage('Sorry, you need ' .. selection.requiredItemCount .. ' ' .. ItemType(selection.requiredItemId):getPluralName() .. ' to buy a ' .. ItemType(selection.tapestryId):getName() .. '.')
            end
        end
    end
end
 
Sorry I shouldn't have said loop, actually I meant we can re-structure the table so that it's more dynamic now and we're able to keep our code short and neat!

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_Tutorial")
    local tapestries = {
        {tapestryId = 1869, requiredItemId = 2157, requiredItemCount = 55},
        {tapestryId = 1866, requiredItemId = 2160, requiredItemCount = 88},
        {tapestryId = 1863, requiredItemId = 2152, requiredItemCount = 4},
        {tapestryId = 1860, requiredItemId = 2148, requiredItemCount = 15},
        {tapestryId = 1872, requiredItemId = 2157, requiredItemCount = 5},
        {tapestryId = 1857, requiredItemId = 2157, requiredItemCount = 11}
    }

    if modalWindowId == 1000 then
        if buttonId == 100 then
            local selection = tapestries[choiceId]
            if not selection then
                return player:sendCancelMessage('[ERROR]: Sorry, your selection was not found.')
            end
            if player:getItemCount(selection.requiredItemId) >= selection.requiredItemCount then
                player:addItem(selection.tapestryId, 1)
            else
                player:sendCancelMessage('Sorry, you need ' .. selection.requiredItemCount .. ' ' .. ItemType(selection.requiredItemId):getPluralName() .. ' to buy a ' .. ItemType(selection.tapestryId):getName() .. '.')
            end
        end
    end
end
ahh ok thanks
 
You said it does only work with tfs 1.0 and 9.7 or higher..
I know because this only exist since tfs 1.0 and prob only since client 9.7...
But what if I used ninjalulz downgrade of tfs 1.2 for the 8.6 client with otclient as my client, would it work or would I still have to make adjustments?
 
Can i used it on tibia 8.54 ? Need this :
ad367be59e3493ccb215ca7e19f8af62.gif
 
Guys, is there any way to change the background color and button styles? Thank you!
 
Back
Top