Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

tfs 1.2 problem z npc VoiceModule


Jukesnk12

Rekomendowane odpowiedzi

Opublikowano
Lua Script Error: [Npc interface]
data/npc/scripts/The Queen Of The Banshees.lua
data/npc/scripts/The Queen Of The Banshees.lua:11: attempt to index global 'VoiceModule' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/The Queen Of The Banshees.lua:11: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: The Queen Of The Banshees.lua




Lua Script Error: [Npc interface]


 

data/npc/scripts/Ormuhn.lua
data/npc/scripts/Ormuhn.lua:10: attempt to call method 'addSpellKeyword' (a nil value)
stack traceback:
        [C]: in function 'addSpellKeyword'
        data/npc/scripts/Ormuhn.lua:10: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: Ormuhn.lua

 

Lua Script Error: [Npc interface]
data/npc/scripts/Quentin.lua:onCreatureSay
data/npc/scripts/Quentin.lua:23: attempt to call global 'msgcontains' (a nil value)
stack traceback:
        [C]: in function 'msgcontains'
        data/npc/scripts/Quentin.lua:23: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:431: in function 'onCreatureSay'
        data/npc/scripts/Quentin.lua:8: in function <data/npc/scripts/Quentin.lua:8>

 

@rafaeru Mam taki problem z callback, voicemodule, addspellkeyword i nie wiem jak to rozwiazać. Npc reagują, otwiera się okno dialogowe ale nie odpisują, problem dotyczy kazdego npc

 

 data\npc\lib/npc.lua


 

Cytat

 

-- Including the Advanced NPC System
dofile('data/npc/lib/npcsystem/npcsystem.lua')
dofile('data/npc/lib/npcsystem/customModules.lua')

isPlayerPremiumCallback = Player.isPremium

function msgcontains(message, keyword)
    local message, keyword = message:lower(), keyword:lower()
    if message == keyword then
        return true
    end

    return message:find(keyword) and not message:find('(%w+)' .. keyword)
end

function doNpcSellItem(cid, itemId, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 0
    local item = 0
    local player = Player(cid)
    if ItemType(itemId):isStackable() then
        local stuff
        if inBackpacks then
            stuff = Game.createItem(backpack, 1)
            item = stuff:addItem(itemId, math.min(100, amount))
        else
            stuff = Game.createItem(itemId, math.min(100, amount))
        end

        return player:addItemEx(stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0
    end

    local a = 0
    if inBackpacks then
        local container, itemType, b = Game.createItem(backpack, 1), ItemType(backpack), 1
        for i = 1, amount do
            local item = container:addItem(itemId, subType)
            if isInArray({(itemType:getCapacity() * b), amount}, i) then
                if player:addItemEx(container, ignoreCap) ~= RETURNVALUE_NOERROR then
                    b = b - 1
                    break
                end

                a = i
                if amount > i then
                    container = Game.createItem(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do -- normal method for non-stackable items
        local item = Game.createItem(itemId, subType)
        if player:addItemEx(item, ignoreCap) ~= RETURNVALUE_NOERROR then
            break
        end
        a = i
    end
    return a, 0
end

local func = function(cid, text, type, e, pcid)
    local npc = Npc(cid)
    if not npc then
        return
    end

    local player = Player(pcid)
    if player then
        npc:say(text, type, false, player, npc:getPosition())
        e.done = true
    end
end

function doCreatureSayWithDelay(cid, text, type, delay, e, pcid)
    if Player(pcid) then
        e.done = false
        e.event = addEvent(func, delay < 1 and 1000 or delay, cid, text, type, e, pcid)
    end
end

function doPlayerTakeItem(cid, itemid, count)
    local player = Player(cid)
    if player:getItemCount(itemid) < count then
        return false
    end

    while count > 0 do
        local tempcount = 0
        if ItemType(itemid):isStackable() then
            tempcount = math.min (100, count)
        else
            tempcount = 1
        end

        local ret = player:removeItem(itemid, tempcount)
        if ret then
            count = count - tempcount
        else
            return false
        end
    end

    if count ~= 0 then
        return false
    end
    return true
end

function doPlayerSellItem(cid, itemid, count, cost)
    local player = Player(cid)
    if doPlayerTakeItem(cid, itemid, count) then
        if not player:addMoney(cost) then
            error('Could not add money to ' .. player:getName() .. '(' .. cost .. 'gp)')
        end
        return true
    end
    return false
end

function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
    local player = Player(cid)
    if not player:removeMoney(cost) then
        return false
    end

    for i = 1, count do
        local container = Game.createItem(containerid, 1)
        for x = 1, ItemType(containerid):getCapacity() do
            container:addItem(itemid, charges)
        end

        if player:addItemEx(container, true) ~= RETURNVALUE_NOERROR then
            return false
        end
    end
    return true
end

function getCount(string)
    local b, e = string:find("%d+")
    return b and e and tonumber(string:sub(b, e)) or -1
end
 

 

 

 

 

 data\npc\lib\npcsystem\customModules.lua

 

Cytat

 

-- Custom Modules, created to help us in this datapack
local travelDiscounts = {
    ['postman'] = {price = 10, storage = Storage.postman.Rank, value = 3},
    ['new frontier'] = {price = 50, storage = Storage.TheNewFrontier.Mission03, value = 1}
}

function StdModule.travelDiscount(player, discounts)
    local discountPrice, discount = 0
    if type(discounts) == 'string' then
        discount = travelDiscounts[discounts]
        if discount and player:getStorageValue(discount.storage) >= discount.value then
            return discount.price
        end
    else
        for i = 1, #discounts do
            discount = travelDiscounts[discounts[i]]
            if discount and player:getStorageValue(discount.storage) >= discount.value then
                discountPrice = discountPrice + discount.price
            end
        end
    end

    return discountPrice
end

function StdModule.kick(cid, message, keywords, parameters, node)
    local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("StdModule.travel called without any npcHandler instance.")
    end

    if not npcHandler:isFocused(cid) then
        return false
    end

    npcHandler:releaseFocus(cid)
    npcHandler:say(parameters.text or "Off with you!", cid)

    local destination = parameters.destination
    if type(destination) == 'table' then
        destination = destination[math.random(#destination)]
    end

    Player(cid):teleportTo(destination, true)

    npcHandler:resetNpc(cid)
    return true
end

local GreetModule = {}
function GreetModule.greet(cid, message, keywords, parameters)
    if not parameters.npcHandler:isInRange(cid) then
        return true
    end

    if parameters.npcHandler:isFocused(cid) then
        return true
    end

    local parseInfo = { [TAG_PLAYERNAME] = Player(cid):getName() }
    parameters.npcHandler:say(parameters.npcHandler:parseMessage(parameters.text, parseInfo), cid, true)
    parameters.npcHandler:addFocus(cid)
    return true
end

function GreetModule.farewell(cid, message, keywords, parameters)
    if not parameters.npcHandler:isFocused(cid) then
        return false
    end

    local parseInfo = { [TAG_PLAYERNAME] = Player(cid):getName() }
    parameters.npcHandler:say(parameters.npcHandler:parseMessage(parameters.text, parseInfo), cid, true)
    parameters.npcHandler:resetNpc(cid)
    parameters.npcHandler:releaseFocus(cid)
    return true
end

-- Adds a keyword which acts as a greeting word
function KeywordHandler:addGreetKeyword(keys, parameters, condition, action)
    local keys = keys
    keys.callback = FocusModule.messageMatcherDefault
    return self:addKeyword(keys, GreetModule.greet, parameters, condition, action)
end

-- Adds a keyword which acts as a farewell word
function KeywordHandler:addFarewellKeyword(keys, parameters, condition, action)
    local keys = keys
    keys.callback = FocusModule.messageMatcherDefault
    return self:addKeyword(keys, GreetModule.farewell, parameters, condition, action)
end

-- Adds a keyword which acts as a spell word
function KeywordHandler:addSpellKeyword(keys, parameters)
    local keys = keys
    keys.callback = FocusModule.messageMatcherDefault

    local npcHandler, spellName, price, vocationId = parameters.npcHandler, parameters.spellName, parameters.price, parameters.vocation
    local spellKeyword = self:addKeyword(keys, StdModule.say, {npcHandler = npcHandler, text = string.format("Do you want to learn the spell '%s' for %s?", spellName, price > 0 and price .. ' gold' or 'free')},
        function(player)
            local baseVocationId = player:getVocation():getBase():getId()
            if type(vocationId) == 'table' then
                return isInArray(vocationId, baseVocationId)
            else
                return vocationId == baseVocationId
            end
        end
    )

    spellKeyword:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, spellName = spellName, level = parameters.level, price = price})
    spellKeyword:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Maybe next time.', reset = true})
end

local hints = {
    [-1] = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.',
    [0] = 'Send private messages to other players by right-clicking on the player or the player\'s name and select \'Message to ....\'. You can also open a \'private message channel\' and type in the name of the player.',
    [1] = 'Use the shortcuts \'SHIFT\' to look, \'CTRL\' for use and \'ALT\' for attack when clicking on an object or player.',
    [2] = 'If you already know where you want to go, click on the automap and your character will walk there automatically if the location is reachable and not too far away.',
    [3] = 'To open or close skills, battle or VIP list, click on the corresponding button to the right.',
    [4] = '\'Capacity\' restricts the amount of things you can carry with you. It raises with each level.',
    [5] = 'Always have a look on your health bar. If you see that you do not regenerate health points anymore, eat something.',
    [6] = 'Always eat as much food as possible. This way, you\'ll regenerate health points for a longer period of time.',
    [7] = 'After you have killed a monster, you have 10 seconds in which the corpse is not moveable and no one else but you can loot it.',
    [8] = 'Be careful when you approach three or more monsters because you only can block the attacks of two. In such a situation even a few rats can do severe damage or even kill you.',
    [9] = 'There are many ways to gather food. Many creatures drop food but you can also pick blueberries or bake your own bread. If you have a fishing rod and worms in your inventory, you can also try to catch a fish.',
    [10] = {'Baking bread is rather complex. First of all you need a scythe to harvest wheat. Then you use the wheat with a millstone to get flour. ...', 'This can be be used on water to get dough, which can be used on an oven to bake bread. Use milk instead of water to get cake dough.'},
    [11] = 'Dying hurts! Better run away than risk your life. You are going to lose experience and skill points when you die.',
    [12] = 'When you switch to \'Offensive Fighting\', you deal out more damage but you also get hurt more easily.',
    [13] = 'When you are on low health and need to run away from a monster, switch to \'Defensive Fighting\' and the monster will hit you less severely.',
    [14] = 'Many creatures try to run away from you. Select \'Chase Opponent\' to follow them.',
    [15] = 'The deeper you enter a dungeon, the more dangerous it will be. Approach every dungeon with utmost care or an unexpected creature might kill you. This will result in losing experience and skill points.',
    [16] = 'Due to the perspective, some objects in Tibia are not located at the spot they seem to appear (ladders, windows, lamps). Try clicking on the floor tile the object would lie on.',
    [17] = 'If you want to trade an item with another player, right-click on the item and select \'Trade with ...\', then click on the player with whom you want to trade.',
    [18] = 'Stairs, ladders and dungeon entrances are marked as yellow dots on the automap.',
    [19] = 'You can get food by killing animals or monsters. You can also pick blueberries or bake your own bread. If you are too lazy or own too much money, you can also buy food.',
    [20] = 'Quest containers can be recognised easily. They don\'t open up regularly but display a message \'You have found ....\'. They can only be opened once.',
    [21] = 'Better run away than risk to die. You\'ll lose experience and skill points each time you die.',
    [22] = 'You can form a party by right-clicking on a player and selecting \'Invite to Party\'. The party leader can also enable \'Shared Experience\' by right-clicking on him- or herself.',
    [23] = 'You can assign spells, the use of items, or random text to \'hotkeys\'. You find them under \'Options\'.',
    [24] = 'You can also follow other players. Just right-click on the player and select \'Follow\'.',
    [25] = 'You can found a party with your friends by right-clicking on a player and selecting \'Invite to Party\'. If you are invited to a party, right-click on yourself and select \'Join Party\'.',
    [26] = 'Only found parties with people you trust. You can attack people in your party without getting a skull. This is helpful for training your skills, but can be abused to kill people without having to fear negative consequences.',
    [27] = 'The leader of a party has the option to distribute gathered experience among all players in the party. If you are the leader, right-click on yourself and select \'Enable Shared Experience\'.',
    [28] = 'There is nothing more I can tell you. If you are still in need of some {hints}, I can repeat them for you.'
}

function StdModule.rookgaardHints(cid, message, keywords, parameters, node)
    local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("StdModule.say called without any npcHandler instance.")
    end

    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local hintId = player:getStorageValue(Storage.RookgaardHints)
    npcHandler:say(hints[hintId], cid)
    if hintId >= #hints then
        player:setStorageValue(Storage.RookgaardHints, -1)
    else
        player:setStorageValue(Storage.RookgaardHints, hintId + 1)
    end
    return true
end

-- VoiceModule
VoiceModule = {
    voices = nil,
    voiceCount = 0,
    lastVoice = 0,
    timeout = nil,
    chance = nil,
    npcHandler = nil
}

-- Creates a new instance of VoiceModule
function VoiceModule:new(voices, timeout, chance)
    local obj = {}
    setmetatable(obj, self)
    self.__index = self

    obj.voices = voices
    for i = 1, #obj.voices do
        local voice = obj.voices[i]
        if voice.yell then
            voice.yell = nil
            voice.talktype = TALKTYPE_YELL
        else
            voice.talktype = TALKTYPE_SAY
        end
    end

    obj.voiceCount = #voices
    obj.timeout = timeout or 10
    obj.chance = chance or 25
    return obj
end

function VoiceModule:init(handler)
    return true
end

function VoiceModule:callbackOnThink()
    if self.lastVoice < os.time() then
        self.lastVoice = os.time() + self.timeout
        if math.random(100) < self.chance  then
            local voice = self.voices[math.random(self.voiceCount)]
            Npc():say(voice.text, voice.talktype)
        end
    end
    return true
end
 

 

 

 

 

data\npc\lib\npcsystem\npcsystem.lua

Cytat

 

-- Advanced NPC System by Jiddo

shop_amount = {}
shop_cost = {}
shop_rlname = {}
shop_itemid = {}
shop_container = {}
shop_npcuid = {}
shop_eventtype = {}
shop_subtype = {}
shop_destination = {}
shop_premium = {}

npcs_loaded_shop = {}
npcs_loaded_travel = {}

if NpcSystem == nil then
    -- Loads the underlying classes of the npcsystem.
    dofile('data/npc/lib/npcsystem/keywordhandler.lua')
    dofile('data/npc/lib/npcsystem/npchandler.lua')
    dofile('data/npc/lib/npcsystem/modules.lua')

    -- Global npc constants:

    -- Greeting and unGreeting keywords. For more information look at the top of modules.lua
    FOCUS_GREETWORDS = {'hi', 'hello'}
    FOCUS_FAREWELLWORDS = {'bye', 'farewell'}

    -- The word for requesting trade window. For more information look at the top of modules.lua
    SHOP_TRADEREQUEST = {'trade'}

    -- The word for accepting/declining an offer. CAN ONLY CONTAIN ONE FIELD! For more information look at the top of modules.lua
    SHOP_YESWORD = {'yes'}
    SHOP_NOWORD = {'no'}

    -- Pattern used to get the amount of an item a player wants to buy/sell.
    PATTERN_COUNT = '%d+'

    -- Talkdelay behavior. For more information, look at the top of npchandler.lua.
    NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK

    -- Constant strings defining the keywords to replace in the default messages.
    --    For more information, look at the top of npchandler.lua...
    TAG_PLAYERNAME = '|PLAYERNAME|'
    TAG_ITEMCOUNT = '|ITEMCOUNT|'
    TAG_TOTALCOST = '|TOTALCOST|'
    TAG_ITEMNAME = '|ITEMNAME|'
    TAG_TIME = '|TIME|'
    TAG_BLESSCOST = '|BLESSCOST|'
    TAG_PVPBLESSCOST = '|PVPBLESSCOST|'
    TAG_TRAVELCOST = '|TRAVELCOST|'

    NpcSystem = {}

    -- Gets an npcparameter with the specified key. Returns nil if no such parameter is found.
    function NpcSystem.getParameter(key)
        local ret = getNpcParameter(tostring(key))
        if (type(ret) == 'number' and ret == 0) or ret == nil then
            return nil
        else
            return ret
        end
    end

    -- Parses all known parameters for the npc. Also parses parseable modules.
    function NpcSystem.parseParameters(npcHandler)
        local ret = NpcSystem.getParameter('idletime')
        if ret ~= nil then
            npcHandler.idleTime = tonumber(ret)
        end
        local ret = NpcSystem.getParameter('talkradius')
        if ret ~= nil then
            npcHandler.talkRadius = tonumber(ret)
        end
        local ret = NpcSystem.getParameter('message_greet')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_GREET, ret)
        end
        local ret = NpcSystem.getParameter('message_farewell')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_FAREWELL, ret)
        end
        local ret = NpcSystem.getParameter('message_decline')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_DECLINE, ret)
        end
        local ret = NpcSystem.getParameter('message_needmorespace')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_NEEDMORESPACE, ret)
        end
        local ret = NpcSystem.getParameter('message_needspace')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_NEEDSPACE, ret)
        end
        local ret = NpcSystem.getParameter('message_sendtrade')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_SENDTRADE, ret)
        end
        local ret = NpcSystem.getParameter('message_noshop')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_NOSHOP, ret)
        end
        local ret = NpcSystem.getParameter('message_oncloseshop')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_ONCLOSESHOP, ret)
        end
        local ret = NpcSystem.getParameter('message_onbuy')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_ONBUY, ret)
        end
        local ret = NpcSystem.getParameter('message_onsell')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_ONSELL, ret)
        end
        local ret = NpcSystem.getParameter('message_missingmoney')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_MISSINGMONEY, ret)
        end
        local ret = NpcSystem.getParameter('message_needmoney')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_NEEDMONEY, ret)
        end
        local ret = NpcSystem.getParameter('message_missingitem')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_MISSINGITEM, ret)
        end
        local ret = NpcSystem.getParameter('message_needitem')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_NEEDITEM, ret)
        end
        local ret = NpcSystem.getParameter('message_idletimeout')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_IDLETIMEOUT, ret)
        end
        local ret = NpcSystem.getParameter('message_walkaway')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_WALKAWAY, ret)
        end
        local ret = NpcSystem.getParameter('message_alreadyfocused')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_ALREADYFOCUSED, ret)
        end
        local ret = NpcSystem.getParameter('message_buy')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_BUY, ret)
        end
        local ret = NpcSystem.getParameter('message_sell')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_SELL, ret)
        end
        local ret = NpcSystem.getParameter('message_bought')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_BOUGHT, ret)
        end
        local ret = NpcSystem.getParameter('message_sold')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_SOLD, ret)
        end
        local ret = NpcSystem.getParameter('message_walkaway_male')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_WALKAWAY_MALE, ret)
        end
        local ret = NpcSystem.getParameter('message_walkaway_female')
        if ret ~= nil then
            npcHandler:setMessage(MESSAGE_WALKAWAY_FEMALE, ret)
        end

        -- Parse modules.
        for parameter, module in pairs(Modules.parseableModules) do
            local ret = NpcSystem.getParameter(parameter)
            if ret ~= nil then
                local number = tonumber(ret)
                if number ~= 0 and module.parseParameters ~= nil then
                    local instance = module:new()
                    npcHandler:addModule(instance)
                    instance:parseParameters()
                end
            end
        end
    end
end

 

 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...