Infra_

Untitled

Apr 13th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. local Teleport = createMarker(X, Y, Z, "corona", SIZE, 0, 0, 0)
  2.  
  3. addEventHandler("onClientMarkerHit", getRootElement(), function(playerid)
  4.     if playerid == localPlayer then
  5.         if isPedInVehicle(localPlayer) then
  6.             local vehicleid = getPedOccupiedVehicle(localPlayer)
  7.  
  8.             if source == Teleport then
  9.                 fadeCamera(false, 0.7, 0, 0, 0)
  10.                 easeGameSpeed(0.2, 1500, function()
  11.                     setElementPosition(vehicleid, targetX, targetY, targetZ)
  12.                     setElementRotation(vehicleid, targetRotX, targetRotY, targetRotZ)
  13.  
  14.                     setCameraTarget(localPlayer)
  15.                    
  16.                     fadeCamera(true, 1.0)
  17.                     setTimer(function()
  18.                         --setElementVelocity(vehicleid, velX, velY, velZ) -- Optional: Velocity
  19.                         --setVehicleTurnVelocity(vehicleid, angularVelX, angularVelY, angularVelZ) -- Optional: Angular Velocity
  20.                         easeGameSpeed(1.0, 2000)
  21.                     end, 500, 1)
  22.                 end)
  23.             end
  24.  
  25.         end
  26.     end
  27. end)
  28.  
  29. local ease = {}
  30. function easeGameSpeed(targetSpeed, overTime, callback)
  31.     ease.startedAt      =   getTickCount()
  32.     ease.startSpeed     =   getGameSpeed()
  33.     ease.targetSpeed    =   math.round(targetSpeed, 4, "floor")
  34.     ease.overTime       =   overTime
  35.     ease.callback       =   (type(callback) == "function" or type(callback) == "nil") and (type(callback) == "function" and callback or nil) or nil
  36.     ease.isActive       =   true
  37. end
  38.  
  39. addEventHandler("onClientRender", root, function()
  40.     if ease.isActive then
  41.         local progress = (getTickCount() - ease.startedAt) / ((ease.startedAt + ease.overTime) - ease.startedAt)
  42.         local currentSpeed = math.round(getGameSpeed(), 1, (ease.startSpeed > ease.targetSpeed and "ceil" or "floor"))
  43.  
  44.         local X, Y, Z = interpolateBetween(currentSpeed, 0.0, 0.0, ease.targetSpeed, 0.0, 0.0, progress, "InOutQuad")
  45.         X = math.round(X, 4, (ease.startSpeed > ease.targetSpeed and "floor" or "ceil"))
  46.         if ease.startSpeed > ease.targetSpeed and X <= ease.targetSpeed then
  47.             X = math.round(X, 1, "ceil")
  48.         elseif ease.startSpeed < ease.targetSpeed and X >= ease.targetSpeed then
  49.             X = math.round(X, 1, "floor")
  50.         end
  51.        
  52.         setGameSpeed(X)
  53.         if X == ease.targetSpeed then
  54.             ease.isActive = false
  55.             if type(ease.callback) == "function" then
  56.                 ease.callback();
  57.             end
  58.         end
  59.     end
  60. end)
  61.  
  62. function math.round(number, decimals, method)
  63.     decimals = decimals or 0
  64.     local factor = 10 ^ decimals
  65.     if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
  66.     else return tonumber(("%."..decimals.."f"):format(number)) end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment