manawydan Posted April 22, 2013 Share Posted April 22, 2013 ola, quero criar um ped que pilote um avião, atachar um misel(objeto) no avião e fazer o missel desatachar e mover( com MoveObject). pórem eu não sei como posso pegar a posição do "chão" para que o missel mova até ele. como poderei pegar a posição do "chão"? obrigado!! Link to comment
DNL291 Posted April 22, 2013 Share Posted April 22, 2013 Use: getGroundPosition(x,y,z) É desanexar não desatachar. Link to comment
manawydan Posted April 22, 2013 Author Share Posted April 22, 2013 essa função pode ser usada em peds? Link to comment
DNL291 Posted April 23, 2013 Share Posted April 23, 2013 É usada pra obter a altura entre o chão e as coordenadas passadas. Se você quer saber qual o nível Z (altura), entre um ped e o chão, basta você usar getElementPosition(thePed) para obter as posições X,Y,Z de um ped, e passá-las nos argumentos da função getGroundPosition. A função retornará o nível entre o chão e a posição que foi passada (o nível Z da posição do ped). Link to comment
manawydan Posted April 23, 2013 Author Share Posted April 23, 2013 obrigado tentarei criar o script! Link to comment
manawydan Posted April 23, 2013 Author Share Posted April 23, 2013 qual o nome do controle que faz a turbina do hydra avançar? (eu testei varios e não achei. no jogo a bind é 8 ) Link to comment
manawydan Posted April 23, 2013 Author Share Posted April 23, 2013 eu tentei esse antes e não tinha funcionado. Link to comment
manawydan Posted April 23, 2013 Author Share Posted April 23, 2013 Client addEventHandler("ControlState", root, function (thePed, control, bol) setPedControlState( thePed, control, bol ) end) addEventHandler("AnalogControlState", root, function (thePed, control, Time) setPedAnalogControlState( thePed, control, Time ) end) addEventHandler( "onClientResourceStart", getRootElement( ), function() addEvent ( "ControlState", true ) addEvent ( "AnalogControlState", true ) end) Server function PedHelpHydraStart() aviao = createVehicle(520, 2051.0708007813, -2494.2114257813, 14.546875, 0, 0, 90) pedPilot = createPed(287, 2050.0708007813, -2493.2114257813, 13.546875) warpPedIntoVehicle(pedPilot, aviao) triggerClientEvent ( "ControlState", root, pedPilo, "accelerate", true) triggerClientEvent ( "AnalogControlState", root, pedPilo, "special_control_up", 0.5) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), PedHelpHydraStart) Link to comment
Vision Posted April 23, 2013 Share Posted April 23, 2013 Tente isso -- client addEvent ( "ControlState", true ) addEvent ( "AnalogControlState", true ) addEventHandler ( "ControlState", root, function ( thePed, control, bol ) setPedControlState ( thePed, control, bol ) end ) addEventHandler ( "AnalogControlState", root, function ( thePed, control, Time ) setPedAnalogControlState ( thePed, control, Time ) end ) -- server function PedHelpHydraStart ( ) aviao = createVehicle ( 520, 2051.0708007813, -2494.2114257813, 14.546875, 0, 0, 90 ) pedPilot = createPed ( 287, 2050.0708007813, -2493.2114257813, 13.546875 ) warpPedIntoVehicle ( pedPilot, aviao ) triggerClientEvent ( "ControlState", root, pedPilot, "accelerate", true ) triggerClientEvent ( "AnalogControlState", root, pedPilot, "special_control_up", 0.5 ) end setTimer ( PedHelpHydraStart, 100, 1 ) Link to comment
manawydan Posted April 23, 2013 Author Share Posted April 23, 2013 testei e não funciono. o ped nao voa. o debug diz que os eventos "triggerados" pelo server não esta adicionado no lado do client. Link to comment
DNL291 Posted April 23, 2013 Share Posted April 23, 2013 Use um timer para o hydra andar e suba o trem de pouso. Dessa forma, client: addEvent("ControlState", true) addEvent("AnalogControlState", true) addEventHandler("onClientResourceStart", resourceRoot, function() setTimer(triggerServerEvent, 50, 1, "onTriggerHydraBot", localPlayer) end ) addEventHandler ( "ControlState", root, function ( thePed, control, bol ) setPedControlState ( thePed, control, bol ) end ) addEventHandler ( "AnalogControlState", root, function ( thePed, control, Time ) setPedAnalogControlState ( thePed, control, Time ) end ) Server: addEvent("onTriggerHydraBot", true) addEventHandler("onTriggerHydraBot", root, function() local aviao = createVehicle ( 520, 2051.0708007813, -2494.2114257813, 14.546875, 0, 0, 90 ) local pedPilot = createPed ( 287, 2050.0708007813, -2493.2114257813, 13.546875 ) warpPedIntoVehicle ( pedPilot, aviao ) triggerClientEvent ( "ControlState", root, pedPilot, "accelerate", true ) setTimer( function() triggerClientEvent( "AnalogControlState", root, pedPilot, "special_control_up", 0.4 ) setVehicleLandingGearDown(aviao, false) end, 10000, 1 ) end ) Link to comment
manawydan Posted April 24, 2013 Author Share Posted April 24, 2013 obrigado dnl!! criei uma função para atualizar a posição do ped. function AtualizarPositionPedPilot() local peds = getElementsByType ( "ped" ) for theKey,thePed in ipairs(peds) do if getElementData(thePed, "PilotHydra") == true then local xp, yp, zp = getElementPosition(thePed) local z = getGroundPosition ( xp, yp, zp ) end end end addEventHandler ( "onClientRender", getRootElement (), AtualizarPositionPedPilot ) ela é necesaria? Link to comment
DNL291 Posted April 24, 2013 Share Posted April 24, 2013 Se você quer verificar constantemente a distância entre o ped e o chão, então é necessária. Mas recomendo você não usar um loop-for em todos os peds no evento onClientRender. Se puder, envie o elemento ped com triggerClientEvent, armazene o ped em algo ou em uma tabela e você obtém ele sem precisar de loop-for. Leve apenas como uma sugestão, faça isso se você quer um melhor desempenho para o script. Link to comment
manawydan Posted April 24, 2013 Author Share Posted April 24, 2013 obrigado pela dica! agora acredito que a duvida final: como vou fazer o missel se mover( é claro moveObject) mas como calcular? nunca usei getGroundPosition. Client addEvent("ControlState", true) addEvent("AnalogControlState", true) addEventHandler("onClientResourceStart", resourceRoot, function() setTimer(triggerServerEvent, 50, 1, "onTriggerHydraBot", localPlayer) end ) addEventHandler ( "ControlState", root, function ( thePed, control, bol ) setPedControlState ( thePed, control, bol ) end ) addEventHandler ( "AnalogControlState", root, function ( thePed, control, Time ) setPedAnalogControlState ( thePed, control, Time ) end ) function AtualizarPositionPedPilot() local peds = getElementsByType ( "ped" ) for theKey,thePed in ipairs(peds) do if getElementData(thePed, "PilotHydra") == true then local xp, yp, zp = getElementPosition(thePed) local zzz = getGroundPosition ( xp, yp, zp ) end end end addEventHandler ( "onClientRender", getRootElement (), AtualizarPositionPedPilot ) server misselRecarregado = 1 --86 ou 90 id dos misseis function MisselEmpty() misselRecarregado = 0 end function MisselReload() setTimer( function() misselRecarregado = 1 missel = createObject(3786, 0, 0, 0) attachElements ( missel, aviao, 0, 0, -2.12, 0, -90, 0 ) end, 10000, 1) end addEvent("onTriggerHydraBot", true) addEventHandler("onTriggerHydraBot", root, function() aviao = createVehicle ( 520, 2051.0708007813, -2494.2114257813, 14.546875, 0, 0, 90 ) pedPilot = createPed ( 287, 2050.0708007813, -2493.2114257813, 13.546875 ) setElementData(pedPilot, "PilotHydra", true) warpPedIntoVehicle ( pedPilot, aviao ) triggerClientEvent ( "ControlState", root, pedPilot, "accelerate", true ) setTimer( function() triggerClientEvent( "AnalogControlState", root, pedPilot, "special_control_up", 0.4 ) setVehicleLandingGearDown(aviao, false) missel = createObject(3786, 2050.0708007813, -2493.2114257813, 25.546875) attachElements ( missel, aviao, 0, 0, -2.12, 0, -90, 0 ) end, 10000, 1 ) end ) function ShotNow() if aviao and pedPilot then if (misselRecarregado == 1) then detachElements ( missel, aviao ) setElementRotation(missel,0,-90,0) MisselEmpty() MisselReload() end end end addCommandHandler("shot", ShotNow) Link to comment
DNL291 Posted April 24, 2013 Share Posted April 24, 2013 Tente isso e diga o resultado: Client: addEvent("ControlState", true) addEvent("AnalogControlState", true) addEventHandler("onClientResourceStart", resourceRoot, function() setTimer(triggerServerEvent, 50, 1, "onTriggerHydraBot", localPlayer) end ) addEventHandler ( "ControlState", root, function ( thePed, control, bol ) setPedControlState ( thePed, control, bol ) end ) addEventHandler ( "AnalogControlState", root, function ( thePed, control, Time ) setPedAnalogControlState ( thePed, control, Time ) end ) function AtualizarPositionPedPilot() local peds = getElementsByType ( "ped" ) for theKey,thePed in ipairs(peds) do if getElementData(thePed, "PilotHydra") == true then local xp, yp, zp = getElementPosition(thePed) zzz = getGroundPosition ( xp, yp, zp ) end end end addEventHandler ( "onClientRender", getRootElement (), AtualizarPositionPedPilot ) addCommandHandler("shot", function(player) if (zzz) then triggerServerEvent("miselShot", player, zzz) end end ) Server: local misselRecarregado = 1 --86 ou 90 id dos misseis function MisselEmpty() misselRecarregado = 0 end function MisselReload() setTimer( function() misselRecarregado = 1 missel = createObject(3786, 0, 0, 0) attachElements ( missel, aviao, 0, 0, -2.12, 0, -90, 0 ) end, 10000, 1) end addEvent("onTriggerHydraBot", true) addEventHandler("onTriggerHydraBot", root, function() aviao = createVehicle ( 520, 2051.0708007813, -2494.2114257813, 14.546875, 0, 0, 90 ) pedPilot = createPed ( 287, 2050.0708007813, -2493.2114257813, 13.546875 ) setElementData(pedPilot, "PilotHydra", true) warpPedIntoVehicle ( pedPilot, aviao ) triggerClientEvent ( "ControlState", root, pedPilot, "accelerate", true ) setTimer( function() triggerClientEvent( "AnalogControlState", root, pedPilot, "special_control_up", 0.4 ) setVehicleLandingGearDown(aviao, false) missel = createObject(3786, 2050.0708007813, -2493.2114257813, 25.546875) attachElements ( missel, aviao, 0, 0, -2.12, 0, -90, 0 ) end, 10000, 1 ) end ) addEvent("miselShot", true) function ShotNow(miselPos) if (aviao and pedPilot and miselPos) then if (misselRecarregado == 1) then detachElements ( missel, aviao ) --setElementRotation(missel,0,-90,0) local x, y, z = getElementPosition(missel) moveObject(missel, 3500, x, y, z-tonumber(miselPos)) MisselEmpty() MisselReload() end end end addEventHandler("miselShot", root, ShotNow) Se você não estiver achando o tempo da função moveObject adequado, você pode calcular o tempo correto, obtendo a distância (Z) entre os 2 pontos e fazendo um calculo matemático para ter o tempo (em milisegundos) mais adequado para o objeto ser movido ao seu destino. Link to comment
manawydan Posted April 24, 2013 Author Share Posted April 24, 2013 eu testei e não funciono. segundo o debug: Bad Argument @ 'triggerServerEvent' [expected element at argument 2, got string 'shot'] Link to comment
DNL291 Posted April 25, 2013 Share Posted April 25, 2013 No final do client: addCommandHandler("shot", function() if (zzz) then triggerServerEvent("miselShot", localPlayer, zzz) end end ) Link to comment
manawydan Posted April 25, 2013 Author Share Posted April 25, 2013 o missel se moveu, porem foi coisa de uns 5 metros e paro de se mover. e o aviao estava bem alto para o missel mover pouco. Link to comment
DNL291 Posted April 26, 2013 Share Posted April 26, 2013 Eu coloquei para obter a posição hydra do invés do ped, parece que agora o misel chega ao chão. Client: addEvent("ControlState", true) addEvent("AnalogControlState", true) addEventHandler("onClientResourceStart", resourceRoot, function() setTimer(triggerServerEvent, 50, 1, "onTriggerHydraBot", localPlayer) end ) addEventHandler ( "ControlState", root, function ( thePed, control, bol ) setPedControlState ( thePed, control, bol ) end ) addEventHandler ( "AnalogControlState", root, function ( thePed, control, Time ) setPedAnalogControlState ( thePed, control, Time ) end ) function AtualizarPositionPedPilot() local vehicles = getElementsByType ( "vehicle" ) for _,theVehicle in ipairs(vehicles) do if (getElementData(theVehicle, "hydraMisel") == true) then local hx, hy, hz = getElementPosition(theVehicle) zzz = getGroundPosition ( hx, hy, hz ) end end end addEventHandler ( "onClientRender", getRootElement (), AtualizarPositionPedPilot ) addCommandHandler("shot", function() if (zzz) then triggerServerEvent("miselShot", localPlayer, zzz) end end ) Server: local misselRecarregado = 1 --86 ou 90 id dos misseis function MisselEmpty() misselRecarregado = 0 end function MisselReload() setTimer( function() misselRecarregado = 1 missel = createObject(3786, 0, 0, 0) attachElements ( missel, aviao, 0, 0, -2.12, 0, -90, 0 ) end, 10000, 1) end addEvent("onTriggerHydraBot", true) addEventHandler("onTriggerHydraBot", root, function() aviao = createVehicle ( 520, 2051.0708007813, -2494.2114257813, 14.546875, 0, 0, 90 ) pedPilot = createPed ( 287, 2050.0708007813, -2493.2114257813, 13.546875 ) setElementData(aviao, "hydraMisel", true) warpPedIntoVehicle ( pedPilot, aviao ) triggerClientEvent ( "ControlState", root, pedPilot, "accelerate", true ) setTimer( function() triggerClientEvent( "AnalogControlState", root, pedPilot, "special_control_up", 0.4 ) setVehicleLandingGearDown(aviao, false) missel = createObject(3786, 2050.0708007813, -2493.2114257813, 25.546875) attachElements ( missel, aviao, 0, 0, -2.12, 0, -90, 0 ) end, 10000, 1 ) end ) addEvent("miselShot", true) function ShotNow(miselPos) if (aviao and pedPilot and miselPos) then if (misselRecarregado == 1) then detachElements ( missel, aviao ) --setElementRotation(missel,0,-90,0) local x, y, z = getElementPosition(missel) moveObject(missel, 3500, x, y, z-tonumber(miselPos)) MisselEmpty() MisselReload() end end end addEventHandler("miselShot", root, ShotNow) Você pode aumentar/diminuir o tempo para o misel se mover na função moveObject. Link to comment
manawydan Posted April 26, 2013 Author Share Posted April 26, 2013 realmente muito obrigado! quando eu manda para a comunidade vou colocar créditos para voce tambem (minimo que posso fazer, voce fez o script mais que eu). novamente 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