I use tfs 1.5 8.6
the scrupt that im using was found here: NPC - [TFS 1.X] NPC Addons (Modal Window) (https://otland.net/threads/tfs-1-x-npc-addons-modal-window.274567/)
this is the error that i get in console when i say addons to the npc
here addonModal.lua
this is the part of the npc that i causing the error
I have changed he word self to player, still not work
the scrupt that im using was found here: NPC - [TFS 1.X] NPC Addons (Modal Window) (https://otland.net/threads/tfs-1-x-npc-addons-modal-window.274567/)
this is the error that i get in console when i say addons to the npc
Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/addoner.lua:onCreatureSay
data/lib/addonModal.lua:13: attempt to index local 'choice' (a boolean value)
stack traceback:
data/lib/addonModal.lua:13: in function 'sendMainAddonWindow'
data/npc/scripts/addoner.lua:817: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:430: in function 'onCreatureSay'
data/npc/scripts/addoner.lua:805: in function <data/npc/scripts/addoner.lua:805>
here addonModal.lua
Code:
function Player:sendMainAddonWindow(config)
local window = ModalWindow {
title = "Selecione um dos Addons",
message = "Para prosseguir seleciona o 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 = "Selecionar"
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 = "Selecione uma opcao para prosseguir",
message = "Clique em Detalhes para verificar os itens necessarios ou clique em Aceitar para pegar o seu addon",
}
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
this is the part of the npc that i causing the error
Code:
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "addons") then
npcHandler:say("Follow the addons available, remembering if you already have the full addon it will not appear for you.", cid)
player:sendMainAddonWindow(config)
end
end
Post automatically merged:
I have changed he word self to player, still not work
Lua:
function Player:sendMainAddonWindow(config)
local window = ModalWindow {
title = "Selecione um dos Addons",
message = "Para prosseguir seleciona o Addon",
}
local cid = player:getId()
-- Add choices from the action script
for i = 1, #config.system do
if not player:hasOutfit(config.system[i].male, 3) and not player:hasOutfit(config.system[i].female, 3) then
local choice = window:addChoice(config.system[i].addonName)
choice.addonName = i
end
end
buttonText = "Selecionar"
window:addButton(buttonText,
function(button, choice)
local player = Player(cid)
if player then
player:sendAllAddonListWindow(config, choice.id)
end
end
)
window:setDefaultEnterButton(buttonText)
window:addButton("Exit")
window:setDefaultEnterButton("Selecionar")
window:setDefaultEscapeButton("Exit")
window:sendToPlayer(player)
end
function Player:checkSexPlayer(config)
if player: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 = player:checkSexPlayer(config.system[lastChoice])
local addonTable = config.system[lastChoice].items[idOutfit]
local onlyIdOutfits = config.system[lastChoice].outfitId
local cid = player:getId()
if not player:hasOutfit(onlyIdOutfits.male, 1) and not player:hasOutfit(onlyIdOutfits.female, 1) then
buttonText = "First"
window:addButton(buttonText,
function(button, choice)
local player = Player(cid)
if player then
player:acceptAddonWindow(addonTable, 1, onlyIdOutfits, lastChoice, config)
end
end
)
end
if not player:hasOutfit(onlyIdOutfits.male, 2) and not player:hasOutfit(onlyIdOutfits.female, 2) then
buttonText = "Second"
window:addButton(buttonText,
function(button, choice)
local player = Player(cid)
if player then
player:acceptAddonWindow(addonTable, 2, onlyIdOutfits, lastChoice, config)
end
end
)
end
window:addButton("Exit")
window:setDefaultEscapeButton("Exit")
window:sendToPlayer(player)
end
function Player:acceptAddonWindow(config, addonId, onlyIdOutfits, lastChoice, configMainTable)
local window = ModalWindow {
title = "Selecione uma opcao para prosseguir",
message = "Clique em Detalhes para verificar os itens necessarios ou clique em Aceitar para pegar o seu addon",
}
local cid = player:getId()
local checkItensAddon = player:checkItensAddon(config[addonId])
if checkItensAddon then
window:addButton("OK",
function(button, choice)
local player = Player(cid)
if player then
player:setAddonId(onlyIdOutfits, addonId)
end
return true
end
)
end
buttonText = "Back"
window:addButton(buttonText,
function(button, choice)
local player = Player(cid)
if player then
player:sendAllAddonListWindow(configMainTable, lastChoice)
end
end
)
buttonText = "Detalhes"
window:addButton(buttonText,
function(button, choice)
local player = Player(cid)
if player then
player:detailsAddonWindowFirst(config[addonId], config , addonId, onlyIdOutfits, lastChoice, configMainTable)
end
end
)
window:addButton("Exit")
window:setDefaultEscapeButton("Exit")
window:sendToPlayer(player)
end
function Player:detailsAddonWindowFirst(config, tableConfig, addonId, onlyIdOutfits, lastChoice, configMainTable)
local window = ModalWindow {
title = "Itens Requiridos para seu Addon",
message = player:detailsAddonWindow(config),
}
local cid = player:getId()
local checkItensAddon = player:checkItensAddon(config)
if checkItensAddon then
window:addButton("OK",
function(button, choice)
local player = Player(cid)
if player then
player:setAddonId(config, onlyIdOutfits, addonId, configMainTable, lastChoice)
end
return true
end
)
end
window:addButton("Back",
function(button, choice)
local player = Player(cid)
if player then
player:acceptAddonWindow(tableConfig, addonId, onlyIdOutfits , lastChoice, configMainTable)
end
return true
end
)
window:sendToPlayer(player)
end
function Player:checkItensAddon(config)
for i = 1, #config.reqItems do
if player: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 = player: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
player:removeItem(config.reqItems[i].item, config.reqItems[i].count)
end
player:addOutfitAddon(outfits.female, addonId)
player:addOutfitAddon(outfits.male, addonId)
player:getPosition():sendMagicEffect(CONST_ME_FIREATTACK)
end
Last edited: