Ir para conteúdo
  • Cadastre-se

(Resolvido)[Pedido] Comando !withdraw


Ir para solução Resolvido por brendoonh,

Posts Recomendados

Fala galera, peguei um comando aqui no TK, de !withdraw tirar dinheiro do banco,

mais não esta funcionando está dando erro em linha 9!

Citar

[Error - TalkAction Interface] data/talkactions/scripts/withdraw.lua:onSay Description: data/talkactions/scripts/withdraw.lua:9: attempt to compare string with number stack traceback: data/talkactions/scripts/withdraw.lua:9: in function

 

Scripts

function onSay(cid, words, param) 
    if getPlayerTown(cid) == 24 then 
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot withdraw money being in Rookgaard.") 
        return 
    end 
     
    if isPlayer(cid) == TRUE and param ~= "" then 
        if getTilePzInfo(getPlayerPosition(cid)) == TRUE then 
                if getPlayerBalance(cid) >= param then           -----------> ERRO NESSA LINHA
                    doPlayerSetBalance(cid, getPlayerBalance(cid) - param) 
                    doPlayerAddMoney(cid, param) 
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Here you are, ".. param .." gold.") 
                else 
                    doPlayerSendCancel(cid, "You do not have enough money.") 
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
                end 
        else 
            doPlayerSendCancel(cid, "You can only use this command in PZ.") 
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
        end 
    end 
end

 

Link para o post
Compartilhar em outros sites

Tenta

 

function onSay(cid, words, param) 
    if getPlayerTown(cid) == 24 then 
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot withdraw money being in Rookgaard.") 
        return 
    end 
     
    if isPlayer(cid) == TRUE and param ~= "" then 
        if getTilePzInfo(getPlayerPosition(cid)) == TRUE then 
                if getPlayerBalance(cid) == param then
                    doPlayerSetBalance(cid, getPlayerBalance(cid) - param) 
                    doPlayerAddMoney(cid, param) 
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Here you are, ".. param .." gold.") 
                else 
                    doPlayerSendCancel(cid, "You do not have enough money.") 
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
                end 
        else 
            doPlayerSendCancel(cid, "You can only use this command in PZ.") 
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
        end 
    end 
end
Editado por Noob II (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
7 minutos atrás, Noob II disse:

Tenta

 


function onSay(cid, words, param) 
    if getPlayerTown(cid) == 24 then 
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot withdraw money being in Rookgaard.") 
        return 
    end 
     
    if isPlayer(cid) == TRUE and param ~= "" then 
        if getTilePzInfo(getPlayerPosition(cid)) == TRUE then 
                if getPlayerBalance(cid) == param then
                    doPlayerSetBalance(cid, getPlayerBalance(cid) - param) 
                    doPlayerAddMoney(cid, param) 
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Here you are, ".. param .." gold.") 
                else 
                    doPlayerSendCancel(cid, "You do not have enough money.") 
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
                end 
        else 
            doPlayerSendCancel(cid, "You can only use this command in PZ.") 
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
        end 
    end 
end

Testei

ta acusando que o meu player nao tem money!

00:12 Your account balance is 3616 gold.

Link para o post
Compartilhar em outros sites
  • Solução
function onSay(cid, words, param)
local config = {
bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}
if config.bankSystemEnabled == TRUE then
if config.playerIsFighting == FALSE then
local m = tonumber(param)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires param.")
return TRUE
end
if(not m) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires numeric param.")
return TRUE
end
m = math.abs(m)
if m <= getPlayerBalance(cid) then
doPlayerWithdrawMoney(cid, m)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Here you are, " .. m .. " gold. Your account balance is " .. getPlayerBalance(cid) .. ".")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There is not enough gold on your account.")
end
return TRUE
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
return TRUE
end
else
return FALSE
end
end

testa ai

Link para o post
Compartilhar em outros sites
28 minutos atrás, brendoonh disse:

function onSay(cid, words, param)
local config = {
bankSystemEnabled = getBooleanFromString(getConfigInfo('bankSystem')),
playerIsFighting = hasCondition(cid, CONDITION_INFIGHT)
}
if config.bankSystemEnabled == TRUE then
if config.playerIsFighting == FALSE then
local m = tonumber(param)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires param.")
return TRUE
end
if(not m) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command requires numeric param.")
return TRUE
end
m = math.abs(m)
if m <= getPlayerBalance(cid) then
doPlayerWithdrawMoney(cid, m)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Here you are, " .. m .. " gold. Your account balance is " .. getPlayerBalance(cid) .. ".")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There is not enough gold on your account.")
end
return TRUE
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Bank can not be used in fight.")
return TRUE
end
else
return FALSE
end
end

