• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Quick Tip: Free Boat Travel ["/reload config"]

J.Dre

Unity Games
Joined
May 18, 2011
Messages
2,647
Solutions
3
Reaction score
648
Location
United States
Thought of this when someone asked for a boat NPC in support.

"Do you want to sail to Carlin for 0 gold coins?" NO!

"Do you want to sail to Carlin for free?" YES!

This will allow freeTravel to all players with a simple config.lua edit. It's easy to implement and looks much better in game.

Code:
freeTravel = true

npc/lib/npcsystem/modules.lua

Replace your modules with these in modules.lua:

Code:
    function StdModule.travel(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if(npcHandler == nil) then
            print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'StdModule.travel - Call without any npcHandler instance.')
            return false
        end

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

        local storage, pzLocked = parameters.storageValue or (EMPTY_STORAGE + 1), parameters.allowLocked or false
        if getConfigInfo('freeTravel') then
            parameters.cost = 0
        end
        if(parameters.premium and not isPremium(cid)) then
            npcHandler:say('I\'m sorry, but you need a premium account in order to travel onboard our ships.', cid)
        elseif(parameters.level ~= nil and getPlayerLevel(cid) < parameters.level) then
            npcHandler:say('You must reach level ' .. parameters.level .. ' before I can let you go there.', cid)
        elseif(parameters.storageId ~= nil and getPlayerStorageValue(cid, parameters.storageId) < storage) then
            npcHandler:say(parameters.storageInfo or 'You may not travel there yet!', cid)
        elseif(not pzLocked and isPlayerPzLocked(cid)) then
            npcHandler:say('First get rid of those blood stains! You are not going to ruin my vehicle!', cid)
        elseif(not doPlayerRemoveMoney(cid, parameters.cost)) then
            npcHandler:say('You don\'t have enough money.', cid)
        else
            npcHandler:say('Set the sails!', cid)
            npcHandler:releaseFocus(cid)

            doTeleportThing(cid, parameters.destination, false)
            doSendMagicEffect(parameters.destination, CONST_ME_TELEPORT)
        end

        npcHandler:resetNpc(cid)
        return true
    end

    function TravelModule.travel(cid, message, keywords, parameters, node)
        local module = parameters.module
        if(not module.npcHandler:isFocused(cid)) then
            return false
        end

        if getConfigInfo('freeTravel') then
            parameters.cost = 0
        end
      
        module.npcHandler:say('Do you want to travel to ' .. keywords[1] .. ' for ' .. parameters.cost .. ' gold coins?', cid)
        return true
    end

    function TravelModule.onConfirm(cid, message, keywords, parameters, node)
        local module = parameters.module
        if(not module.npcHandler:isFocused(cid)) then
            return false
        end

        if getConfigInfo('freeTravel') then
            parameters.cost = 0
        end
      
        local parent = node:getParent():getParameters()
        if(isPremium(cid) or not parent.premium) then
            if(not isPlayerPzLocked(cid)) then
                if(doPlayerRemoveMoney(cid, parent.cost)) then
                    module.npcHandler:say('Set the sails!', cid)
                    module.npcHandler:releaseFocus(cid)

                    doTeleportThing(cid, parent.destination, true)
                    doSendMagicEffect(parent.destination, CONST_ME_TELEPORT)
                else
                    module.npcHandler:say('You don\'t have enough money.', cid)
                end
            else
                module.npcHandler:say('First get rid of those blood stains! You are not going to ruin my vehicle!', cid)
            end
        else
            module.npcHandler:say('I\'m sorry, but you need a premium account in order to travel onboard our ships.', cid)
        end

        module.npcHandler:resetNpc(cid)
        return true
    end

    function TravelModule.bring(cid, message, keywords, parameters, node)
        local module = parameters.module
        if(not module.npcHandler:isFocused(cid)) then
            return false
        end

        if getConfigInfo('freeTravel') then
            parameters.cost = 0
        end
      
        if((isPremium(cid) or not parameters.premium) and not isPlayerPzLocked(cid) and doPlayerRemoveMoney(cid, parameters.cost)) then
            module.npcHandler:say('Set the sails!', cid)
            module.npcHandler:releaseFocus(cid)

            doTeleportThing(cid, parameters.destination, false)
            doSendMagicEffect(parameters.destination, CONST_ME_TELEPORT)
        end

        module.npcHandler:releaseFocus(cid)
        return true
    end


Here's an example travel node for NPC's:

Code:
--Travel Nodes
local travelNode = keywordHandler:addKeyword({"carlin"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to sail to Carlin for " .. (getConfigInfo("freeTravel") and "free?" or "110 gold coins?")})
    travelNode:addChildKeyword({"yes"}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 110, destination = {x=32387, y=31820, z=6} })
    travelNode:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = "We would like to serve you some time."})

Easy peasy. Done.
thumbs-up-smiley%5B1%5D.gif
 
Last edited:
Back
Top