• 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!

NPC

equero

New Member
Joined
Feb 22, 2013
Messages
51
Reaction score
1
Hi.
I can't resolve my problem with NPC. TFS 0.3.6 8.6
I can't sell anything at rashid. Only hi>sell royal helmet>yes // Works
the button "sell" does not work
[Error - Npc interface] (Unknown script file) Description: data/npc/lib/npcsystem/modules.lua:1229: bad argument #2 to 'error' (number expe cted, got string) stack traceback: [C]: in function 'error' data/npc/lib/npcsystem/modules.lua:1229: in function 'callbackOnSell' data/npc/lib/npcsystem/npchandler.lua:265: in function 'processModuleCal lback' data/npc/lib/npcsystem/npchandler.lua:450: in function 'onSell' data/npc/lib/npcsystem/modules.lua:1296: in function <data/npc/lib/npcsy stem/modules.lua:1295> [Error - Npc interface] (Unknown script file) Description: data/npc/lib/npcsystem/modules.lua:1229: bad argument #2 to 'error' (number expe cted, got string) stack traceback: [C]: in function 'error' data/npc/lib/npcsystem/modules.lua:1229: in function 'callbackOnSell' data/npc/lib/npcsystem/npchandler.lua:265: in function 'processModuleCal lback' data/npc/lib/npcsystem/npchandler.lua:450: in function 'onSell' data/npc/lib/npcsystem/modules.lua:1296: in function <data/npc/lib/npcsy stem/modules.lua:1295>

Someone know what is wrong??
 
I would assume that (number expected, got string) is the issue.
But what do you expect us to do without the script?
 
Sorry. Too much things i forgot about that xD
Rashid.xml :
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Rashid" script="loot.lua" walkinterval="2000" floorchange="0">
    <health now="150" max="150"/>
    <look type="146" head="12" body="101" legs="122" feet="115" addons="3"/>
    <parameters>
        <parameter key="module_shop" value="1"/>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I buy swords, clubs, axes, helmets, boots, legs, shields and armors."/>
        <parameter key="shop_sellable" value="royal helmet,2498,40000;warrior helmet,2475,6000;crusader helmet,2497,9000;crown helmet,2491,5000;devil helmet,2462,4000;mystic turban,2663,500;chain helmet,2458,35;iron helmet,2459,30;steel boots,2645,40000;boots of haste,2195,40000;golden boots,2646,100000;magic plate armor,2472,100000;dragon scale mail,2492,60000;demon armor,2494,90000;golden armor,2466,30000;crown armor,2487,20000;knight armor,2476,5000;blue robe,2656,15000;lady armor,2500,2500;plate armor,2463,400;brass armor,2465,200;chain armor,2464,100;golden legs,2470,80000;crown legs,2488,15000;knight legs,2477,6000;plate legs,2647,500;brass legs,2487,100;mastermind shield,2514,80000;demon shield,2520,40000;blessed shield,2523,150000;great shield,2522,100000;vampire shield,2534,25000;medusa shield,2536,8000;amazon shield,2537,4000;crown shield,2519,5000;tower shield,2528,4000;guardian shield,2515,200;beholder shield,2518,1500;dwarven shield,2525,100;magic longsword,2390,150000;warlord sword,2408,100000;magic sword,2400,90000;giant sword,2393,10000;bright sword,2407,6000;ice rapier,2396,4000;fire sword,2392,3000;serpent sword,2409,1500;spike sword,2383,800;two handed sword,2377,400;broad sword,2413,70;short sword,2406,30;sword,2376,25;dragon lance,2414,10000;stonecutter axe,2431,90000;guardian halberd,2427,7500;fire axe,2432,10000;knight axe,2430,2000;double axe,2387,200;halberd,2381,200;battle axe,2378,100;hatchet,2388,20;war hammer,2391,6000;thunder hammer,2421,90000;skull staff,2436,1000;dragon hammer,2434,2000;clerical mace,2423,200;battle hammer,2417,60;mace,2398,30;paladin armor,8891,32000;dragon slayer,7873,15000;demonrage sword,7382,18000;dl,2495,120000;da,2494,160000;dh,2493,70000;"/>
    </parameters>
