Jump to content

posição "chão"


Recommended Posts

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

É 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

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

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

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

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

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

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

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

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

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