• 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.3] [Revscriptsys] Easy to configure mount selling modal window

Lundrial

lundrial:getTitle()
Joined
Apr 15, 2014
Messages
142
Reaction score
103
Location
Chile
I was too lazy to include zones to tame mounts so I made a mount seller modal window via talkactions in revscriptsys, it may be useful for someone:
Features:
Doesn't show mounts you already own/don't have the items to get
Includes a list with all the mounts locked and what item/quantity it needs
Easy to add new mounts

make a .lua file on data/scripts/talkactions or wherever you want in scripts folder and add:
Lua:
local mounts = {
    [1] = {name = 'Widow Queen', id = 1, item = 13307, count = 2}, -- Self explanatory
    [2] = {name = 'Racing Bird', id = 2, item = 13298, count = 5},
}

local mount = TalkAction("!mount")
function mount.onSay(player, words, param)
    if param == "unlock" then
        player:registerEvent("Mount_Modal_Window")
        local title = "Mount Unlocker"
        local message = "List of available mounts to unlock:"
    
        local window = ModalWindow(1800, title, message)
        window:addButton(100, "Unlock")
        window:addButton(101, "Cancel")
    
        for i = 1, #mounts do
            if (player:getItemCount(mounts[i].item) >= mounts[i].count) and (not player:hasMount(mounts[i].id)) then
                window:addChoice(i,""..mounts[i].name)
            end
        end

        window:setDefaultEnterButton(100)
        window:setDefaultEscapeButton(101)
        
        window:sendToPlayer(player)
    elseif param == "list" then
        local list = "List of locked mounts and item needed:"
        for j = 1, #mounts do
            if not player:hasMount(mounts[j].id) then
                list = list ..'\n['.. mounts[j].name..'] \nItem: ' ..ItemType(mounts[j].item):getName() ..' x'..mounts[j].count
            end
        end
        player:showTextDialog(8977, list)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '\nMount Commands:\n!mount list -- Shows locked mounts\n!mount unlock -- Unlock mounts')
    end
    return false
end

mount:separator(" ")
mount:register()

local mountmodal = CreatureEvent("Mount_Modal_Window")
mountmodal:type("modalwindow")

function mountmodal.onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId == 1800 then
        if buttonId == 100 then
            if doPlayerRemoveItem(player, mounts[choiceId].item, mounts[choiceId].count) then
                player:addMount(mounts[choiceId].id)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ''.. mounts[choiceId].name ..' unlocked!')
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Couldn\'t unlock mount.')
            end
        end
    end
    player:unregisterEvent("Mount_Modal_Window")
    return true
end

mountmodal:register()

Pics:
1580355629227.png
1580355652064.png

1580355700552.png

1580355726943.png
 
@Lundrial when you put !mount unlock and you dont have the items it show this:

Lua Script Error: [Scripts Interface]
/server/data/scripts/mount.lua:callback
/server/data/scripts/mount.lua:50: attempt to index a nil value
stack traceback:
[C]: in function '__index'
/server/data/scripts/mount.lua:50: in function </server/data/scripts/mount.lua:47>

theres a way to put that you need items? Thank you for the script!!
 
@Lundrial when you put !mount unlock and you dont have the items it show this:

Lua Script Error: [Scripts Interface]
/server/data/scripts/mount.lua:callback
/server/data/scripts/mount.lua:50: attempt to index a nil value
stack traceback:
[C]: in function '__index'
/server/data/scripts/mount.lua:50: in function </server/data/scripts/mount.lua:47>

theres a way to put that you need items? Thank you for the script!!
could you give me the steps to reproduce it? I couldn't reproduce it on my test ot, maybe it's related to the client?
 
could you give me the steps to reproduce it? I couldn't reproduce it on my test ot, maybe it's related to the client?

It may happen for indices that are out of bounds. If a choice hasn't been selected (which is a possible scenario using your code), it will default to 0xFF (choiceId).
 
it happend when you write !mount unlock, and you dont have the items, if you dont have the items should not be the button unlock activated
 
show your script then, we can't help you without seeing anything
 
show your script then, we can't help you without seeing anything
local mounts = {
[1] = {name = 'Widow Queen', id = 1, item = 13307, count = 2}, -- Self explanatory
[2] = {name = 'Racing Bird', id = 2, item = 13298, count = 5},
}

local mount = TalkAction("!mount")
function mount.onSay(player, words, param)
if param == "unlock" then
player:registerEvent("Mount_Modal_Window")
local title = "Mount Unlocker"
local message = "List of available mounts to unlock:"