</npc>
loot.lua:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'helmets'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy royal (40k), warrior (6k), crusader (9k), crown (5k), devil (4k), chain (35gp) and iron helmets (30gp), also mystic turbans (500gp).'})
keywordHandler:addKeyword({'boots'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden boots (100k), steel boots (40k) and boots of haste (40k).'})
keywordHandler:addKeyword({'armors'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden (30k), crown (20k), knight (5k), lady (7,5k), plate (400gp), brass (200gp) and chain armors (100gp), also mpa (100k), dsm (60k) and blue robes (15k).'})
keywordHandler:addKeyword({'legs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden (80k), crown (15k), knight (6k), plate (500gp) and brass legs (100gp).'})
keywordHandler:addKeyword({'shields'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy blessed (150k), great (100k), demon (40k), vampire (25k), medusa (8k), amazon (4k), crown (5k), tower (4k), dragon (3k), guardian (2k), beholder (1k), and dwarven shields (100gp), also mms (80k).'})
keywordHandler:addKeyword({'swords'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy giant (10k), bright (6k), fire (3k) serpent (1.5k), spike (800gp) and two handed swords (400gp), also ice rapiers (4k), magic longswords (150k), magic swords (90k), warlord swords (100k) broad swords (70gp), short swords (30gp), sabres (25gp) and swords (25gp).'})
keywordHandler:addKeyword({'axes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy fire (10k), guardian halberds (7,5k) knight (2k), double (200gp) and battle axes (100gp), also dragon lances (10k), stonecutters axes (90k), halberds (200gp) and hatchets (20gp).'})
keywordHandler:addKeyword({'clubs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy thunder hammers (90k), war (6k), dragon (2k) and battle hammers (60gp), also skull staffs (10k) and clerical maces (200gp).'})

npcHandler:addModule(FocusModule:new())
Post automatically merged:

npc handler:
Lua:
-- This file is part of Jiddo's advanced NpcSystem v3.0x. This npcsystem is free to use by anyone, for any purpuse.
-- Initial release date: 2007-02-21
-- Credits: Jiddo, honux(I'm using a modified version of his Find function).
-- Please include full credits whereever you use this system, or parts of it.
-- For support, questions and updates, please consult the following thread:
-- http://otfans.net/showthread.php?t=67810

if(NpcHandler == nil) then
    
    -- Constant talkdelay behaviors.
    TALKDELAY_NONE = 0 -- No talkdelay. Npc will reply immedeatly.
    TALKDELAY_ONTHINK = 1 -- Talkdelay handled through the onThink callback function. (Default)
    TALKDELAY_EVENT = 2 -- Not yet implemented
    
    -- Currently applied talkdelay behavior. TALKDELAY_ONTHINK is default.
    NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK
    
    
    
    -- Constant indexes for defining default messages.
    MESSAGE_GREET         = 1 -- When the player greets the npc.
    MESSAGE_FAREWELL     = 2 -- When the player unGreets the npc.
    MESSAGE_BUY         = 3 -- When the npc asks the player if he wants to buy something.
    MESSAGE_SELL         = 4 -- When the npc asks the player if he wants to sell something.
    MESSAGE_ONBUY         = 5 -- When the player successfully buys something
    MESSAGE_ONSELL         = 6 -- When the player successfully sells something
    MESSAGE_NEEDMOREMONEY = 7 -- When the player does not have enough money
    MESSAGE_NOTHAVEITEM = 8 -- When the player is trying to sell an item he does not have.
    MESSAGE_IDLETIMEOUT = 9 -- When the player has been idle for longer then idleTime allows.
    MESSAGE_WALKAWAY     = 10 -- When the player walks out of the talkRadius of the npc.
    MESSAGE_ALREADYFOCUSED = 11 -- When the player already has the focus of this nopc.
    MESSAGE_PLACEDINQUEUE = 12 -- When the player has been placed in the costumer queue.
    MESSAGE_DECLINE     = 13 -- When the player sais no to something.
    
    -- Constant indexes for callback functions. These are also used for module callback ids.
    CALLBACK_CREATURE_APPEAR     = 1
    CALLBACK_CREATURE_DISAPPEAR = 2
    CALLBACK_CREATURE_SAY         = 3
    CALLBACK_ONTHINK             = 4
    CALLBACK_GREET                 = 5
    CALLBACK_FAREWELL             = 6
    CALLBACK_MESSAGE_DEFAULT     = 7
    
    -- Addidional module callback ids
    CALLBACK_MODULE_INIT        = 10
    CALLBACK_MODULE_RESET        = 11
    
    
    -- Constant strings defining the keywords to replace in the default messages.
    TAG_PLAYERNAME = '|PLAYERNAME|'
    TAG_ITEMCOUNT = '|ITEMCOUNT|'
    TAG_TOTALCOST = '|TOTALCOST|'
    TAG_ITEMNAME = '|ITEMNAME|'
    TAG_QUEUESIZE = '|QUEUESIZE|'
    
    
    NpcHandler = {
        keywordHandler = nil,
        queue = nil,
        focus = 0,
        talkStart = 0,
        idleTime = 30,
        talkRadius = 5,
        talkDelayTime = 1, -- Seconds to delay outgoing messages.
        talkDelay = nil,
        callbackFunctions = nil,
        modules = nil,
        messages = {
                -- These are the default replies of all npcs. They can/should be changed individually for each npc.
            [MESSAGE_GREET]         = 'Welcome, |PLAYERNAME|! I have been expecting you.',
            [MESSAGE_FAREWELL]         = 'Good bye, |PLAYERNAME|!',
            [MESSAGE_BUY]             = 'Do you want to buy |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?',
            [MESSAGE_SELL]             = 'Do you want to sell |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?',
            [MESSAGE_ONBUY]         = 'It was a pleasure doing business with you.',
            [MESSAGE_ONSELL]         = 'Thank you for this item, |PLAYERNAME|.',
            [MESSAGE_NEEDMOREMONEY] = 'You do not have enough money.',
            [MESSAGE_NOTHAVEITEM]     = 'You don\'t even have that item!',
            [MESSAGE_IDLETIMEOUT]     = 'Next please!',
            [MESSAGE_WALKAWAY]         = 'How rude!',
            [MESSAGE_ALREADYFOCUSED]= '|PLAYERNAME|, I am already talking to you.',
            [MESSAGE_PLACEDINQUEUE] = '|PLAYERNAME|, please wait for your turn. There are |QUEUESIZE| customers before you.',
            [MESSAGE_DECLINE]        = 'Not good enough, is it?'
        }
    }
    
    
    -- Creates a new NpcHandler with an empty callbackFunction stack.
    function NpcHandler:new(keywordHandler)
        local obj = {}
        obj.callbackFunctions = {}
        obj.modules = {}
        obj.talkDelay = {
                message = nil,
                time = nil
            }
        obj.queue = Queue:new(obj)
        obj.keywordHandler = keywordHandler
        obj.messages = {}
        setmetatable(obj.messages, self.messages)
        self.messages.__index = self.messages
        
        setmetatable(obj, self)
        self.__index = self
        return obj
    end
    
    -- Re-defines the maximum idle time allowed for a player when talking to this npc.
    function NpcHandler:setMaxIdleTime(newTime)
        self.idleTime = newTime
    end
    
    -- Attaches a new costumer queue to this npchandler.
    function NpcHandler:setQueue(newQueue)
        self.queue = newQueue
        self.queue:setHandler(self)
    end
    
    -- Attackes a new keyword handler to this npchandler
    function NpcHandler:setKeywordHandler(newHandler)
        self.keywordHandler = newHandler
    end
    
    -- Function used to change the focus of this npc.
    function NpcHandler:changeFocus(newFocus)
        self.focus = newFocus
        self:updateFocus()
    end
    
    -- This function should be called on each onThink and makes sure the npc faces the player it is talking to.
    --    Should also be called whenever a new player is focused.
    function NpcHandler:updateFocus()
        doNpcSetCreatureFocus(self.focus)
    end
    
    -- Used when the npc should un-focus the player.
    function NpcHandler:releaseFocus()
        self:changeFocus(0)
    end
    
    -- Returns the callback function with the specified id or nil if no such callback function exists.
    function NpcHandler:getCallback(id)
        local ret = nil
        if(self.callbackFunctions ~= nil) then
            ret = self.callbackFunctions[id]
        end
        return ret
    end
    
    -- Changes the callback function for the given id to callback.
    function NpcHandler:setCallback(id, callback)
        if(self.callbackFunctions ~= nil) then
            self.callbackFunctions[id] = callback
        end
    end
    
    -- Adds a module to this npchandler and inits it.
    function NpcHandler:addModule(module)
        if(self.modules ~= nil) then
            table.insert(self.modules, module)
            module:init(self)
        end
    end
    
    -- Calls the callback function represented by id for all modules added to this npchandler with the given arguments.
    function NpcHandler:processModuleCallback(id, ...)
        local ret = true
        for i, module in pairs(self.modules) do
            local tmpRet = true
            if(id == CALLBACK_CREATURE_APPEAR and module.callbackOnCreatureAppear ~= nil) then
                tmpRet = module:callbackCreatureAppear(unpack(arg))
                
            elseif(id == CALLBACK_CREATURE_DISAPPEAR and module.callbackOnCreatureDisappear ~= nil) then
                tmpRet = module:callbackCreatureDisappear(unpack(arg))
                
            elseif(id == CALLBACK_CREATURE_SAY and module.callbackOnCreatureSay ~= nil) then
                tmpRet = module:callbackCreatureSay(unpack(arg))
                
            elseif(id == CALLBACK_ONTHINK and module.callbackOnThink ~= nil) then
                tmpRet = module:callbackOnThink(unpack(arg))
                
            elseif(id == CALLBACK_GREET and module.callbackOnGreet ~= nil) then
                tmpRet = module:callbackOnGreet(unpack(arg))
                
            elseif(id == CALLBACK_FAREWELL and module.callbackOnFarewell ~= nil) then
                tmpRet = module:callbackOnFarewell(unpack(arg))
                
            elseif(id == CALLBACK_MESSAGE_DEFAULT and module.callbackOnMessageDefault ~= nil) then
                tmpRet = module:callbackOnMessageDefault(unpack(arg))
                
            elseif(id == CALLBACK_MODULE_RESET and module.callbackOnModuleReset ~= nil) then
                tmpRet = module:callbackOnModuleReset(unpack(arg))
            end
            if(not tmpRet) then
                ret = false
                break
            end
        end
        return ret
    end
    
    -- Returns the message represented by id.
    function NpcHandler:getMessage(id)
        local ret = nil
        if(self.messages ~= nil) then
            ret = self.messages[id]
        end
        return ret
    end
    
    -- Changes the default response message with the specified id to newMessage.
    function NpcHandler:setMessage(id, newMessage)
        if(self.messages ~= nil) then
            self.messages[id] = newMessage
        end
    end
    
    -- Translates all message tags found in msg using parseInfo
    function NpcHandler:parseMessage(msg, parseInfo)
        local ret = msg
        for search, replace in pairs(parseInfo) do
            ret = string.gsub(ret, search, replace)
        end
        return ret
    end
    
    -- Makes sure the npc un-focuses the furrently focused player, and greets the next player in the queue is it is not empty.
    function NpcHandler:unGreet()
        if(self.focus == 0) then
            return
        end
        local callback = self:getCallback(CALLBACK_FAREWELL)
        if(callback == nil or callback()) then
            if(self:processModuleCallback(CALLBACK_FAREWELL)) then
                if(self.queue == nil or not self.queue:greetNext()) then
                    local msg = self:getMessage(MESSAGE_FAREWELL)
                    local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(self.focus) }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg)
                    self:releaseFocus()
                end
            end
        end
    end
    
    -- Greets a new player.
    function NpcHandler:greet(cid)
        if(cid ~= 0) then
            local callback = self:getCallback(CALLBACK_GREET)
            if(callback == nil or callback(cid)) then
                if(self:processModuleCallback(CALLBACK_GREET, cid)) then
                    local msg = self:getMessage(MESSAGE_GREET)
                    local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg)
                else
                    return
                end
            else
                return
            end
        end
        self:changeFocus(cid)
    end
    
    -- Handles onCreatureAppear events. If you with to handle this yourself, please use the CALLBACK_CREATURE_APPEAR callback.
    function NpcHandler:onCreatureAppear(cid)
        local callback = self:getCallback(CALLBACK_CREATURE_APPEAR)
        if(callback == nil or callback(cid)) then
            if(self:processModuleCallback(CALLBACK_CREATURE_APPEAR, cid)) then
                
            end
        end
    end
    
    -- Handles onCreatureDisappear events. If you with to handle this yourself, please use the CALLBACK_CREATURE_DISAPPEAR callback.
    function NpcHandler:onCreatureDisappear(cid)
        local callback = self:getCallback(CALLBACK_CREATURE_DISAPPEAR)
        if(callback == nil or callback(cid)) then
            if(self:processModuleCallback(CALLBACK_CREATURE_DISAPPEAR, cid)) then
                if(self.focus == cid) then
                    self:unGreet()
                end
            end
        end
    end
    
    -- Handles onCreatureSay events. If you with to handle this yourself, please use the CALLBACK_CREATURE_SAY callback.
    function NpcHandler:onCreatureSay(cid, msgtype, msg)
        local callback = self:getCallback(CALLBACK_CREATURE_SAY)
        if(callback == nil or callback(cid, msgtype, msg)) then
            if(self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, msgtype, msg)) then
                if(not self:isInRange(cid)) then
                    return
                end
                if(self.keywordHandler ~= nil) then
                    local ret = self.keywordHandler:processMessage(cid, msg)
                    if(not ret) then
                        local callback = self:getCallback(CALLBACK_MESSAGE_DEFAULT)
                        if(callback ~= nil and callback(cid, msgtype, msg)) then
                            self.talkStart = os.time()
                        end
                    else
                        self.talkStart = os.time()
                    end
                end
            end
        end
    end
    
    -- Handles onThink events. If you with to handle this yourself, please use the CALLBACK_ONTHINK callback.
    function NpcHandler:onThink()
        local callback = self:getCallback(CALLBACK_ONTHINK)
        if(callback == nil or callback()) then
            
            if(NPCHANDLER_TALKDELAY == TALKDELAY_ONTHINK and self.talkDelay.time ~= nil and self.talkDelay.message ~= nil and os.time() >= self.talkDelay.time) then
                selfSay(self.talkDelay.message)
                self.talkDelay.time = nil
                self.talkDelay.message = nil
            end
            
            if(self:processModuleCallback(CALLBACK_ONTHINK)) then
                if(self.focus ~= 0) then
                    if(not self:isInRange(self.focus)) then
                        self:onWalkAway(self.focus)
                    elseif(os.time()-self.talkStart > self.idleTime) then
                        self:unGreet()
                    else
                        self:updateFocus()
                    end
                end
            end
        end
    end
    
    -- Tries to greet the player iwth the given cid. This function does not override queue order, current focus etc.
    function NpcHandler:onGreet(cid)
        if(self:isInRange(cid)) then
            if(self.focus == 0) then
                self:greet(cid)
            elseif(cid == self.focus) then
                local msg = self:getMessage(MESSAGE_ALREADYFOCUSED)
                local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
                msg = self:parseMessage(msg, parseInfo)
                self:say(msg)
            else
                if(not self.queue:isInQueue(cid)) then
                    self.queue:push(cid)
                end
                local msg = self:getMessage(MESSAGE_PLACEDINQUEUE)
                local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid), [TAG_QUEUESIZE] = self.queue:getSize() }
                msg = self:parseMessage(msg, parseInfo)
                self:say(msg)
            end
        end
    end
    
    -- Simply calls the underlying unGreet function.
    function NpcHandler:onFarewell()
        self:unGreet()
    end
    
    -- Should be called on this npc's focus if the distance to focus is greater then talkRadius.
    function NpcHandler:onWalkAway(cid)
        if(cid == self.focus) then
            local callback = self:getCallback(CALLBACK_CREATURE_DISAPPEAR)
            if(callback == nil or callback()) then
                if(self:processModuleCallback(CALLBACK_CREATURE_DISAPPEAR, cid)) then
                    if(self.queue == nil or not self.queue:greetNext()) then
                        local msg = self:getMessage(MESSAGE_WALKAWAY)
                        local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(self.focus) }
                        msg = self:parseMessage(msg, parseInfo)
                        self:say(msg)
                        self:releaseFocus()
                    end
                end
            end
        end
    end
    
    -- Returns true if cid is within the talkRadius of this npc.
    function NpcHandler:isInRange(cid)
        local playerPos = getPlayerPosition(cid)
        if playerPos == LUA_ERROR or playerPos == LUA_NO_ERROR then
            return false
        end
        
        local sx, sy, sz = selfGetPosition()
        local dx = math.abs(sx-playerPos.x)
        local dy = math.abs(sy-playerPos.y)
        local dz = math.abs(sz-playerPos.z)
        
        local dist = (dx^2 + dy^2)^0.5
        
        return (dist <= self.talkRadius and dz == 0)
    end
    
    -- Resets the npc into it's initial state (in regard of the keyrodhandler).
    --    All modules are also receiving a reset call through their callbackOnModuleReset function.
    function NpcHandler:resetNpc()
        if(self:processModuleCallback(CALLBACK_MODULE_RESET)) then
            self.keywordHandler:reset()
        end
    end
    
    
    -- Makes the npc represented by this instance of NpcHandler say something.
    --    This implements the currently set type of talkdelay.
    --    shallDelay is a boolean value. If it is false, the message is not delayed. Default value is true.
    function NpcHandler:say(message, shallDelay)
        if(shallDelay == nil) then
            shallDelay = true
        end
        if(NPCHANDLER_TALKDELAY == TALKDELAY_NONE or shallDelay == false) then
            selfSay(message)
            return
        end
        self.talkDelay.message = message
        self.talkDelay.time = os.time()+self.talkDelayTime
    end
    
    
end
Post automatically merged:

modules
 

Attachments

Back
Top