• 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+ Help with modalwindow

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
177
Location
Sweden
Hello, I need some help if anyone feel interested. Its suppose to work like this.
Player gets storage 50012 = 1, he can then click a item which opens up a modal window and depending on which storage he has access to he can choose, in this case 'asshole', if player clicks ok, its suppose to spawn dog in this code, however if you have access and click 'assholeN' its suppose to spawn a cat. I'm very unsure with this new TFS on how to send the functions and such, right now the script spawns a dog whether i click 'asshole' or 'assholeN'.

Here's my script:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- The helper lib is used by passing a table value to the ModalWindow function
local window = ModalWindow {
    title = 'Magic Mailbox: Choose your battle opponent!',
    message = 'Magic Mailbox:\nBelow are avaiable bosses shown for you to fight. Choose one and hit ok.'
}

local tppos = {x=1000, y=1000, z=7}
local pos = {x=1147, y=854, z=7}

if (getPlayerStorageValue(player, 50012) >= 1) then
local asshole = window:addChoice("asshole")
end
if (getPlayerStorageValue(player, 50013) >= 1) then
local assholeN = window:addChoice("assholeN")
end

-- Add a button with a specific callback
window:addButton('Ok',
    function(button, asshole, assholeN)
        if asshole then
            Game.createMonster("Dog", pos)
        elseif assholeN then
            Game.createMonster("Cat", pos)
        end
    end
)
-- Set this button as the default enter button
window:setDefaultEnterButton('Ok')

-- Add a button without a specific callback
window:addButton('Close')
window:setDefaultEscapeButton('Close')

-- If a button without a specific callback is pressed, this fucntion will be called
window:setDefaultCallback(
    function(button, choice)
    doTeleportThing(player, tppos)
    doSendMagicEffect(tppos, 11)
    doCreatureSay(player, "You denied your boss fight, pussy.", TALKTYPE_ORANGE_1)
    end
)

window:sendToPlayer(player)
end
 
Solution
the params for your callback are wrong
Lua:
function(button, choice)
    if choice.text == "asshole" then
        -- poop
    elseif choice.text == "assholeN" then
        -- poop 2
    end
end
the params for your callback are wrong
Lua:
function(button, choice)
    if choice.text == "asshole" then
        -- poop
    elseif choice.text == "assholeN" then
        -- poop 2
    end
end
 
Last edited:
Solution
Back
Top