\\Virus// Posted July 15, 2020 Share Posted July 15, 2020 olá , bom dia/boa tarde/boa noite/ estou com um problema com o meu script de Ligar/desligar motor com os "triggerServerEvent"."o script faz com que, quando um player entra no carro ele começa desligado, e o player tem que pressionar [ i ] para ligar o veiculo,porém por algum motivo bizarro quando um player está em um veiculo e outro entra/sai de outro veiculo os dois veículos desligam e não consigo identificar o problema, por isso estou pedindo ajuda aq ;-;" Script: ----/////////------ --Lado do Cliente ----/////////------ function ligarMotor() triggerServerEvent("motor",getLocalPlayer()) end --Seta o Motor Como Desligado ao Entrar + Bind para Ligar/desligar o motor addEventHandler("onClientVehicleEnter",getRootElement(),function() outputChatBox("#FFFF00Para Ligar/Desligar o Motor Aperte [ i ]",r,g,b,true) triggerServerEvent("motor",getLocalPlayer()) bindKey("i","down",ligarMotor) ----//////--- --Seta o Motor Como Desligado ao Sair ----//////--- end) addEventHandler("onClientVehicleStartExit",getRootElement(),function() unbindKey("i","down",ligarMotor) triggerServerEvent("motor",getLocalPlayer()) triggerServerEvent("certezza",getLocalPlayer()) end) ------------------------------------------------------------------------- ----/////////------ --Lado do Server ----/////////------ ---desliga e liga o motor baseado no input do cliente local function motorToggle() local theVehicle = getPedOccupiedVehicle(source) if (getVehicleEngineState(theVehicle) == true) then setVehicleEngineState(theVehicle,false) setVehicleLightState(theVehicle,0,1) setVehicleLightState(theVehicle,1,1) setVehicleLightState(theVehicle,2,1) setVehicleLightState(theVehicle,3,1) elseif (getVehicleEngineState(theVehicle) == false) then setVehicleEngineState(theVehicle,true) setVehicleLightState(theVehicle,0,0) setVehicleLightState(theVehicle,1,0) setVehicleLightState(theVehicle,2,0) setVehicleLightState(theVehicle,3,0) end end addEvent("motor",true) addEventHandler("motor",getRootElement(),motorToggle) --///--- --dá a certeza que o motor vai desligar ao sair (mesmo se ja estiver desligado) ---///-- local function certeza() local theVehicle = getPedOccupiedVehicle(source) if (getVehicleEngineState(theVehicle) == true) then setVehicleEngineState(theVehicle,false) setVehicleLightState(theVehicle,0,1) setVehicleLightState(theVehicle,1,1) setVehicleLightState(theVehicle,2,1) setVehicleLightState(theVehicle,3,1) end end addEvent("certezza",true) addEventHandler("certezza",getRootElement(),certeza) se alguém puder me ajudar ficarei mt grato 1 Link to comment
NickScripter Posted July 15, 2020 Share Posted July 15, 2020 (edited) 51 minutes ago, \\Virus// said: olá , bom dia/boa tarde/boa noite/ estou com um problema com o meu script de Ligar/desligar motor com os "triggerServerEvent"."o script faz com que, quando um player entra no carro ele começa desligado, e o player tem que pressionar [ i ] para ligar o veiculo,porém por algum motivo bizarro quando um player está em um veiculo e outro entra/sai de outro veiculo os dois veículos desligam e não consigo identificar o problema, por isso estou pedindo ajuda aq ;-;" Script: ----/////////------ --Lado do Cliente ----/////////------ function ligarMotor() triggerServerEvent("motor",getLocalPlayer()) end --Seta o Motor Como Desligado ao Entrar + Bind para Ligar/desligar o motor addEventHandler("onClientVehicleEnter",getRootElement(),function() outputChatBox("#FFFF00Para Ligar/Desligar o Motor Aperte [ i ]",r,g,b,true) triggerServerEvent("motor",getLocalPlayer()) bindKey("i","down",ligarMotor) ----//////--- --Seta o Motor Como Desligado ao Sair ----//////--- end) addEventHandler("onClientVehicleStartExit",getRootElement(),function() unbindKey("i","down",ligarMotor) triggerServerEvent("motor",getLocalPlayer()) triggerServerEvent("certezza",getLocalPlayer()) end) ------------------------------------------------------------------------- ----/////////------ --Lado do Server ----/////////------ ---desliga e liga o motor baseado no input do cliente local function motorToggle() local theVehicle = getPedOccupiedVehicle(source) if (getVehicleEngineState(theVehicle) == true) then setVehicleEngineState(theVehicle,false) setVehicleLightState(theVehicle,0,1) setVehicleLightState(theVehicle,1,1) setVehicleLightState(theVehicle,2,1) setVehicleLightState(theVehicle,3,1) elseif (getVehicleEngineState(theVehicle) == false) then setVehicleEngineState(theVehicle,true) setVehicleLightState(theVehicle,0,0) setVehicleLightState(theVehicle,1,0) setVehicleLightState(theVehicle,2,0) setVehicleLightState(theVehicle,3,0) end end addEvent("motor",true) addEventHandler("motor",getRootElement(),motorToggle) --///--- --dá a certeza que o motor vai desligar ao sair (mesmo se ja estiver desligado) ---///-- local function certeza() local theVehicle = getPedOccupiedVehicle(source) if (getVehicleEngineState(theVehicle) == true) then setVehicleEngineState(theVehicle,false) setVehicleLightState(theVehicle,0,1) setVehicleLightState(theVehicle,1,1) setVehicleLightState(theVehicle,2,1) setVehicleLightState(theVehicle,3,1) end end addEvent("certezza",true) addEventHandler("certezza",getRootElement(),certeza) se alguém puder me ajudar ficarei mt grato Nesse caso, no Server, você precisa adicionar uma função para verificar qual o assento do jogador. Recomendo você usar getPedOccupiedVehicleSeat para verificar se o passageiro é o motorista (no caso, 0) Ficaria então: ------------------------------------------------------------------------- ----/////////------ --Lado do Server ----/////////------ ---desliga e liga o motor baseado no input do cliente local function motorToggle() local theVehicle = getPedOccupiedVehicle(source) if getPedOccupiedVehicleSeat(source) == 0 then if (getVehicleEngineState(theVehicle) == true) then setVehicleEngineState(theVehicle,false) setVehicleLightState(theVehicle,0,1) setVehicleLightState(theVehicle,1,1) setVehicleLightState(theVehicle,2,1) setVehicleLightState(theVehicle,3,1) elseif (getVehicleEngineState(theVehicle) == false) then setVehicleEngineState(theVehicle,true) setVehicleLightState(theVehicle,0,0) setVehicleLightState(theVehicle,1,0) setVehicleLightState(theVehicle,2,0) setVehicleLightState(theVehicle,3,0) end end end addEvent("motor",true) addEventHandler("motor",getRootElement(),motorToggle) Edited July 15, 2020 by NickScripter 1 Link to comment
\\Virus// Posted July 15, 2020 Author Share Posted July 15, 2020 1 minute ago, NickScripter said: Nesse caso, no Server, você precisa adicionar uma função para verificar qual o assento do jogador. Recomendo você usar getPedOccupiedVehicleSeat para verificar se o passageiro é o motorista (no caso, 0) Ficaria então: ------------------------------------------------------------------------- ----/////////------ --Lado do Server ----/////////------ ---desliga e liga o motor baseado no input do cliente local function motorToggle() local theVehicle = getPedOccupiedVehicle(source) if getPedOccupiedVehicleSeat(source) == 0 then if (getVehicleEngineState(theVehicle) == true) then setVehicleEngineState(theVehicle,false) setVehicleLightState(theVehicle,0,1) setVehicleLightState(theVehicle,1,1) setVehicleLightState(theVehicle,2,1) setVehicleLightState(theVehicle,3,1) elseif (getVehicleEngineState(theVehicle) == false) then setVehicleEngineState(theVehicle,true) setVehicleLightState(theVehicle,0,0) setVehicleLightState(theVehicle,1,0) setVehicleLightState(theVehicle,2,0) setVehicleLightState(theVehicle,3,0) end end end addEvent("motor",true) addEventHandler("motor",getRootElement(),motorToggle) bom Mt obrigado vou testar aqui e ver se funciona! não funcionou man, continua com o mesmo bug, quando alguem esta em um veiculo assim com eu e sai/entra do carro ambos os carros desligam, ele n tá agindo individualmente ;-; mas obg pela ajuda 1 Link to comment
NickScripter Posted July 15, 2020 Share Posted July 15, 2020 (edited) 6 minutes ago, \\Virus// said: bom Mt obrigado vou testar aqui e ver se funciona! não funcionou man, continua com o mesmo bug, quando alguem esta em um veiculo assim com eu e sai/entra do carro ambos os carros desligam, ele n tá agindo individualmente ;-; mas obg pela ajuda Recomendo você tentar usar essa função que falei acima no client em OnClientVehicleEnter e OnClientVehicleStartExit, para chamar o triggerServerEvent apenas quando for o passageiro 1 para evitar de que outros passageiros chamem essa função. Lembrando que terá que trocar o source por localPlayer Edited July 15, 2020 by NickScripter Link to comment
\\Virus// Posted July 15, 2020 Author Share Posted July 15, 2020 Just now, NickScripter said: Recomendo você tentar usar essa função que falei acima no client em OnClientVehicleEnter e OnClientVehicleStartExit, para chamar o triggerServerEvent apenas quando for o passageiro 1 para evitar de que outros passageiros chamem essa função. tem como vc me adicionar no discord? eu posso te mostrar o problema ná pratica pq estou com um amigo aqui no svr Link to comment
NickScripter Posted July 15, 2020 Share Posted July 15, 2020 ----/////////------ --Lado do Cliente ----/////////------ function ligarMotor() triggerServerEvent("motor",getLocalPlayer()) end --Seta o Motor Como Desligado ao Entrar + Bind para Ligar/desligar o motor addEventHandler("onClientVehicleEnter",getRootElement(),function() if(getPedOccupiedVehicleSeat(localPlayer) == 0 then outputChatBox("#FFFF00Para Ligar/Desligar o Motor Aperte [ i ]",r,g,b,true) triggerServerEvent("motor",getLocalPlayer()) bindKey("i","down",ligarMotor) else return end ----//////--- --Seta o Motor Como Desligado ao Sair ----//////--- end) addEventHandler("onClientVehicleStartExit",getRootElement(),function() if(getPedOccupiedVehicleSeat(localPlayer) == 0 then unbindKey("i","down",ligarMotor) triggerServerEvent("motor",getLocalPlayer()) triggerServerEvent("certezza",getLocalPlayer()) else return end end) Tente assim. Link to comment
\\Virus// Posted July 15, 2020 Author Share Posted July 15, 2020 (edited) 5 minutes ago, NickScripter said: ----/////////------ --Lado do Cliente ----/////////------ function ligarMotor() triggerServerEvent("motor",getLocalPlayer()) end --Seta o Motor Como Desligado ao Entrar + Bind para Ligar/desligar o motor addEventHandler("onClientVehicleEnter",getRootElement(),function() if(getPedOccupiedVehicleSeat(localPlayer) == 0 then outputChatBox("#FFFF00Para Ligar/Desligar o Motor Aperte [ i ]",r,g,b,true) triggerServerEvent("motor",getLocalPlayer()) bindKey("i","down",ligarMotor) else return end ----//////--- --Seta o Motor Como Desligado ao Sair ----//////--- end) addEventHandler("onClientVehicleStartExit",getRootElement(),function() if(getPedOccupiedVehicleSeat(localPlayer) == 0 then unbindKey("i","down",ligarMotor) triggerServerEvent("motor",getLocalPlayer()) triggerServerEvent("certezza",getLocalPlayer()) else return end end) Tente assim. ainda continua com o mesmo problema ;-; parece "Facil" de resolver mas fiquei cerca de quase 3 horas tentando achar esse problema e não encontrei ;-; isso antes de vir pedir ajuda aq ;-; Edited July 15, 2020 by \\Virus// esqueci de detalhes Link to comment
Angelo Pereira Posted July 15, 2020 Share Posted July 15, 2020 Bom, se eu fosse você, eu criava todo o script do lado server-side, assim, evitando constantemente o uso de envios de eventos para o server-side. Teste lá : -- / lado server-side. --# bindkey. addEventHandler("onPlayerLogin", root, function () bindKey ( source, "i", "down", ligar_desligar_motor ) end) addEventHandler("onResourceStart", resourceRoot, function () for i, player in ipairs( getElementsByType("player") ) do bindKey ( player, "i", "down", ligar_desligar_motor ) end end) addEventHandler("onResourceStop", resourceRoot, function () for i, player in ipairs( getElementsByType("player") ) do unbindKey ( player, "i", "down", ligar_desligar_motor ) end end) -- funções. function ligar_desligar_motor ( player ) local veh = getPedOccupiedVehicle ( player ) if veh and getPedOccupiedVehicleSeat( player ) == 0 then if ( getVehicleEngineState (veh) == false ) then setVehicleEngineState (veh, true) setVehicleLightState (veh,0,0) setVehicleLightState (veh,1,0) setVehicleLightState (veh,2,0) setVehicleLightState (veh,3,0) else setVehicleEngineState (veh, false) setVehicleLightState (veh,0,1) setVehicleLightState (veh,1,1) setVehicleLightState (veh,2,1) setVehicleLightState (veh,3,1) end end end -- eventos. addEventHandler ( "onPlayerVehicleEnter", root, function ( theVehicle, seat ) if seat == 0 then if ( getVehicleEngineState (theVehicle) == false ) then setVehicleEngineState (theVehicle, true) setVehicleLightState (theVehicle,0,0) setVehicleLightState (theVehicle,1,0) setVehicleLightState (theVehicle,2,0) setVehicleLightState (theVehicle,3,0) end end end) addEventHandler ( "onPlayerVehicleExit", root, function ( theVehicle, seat ) if seat == 0 then if ( getVehicleEngineState (theVehicle) == true ) then setVehicleEngineState (theVehicle, false) setVehicleLightState (theVehicle,0,1) setVehicleLightState (theVehicle,1,1) setVehicleLightState (theVehicle,2,1) setVehicleLightState (theVehicle,3,1) end end end) 1 Link to comment
\\Virus// Posted July 15, 2020 Author Share Posted July 15, 2020 (edited) 3 hours ago, Angelo Pereira said: Bom, se eu fosse você, eu criava todo o script do lado server-side, assim, evitando constantemente o uso de envios de eventos para o server-side. Teste lá : -- / lado server-side. --# bindkey. addEventHandler("onPlayerLogin", root, function () bindKey ( source, "i", "down", ligar_desligar_motor ) end) addEventHandler("onResourceStart", resourceRoot, function () for i, player in ipairs( getElementsByType("player") ) do bindKey ( player, "i", "down", ligar_desligar_motor ) end end) addEventHandler("onResourceStop", resourceRoot, function () for i, player in ipairs( getElementsByType("player") ) do unbindKey ( player, "i", "down", ligar_desligar_motor ) end end) -- funções. function ligar_desligar_motor ( player ) local veh = getPedOccupiedVehicle ( player ) if veh and getPedOccupiedVehicleSeat( player ) == 0 then if ( getVehicleEngineState (veh) == false ) then setVehicleEngineState (veh, true) setVehicleLightState (veh,0,0) setVehicleLightState (veh,1,0) setVehicleLightState (veh,2,0) setVehicleLightState (veh,3,0) else setVehicleEngineState (veh, false) setVehicleLightState (veh,0,1) setVehicleLightState (veh,1,1) setVehicleLightState (veh,2,1) setVehicleLightState (veh,3,1) end end end -- eventos. addEventHandler ( "onPlayerVehicleEnter", root, function ( theVehicle, seat ) if seat == 0 then if ( getVehicleEngineState (theVehicle) == false ) then setVehicleEngineState (theVehicle, true) setVehicleLightState (theVehicle,0,0) setVehicleLightState (theVehicle,1,0) setVehicleLightState (theVehicle,2,0) setVehicleLightState (theVehicle,3,0) end end end) addEventHandler ( "onPlayerVehicleExit", root, function ( theVehicle, seat ) if seat == 0 then if ( getVehicleEngineState (theVehicle) == true ) then setVehicleEngineState (theVehicle, false) setVehicleLightState (theVehicle,0,1) setVehicleLightState (theVehicle,1,1) setVehicleLightState (theVehicle,2,1) setVehicleLightState (theVehicle,3,1) end end end) bom, cheguei agr do mercado, vo da uma testada pra ver, mas mt obrigado pela ajuda mano sou mt grato por cada um que ta ajudando te adicionei no dc la mano se quiser aceitar la agradeço mt NOSAAAAAAAAAAAAAAAAAAAAAA BRIGADAO MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN ME ajudou mt msm cara seriao velhooooooooo ❤️ Edited July 15, 2020 by \\Virus// 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