Ir para conteúdo
  • Cadastre-se

script npc fazer uma modificação (vodkart)


Posts Recomendados

.Qual servidor ou website você utiliza como base? 

tfs 1.2 10.98

 

Qual o motivo deste tópico? 

 

bom dia rapaze! eu tenho esse script feito pelo vodkart, funciona perfeitamente! só queria fazer uma modificação eu mudei versão do meu otserv! 

e ai no caso ele não esta removendo o dinheiro do banco, exemplo se o player tem dinheiro na bag, ele viaja normalmente mais se ele não tiver dinheiro na bag e tiver dinheiro no banco ele não viaja

ai queria fazer essa modificação.

 

Está surgindo algum erro? Se sim coloque-o aqui. 

Citar

 

 

Você tem o código disponível? Se tiver publique-o aqui: 

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())

 

Você tem alguma imagem que possa auxiliar no problema? Se sim, coloque-a aqui. 

 

Link para o post
Compartilhar em outros sites
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 pairs(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 travel = lowerTable(viagens)

    if travel[msg] then
        local player = Player(cid)
        local var = travel[msg]

        if var.level > 0 and player:getLevel() < 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
        else
            local cost = var.cost
            local playerMoney = player:getMoney()
            local playerBankBalance = player:getBankBalance()
            
            if playerMoney < cost and playerBankBalance >= cost then
                player:withdrawMoneyFromBank(cost)
            elseif playerMoney < cost and playerBankBalance < cost then
                npcHandler:say("Sorry, you don't have enough money in your backpack or in the bank.", cid)
                return true
            else
                player:removeMoney(cost)
            end

            npcHandler:say("Bon voyage!!", cid)
            npcHandler:releaseFocus(cid)
            local playerPos = getCreaturePosition(cid)
            Position(playerPos):sendMagicEffect(CONST_ME_TELEPORT)
            doTeleportThing(cid, var.destination)
			npcHandler:say("The boat lost its way and stopped in Magician, Careful!", cid)
        end
    else
        npcHandler:say("I don't sail to this city...", cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Editado por GM Vortex (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
1 hora atrás, GM Vortex disse:


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 pairs(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 travel = lowerTable(viagens)

    if travel[msg] then
        local player = Player(cid)
        local var = travel[msg]

        if var.level > 0 and player:getLevel() < 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
        else
            local cost = var.cost
            local playerMoney = player:getMoney()
            local playerBankBalance = player:getBankBalance()
            
            if playerMoney < cost and playerBankBalance >= cost then
                player:withdrawMoneyFromBank(cost)
            elseif playerMoney < cost and playerBankBalance < cost then
                npcHandler:say("Sorry, you don't have enough money in your backpack or in the bank.", cid)
                return true
            else
                player:removeMoney(cost)
            end

            npcHandler:say("Bon voyage!!", cid)
            npcHandler:releaseFocus(cid)
            local playerPos = getCreaturePosition(cid)
            Position(playerPos):sendMagicEffect(CONST_ME_TELEPORT)
            doTeleportThing(cid, var.destination)
			npcHandler:say("The boat lost its way and stopped in Magician, Careful!", cid)
        end
    else
        npcHandler:say("I don't sail to this city...", cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Bom dia man! deu erro no console

 

Lua Script Error: [Npc interface]
data/npc/scripts/claudiao.lua:onCreatureSay
data/npc/scripts/claudiao.lua:58: attempt to call method 'withdrawMoneyFromBank' (a nil value)
stack traceback:
        [C]: in function 'withdrawMoneyFromBank'
        data/npc/scripts/claudiao.lua:58: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
        data/npc/scripts/capitao batata.lua:15: in function <data/npc/scripts/claudiao.lua:14>

 

 

 

meu modules.lua 

 

 

 

  function Player.removeMoneyNpc(self, amount)
    local moneyCount = self:getMoney()
    local bankCount = self:getBankBalance()
    if amount > moneyCount + bankCount then
        return false
    end

    self:removeMoney(math.min(amount, moneyCount))
    if amount > moneyCount then
        local newBalance = bankCount - math.max(amount - moneyCount, 0)
        self:setBankBalance(newBalance)
        if moneyCount == 0 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, ("Você pagou %d gps da sua conta bancária. Seu saldo foi de %d para %d gps."):format(amount, bankCount, newBalance))
        else
            self:sendTextMessage(MESSAGE_INFO_DESCR, ("You paid %d from inventory and %d gold from bank account. Your account balance went from %d to %d gps."):format(moneyCount, amount - moneyCount, bankCount, newBalance))
        end
    end
    return true
end

 

 

eu tenho esse outro npc aqui e funciona normalmente das duas maneiras, quiser usar como base

 

Citar

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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({'fort'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Você deseja ir para Fort em troca de 300 gps?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 300, destination = {x=768, y=1088, z=6} })
    travelNode:addChildKeyword({'sim'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 300, destination = {x=768, y=1088, z=6} })
    


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

 

Editado por Vitorelias (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
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 lowerTable(table)
    local lowerCaseTable = {}
    for key, value in pairs(table) do
        lowerCaseTable[key:lower()] = value
    end
    return lowerCaseTable
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser, msg = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid, msg:lower()
    local travels = {
        ['dark city'] = {premium = false, level = 0, cost = 200, destination = {x=766, y=1090, z=6}},
 
    }

    local travel = lowerTable(travels)

    if travel[msg] then
        local player = Player(cid)
        local var = travel[msg]

        if var.level > 0 and player:getLevel() < var.level then
            npcHandler:say("Sorry, you must be level " .. var.level .. " to travel to this place.", cid)
        elseif var.premium and not isPremium(cid) then
            npcHandler:say("Sorry, to go to " .. msg .. " it is necessary to be VIP.", cid)
        else
            local cost = var.cost
            local playerMoney = player:getMoney()
            local playerBankBalance = player:getBankBalance()
            
            if playerMoney < cost and playerBankBalance >= cost then
                player:removeMoney(cost) 
                player:setBankBalance(playerBankBalance - cost) 
            elseif playerMoney < cost and playerBankBalance < cost then
                npcHandler:say("Sorry, you don't have enough money in your backpack or in the bank.", cid)
            else
                player:removeMoney(cost) 
            end

            npcHandler:say("Bon voyage!", cid)
            npcHandler:releaseFocus(cid)
            local playerPos = getCreaturePosition(cid)
            Position(playerPos):sendMagicEffect(CONST_ME_TELEPORT)
            doTeleportThing(cid, var.destination)
            npcHandler:say("The boat lost its way and stopped in Magician, careful!", cid)
        end
    else
        npcHandler:say("I don't sail to this city...", cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Link para o post
Compartilhar em outros sites
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

local magician_pos = {x=1249, y=783, z=6}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    local travelDestinations = {
        ['dark city'] = {premium = false, level = 0, cost = 200, destination = {x=766, y=1090, z=6}, chance = 50}
    }

    local player = Player(cid)
    local travel = travelDestinations[msg:lower()]
    
    if travel then
        if travel.level > 0 and player:getLevel() < travel.level then
            npcHandler:say("Sorry, you must be level " .. travel.level .. " to travel to this place.", cid)
        elseif travel.premium and not player:isPremium() then
            npcHandler:say("Sorry, to go to " .. msg .. " it is necessary to be VIP.", cid)
        else
            local travelCost = travel.cost
            local success = player:removeTotalMoney(travelCost)
            if success then
                local remainingBalance = player:getBankBalance()
                local message = ""
                if remainingBalance > 0 then
                    message = ("You paid %d gold for the travel service for %s. Your current balance is %d gold in the bank."):format(travelCost, msg, remainingBalance)
                else
                    message = ("You paid %d gold for the travel service to %s. Your bank balance is empty."):format(travelCost, msg)
                end
                player:sendTextMessage(MESSAGE_INFO_DESCR, message)

                local mychance = travel.chance or 100
                if player:getSlotItem(CONST_SLOT_NECKLACE) and player:getSlotItem(CONST_SLOT_NECKLACE).itemid == 10219 then
                    mychance = 100
                end

                if math.random(1, 100) <= mychance then
                    local pos = travel.destination
                    local magicEffect = CONST_ME_TELEPORT
                    Position(pos):sendMagicEffect(magicEffect)
                    doTeleportThing(cid, pos)
                    npcHandler:say("Bon voyage!", cid)
                else
                    local pos = magician_pos
                    local magicEffect = CONST_ME_TELEPORT
                    Position(pos):sendMagicEffect(magicEffect)
                    doTeleportThing(cid, pos)
                    npcHandler:say("The boat lost its way and stopped in Magician. Careful!", cid)
                end
            else
                npcHandler:say("You don't have enough money to travel to " .. msg .. ".", cid)
            end
        end
    else
        npcHandler:say("I don't sail to this city...", cid)
    end
    
    npcHandler:releaseFocus(cid)
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

testado e funcionado OK!!

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo