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

Lua TFS 1.3 NPC that update normal mount to armored mount

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys, I would like a script for a npc where the player can put a armor in the mount. For example:

The player has the dragonling mount and go to this npc with 10 piece of draconian steel + 5 piece of hell steel in the bag, the npc will remove the dragonling mount and give the azudocus mount to the player.
If the player has the dragonling mount and go to this npc with 10 piece of royal steel + 5 pieces of hell steel in the bag, the npc will remove the dragonling mount and give the carpacosaurus mount to the player.
If the player has the manta ray mount and go to this npc with 5 piece of royal satin in the bag, the npc will remove the manta ray mount and give the crimson ray mount to the player.

It would be a great help with anyone can help me with this.
 
Solution
X
uhhh

Try this. lol
LUA:
local config = {
    --[[
    ["new mount name"] = {
        newMountId = 111,
        requiredMountId = 111,
        requiredMountName = "blah",
        requiredItems = {
            {itemId = 1111, amount = 1},
            {itemId = 1111, amount = 1}
        }
    },
    ]]--
    ["azudocus"] = { -- ensure mount names are lowercase
        newMountId = 111,
        requiredMountId = 111,
        requiredMountName = "dragonling",
        requiredItems = {
            {itemId = 1111, amount = 1},
            {itemId = 1111, amount = 1}
        }
    }
}

local mountTarget = {}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)...
uhhh

Try this. lol
LUA:
local config = {
    --[[
    ["new mount name"] = {
        newMountId = 111,
        requiredMountId = 111,
        requiredMountName = "blah",
        requiredItems = {
            {itemId = 1111, amount = 1},
            {itemId = 1111, amount = 1}
        }
    },
    ]]--
    ["azudocus"] = { -- ensure mount names are lowercase
        newMountId = 111,
        requiredMountId = 111,
        requiredMountName = "dragonling",
        requiredItems = {
            {itemId = 1111, amount = 1},
            {itemId = 1111, amount = 1}
        }
    }
}

local mountTarget = {}

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

local function greetCallback(cid)
    local player = Player(cid)
    if player then
        local playerId = player:getId()
        mountTarget[playerId] = ""
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    local player = Player(cid)
    if not player then
        return true
    end
    local playerId = player:getId()
    
    local index = config[msg:lower()]
    if not index and mountTarget[playerId] == "" then
        local text = ""
        for v, k in pairs(config) do
            if not player:hasMount(k.newMountId) then
                if text ~= "" then
                    text = text .. ", "
                end
                text = text .. v
            end
        end
        if text == "" then
            npcHandler:say("You have obtained all of the mount upgrades I have available.", cid)
            return true
        end
        npcHandler:say("Available mount upgrades: " .. text .. ".", cid)
        return true
    end
    
    if mountTarget[playerId] == "" then
        if player:hasMount(index.newMountId) then
            npcHandler:say("You have already obtained this mount upgrade.", cid)
            return true
        end
        local text = ""
        for i = 1, #index.requiredItems do
            if text ~= "" then
                text = text .. ", "
            end
            text = text .. index.requiredItems[i].amount .. " " .. ItemType(index.requiredItems[i].itemId):getName()
        end
        npcHandler:say("To get this mount upgrade you need to provide me with " .. text .. " and further requires you to give up a " .. index.requiredMountName .. " mount. Would you like to proceed?", cid)
        mountTarget[playerId] = msg:lower()
        return true
    end

    if not msgcontains(msg, "yes") then
        npcHandler:say("Another time then.", cid)
        mountTarget[playerId] = ""
        return true
    end
    
    index = config[mountTarget[playerId]]
    
    if not player:hasMount(index.requiredMountId) then
        npcHandler:say("You do not currently own a " .. index.requiredMountName .. " mount. Come back and see me when you do.", cid)
        mountTarget[playerId] = ""
        return true
    end
    
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i].itemId) < index.requiredItems[i].amount then
            npcHandler:say("You are missing some items required for the upgrade. Come back and see me when you have them in your inventory.", cid)
            mountTarget[playerId] = ""
            return true
        end
    end
    
    player:removeMount(index.requiredMountId)
    for i = 1, #index.requiredItems do
        player:removeItem(index.requiredItems[i].itemId, index.requiredItems[i].amount)
    end
    
    player:addMount(index.newMountId)
    local outfit = player:getOutfit()
    outfit.lookMount = index.newMountId
    player:setOutfit(outfit)

    npcHandler:say("Great! Come back to see me if you want another upgrade!", cid)
    mountTarget[playerId] = ""
    return true
