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

vitorelias1

New Member
Joined
Sep 27, 2022
Messages
27
Reaction score
2
hello guys!

I have this travel npc script
I changed the version of my otserv and some traveling NPCs have the option of traveling without money in the backpack it removes the money from the bank I would like to modify this script to work if the player does not have money in the backpack it removes it from the bank


Lua:
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 onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
    function lowerTable(tabela) -- by vodkart
        local tab = {}
        for var, ret in next, tabela do
            tab[var:lower()] = ret
        end
        return tab
    end
    if not npcHandler:isFocused(cid) then
        return false
    end
    local talkUser,msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, msg:lower()
    local viagens = {
                ['Dark City'] = {premium = false, level = 0, cost = 200, destination = {x=766, y=1090, z=6}},

    }
    local magician_pos = {x=1249, y=783, z=6}
    local travel = lowerTable(viagens)
    if travel[msg] then
        local var = travel[msg]
        if var.level > 0 and getPlayerLevel(cid) < var.level then
            npcHandler:say("Sorry but you must be level ".. var.level .." to travel to this place.", cid) return true
        elseif var.premium and not isPremium(cid) then
            npcHandler:say("Sorry, to go to "..msg.." it is necessary to be VIP.", cid) return true     
        elseif not doPlayerRemoveMoney(cid, var.cost) then   
            npcHandler:say("Sorry, you don't have enough GPS. Is required ".. var.cost .."gps to go to "..msg..".", cid) return true
        end
        if var.chance ~= nil and var.chance > 0 then
            if getPlayerSlotItem(cid, CONST_SLOT_NECKLACE).itemid == 10219 then
                mychance = 100
            else
                mychance = var.chance
            end
        end
        npcHandler:say("Bon voyage!", cid)           
        npcHandler:releaseFocus(cid)
        if var.chance ~= nil and var.chance > 0 then
            if mychance > math.random(1, 100) then
                doTeleportThing(cid, garath_pos)
                npcHandler:say("The boat lost its way and stopped in Magician, Careful!", cid)
            else
                doTeleportThing(cid, var.destination)
            end
        else
            doTeleportThing(cid, var.destination)
        end     
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
    else
        selfSay("I don't sail to this city...", cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
hello guys!

I have this travel npc script
I changed the version of my otserv and some traveling NPCs have the option of traveling without money in the backpack it removes the money from the bank I would like to modify this script to work if the player does not have money in the backpack it removes it from the bank


Lua:
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 onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
    function lowerTable(tabela) -- by vodkart
        local tab = {}
        for var, ret in next, tabela do
            tab[var:lower()] = ret
        end
        return tab
    end
    if not npcHandler:isFocused(cid) then
        return false
    end
    local talkUser,msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, msg:lower()
    local viagens = {
                ['Dark City'] = {premium = false, level = 0, cost = 200, destination = {x=766, y=1090, z=6}},

    }
    local magician_pos = {x=1249, y=783, z=6}
    local travel = lowerTable(viagens)
    if travel[msg] then
        local var = travel[msg]
        if var.level > 0 and getPlayerLevel(cid) < var.level then
            npcHandler:say("Sorry but you must be level ".. var.level .." to travel to this place.", cid) return true
        elseif var.premium and not isPremium(cid) then
            npcHandler:say("Sorry, to go to "..msg.." it is necessary to be VIP.", cid) return true     
        elseif not doPlayerRemoveMoney(cid, var.cost) then   
            npcHandler:say("Sorry, you don't have enough GPS. Is required ".. var.cost .."gps to go to "..msg..".", cid) return true
        end
        if var.chance ~= nil and var.chance > 0 then
            if getPlayerSlotItem(cid, CONST_SLOT_NECKLACE).itemid == 10219 then
                mychance = 100
            else
                mychance = var.chance
            end
        end
        npcHandler:say("Bon voyage!", cid)           
        npcHandler:releaseFocus(cid)
        if var.chance ~= nil and var.chance > 0 then
            if mychance > math.random(1, 100) then
                doTeleportThing(cid, garath_pos)
                npcHandler:say("The boat lost its way and stopped in Magician, Careful!", cid)
            else
                doTeleportThing(cid, var.destination)
            end
        else
            doTeleportThing(cid, var.destination)
        end     
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
    else
        selfSay("I don't sail to this city...", cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
You just need to change doPlayerRemoveMoney for the correct function that remove money also from bank.

which server do you use?
 
You just need to change doPlayerRemoveMoney for the correct function that remove money also from bank.

which server do you use?
Good morning man, I already have the function, I've already changed the src, the other traveling NPCs also work perfectly but this one doesn't work.
I use tfs 1.2 10.98
this is script this simple script works perfectly it removes the money from the bank now the script above wanted it to work the same way

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local target = -3
NpcSystem.parseParameters(npcHandler)



-- OTServ event handling functions start
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
-- OTServ event handling functions end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'magician'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Magician for 900 gps?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 100, destination = {x=965, y=486, z=7} })
    travelNode:addChildKeyword({'sim'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 100, destination = {x=965, y=486, z=7} })
    

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
 
Back
Top