SHARE
TWEET

Untitled

a guest Jun 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local events = require 'lib.samp.events'
  2. CarTp = false
  3.  
  4. function main()
  5.     repeat wait(0) until isSampAvailable();
  6.     sampRegisterChatCommand("arztp",
  7.         function()
  8.             result, x, y, z = getTargetBlipCoordinatesFixed()
  9.                 if result then
  10.                     if isCharInAnyCar(PLAYER_PED) then
  11.                         lua_thread.create(carTeleport, x, y, z)
  12.                     else
  13.                         lua_thread.create(teleport, x, y, z)
  14.                     end
  15.                 else
  16.                     printStringNow("~>~ ~r~marker not found ~<~", 2500)
  17.                 end
  18.         end)
  19.         sampRegisterChatCommand("arztpc",
  20.         function()
  21.             result, x, y, z = SearchMarker(getCharCoordinates(PLAYER_PED))
  22.                 if result then
  23.                     if isCharInAnyCar(PLAYER_PED) then
  24.                         lua_thread.create(carTeleport, x, y, z)
  25.                     else
  26.                         lua_thread.create(teleport, x, y, z)
  27.                     end
  28.                 else
  29.                     printStringNow("~>~ ~r~checkpoint not found ~<~", 2500)
  30.                 end
  31.         end)
  32.     wait(-1)
  33. end
  34.  
  35. function carTeleport(x, y, z)
  36.     CarTp = true
  37.     nopHook("onSendUnoccupiedSync", true)
  38.     nopHook("onSendPassengerSync", true)
  39.     nopHook("onSendVehicleSync", true)
  40.     lockPlayerControl(true)
  41.     coordmaster(x, y, z)
  42. end
  43.  
  44. function teleport(x, y, z)
  45.     nopHook("onSendPlayerSync", true)
  46.     nopHook("onSetPlayerPos", true)
  47.     lockPlayerControl(true)
  48.     coordmaster(x, y, z)
  49. end
  50.  
  51. function sendOnfootSync(x, y, z)
  52.     local data = allocateMemory(68)
  53.     local _, pId = sampGetPlayerIdByCharHandle(PLAYER_PED)
  54.     sampStorePlayerOnfootData(pId, data)
  55.     setStructFloatElement(data, 6, x, false)
  56.     setStructFloatElement(data, 10, y, false)
  57.     setStructFloatElement(data, 14, z, false)
  58.     setStructFloatElement(data, 38, 0.9, false)
  59.     setStructFloatElement(data, 42, 0.9, false)
  60.     setStructFloatElement(data, 46, -0.9, false)
  61.     sampSendOnfootData(data)
  62.     freeMemory(data)
  63. end
  64.  
  65. function sendSpectatorSync(x, y, z)
  66.     local data = allocateMemory(20)
  67.     setStructElement(data, 0, 2, 0, false)
  68.     setStructElement(data, 2, 2, 0, false)
  69.     setStructElement(data, 4, 2, 0, false)  
  70.     setStructFloatElement(data, 6, x, false)
  71.     setStructFloatElement(data, 10, y, false)
  72.     setStructFloatElement(data, 14, z, false)
  73.     sampSendSpectatorData(data)
  74.     freeMemory(data)
  75. end
  76.  
  77. function sendPassengerSync(x, y, z)
  78.     local data = allocateMemory(24)
  79.     local _, pId = sampGetPlayerIdByCharHandle(PLAYER_PED)
  80.     sampStorePlayerPassengerData(pId, data)
  81.     setStructElement(data, 2, 1, 1, false)  
  82.     setStructFloatElement(data, 12, x, false)
  83.     setStructFloatElement(data, 16, y, false)
  84.     setStructFloatElement(data, 20, z, false)
  85.     sampSendPassengerData(data)
  86.     freeMemory(data)
  87. end
  88.  
  89. function sendUnoccupiedSyncBySeatId(x, y, z, seatId)
  90.     local data = allocateMemory(67)
  91.     local car = storeCarCharIsInNoSave(PLAYER_PED)
  92.     local _, vehicleId = sampGetVehicleIdByCarHandle(car)
  93.     local rx, ry, rz = getCarRoll(car)
  94.     setStructElement(data, 0, 2, vehicleId, false)
  95.     setStructElement(data, 2, 1, seatId, false)
  96.     -- roll
  97.     setStructFloatElement(data, 3, rx, false)
  98.     setStructFloatElement(data, 7, ry, false)
  99.     setStructFloatElement(data, 11, rz, false)
  100.     -- direction
  101.     setStructFloatElement(data, 15, 0.09, false)
  102.     setStructFloatElement(data, 19, -0.8, false)
  103.     setStructFloatElement(data, 23, 0.02, false)
  104.     -- position
  105.     setStructFloatElement(data, 27, x, false)
  106.     setStructFloatElement(data, 31, y, false)
  107.     setStructFloatElement(data, 35, z, false)
  108.     -- speed
  109.     setStructFloatElement(data, 39, 0.0012, false)
  110.     setStructFloatElement(data, 43, 0.02, false)
  111.     setStructFloatElement(data, 47, 0.0017, false)
  112.     -- turning speed
  113.     setStructFloatElement(data, 51, 0.005, false)
  114.     setStructFloatElement(data, 55, -0.002, false)
  115.     setStructFloatElement(data, 59, 0.3, false)
  116.     -- car health
  117.     setStructElement(data, 63, 4, 0, false)
  118.     sampSendUnoccupiedData(data)
  119.     freeMemory(data)
  120. end
  121.  
  122. function sendOnFootFakePosition(x, y, z)
  123.     for i = 0, 2 do
  124.         sendOnfootSync(x, y, z)
  125.         sendSpectatorSync(x, y, z)
  126.     end
  127. end
  128.  
  129. function sendInCarFakePosition(x, y, z)
  130.     for i = 0, 2 do
  131.         local data = allocateMemory(24)
  132.         local _, pId = sampGetPlayerIdByCharHandle(PLAYER_PED)
  133.         sampStorePlayerPassengerData(pId, data)
  134.         local seatId = getStructElement(data, 2, 1, false)
  135.         freeMemory(data)
  136.         sendUnoccupiedSyncBySeatId(x, y, z, seatId)
  137.         sendPassengerSync(x, y, z)
  138.     end
  139. end
  140.  
  141. function coordmaster(x, y, z)
  142.     if CarTp then
  143.         local step = 10
  144.         local car = storeCarCharIsInNoSave(PLAYER_PED)
  145.         local cx, cy, cz = getCarCoordinates(car)
  146.         local angle = getAngle(cx, cy, x, y)
  147.         while true do
  148.             wait(0)
  149.             printStringNow("~Y~please wait~s~", 50)
  150.             if getDistanceBetweenCoords2d(cx, cy, x, y) > step then
  151.                 cx = cx + math.sin(angle) * step  
  152.                 cy = cy + math.cos(angle) * step
  153.                 sendInCarFakePosition(cx, cy, cz)
  154.             else
  155.                 sendInCarFakePosition(x, y, z)
  156.                 setCarCoordinates(car, x, y, z)
  157.                 nopHook("onSendUnoccupiedSync", false)
  158.                 nopHook("onSendPassengerSync", false)
  159.                 lockPlayerControl(false)
  160.                 CarTp = false
  161.                 printStringNow("~>~ ~p~successful ~s~teleport ~<~",2500)
  162.                 addOneOffSound(0.0, 0.0, 0.0, 1139)
  163.                 break
  164.             end
  165.         end
  166.     else
  167.         local step = 30
  168.         local cx, cy, cz = getCharCoordinates(PLAYER_PED)
  169.         local angle = getAngle(cx, cy, x, y)
  170.         while true do
  171.             wait(0)
  172.             printStringNow("~Y~please wait~s~", 50)
  173.             if getDistanceBetweenCoords2d(cx, cy, x, y) > step then
  174.                 cx = cx + math.sin(angle) * step  
  175.                 cy = cy + math.cos(angle) * step
  176.                 sendOnFootFakePosition(cx, cy, cz)
  177.             else
  178.                 sendOnFootFakePosition(x, y, z + 55)
  179.                 setCharCoordinates(PLAYER_PED, x, y, z)
  180.                 wait(250)
  181.                 nopHook("onSendPlayerSync", false)
  182.                 nopHook("onSetPlayerPos", false)
  183.                 lockPlayerControl(false)
  184.                 printStringNow("~>~ ~p~successful ~s~teleport ~<~",2500)
  185.                 addOneOffSound(0.0, 0.0, 0.0, 1139)
  186.                 break
  187.             end
  188.         end
  189.     end
  190. end
  191.  
  192. function getAngle(x1, y1, x2, y2)
  193.     return math.atan2(x2 - x1, y2 - y1);
  194. end
  195.  
  196. function nopHook(name, bool)
  197.     local samp = require 'samp.events'
  198.     samp[name] = function()
  199.         if bool then
  200.             return false
  201.         end
  202.     end
  203. end
  204.  
  205. function getTargetBlipCoordinatesFixed()                      
  206.     local bool, x, y, z = getTargetBlipCoordinates()
  207.         if not bool then  
  208.             return false
  209.         end
  210.     requestCollision(x, y)
  211.     loadScene(x, y, z)
  212.     local bool, x, y, z = getTargetBlipCoordinates()
  213.     return bool, x, y, z
  214. end
  215.  
  216. function SearchMarker(posX, posY, posZ)
  217.     local ret_posX = 0.0
  218.     local ret_posY = 0.0
  219.     local ret_posZ = 0.0
  220.     local isFind = false
  221.     for id = 0, 31 do
  222.         local MarkerStruct = 0
  223.         MarkerStruct = 0xC7F168 + id * 56
  224.         local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
  225.         local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
  226.         local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
  227.         if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
  228.                 ret_posX = MarkerPosX
  229.                 ret_posY = MarkerPosY
  230.                 ret_posZ = MarkerPosZ
  231.                 isFind = true
  232.         end
  233.     end
  234.     return isFind, ret_posX, ret_posY, ret_posZ
  235.   end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top