end

local function onAddFocus(cid)
    local player = Player(cid)
    if player then
        local playerId = player:getId()
        mountTarget[playerId] = ""
    end
end

local function onReleaseFocus(cid)
    local player = Player(cid)
    if player then
        local playerId = player:getId()
        mountTarget[playerId] = ""
    end
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
uhhh

Try this. lol
LUA:
local config = {
    --[[
    ["new mount name"] = {
        newMountId = 111,
        requiredMountId = 111,
        requiredMountName = "blah",
        requiredItems = {
            {itemId = 1111, amount = 1},
            {itemId = 1111, amount = 1}
        }
    },
    ]]--
    ["azudocus"] = { -- ensure mount names are lowercase
        newMountId = 111,
        requiredMountId = 111,
        requiredMountName = "dragonling",
        requiredItems = {
            {itemId = 1111, amount = 1},
            {itemId = 1111, amount = 1}
        }
    }
}

local mountTarget = {}

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

local function greetCallback(cid)
    local player = Player(cid)
    if player then
        local playerId = player:getId()
        mountTarget[playerId] = ""
    end
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local player = Player(cid)
    if not player then
        return true
    end
    local playerId = player:getId()
   
    local index = config[msg:lower()]
    if not index and mountTarget[playerId] == "" then
        local text = ""
        for v, k in pairs(config) do
            if not player:hasMount(k.newMountId) then
                if text ~= "" then
                    text = text .. ", "
                end
                text = text .. v
            end
        end
        if text == "" then
            npcHandler:say("You have obtained all of the mount upgrades I have available.", cid)
            return true
        end
        npcHandler:say("Available mount upgrades: " .. text .. ".", cid)
        return true
    end
   
    if mountTarget[playerId] == "" then
        if player:hasMount(index.newMountId) then
            npcHandler:say("You have already obtained this mount upgrade.", cid)
            return true
        end
        local text = ""
        for i = 1, #index.requiredItems do
            if text ~= "" then
                text = text .. ", "
            end
            text = text .. index.requiredItems[i].amount .. " " .. ItemType(index.requiredItems[i].itemId):getName()
        end
        npcHandler:say("To get this mount upgrade you need to provide me with " .. text .. " and further requires you to give up a " .. index.requiredMountName .. " mount. Would you like to proceed?", cid)
        mountTarget[playerId] = msg:lower()
        return true
    end

    if not msgcontains(msg, "yes") then
        npcHandler:say("Another time then.", cid)
        mountTarget[playerId] = ""
        return true
    end
   
    index = config[mountTarget[playerId]]
   
    if not player:hasMount(index.requiredMountId) then
        npcHandler:say("You do not currently own a " .. index.requiredMountName .. " mount. Come back and see me when you do.", cid)
        mountTarget[playerId] = ""
        return true
    end
   
    for i = 1, #index.requiredItems do
        if player:getItemCount(index.requiredItems[i].itemId) < index.requiredItems[i].amount then
            npcHandler:say("You are missing some items required for the upgrade. Come back and see me when you have them in your inventory.", cid)
            mountTarget[playerId] = ""
            return true
        end
    end
   
    player:removeMount(index.requiredMountId)
    for i = 1, #index.requiredItems do
        player:removeItem(index.requiredItems[i].itemId, index.requiredItems[i].amount)
    end
   
    player:addMount(index.newMountId)
    local outfit = player:getOutfit()
    outfit.lookMount = index.newMountId
    player:setOutfit(outfit)

    npcHandler:say("Great! Come back to see me if you want another upgrade!", cid)
    mountTarget[playerId] = ""
    return true
end

local function onAddFocus(cid)
    local player = Player(cid)
    if player then
        local playerId = player:getId()
        mountTarget[playerId] = ""
    end
end

local function onReleaseFocus(cid)
    local player = Player(cid)
    if player then
        local playerId = player:getId()
        mountTarget[playerId] = ""
    end
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Nice it works, but is there a way for the npc to say the name of mounts he will improve to? For example player say hi - mounts then the npc will give a list of mounts he can improve like "azudocus"
 
Back
Top