local window = ModalWindow(1800, title, message)
window:addButton(100, "Unlock")
window:addButton(101, "Cancel")

for i = 1, #mounts do
if (player:getItemCount(mounts.item) >= mounts.count) and (not player:hasMount(mounts.id)) then
window:addChoice(i,""..mounts.name)
end
end

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

window:sendToPlayer(player)
elseif param == "list" then
local list = "List of locked mounts and item needed:"
for j = 1, #mounts do
if not player:hasMount(mounts[j].id) then
list = list ..'\n['.. mounts[j].name..'] \nItem: ' ..ItemType(mounts[j].item):getName() ..' x'..mounts[j].count
end
end
player:showTextDialog(8977, list)
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '\nMount Commands:\n!mount list -- Shows locked mounts\n!mount unlock -- Unlock mounts')
end
return false
end

mount:separator(" ")
mount:register()

local mountmodal = CreatureEvent("Mount_Modal_Window")
mountmodal:type("modalwindow")

function mountmodal.onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId == 1800 then
if buttonId == 100 then
if doPlayerRemoveItem(player, mounts[choiceId].item, mounts[choiceId].count) then
player:addMount(mounts[choiceId].id)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ''.. mounts[choiceId].name ..' unlocked!')
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Couldn\'t unlock mount.')
end
end
end
player:unregisterEvent("Mount_Modal_Window")
return true
end

mountmodal:register()

the same from this topic...
 
@Lundrial Do you know how to change the script so the unlock button is not there when you dont have any items in ur inventory dosent show? Because if u click on "Unlock" when no button u get an error in console "
Lua Script Error: [Scripts Interface]
C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:callback
C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:51: attempt to index a nil value
stack traceback:
[C]: in function '__index'
C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:51: in function <C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:48>"
 

Attachments

@Lundrial Do you know how to change the script so the unlock button is not there when you dont have any items in ur inventory dosent show? Because if u click on "Unlock" when no button u get an error in console "
Lua Script Error: [Scripts Interface]
C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:callback
C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:51: attempt to index a nil value
stack traceback:
[C]: in function '__index'
C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:51: in function <C:\Ots\Server map\data\scripts\talkactions\Mountseller.lua:48>"
Here is my solution to the problem.

Untested
Lua:
local mounts = {
    [1] = {name = 'Widow Queen', id = 1, item = 13307, count = 2}, -- Self explanatory
    [2] = {name = 'Racing Bird', id = 2, item = 13298, count = 5},
}

local mount = TalkAction("!mount")
function mount.onSay(player, words, param)
    if param == "unlock" then
        player:registerEvent("Mount_Modal_Window")
        local title = "Mount Unlocker"
        local message = "List of available mounts to unlock:"
   
        local window = ModalWindow(1800, title, message)
        window:addButton(100, "Unlock")
        window:addButton(101, "Cancel")
   
        local mountsAvailable = 0
        local mountsAvailableForUnlock = 0
        for i = 1, #mounts do
            if not player:hasMount(mounts[i].id) then
                mountsAvailable = mountsAvailable + 1
                if player:getItemCount(mounts[i].item) >= mounts[i].count then
                    mountsAvailableForUnlock = mountsAvailableForUnlock + 1
                    window:addChoice(i,""..mounts[i].name)
                end
            end
        end
   
        window:setDefaultEnterButton(100)
        window:setDefaultEscapeButton(101)
       
        if mountsAvailableForUnlock > 0 then
            window:sendToPlayer(player)
        else
            local text = "There " .. (mountsAvailable > 0 and ("is " .. mountsAvailable .. " mount" .. (mountsAvailable > 1 and "s" or "")) or "are no more mounts") .. " available to unlock."
            text = text .. (mountsAvailable > 0 and "You do not have the required items in your inventory to unlock any of the mounts available." or "") .. ""
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
        end
    elseif param == "list" then
        local list = "List of locked mounts and item needed:"
        for j = 1, #mounts do
            if not player:hasMount(mounts[j].id) then
                list = list ..'\n['.. mounts[j].name..'] \nItem: ' ..ItemType(mounts[j].item):getName() ..' x'..mounts[j].count
            end
        end
        player:showTextDialog(8977, list)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '\nMount Commands:\n!mount list -- Shows locked mounts\n!mount unlock -- Unlock mounts')
    end
    return false
end

mount:separator(" ")
mount:register()

local mountmodal = CreatureEvent("Mount_Modal_Window")
mountmodal:type("modalwindow")