testa ai

Obrigado @brendoonh ajudo muito!!

 

Link para o post
Compartilhar em outros sites

Fiquei sem internet por 1 dia e não deu tempo ajudar, mas vi que o membro acima já lhe passou um script.

Mas se quiser usar o seu próprio script olha ai, testei e tá funcionando normal ^^

 

function onSay(cid, words, param)
    
    if getPlayerTown(cid) == 24 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot withdraw money while being in Rookgaard.")
        return true
    end
    
    if isPlayer(cid) == TRUE and param ~= nil then
        if getTilePzInfo(getPlayerPosition(cid)) == TRUE then
            if tonumber(param) ~= nil then
                param = tonumber(param) 
                if getPlayerBalance(cid) >= param then 
                    doPlayerSetBalance(cid, getPlayerBalance(cid) - param)
                    doPlayerAddMoney(cid, param)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Here you are, ".. param .." gold.")
                else
                    doPlayerSendCancel(cid, "You do not have enough money.")
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                end
            else
                doPlayerSendCancel(cid, "" .. param .. " is not a known currency value. Use numbers only. -> ex: 5000")
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            end
        else
            doPlayerSendCancel(cid, "You may only use this command while in a protection zone.")
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        end
    end
    
    return true
end

Link para o post
Compartilhar em outros sites

@Tópico movido para área correta, mais atenção da próxima vez!

 

Tal erro era causado pelo fato do script está tentando comparar string com number, como o membro acima postou, bastava usar a função tonumber, transformando a string e numero e fazendo a comparação corretamente.

 

Quando você fala algo no game, vamos supor que o numero 24, ex: 21:30 KotZletY [132]: 24 

como falei o numero 24, ele na distro é reconhecido assim "24", em string, e não tem como comparar, a função tonumber resolve isso, transformando a string "24", no numero 24 em si, podendo então fazer a comparação corretamente! 

                                                              ezgif-1-98aab239f3.gif.1a897c9c3225228909e7b356a5cfb8e4.gif

Link para o post
Compartilhar em outros sites
27 minutos atrás, Noob II disse:

Fiquei sem internet por 1 dia e não deu tempo ajudar, mas vi que o membro acima já lhe passou um script.

Mas se quiser usar o seu próprio script olha ai, testei e tá funcionando normal ^^

 

 


function onSay(cid, words, param)
    
    if getPlayerTown(cid) == 24 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot withdraw money while being in Rookgaard.")
        return true
    end
    
    if isPlayer(cid) == TRUE and param ~= nil then
        if getTilePzInfo(getPlayerPosition(cid)) == TRUE then
            if tonumber(param) ~= nil then
                param = tonumber(param) 
                if getPlayerBalance(cid) >= param then 
                    doPlayerSetBalance(cid, getPlayerBalance(cid) - param)
                    doPlayerAddMoney(cid, param)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Here you are, ".. param .." gold.")
                else
                    doPlayerSendCancel(cid, "You do not have enough money.")
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                end
            else
                doPlayerSendCancel(cid, "" .. param .. " is not a known currency value. Use numbers only. -> ex: 5000")
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            end
        else
            doPlayerSendCancel(cid, "You may only use this command while in a protection zone.")
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        end
    end
    
    return true
end

 

@Noob II, obrigado por ter ajudado, que isso sei que sempre quando da o pessoal ajuda!

 

21 minutos atrás, KotZletY disse:

Tal erro era causado pelo fato do script está tentando comparar string com number, como o membro acima postou, bastava usar a função tonumber, transformando a string e numero e fazendo a comparação corretamente.

 

Quando você fala algo no game, vamos supor que o numero 24, ex: 21:30 KotZletY [132]: 24 

como falei o numero 24, ele na distro é reconhecido assim "24", em string, e não tem como comparar, a função tonumber resolve isso, transformando a string "24", no numero 24 em si, podendo então fazer a comparação corretamente! 

Obrigado pelo dia @kotZletY, vou aprimorar mais isso e aprender mais, pelo oque fiz e uma coisa bem simples, onde passou despercebido!

obrigado a todos e rep++ ai !

podem fechar!

Link para o post
Compartilhar em outros sites

Não tem necessidade de fechar, caso algum membro tenha a necessidade de postar alguma duvida ou algo relevante ao conteúdo do tópico, precisa está aberto para isso.

Mesmo que não tenha, não precisa fecha. Haha!

 

xD

                                                              ezgif-1-98aab239f3.gif.1a897c9c3225228909e7b356a5cfb8e4.gif

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.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo