• 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 [TFS 1.X][Canary] NPC Addons (base)

Liikuid

Spin Machine!
Joined
Jul 17, 2010
Messages
257
Reaction score
24
Location
Iquique, Chile
Hello everyone,

I've been searching for an NPC addon, but I couldn't find one for my current distro version. Varkhal seems a bit outdated. To be honest, I got lazy and decided to create one from scratch. I tested it with the classic outfits and addons, and it worked wonderfully. Here's the NPC for you:

Lua:
local internalNpcName = "Addoner"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}

npcConfig.name = internalNpcName
npcConfig.description = internalNpcName

npcConfig.health = 150
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 1068,
    lookHead = 0,
    lookBody = 76,
    lookLegs = 53,
    lookFeet = 0,
    lookAddons = 1,
    lookMount = 0
}


npcConfig.flags = {
    floorchange = false
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end

npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end

npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end

npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end

npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end

npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end

local outfits = {
    ["Hunter"] = {
        MaleOutfitId = 129,
        FemaleOutfitId = 137,
        addons = {
            { name = "first addon", items = { {1111, 1} }, storageAddon = 35100 },
            { name = "second addon", items = { {942, 3} }, storageAddon = 35101 }
        }
    },
    ["Citizen"] = {
        MaleOutfitId = 128,
        FemaleOutfitId = 136,
        addons = {
            { name = "first addon", items = { {1111, 1}, {1112, 2}, {1113, 3} }, storageAddon = 35104 },
            { name = "second addon", items = { {942, 1} }, storageAddon = 35105 }
        }
    }
}

local function creatureSayCallback(npc, creature, type, message)
    local player = Player(creature)
    local playerId = player:getId()

    if not npcHandler:checkInteraction(npc, creature) then
        return false
    end

    local playerTopic = npcHandler:getTopic(playerId)

    if playerTopic == 0 then
        for outfitName, outfitData in pairs(outfits) do
            if MsgContains(message, "first " .. outfitName .. " addon") then
                local addonData = outfitData.addons[1] -- first addon
                local addonItems = addonData.items
                local addonText = ""

                for i, item in ipairs(addonItems) do
                    local itemID, itemCount = item[1], item[2]
                    if i > 1 then
                        addonText = addonText .. ", "
                        if i == #addonItems then
                            addonText = addonText .. "and "
                        end
                    end
                    addonText = addonText .. itemCount .. " " .. ItemType(itemID):getName()
                end

                npcHandler:setTopic(playerId, outfitName .. "1")
                npcHandler:say("To obtain the " .. outfitName .. " first addon, you will need " .. addonText .. ". Would you like to proceed?", npc, creature)
                return true
            elseif MsgContains(message, "second " .. outfitName .. " addon") then
                local addonData = outfitData.addons[2] -- second addon
                local addonItems = addonData.items
                local addonText = ""

                for i, item in ipairs(addonItems) do
                    local itemID, itemCount = item[1], item[2]
                    if i > 1 then
                        addonText = addonText .. ", "
                        if i == #addonItems then
                            addonText = addonText .. "and "
                        end
                    end
                    addonText = addonText .. itemCount .. " " .. ItemType(itemID):getName()
                end

                npcHandler:setTopic(playerId, outfitName .. "2")
                npcHandler:say("To obtain the " .. outfitName .. " second addon, you will need " .. addonText .. ". Would you like to proceed?", npc, creature)
                return true
            end
        end
    elseif playerTopic ~= 0 then
        if MsgContains(message, "yes") then
            local outfitName = string.match(playerTopic, "([^%d]+)")
            local addonIndex = tonumber(string.match(playerTopic, "%d+"))
            local outfitData = outfits[outfitName]
            local addonData = outfitData.addons[addonIndex]
            local addonItems = addonData.items

            if player:getStorageValue(addonData.storageAddon) == 1 then
                npcHandler:say("You already have this addon for the " .. outfitName .. ".", npc, creature)
            else
                local hasRequiredItems = true

                for _, item in ipairs(addonItems) do
                    local itemID, itemCount = item[1], item[2]
                    if player:getItemCount(itemID) < itemCount then
                        hasRequiredItems = false
                        break
                    end
                end

                if hasRequiredItems then
                    player:setStorageValue(addonData.storageAddon, 1)
                    for _, item in ipairs(addonItems) do
                        local itemID, itemCount = item[1], item[2]
                        player:removeItem(itemID, itemCount)
                    end
                    npcHandler:say("You have obtained the " .. addonData.name .. " for the " .. outfitName .. ".", npc, creature)
                    player:addOutfitAddon(outfitData.MaleOutfitId, addonIndex)
                    player:addOutfitAddon(outfitData.FemaleOutfitId, addonIndex)
                else
                    npcHandler:say("You don't have the required items for the " .. addonData.name .. ".", npc, creature)
                end
            end

            npcHandler:setTopic(playerId, 0)
        else
            npcHandler:say("Goodbye.", npc, creature)
            npcHandler:setTopic(playerId, 0)
        end
    end
end

npcHandler:setMessage(MESSAGE_GREET, "To buy the first addon say {first NAME addon}, for the second addon say {second NAME addon}.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)


-- npcType registering the npcConfig table
npcType:register(npcConfig)

npcHandler:addModule(FocusModule:new())


The only thing you'll need to do on your part is add the missing outfits and items from the corresponding addons (I'll finish it in a little while or tomorrow, in which case, I'll update the post with the NPC, at least with the basic outfits).

Greetings!
 
thanks bro i was looking for this NPC, but i dont have knowledge for scripting
thanks for share
 
Back
Top