Jump to content

Como detectar que o veículo está dando a ré?


Recommended Posts

  • Other Languages Moderators

Olá novamente galera.

Estou fazendo um script básico que começa a tocar um som de "pi" quando o veículo estiver dando a ré, e para de tocar quando o veículo anda pra frente novamente.

Eu tentei usar getElementSpeed mas não consegui diferenciar a velocidade pra frente da velocidade pra trás. (os valores não ficam negativos).

Alguém sabe como faço para detectar quando o veículo está indo para trás?

Link to comment
  • Other Languages Moderators
3 hours ago, DNL291 said:

Já tentou usando getControlState?

Não, hauahuahaua.
Mas eu já sei que não funcionaria pois ele não diferencia o freio da ré. '-'

getControlState (thePlayer, "brake_reverse")

Como pode ver, o freio e a ré são o mesmo controle. Mas quero que ative somente quando for a ré.

Link to comment

Talvez isso te ajude.

https://forum.multitheftauto.com/topic/88782-wip-vehicle-brake-light-system/

ou tente usar isto:

function detect()
    local theVehicle = getPedOccupiedVehicle(localPlayer)
    if theVehicle then
        local getMatrix = getElementMatrix(theVehicle)
        local getVelocity = Vector3(getElementVelocity(theVehicle))
        local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) 
        if (getVectorDirection < 0) then
            outputChatBox("Ré")
        end
    end 
end
setTimer(detect, 1000, 0)

 

Edited by MainSCR
Link to comment
  • Other Languages Moderators
13 hours ago, MainSCR said:
  1. function detect()
  2. local theVehicle = getPedOccupiedVehicle(localPlayer)
  3. if theVehicle then
  4. local getMatrix = getElementMatrix(theVehicle)
  5. local getVelocity = Vector3(getElementVelocity(theVehicle))
  6. local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3])
  7. if (getVectorDirection < 0) then
  8. outputChatBox("Ré")
  9. end
  10. end
  11. end
  12. setTimer(detect, 1000, 0)

Isso não está funcionando direito. Mostra a ré as vezes quando estou indo pra frente e quando estou parado.

Link to comment
1 hour ago, Lord Henry said:

Isso não está funcionando direito. Mostra a ré as vezes quando estou indo pra frente e quando estou parado.

function detect()
    local theVehicle = getPedOccupiedVehicle(localPlayer)
    if theVehicle then
        local getMatrix = getElementMatrix(theVehicle)
        local getVelocity = Vector3(getElementVelocity(theVehicle))
        local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) 
		if (getVectorDirection == 0 or getVectorDirection > 0) then
			return
		end
        if (getVectorDirection < 0) then
			print(getVectorDirection)
			outputChatBox("Ré")
        end
    end 
end
setTimer(detect, 1000, 0)

Tenta isso.

Edited by MainSCR
  • Thanks 1
Link to comment
  • Other Languages Moderators

A propósito, finalmente funcionou.
Fiz um script teste assim:

function isVehicleReturning (theVehicle)
	local getMatrix = getElementMatrix(theVehicle)
	local getVelocity = Vector3(getElementVelocity(theVehicle))
	local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) 
	if (getVectorDirection >= 0) then
		return false
	end
	if (getVectorDirection < 0) then
		return true
	end
end

function vehCheck ()
	local vehicle = getPedOccupiedVehicle (localPlayer)
	if vehicle then
		dxDrawText (tostring(isVehicleReturning (vehicle)), 10, 5) -- Mostra isso no canto superior esquerdo da tela.
	end
end
addEventHandler ("onClientRender", getRootElement(), vehCheck)

 

Link to comment
On 17/12/2017 at 21:33, Lord Henry said:

Isso


if (getVectorDirection == 0 or getVectorDirection > 0) then

Seria o mesmo que isso?


if (getVectorDirection >= 0) then

 

Sim

On 17/12/2017 at 22:22, Lord Henry said:

A propósito, finalmente funcionou.
Fiz um script teste assim:


function isVehicleReturning (theVehicle)
	local getMatrix = getElementMatrix(theVehicle)
	local getVelocity = Vector3(getElementVelocity(theVehicle))
	local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) 
	if (getVectorDirection >= 0) then
		return false
	end
	if (getVectorDirection < 0) then
		return true
	end
end

function vehCheck ()
	local vehicle = getPedOccupiedVehicle (localPlayer)
	if vehicle then
		dxDrawText (tostring(isVehicleReturning (vehicle)), 10, 5) -- Mostra isso no canto superior esquerdo da tela.
	end
end
addEventHandler ("onClientRender", getRootElement(), vehCheck)

 

Nice

Link to comment
33 minutes ago, Lord Henry said:

E mais uma coisa:
Você saberia me dizer de onde pegou essa função? Ou você criou? Pois eu gostaria de publicá-la na Wiki, mas preciso dar os devidos créditos.

Eu tinha visto essa função há um tempo atrás em algum resource disponível na internet, mas não estou lembrado qual resource/site que eu vi.

Como andei estudando essa função, sei de có.

Link to comment
23 hours ago, Lord Henry said:

Bom. A página ficou assim:

isVehicleReturning
Se tiver algo faltando, erro de inglês, etc, me avise.

Sobre o inglês, tem alguns erros...

O nome dessa função não ficou adequado, pois returning seria usado caso o veículo estivesse retornando de um ponto B ao A, não necessariamente usando a ré.

O correto seria nomear como isVehicleReversing ou isVehicleMovingBackwards.

 

Quote

This function checks if a vehicle is going back or not.

Aqui basicamente é o mesmo erro que citei antes, seria melhor usar moving backwards.

Quote

This function returns true if the vehicle is returning,

Mesma coisa... Use is going backwards.

Quote

This is useful to create back lights to the vehicle.

Aqui o correto seria usar on. 

Quote

Syntaxe:

Aqui acho que você um pouco com a palavra em português, a palavra correta é Syntax.

Link to comment
  • Other Languages Moderators
Quote

This function checks if a vehicle is going back or not.

Quote

This function returns true if the vehicle is returning,

Quote

This is useful to create back lights to the vehicle.

Quote

Syntaxe:

Corrigidos.

1 hour ago, Banex said:

O correto seria nomear como isVehicleReversing ou isVehicleMovingBackwards.

Dai não tem como corrigir pois teria que deletar a página e recriá-la com o novo nome.

Link to comment
  • Moderators

Acho melhor usar um termo mais técnico nesse caso, que seria reversing, e se aplica melhor pra especificar que é uma marcha à ré.

Não que Moving backwards esteja errado, até porque não sou professor se inglês pra afirmar isso, mas esse segundo, é mais relativo já que se traduz: "movendo-se para trás", mas também pode ser usado.

Link to comment
  • Other Languages Moderators

Acho que isVehicleMovingBackwards fica muito grande pra um nome de função.

6 hours ago, Banex said:

Na verdade não precisa deletar...

Eu alterei o nome da função para você.

Eu não sabia da função de mover... Inclusive pensei que precisava de permissão da moderação para fazer isso. Perdoe minha ignorância.

Edited by Lord Henry
Link to comment
  • 2 weeks later...
On 19/12/2017 at 09:21, Lord Henry said:

E mais uma coisa:
Você saberia me dizer de onde pegou essa função? Ou você criou? Pois eu gostaria de publicá-la na Wiki, mas preciso dar os devidos créditos.

Olá amigos. desculpe dar um UP aqui..
mais alguns anos atrás, trabalhei muito em criação de velocímetros em DX.
e já tinha achado essa função isVehicleReversing em alguns velocímetros da comunidade. a procura de funções ou pegar ideias..

a maioria dos velocímetros da comunidade é open-code/descompilado. porém não tinha exemplos na WIKI desta função/evento (isVehicleReversing)

eu penso assim. tem muitos Resources "inuteis" na comunidade com muitas funções uteis de podem ser usadas.. basta pesquisar.....  =]

uma das funções mais útil que tinha achado era essa, para obter a "Ré"
 

-- 'vehicle gear'
function getVehicleGear()    
    if (vehicle) then
        local vehicleGear = getVehicleCurrentGear(vehicle)
        
        return tonumber(vehicleGear)
    else
        return 0
    end
end


function getFormattedVehicleGear()
    local gear = getVehicleGear()
    local rearString = "R"
    
    if (gear > 0) then
        return gear
    else
        return rearString
    end
end


usada nesse Velocimetro/speedometer aqui criado por Sam@ke

Link to comment
  • 2 weeks later...
On 14/01/2018 at 20:48, #RooTs said:

Olá amigos. desculpe dar um UP aqui..
mais alguns anos atrás, trabalhei muito em criação de velocímetros em DX.
e já tinha achado essa função isVehicleReversing em alguns velocímetros da comunidade. a procura de funções ou pegar ideias..

a maioria dos velocímetros da comunidade é open-code/descompilado. porém não tinha exemplos na WIKI desta função/evento (isVehicleReversing)

eu penso assim. tem muitos Resources "inuteis" na comunidade com muitas funções uteis de podem ser usadas.. basta pesquisar.....  =]

uma das funções mais útil que tinha achado era essa, para obter a "Ré"
 


-- 'vehicle gear'
function getVehicleGear()    
    if (vehicle) then
        local vehicleGear = getVehicleCurrentGear(vehicle)
        
        return tonumber(vehicleGear)
    else
        return 0
    end
end


function getFormattedVehicleGear()
    local gear = getVehicleGear()
    local rearString = "R"
    
    if (gear > 0) then
        return gear
    else
        return rearString
    end
end


usada nesse Velocimetro/speedometer aqui criado por Sam@ke

Seria útil também, mas teria que fazer umas modificações, pra por exemplo quando o carro estiver parado não detectar a ré.

Link to comment
  • Other Languages Moderators
17 minutes ago, MainSCR said:

Seria útil também, mas teria que fazer umas modificações, pra por exemplo quando o carro estiver parado não detectar a ré.

O exemplo da Wiki não detecta a ré quando está parado.

Edited by Lord Henry
Link to comment

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...