Jump to content

Vehicle is broken


Recommended Posts

Posted

Não sei o que está dando errado, no console diz que carrovida <= 256 não se compara com o numero.

function  desligarcar()
    local theVehicle = getPedOccupiedVehicle(source)
    local  carrovida = getElementHealth(theVehicle)
    if carrovida < 256 then
    setVehicleEngineState ( theVehicle, false )
    outputChatBox("#BDBDBDVeículo quebrado, chame um mecânico.",source,0,255,0,true) 
        setVehicleEngineState ( theVehicle, true )
    end
end
addEventHandler("onVehicleDamage", root, desligarcar)

 

Posted
function  desligarcar()
    local theVehicle = getPedOccupiedVehicle(source)
    local  carrovida = getElementHealth(theVehicle)
    if carrovida <= 256 then
    setVehicleEngineState ( theVehicle, false )
    outputChatBox("#BDBDBDVeículo quebrado, chame um mecânico.",source,0,255,0,true) 
        setVehicleEngineState ( theVehicle, true )
    end
end
addEventHandler("onVehicleDamage", root, desligarcar)

 

Uma vida sem desafios não vale a pena ser vivida.

Sócrates

  • Moderators
Posted (edited)

Isso acontece pois source não é um jogador no evento onVehicleDamage e sim o veículo que recebeu o dano. Isso significa que getPedOccupiedVehicle está retornando false. E getElementHealth (false) nunca vai retornar algo também. Ele está reclamando que não tem como fazer a comparação if false < 256 then.

function  desligarcar ()
    local carrovida = getElementHealth (source)
    local thePlayer = getVehicleController (source)
    if (carrovida < 256) then
        setVehicleEngineState (source, false)
        if (isElement (thePlayer)) then
            outputChatBox ("Seu veículo quebrou, chame um mecânico.", thePlayer, 189, 189, 189)
        end
    end
end
addEventHandler ("onVehicleDamage", root, desligarcar)

 

Edited by Lord Henry

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted

Você já havia postado o mesmo tópico aqui:

@ODutii Não precisa criar outro tópico, só postar no primeiro.

Please do not PM me with scripting related question nor support, use the forums instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...