• 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 Boat NPC - taking money from bank

SamX

VoltageOT Developer
Joined
Aug 27, 2010
Messages
557
Reaction score
151
Location
Canada
Hey,

For some reason I can't figure out why the NPC won't send the player to the new location if the player does not have gold on them. It gives me the message saying "Removed xxx from bank account." but does not send the player to the destination. Works fine if player has gold in backpack.

Here is the script.
Code:
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

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 voices = {
        { text = 'Passages to Oran and Visten!' }
}

-- Travel
local travelNode = keywordHandler:addKeyword({'oran'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like a trip to Oran for 150 gold coins?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 2, cost = 150, destination = {x=4068, y=536, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Maybe next time..'})
   
   
local travelNode = keywordHandler:addKeyword({'visten'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like a trip to Visten for 130 gold coins?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 2, cost = 130, destination = {x=1201, y=991, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Maybe next time..'})


-- Basic
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = 'My name is Captain Hurcraft.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I am the captain of this ship.'})

npcHandler:setMessage(MESSAGE_GREET, 'Welcome to my humble shipcraft, |PLAYERNAME|. Where can I {sail} you today?')
npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye. Please tell your friends about my service.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye then.')

npcHandler:addModule(FocusModule:new())
 
Solution
Lua:
    function StdModule.travel(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.travel called without any npcHandler instance.")
        end
        if not npcHandler:isFocused(cid) then
            return false
        end
        local player = Player(cid)
        if player:isPremium() or not parameters.premium then
            if player:isPzLocked() then
                npcHandler:say("First get rid of those blood stains! You are not going to ruin my vehicle!", cid)...
Probably something wrong with the way you have added this feature to remove money from bank and you didn't change StdModule.travel,
 
Probably something wrong with the way you have added this feature to remove money from bank and you didn't change StdModule.travel,
It works fine using the trade function. I located the StdModule.travel function inside modules.lua; however I'm not sure what to add. Any tips?
Code:
    function TravelModule.onConfirm(cid, message, keywords, parameters, node)
        local module = parameters.module
        if not module.npcHandler:isFocused(cid) then
            return false
        end

        if shop_npcuid[cid] ~= Npc().uid then
            return false
        end

        local npcHandler = module.npcHandler

        local cost = shop_cost[cid]
        local destination = Position(shop_destination[cid])

        local player = Player(cid)
        if player:isPremium() or not shop_premium[cid] then
            if not player:removeMoney(cost) then
                if player:getBankBalance() < cost then
                    npcHandler:say("You do not have enough money!", cid)
                else
                    player:setBankBalance(player:getBankBalance() - cost)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, ("Bank Account: %d gold has been withdrawn from your account for this purchase. Your account balance is %d gold coins."):format(cost, player:getBankBalance()))
                end
            elseif player:isPzLocked(cid) then
                npcHandler:say("Get out of there with this blood.", cid)
            else
                npcHandler:say("It was a pleasure doing business with you.", cid)
                npcHandler:releaseFocus(cid)

                local position = player:getPosition()
                player:teleportTo(destination)

                position:sendMagicEffect(CONST_ME_TELEPORT)
                destination:sendMagicEffect(CONST_ME_TELEPORT)
            end
        else
            npcHandler:say("I can only allow premium players to travel there.", cid)
        end

        npcHandler:resetNpc(cid)
        return true
    end

Code:
    function StdModule.travel(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.travel called without any npcHandler instance.")
        end

        if not npcHandler:isFocused(cid) then
            return false
        end
 
It works fine using the trade function. I located the StdModule.travel function inside modules.lua; however I'm not sure what to add. Any tips?
Code:
    function TravelModule.onConfirm(cid, message, keywords, parameters, node)
        local module = parameters.module
        if not module.npcHandler:isFocused(cid) then
            return false
        end

        if shop_npcuid[cid] ~= Npc().uid then
            return false
        end

        local npcHandler = module.npcHandler

        local cost = shop_cost[cid]
        local destination = Position(shop_destination[cid])

        local player = Player(cid)
        if player:isPremium() or not shop_premium[cid] then
            if not player:removeMoney(cost) then
                if player:getBankBalance() < cost then
                    npcHandler:say("You do not have enough money!", cid)
                else
                    player:setBankBalance(player:getBankBalance() - cost)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, ("Bank Account: %d gold has been withdrawn from your account for this purchase. Your account balance is %d gold coins."):format(cost, player:getBankBalance()))
                end
            elseif player:isPzLocked(cid) then
                npcHandler:say("Get out of there with this blood.", cid)
            else
                npcHandler:say("It was a pleasure doing business with you.", cid)
                npcHandler:releaseFocus(cid)

                local position = player:getPosition()
                player:teleportTo(destination)

                position:sendMagicEffect(CONST_ME_TELEPORT)
                destination:sendMagicEffect(CONST_ME_TELEPORT)
            end
        else
            npcHandler:say("I can only allow premium players to travel there.", cid)
        end

        npcHandler:resetNpc(cid)
        return true
    end

Code:
    function StdModule.travel(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.travel called without any npcHandler instance.")
        end

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

        if shop_npcuid[cid] ~= Npc().uid then
            return false
        end

        local npcHandler = module.npcHandler

        local cost = shop_cost[cid]
        local destination = Position(shop_destination[cid])

        local player = Player(cid)
        if player:isPremium() or not shop_premium[cid] then
            if player:isPzLocked() then
                npcHandler:say("Get out of there with this blood.", cid)
                npcHandler:resetNpc(cid)
                return true
            end

            if not player:removeMoney(cost) then
                if player:getBankBalance() < cost then
                    npcHandler:say("You do not have enough money!", cid)
                    npcHandler:resetNpc(cid)
                    return true
                else
                    player:setBankBalance(player:getBankBalance() - cost)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, ("Bank Account: %d gold has been withdrawn from your account for this purchase. Your account balance is %d gold coins."):format(cost, player:getBankBalance()))
                end
            end

            npcHandler:say("It was a pleasure doing business with you.", cid)
            npcHandler:releaseFocus(cid)

            local position = player:getPosition()
            player:teleportTo(destination)

            position:sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
        else
            npcHandler:say("I can only allow premium players to travel there.", cid)
        end

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

        if shop_npcuid[cid] ~= Npc().uid then
            return false
        end

        local npcHandler = module.npcHandler

        local cost = shop_cost[cid]
        local destination = Position(shop_destination[cid])

        local player = Player(cid)
        if player:isPremium() or not shop_premium[cid] then
            if player:isPzLocked() then
                npcHandler:say("Get out of there with this blood.", cid)
                npcHandler:resetNpc(cid)
                return true
            end

            if not player:removeMoney(cost) then
                if player:getBankBalance() < cost then
                    npcHandler:say("You do not have enough money!", cid)
                    npcHandler:resetNpc(cid)
                    return true
                else
                    player:setBankBalance(player:getBankBalance() - cost)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, ("Bank Account: %d gold has been withdrawn from your account for this purchase. Your account balance is %d gold coins."):format(cost, player:getBankBalance()))
                end
            end

            npcHandler:say("It was a pleasure doing business with you.", cid)
            npcHandler:releaseFocus(cid)

            local position = player:getPosition()
            player:teleportTo(destination)

            position:sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
        else
            npcHandler:say("I can only allow premium players to travel there.", cid)
        end

        npcHandler:resetNpc(cid)
        return true
    end
Changed it, still not sending the player to the destination.
 
Changed it, still not sending the player to the destination.
With the code that I sent it's impossible to work for money but not work for balance.

You should place prints and make sure that it's even executing this function.
 
With the code that I sent it's impossible to work for money but not work for balance.

You should place prints and make sure that it's even executing this function.
Tried adding a few prints in the function, guess it's not even executing. Could it perhaps be an issue with the NPC script? Maybe it's not calling properly.
 
Tried adding a few prints in the function, guess it's not even executing. Could it perhaps be an issue with the NPC script? Maybe it's not calling properly.
You should send the entire StdModule.travel. Use pastebin if it's too big.
 
Lua:
    function StdModule.travel(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.travel called without any npcHandler instance.")
        end
        if not npcHandler:isFocused(cid) then
            return false
        end
        local player = Player(cid)
        if player:isPremium() or not parameters.premium then
            if player:isPzLocked() then
                npcHandler:say("First get rid of those blood stains! You are not going to ruin my vehicle!", cid)
                npcHandler:resetNpc(cid)
                return true
            elseif parameters.level and player:getLevel() < parameters.level then
                npcHandler:say("You must reach level " .. parameters.level .. " before I can let you go there.", cid)
                npcHandler:resetNpc(cid)
                return true
            elseif not player:removeMoney(parameters.cost) then
                if player:getBankBalance() < parameters.cost then
                    npcHandler:say("You don't have enough money.", cid)
                    npcHandler:resetNpc(cid)
                    return true
                else
                    player:setBankBalance(player:getBankBalance() - parameters.cost)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, ("Bank Account: %d gold has been withdrawn from your account for this purchase. Your account balance is %d gold coins."):format(parameters.cost, player:getBankBalance()))
                end
            end
            npcHandler:say(parameters.msg or "Set the sails!", cid)
            npcHandler:releaseFocus(cid)
            local destination = Position(parameters.destination)
            local position = player:getPosition()
            player:teleportTo(destination)
            position:sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
        else
            npcHandler:say("I'm sorry, but you need a premium account in order to travel onboard our ships.", cid)
        end
        npcHandler:resetNpc(cid)
        return true
    end
 
Solution
Lua:
    function StdModule.travel(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.travel called without any npcHandler instance.")
        end
        if not npcHandler:isFocused(cid) then
            return false
        end
        local player = Player(cid)
        if player:isPremium() or not parameters.premium then
            if player:isPzLocked() then
                npcHandler:say("First get rid of those blood stains! You are not going to ruin my vehicle!", cid)
                npcHandler:resetNpc(cid)
                return true
            elseif parameters.level and player:getLevel() < parameters.level then
                npcHandler:say("You must reach level " .. parameters.level .. " before I can let you go there.", cid)
                npcHandler:resetNpc(cid)
                return true
            elseif not player:removeMoney(parameters.cost) then
                if player:getBankBalance() < parameters.cost then
                    npcHandler:say("You don't have enough money.", cid)
                    npcHandler:resetNpc(cid)
                    return true
                else
                    player:setBankBalance(player:getBankBalance() - parameters.cost)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, ("Bank Account: %d gold has been withdrawn from your account for this purchase. Your account balance is %d gold coins."):format(parameters.cost, player:getBankBalance()))
                end
            end
            npcHandler:say(parameters.msg or "Set the sails!", cid)
            npcHandler:releaseFocus(cid)
            local destination = Position(parameters.destination)
            local position = player:getPosition()
            player:teleportTo(destination)
            position:sendMagicEffect(CONST_ME_TELEPORT)
            destination:sendMagicEffect(CONST_ME_TELEPORT)
        else
            npcHandler:say("I'm sorry, but you need a premium account in order to travel onboard our ships.", cid)
        end
        npcHandler:resetNpc(cid)
        return true
    end
Works perfectly now! Cheers!
 
Back
Top