Jump to content

pushed away when driving in teleport, pleas help


Recommended Posts

The getCameraPosition function is purely client sided.

Oh

You will have to teleport the vehicle server side and tell the client to start the camera check timer

I wonder for a long time how i can create a bridge between server and client side script, can you give me a tip? :oops:

Link to comment
  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

The getCameraPosition function is purely client sided.

Oh

You will have to teleport the vehicle server side and tell the client to start the camera check timer

I wonder for a long time how i can create a bridge between server and client side script, can you give me a tip? :oops:

Link to comment

Try something like this:

server

  
function teleportPlayerVehicle(player) 
  local vehicle = getPlayerOccupiedVehicle(player) 
  local targetX, targetY, targetZ = 0, 0, 0 -- teleport location 
  if (vehicle) then 
    -- teleport vehicle (setElementInterior or setElementPosition) 
    triggerClientEvent(player, "onVehicleTeleport", player, targetX, targetY, targetZ) 
  end 
end 
  
function onVehicleTeleported() 
  local vehicle = getPlayerOccupiedVehicle(source) 
  if (vehicle) then 
    setVehicleFrozen(vehicle, false) 
  end 
end 
  
addEvent("onVehicleTeleported", true) 
addEventHandler("onVehicleTeleported", getRootElement(), onVehicleTeleported) 
  

client

  
function onVehicleTeleport(targetX, targetY, targetZ) 
  local vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
  local vX, vY, vZ = 0, 0, 0 
  local cX, cY, cZ = 0, 0, 0 
  if (vehicle) then 
    vX, vY, vZ = getElementPosition(vehicle) 
    cX, cY, cZ = getCameraPosition() 
    if (getDistanceBetweenPoints3D(vX, vY, vZ, targetX, targetY, targetZ) < 5.0 and getDistanceBetweenPoints3D(cX, cY, cZ, targetX, targetY, targetZ) < 25.0) then 
      triggerServerEvent("onVehicleTeleported", getLocalPlayer()) 
    else 
      setTimer(onVehicleTeleport, 50, 1, targetX, targetY, targetZ) 
    end 
  end 
end 
  
addEvent("onVehicleTeleport", true) 
addEventHandler("onVehicleTeleport", getRootElement(), onVehicleTeleport) 
  

Link to comment

Try something like this:

server

  
function teleportPlayerVehicle(player) 
  local vehicle = getPlayerOccupiedVehicle(player) 
  local targetX, targetY, targetZ = 0, 0, 0 -- teleport location 
  if (vehicle) then 
    -- teleport vehicle (setElementInterior or setElementPosition) 
    triggerClientEvent(player, "onVehicleTeleport", player, targetX, targetY, targetZ) 
  end 
end 
  
function onVehicleTeleported() 
  local vehicle = getPlayerOccupiedVehicle(source) 
  if (vehicle) then 
    setVehicleFrozen(vehicle, false) 
  end 
end 
  
addEvent("onVehicleTeleported", true) 
addEventHandler("onVehicleTeleported", getRootElement(), onVehicleTeleported) 
  

client

  
function onVehicleTeleport(targetX, targetY, targetZ) 
  local vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
  local vX, vY, vZ = 0, 0, 0 
  local cX, cY, cZ = 0, 0, 0 
  if (vehicle) then 
    vX, vY, vZ = getElementPosition(vehicle) 
    cX, cY, cZ = getCameraPosition() 
    if (getDistanceBetweenPoints3D(vX, vY, vZ, targetX, targetY, targetZ) < 5.0 and getDistanceBetweenPoints3D(cX, cY, cZ, targetX, targetY, targetZ) < 25.0) then 
      triggerServerEvent("onVehicleTeleported", getLocalPlayer()) 
    else 
      setTimer(onVehicleTeleport, 50, 1, targetX, targetY, targetZ) 
    end 
  end 
end 
  
addEvent("onVehicleTeleport", true) 
addEventHandler("onVehicleTeleport", getRootElement(), onVehicleTeleport) 
  

Link to comment

Now i found the problem why i think i "falling down".

Its following: i frezzes the car after 150 milli seconds because so i can fix the problem that the car runs crasy :lol:

But the problem with this metode: sometimes when the car is not hight enought (interiors are in the air...) and then the frezz launches, the car stop teleporting (flying) to the destination point, because 150 milli seconds is not enought to get in the interior.

Why i don´t use more milli seconds?

Because every PC uses different hardware and have different pings.

Now my idea: i need a function to check that the vehicle is on the place it should be beamed, like getVehiclePosition or so. is that possibly?

Link to comment

Now i found the problem why i think i "falling down".

Its following: i frezzes the car after 150 milli seconds because so i can fix the problem that the car runs crasy :lol:

But the problem with this metode: sometimes when the car is not hight enought (interiors are in the air...) and then the frezz launches, the car stop teleporting (flying) to the destination point, because 150 milli seconds is not enought to get in the interior.

Why i don´t use more milli seconds?

Because every PC uses different hardware and have different pings.

Now my idea: i need a function to check that the vehicle is on the place it should be beamed, like getVehiclePosition or so. is that possibly?

Link to comment
That is exactly what the check does.

:oops: sorry ^^

Its a little bit complicated to build it in, i try it but it don´t works, where is setVehicleFrozen(vehicle, true) in this code?

On

local targetX, targetY, targetZ = 0, 0, 0 -- teleport location 

and

-- teleport vehicle (setElementInterior or setElementPosition) 

i need to set the destination point?

That´s my currently code: http://mta.pastebin.com/m5c934a89

And now i tries to build you code in it: http://mta.pastebin.com/m449eab5b but it don´t work :?

notice: the client script is build in in the meta.xml, don´t worry ^^

Link to comment
That is exactly what the check does.

:oops: sorry ^^

Its a little bit complicated to build it in, i try it but it don´t works, where is setVehicleFrozen(vehicle, true) in this code?

On

local targetX, targetY, targetZ = 0, 0, 0 -- teleport location

and

-- teleport vehicle (setElementInterior or setElementPosition)

i need to set the destination point?

That´s my currently code: http://mta.pastebin.com/m5c934a89

And now i tries to build you code in it: http://mta.pastebin.com/m449eab5b but it don´t work :?

notice: the client script is build in in the meta.xml, don´t worry ^^

Link to comment

I've just tested this code (made some minor changes to yours) and it seems to work.

server

  
local targetX, targetY, targetZ = -1396.1995849609, 1093.6236572266, 1048.9255371094 
local sourceX, sourceY, sourceZ = 1078.9619140625, 1602.2117919922, 12.546875 
  
local ColHotringRaceEingang = createColSphere(sourceX, sourceY, sourceZ, 2) 
  
function HotringRaceMarkerEingang(name) 
  if (name ~= getThisResource()) then 
    return 
  else 
    createMarker(sourceX, sourceY, sourceZ, "cylinder", 4, 219, 155, 135, 100) 
  end 
end 
  
function HotringRaceMarkerEingangBeamer(player) 
  local vehicle = false 
  if (getElementType(player) == "player") then 
    vehicle = getPlayerOccupiedVehicle(player) 
    if (vehicle) then 
      setElementInterior(vehicle, 15, targetX, targetY, targetZ) 
      setVehicleFrozen(vehicle, true) 
      setElementInterior(player, 15, targetX, targetY, targetZ) 
      triggerClientEvent(player, "onVehicleTeleport", player, targetX, targetY, targetZ) 
    end 
  end 
end 
  
function onVehicleTeleported() 
  local vehicle = getPlayerOccupiedVehicle(source) 
  if (vehicle) then 
    setVehicleFrozen(vehicle, false) 
  end 
end 
  
addEvent("onVehicleTeleported", true) 
addEventHandler("onVehicleTeleported", getRootElement(), onVehicleTeleported) 
  