function mountmodal.onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId == 1800 then
        if buttonId == 100 then
            if doPlayerRemoveItem(player, mounts[choiceId].item, mounts[choiceId].count) then
                player:addMount(mounts[choiceId].id)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ''.. mounts[choiceId].name ..' unlocked!')
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Couldn\'t unlock mount.')
            end
        end
    end
    player:unregisterEvent("Mount_Modal_Window")
    return true
end

mountmodal:register()
 
Last edited:
Here is my solution to the problem.

Untested
Lua:
local mounts = {
    [1] = {name = 'Widow Queen', id = 1, item = 13307, count = 2}, -- Self explanatory
    [2] = {name = 'Racing Bird', id = 2, item = 13298, count = 5},
}

local mount = TalkAction("!mount")
function mount.onSay(player, words, param)
    if param == "unlock" then
        player:registerEvent("Mount_Modal_Window")
        local title = "Mount Unlocker"
        local message = "List of available mounts to unlock:"
   
        local window = ModalWindow(1800, title, message)
        window:addButton(100, "Unlock")
        window:addButton(101, "Cancel")
   
        local mountsAvailable = 0
        local mountsAvailableForUnlock = 0
        for i = 1, #mounts do
            if not player:hasMount(mounts[i].id)) then
                mountsAvailable = mountsAvailable + 1
                if player:getItemCount(mounts[i].item) >= mounts[i].count then
                    mountsAvailableForUnlock = mountsAvailableForUnlock + 1
                    window:addChoice(i,""..mounts[i].name)
                end
            end
        end
   
        window:setDefaultEnterButton(100)
        window:setDefaultEscapeButton(101)
       
        if mountsAvailableForUnlock > 0 then
            window:sendToPlayer(player)
        else
            local text = "There " .. (mountsAvailable > 0 and ("is " .. mountsAvailable .. " mount" .. (mountsAvailable > 1 and "s" or "")) or "are no more mounts") .. " available to unlock."
            text = text .. (mountsAvailable > 0 and "You do not have the required items in your inventory to unlock any of the mounts available." or "") .. ""
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
        end
    elseif param == "list" then
        local list = "List of locked mounts and item needed:"
        for j = 1, #mounts do
            if not player:hasMount(mounts[j].id) then
                list = list ..'\n['.. mounts[j].name..'] \nItem: ' ..ItemType(mounts[j].item):getName() ..' x'..mounts[j].count
            end
        end
        player:showTextDialog(8977, list)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '\nMount Commands:\n!mount list -- Shows locked mounts\n!mount unlock -- Unlock mounts')
    end
    return false
end

mount:separator(" ")
mount:register()

local mountmodal = CreatureEvent("Mount_Modal_Window")
mountmodal:type("modalwindow")

function mountmodal.onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId == 1800 then
        if buttonId == 100 then
            if doPlayerRemoveItem(player, mounts[choiceId].item, mounts[choiceId].count) then
                player:addMount(mounts[choiceId].id)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ''.. mounts[choiceId].name ..' unlocked!')
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Couldn\'t unlock mount.')
            end
        end
    end
    player:unregisterEvent("Mount_Modal_Window")
    return true
end

mountmodal:register()
Well look at that, working now :) Very good, thank you, all u need to do is edit line 20 if not player:hasMount(mounts.id)) then to if not player:hasMount(mounts.id)then according to the console error i got and fixed, seems to be working fine! rep+++!
 
Well look at that, working now :) Very good, thank you, all u need to do is edit line 20 if not player:hasMount(mounts.id)) then to if not player:hasMount(mounts.id)then according to the console error i got and fixed, seems to be working fine! rep+++!
Edited my post with that change.
I definitely missed that extra )
 
This looks cool. Would love to use this like an shop. "Give X money to get mount Y." ^^
Maybe there is an more easy way than this?
Lua:
    [1] = {name = 'Widow Queen', id = 1, item = 2160, count = 2000}, -- 2160 = cc & count = price
    [2] = {name = 'Racing Bird', id = 2, item = 2160, count = 2500},
 
This looks cool. Would love to use this like an shop. "Give X money to get mount Y." ^^
Maybe there is an more easy way than this?
Lua:
    [1] = {name = 'Widow Queen', id = 1, item = 2160, count = 2000}, -- 2160 = cc & count = price
    [2] = {name = 'Racing Bird', id = 2, item = 2160, count = 2500},

Create a new request thread for it and we will help you
 
Back
Top