• 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+ npc addoner modal windows

Jeyci

Banned User
Joined
May 6, 2023
Messages
289
Solutions
3
Reaction score
36
Hello

I'm using a script that i found here: NPC - [TFS 1.X] NPC Addons (Modal Window) (https://otland.net/threads/tfs-1-x-npc-addons-modal-window.274567/)

i edited the script in order to make the npc accept gold instead of items
Lua:
local config = {
                system = {
                    [1] = {addonName = "Citizen Full", -- Name shown at Modal.
                        outfitId = {male = 128 , female = 136}, -- Check if the player already exists addon, remove from the selection of addons
                        items =  { [136] = {
                                              [1] = {reqItems = { -- Required Items for Addon 1
                                                            [1] = {item = 2160, count = 100}, -- Silver Tokens
                                                        },
                                                    },
                                              [2] = {reqItems = { --
                                                            [1] = {item = 2160, count = 100},
                                                            
                                                        },
                                                    }
                                                },
                                    [128] = {
                                              [1] = {reqItems = { -- Required Items for Addon 1
                                                            [1] = {item = 2160, count = 100}, -- Silver Tokens
                                                        },
                                                    },
                                              [2] = {reqItems = { --
                                                            [1] = {item = 2160, count = 100},
                                                            
                                                        },
                                                    }
                                            },
                                 }
                        },

the modal windows is being displayed but when you choose an addon the windows get closed, no money is removed and no addon is given to players
i have not editen the modalwindow. part. what should i add in order to make the npc accept money instead of items?
Code:
function Player:sendMainAddonWindow(config)
    local window = ModalWindow {
        title = "Choose addons",
        message = "Select an addon",
    }
    
    local cid = self:getId()
    
    -- Add choices from the action script
    for i = 1, #config.system do
        if not self:hasOutfit(config.system[i].male, 3) and not self:hasOutfit(config.system[i].female, 3) then
            local choice = window:addChoice(config.system[i].addonName)
            choice.addonID = i
        end
    end
    
    buttonText = "Select"
    window:addButton(buttonText,
        function(button, choice)
            local self = Player(cid)
            if self then
                self:sendAllAddonListWindow(config, choice.id)
            end
        end
    )
    window:setDefaultEnterButton(buttonText)
    
    
    window:addButton("Exit")

    window:setDefaultEnterButton("Selecionar")
    window:setDefaultEscapeButton("Exit")
    window:sendToPlayer(self)
end

function Player:checkSexPlayer(config)
    if self:getSex() == 0 then
        return config.outfitId.female
    else
        return config.outfitId.male
    end
end
 
function Player:sendAllAddonListWindow(config, lastChoice)
    local window = ModalWindow {
        title = config.system[lastChoice].addonName,
        message = "Selecione o seu Addon (First ou Second Addon)",
    }   
    local idOutfit = self:checkSexPlayer(config.system[lastChoice])
    local addonTable = config.system[lastChoice].items[idOutfit]
    local onlyIdOutfits = config.system[lastChoice].outfitId

    local cid = self:getId()
    
    if not self:hasOutfit(onlyIdOutfits.male, 1) and not self:hasOutfit(onlyIdOutfits.female, 1) then   
        buttonText = "First"
        window:addButton(buttonText,
            function(button, choice)
                local self = Player(cid)
                if self then
                    self:acceptAddonWindow(addonTable, 1, onlyIdOutfits, lastChoice, config)
                end
            end
        )
    end
    
    if not self:hasOutfit(onlyIdOutfits.male, 2) and not self:hasOutfit(onlyIdOutfits.female, 2) then   
        buttonText = "Second"
        window:addButton(buttonText,
            function(button, choice)
                local self = Player(cid)
                if self then
                    self:acceptAddonWindow(addonTable, 2, onlyIdOutfits, lastChoice, config)
                end
            end
        )
    end

    window:addButton("Exit")
    window:setDefaultEscapeButton("Exit")

    window:sendToPlayer(self)
end

function Player:acceptAddonWindow(config, addonId, onlyIdOutfits, lastChoice, configMainTable)
    local window = ModalWindow {
        title = "Select an option",
        message = "Click in details to verify if you have the requeried items.",
    }   
    local cid = self:getId()       
    local checkItensAddon = self:checkItensAddon(config[addonId])
    
    if checkItensAddon then
        window:addButton("OK",
            function(button, choice)
                local self = Player(cid)
                if self then
                    self:setAddonId(onlyIdOutfits, addonId)
                end
                return true
            end
        )
    end
    
    buttonText = "Back"
    window:addButton(buttonText,
        function(button, choice)
            local self = Player(cid)
            if self then
                self:sendAllAddonListWindow(configMainTable, lastChoice)
            end
        end
    )

    buttonText = "Detalhes"
    window:addButton(buttonText,
        function(button, choice)
            local self = Player(cid)
            if self then
                self:detailsAddonWindowFirst(config[addonId], config , addonId, onlyIdOutfits, lastChoice, configMainTable)
            end
        end
    )
    
    window:addButton("Exit")
    window:setDefaultEscapeButton("Exit")
    window:sendToPlayer(self)
end

function Player:detailsAddonWindowFirst(config, tableConfig, addonId, onlyIdOutfits, lastChoice, configMainTable)
    local window = ModalWindow {
        title = "Itens Requiridos para seu Addon",
        message = self:detailsAddonWindow(config),
    }
    
    local cid = self:getId()
    local checkItensAddon = self:checkItensAddon(config)
    
    if checkItensAddon then
        window:addButton("OK",
            function(button, choice)
                local self = Player(cid)
                if self then
                    self:setAddonId(config, onlyIdOutfits, addonId, configMainTable, lastChoice)
                end
                return true
            end
        )
    end
    
    window:addButton("Back",
        function(button, choice)
            local self = Player(cid)
            if self then
                self:acceptAddonWindow(tableConfig, addonId, onlyIdOutfits , lastChoice,  configMainTable)
            end
            return true
        end
    )
    
    window:sendToPlayer(self)
end

function Player:checkItensAddon(config)
    for i = 1, #config.reqItems do
        if self:getItemCount(config.reqItems[i].item) < config.reqItems[i].count then           
            return false
        end
    end
    
    return true
end

function Player:detailsAddonWindow(config)
    local itemTable = config.reqItems   
    local details = "Itens Requiridos para o Addon:\n "
 
    for i = 1, #itemTable do           
        local reqItems = itemTable[i].item             
        
        local reqItemsCount = itemTable[i].count
        local reqItemsOnPlayer = self:getItemCount(reqItems)
            details = details.."\n- ".. (capAll(ItemType(reqItems):getName()) .." ["..reqItemsOnPlayer.."/"..reqItemsCount.."]")
    end
    return details
end

function Player:setAddonId(config, outfits, addonId, configMainTable, lastChoice)
    for i = 1, #config.reqItems do
        self:removeItem(config.reqItems[i].item, config.reqItems[i].count)
    end     
    
    self:addOutfitAddon(outfits.female, addonId)
    self:addOutfitAddon(outfits.male, addonId)
    self:getPosition():sendMagicEffect(CONST_ME_FIREATTACK)
    
    
    
end
no errors in console.
 
Back
Top