addEventHandler("onColShapeHit", ColHotringRaceEingang, HotringRaceMarkerEingangBeamer) 
addEventHandler("onResourceStart", getRootElement(), HotringRaceMarkerEingang) 
  

client

  
function onVehicleTeleport(targetX, targetY, targetZ) 
  local vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
  local vX, vY, vZ = 0, 0, 0 
  local cX, cY, cZ = 0, 0, 0 
  if (vehicle) then 
    vX, vY, vZ = getElementPosition(vehicle) 
    cX, cY, cZ = getCameraPosition() 
    if (getDistanceBetweenPoints3D(vX, vY, vZ, targetX, targetY, targetZ) < 5.0 and getDistanceBetweenPoints3D(cX, cY, cZ, targetX, targetY, targetZ) < 25.0) then 
      triggerServerEvent("onVehicleTeleported", getLocalPlayer()) 
    else 
      setTimer(onVehicleTeleport, 50, 1, targetX, targetY, targetZ) 
    end 
  end 
end 
  
addEvent("onVehicleTeleport", true) 
addEventHandler("onVehicleTeleport", getRootElement(), onVehicleTeleport) 
  

Link to comment

I've just tested this code (made some minor changes to yours) and it seems to work.

server

  
local targetX, targetY, targetZ = -1396.1995849609, 1093.6236572266, 1048.9255371094 
local sourceX, sourceY, sourceZ = 1078.9619140625, 1602.2117919922, 12.546875 
  
local ColHotringRaceEingang = createColSphere(sourceX, sourceY, sourceZ, 2) 
  
function HotringRaceMarkerEingang(name) 
  if (name ~= getThisResource()) then 
    return 
  else 
    createMarker(sourceX, sourceY, sourceZ, "cylinder", 4, 219, 155, 135, 100) 
  end 
end 
  
function HotringRaceMarkerEingangBeamer(player) 
  local vehicle = false 
  if (getElementType(player) == "player") then 
    vehicle = getPlayerOccupiedVehicle(player) 
    if (vehicle) then 
      setElementInterior(vehicle, 15, targetX, targetY, targetZ) 
      setVehicleFrozen(vehicle, true) 
      setElementInterior(player, 15, targetX, targetY, targetZ) 
      triggerClientEvent(player, "onVehicleTeleport", player, targetX, targetY, targetZ) 
    end 
  end 
end 
  
function onVehicleTeleported() 
  local vehicle = getPlayerOccupiedVehicle(source) 
  if (vehicle) then 
    setVehicleFrozen(vehicle, false) 
  end 
end 
  
addEvent("onVehicleTeleported", true) 
addEventHandler("onVehicleTeleported", getRootElement(), onVehicleTeleported) 
  
addEventHandler("onColShapeHit", ColHotringRaceEingang, HotringRaceMarkerEingangBeamer) 
addEventHandler("onResourceStart", getRootElement(), HotringRaceMarkerEingang) 
  

client

  
function onVehicleTeleport(targetX, targetY, targetZ) 
  local vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
  local vX, vY, vZ = 0, 0, 0 
  local cX, cY, cZ = 0, 0, 0 
  if (vehicle) then 
    vX, vY, vZ = getElementPosition(vehicle) 
    cX, cY, cZ = getCameraPosition() 
    if (getDistanceBetweenPoints3D(vX, vY, vZ, targetX, targetY, targetZ) < 5.0 and getDistanceBetweenPoints3D(cX, cY, cZ, targetX, targetY, targetZ) < 25.0) then 
      triggerServerEvent("onVehicleTeleported", getLocalPlayer()) 
    else 
      setTimer(onVehicleTeleport, 50, 1, targetX, targetY, targetZ) 
    end 
  end 
end 
  
addEvent("onVehicleTeleport", true) 
addEventHandler("onVehicleTeleport", getRootElement(), onVehicleTeleport) 
  

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