D3vZ Posted February 11, 2014 Share Posted February 11, 2014 Boa Tarde! O problema do meu script é que quando deixo o motor ligado, ao entrar no carro ele DESLIGA-O, e eu quero que ao entrar no carro ele o deixe ligado! Script: local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () local players = getElementsByType ( "player" ) for _,this_player in ipairs(players) do bindKey ( this_player, "lctrl", "down", stopEngine, "Motor on/off" ) end end function stopEngine ( player, key, state ) if getPedOccupiedVehicleSeat ( player ) == 0 then local vehicle = getPedOccupiedVehicle ( player ) setVehicleEngineState ( vehicle, not getVehicleEngineState ( vehicle ) ) end end function playerJoined() bindKey ( source, "lctrl", "down", stopEngine, "Motor on/off" ) end addEventHandler ("onResourceStart", getRootElement(), thisResourceStart) addEventHandler ( "onVehicleEnter", root, function ( player ) setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) end ) addEventHandler ( "onVehicleExit", stopEngine, function ( player ) setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) end ) Link to comment
yMassai Posted February 11, 2014 Share Posted February 11, 2014 Você esta postando o conteúdo no em local errado. Link to comment
yMassai Posted February 11, 2014 Share Posted February 11, 2014 local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () local players = getElementsByType ( "player" ) for _,this_player in ipairs(players) do bindKey ( this_player, "lctrl", "down", stopEngine, "Motor on/off" ) end end function stopEngine ( player, key, state ) if getPedOccupiedVehicleSeat ( player ) == 0 then local vehicle = getPedOccupiedVehicle ( player ) setVehicleEngineState ( vehicle, not getVehicleEngineState ( vehicle ) ) end end function playerJoined() bindKey ( source, "lctrl", "down", stopEngine, "Motor on/off" ) end addEventHandler ("onResourceStart", getRootElement(), thisResourceStart) addEventHandler ( "onVehicleExit", stopEngine, function ( player ) setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) end ) Tente esse. Link to comment
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 Não funcionou! Agora dá erro no /debugscript3 Link to comment
manawydan Posted February 11, 2014 Share Posted February 11, 2014 o source do evento "onVehicleExit" é o veiculo Link to comment
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 Como assim o "onVehicleExit" é o veiculo? Link to comment
manawydan Posted February 11, 2014 Share Posted February 11, 2014 acredito que esse não seja o código inteiro. tente trocar addEventHandler ( "onVehicleExit", stopEngine, function ( player ) setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) end ) para addEventHandler ( "onVehicleExit",root, function ( player ) setVehicleEngineState ( source, getElementData ( source, "Motor on/off" ) ) end ) Link to comment
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 O script postado é o script completo. O problema actual é o seguinte: - Saiu do veiculo com o motor ligado e ele desliga; - Entro no veiculo com motor desligado e ele liga; O que pretendo?: - Que se sair do carro com o motor ligado ele continua sempre ligado mesmo que não entre ninguém no carro ou quando qualquer jogador entra nele; - Quando entro no carro e o carro tiver o motor ligado continua ligado, se tiver o motor desligado ele continua desligado Mas infelizmente não consigo fazer isso Link to comment
DNL291 Posted February 11, 2014 Share Posted February 11, 2014 Tente: function thisResourceStart () local players = getElementsByType ( "player" ) for _,this_player in ipairs(players) do bindKey ( this_player, "lctrl", "down", toggleEngine ) end end addEventHandler ("onResourceStart", resourceRoot, thisResourceStart) function toggleEngine ( player, key, state ) if getPedOccupiedVehicleSeat ( player ) == 0 then local vehicle = getPedOccupiedVehicle ( player ) setVehicleEngineState ( vehicle, not getVehicleEngineState ( vehicle ) ) end end function playerJoined() bindKey ( source, "lctrl", "down", toggleEngine ) end addEventHandler("onPlayerJoin", root, playerJoined) Link to comment
D3vZ Posted February 11, 2014 Author Share Posted February 11, 2014 @DNL291 Está correcto num ponto mas agora quando entro no veículo o motor activa novamente e só falta a parte de desactivar quando player entra no veiculo ele não active o motor automático Link to comment
DNL291 Posted February 12, 2014 Share Posted February 12, 2014 Se você não quer que outros jogadores controlem o veículo, você deve definir um dono, ou verificar se quem está dirigindo é o jogador que criou o veículo, com getElementSyncer. Não tenho certeza se é isso o que você quer. agora quando entro no veículo o motor activa novamente Tente isto: local engineState = {} function thisResourceStart () local players = getElementsByType ( "player" ) for _,this_player in ipairs(players) do bindKey ( this_player, "lctrl", "down", toggleEngine ) end end addEventHandler ("onResourceStart", resourceRoot, thisResourceStart) function toggleEngine ( player, key, state ) if getPedOccupiedVehicleSeat ( player ) == 0 then local vehicle = getPedOccupiedVehicle ( player ) setVehicleEngineState ( vehicle, not getVehicleEngineState ( vehicle ) ) engineState[vehicle] = getVehicleEngineState(vehicle) end end function playerJoined() bindKey ( source, "lctrl", "down", toggleEngine ) end addEventHandler("onPlayerJoin", root, playerJoined) addEventHandler("onVehicleEnter", root, function () if type(engineState[source]) == "boolean" then getVehicleEngineState(engineState[source]) end end) addEventHandler("onElementDestroy", root, function () if not getElementType(source) == "vehicle" then return end if type(engineState[source]) == "boolean" then engineState[source] = nil end end) Link to comment
D3vZ Posted February 12, 2014 Author Share Posted February 12, 2014 Não é este o script que pretendo, o que pretendo é que qualquer jogador quando entra no veiculo ele continue no seu último estado, ou seja se o último estado do veículo foi desligado o jogador quando entrar o motor continua desligado, se o ultimo estado do veiculo foi ligado quando o jogador entrar o motor continua ligado Link to comment
DNL291 Posted February 12, 2014 Share Posted February 12, 2014 Fiz isso no meu último código, já testou ele? Link to comment
D3vZ Posted February 12, 2014 Author Share Posted February 12, 2014 @DNL291 Sim já fiz isso, mas não funcionou Link to comment
DNL291 Posted February 12, 2014 Share Posted February 12, 2014 Tinha um pequeno erro. Mude isso na linha 26: getVehicleEngineState(engineState[source]) Para: setVehicleEngineState(source, engineState[source]) Link to comment
D3vZ Posted February 12, 2014 Author Share Posted February 12, 2014 Script funcional e operacional como desejado! Agradeço a ajuda! Obrigado! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now