SlonPvpru

[ARZ/Evolve] OnFoot/InCar Fly

Jun 4th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.68 KB | None | 0 0
  1. -- Author: Azller Lollison (in public this source is missing)
  2.  
  3. local sampev = require "lib.samp.events"
  4. local memory = require "memory"
  5. local onFootSpeed = 2.0
  6. local inCarSpeed = 4.0
  7.  
  8. function getCameraPositionUnfixed()
  9.     return memory.getfloat(0xB6F248), memory.getfloat(0xB6F258)
  10. end
  11.  
  12. function main()
  13.     while not isSampAvailable() do wait(0) end
  14.  
  15.     sampRegisterChatCommand("fly", function() flyActivated = not flyActivated; sampAddChatMessage(flyActivated and "Activated" or "Offline", -1) end)
  16.    
  17.     sampRegisterChatCommand("slap", function(id) target = tonumber(id) slapActivated = not slapActivated; sampAddChatMessage(slapActivated and "Activated" or "Offline", -1) end)
  18.  
  19.     while true do wait(0)
  20.         if isKeyDown(18) and flyActivated then
  21.             if not isCharInAnyCar(PLAYER_PED) then
  22.                 local x, y, z = getCharCoordinates(PLAYER_PED)
  23.                 freezeCharPosition(PLAYER_PED, true);
  24.                 sampForceOnfootSync(); wait(0)
  25.                 if isKeyDown(87) then
  26.                     local xAngle, zAngle = getCameraPositionUnfixed()
  27.                     setCharHeading(PLAYER_PED, math.deg(zAngle + math.pi / 2))
  28.                     setCharCoordinatesDontResetAnim(PLAYER_PED, x - onFootSpeed * math.cos(zAngle), y - onFootSpeed * math.sin(zAngle), z)
  29.                 end
  30.                 if isKeyDown(83) then
  31.                     local xAngle, zAngle = getCameraPositionUnfixed()
  32.                     setCharHeading(PLAYER_PED, math.deg(zAngle + math.pi / 2))
  33.                     setCharCoordinatesDontResetAnim(PLAYER_PED, x + onFootSpeed * math.cos(zAngle), y + onFootSpeed * math.sin(zAngle), z)
  34.                 end
  35.                 if isKeyDown(49) then
  36.                     setCharCoordinatesDontResetAnim(PLAYER_PED, x, y, z + 1.5)
  37.                 end
  38.                 if isKeyDown(50) then
  39.                     setCharCoordinatesDontResetAnim(PLAYER_PED, x, y, z - 1.5)
  40.                 end
  41.                 if isKeyDown(107) then
  42.                     onFootSpeed = onFootSpeed + 0.1
  43.                     printStringNow("~r~OnFoot speed: ~w~"..onFootSpeed, 1000)
  44.                 end
  45.                 if isKeyDown(109) then
  46.                     onFootSpeed = onFootSpeed - 0.1
  47.                     printStringNow("~r~OnFoot speed: ~w~"..onFootSpeed, 1000)
  48.                 end
  49.                 freezeCharPosition(PLAYER_PED, false)
  50.                 sampForceOnfootSync()
  51.             else
  52.                 local handle = storeCarCharIsInNoSave(PLAYER_PED)
  53.                 freezeCarPosition(handle, true)
  54.                 local x, y, z = getCarCoordinates(handle)
  55.                 _, id = sampGetVehicleIdByCarHandle(handle)
  56.                 if getDriverOfCar(handle) == 1 then
  57.                     sampForceVehicleSync(id); sampForceVehicleSync(id);
  58.                 else
  59.                     local seatId = getPlayerSeatId(PLAYER_PED);
  60.                     sampForcePassengerSyncSeatId(id, seatId); sampForceUnoccupiedSyncSeatId(id, seatId)
  61.                 end
  62.                 if isKeyDown(87) then
  63.                     local xAngle, zAngle = getCameraPositionUnfixed()
  64.                     setCarHeading(handle, math.deg(zAngle + math.pi / 2))
  65.                     setCarCoordinates(handle, x - inCarSpeed * math.cos(zAngle), y - inCarSpeed * math.sin(zAngle), z)
  66.                 end
  67.                 if isKeyDown(83) then
  68.                     local xAngle, zAngle = getCameraPositionUnfixed()
  69.                     setCarHeading(handle, math.deg(zAngle + math.pi / 2))
  70.                     setCarCoordinates(handle, x + inCarSpeed * math.cos(zAngle), y + inCarSpeed * math.sin(zAngle), z)
  71.                 end
  72.                 if isKeyDown(49) then
  73.                     setCarCoordinates(handle, x, y, z + 3)
  74.                 end
  75.                 if isKeyDown(50) then
  76.                     setCarCoordinates(handle, x, y, z - 3)
  77.                 end
  78.                 if isKeyDown(107) then
  79.                     inCarSpeed = inCarSpeed + 0.1
  80.                     printStringNow("~r~InCar speed: ~w~"..inCarSpeed, 1000)
  81.                 end
  82.                 if isKeyDown(109) then
  83.                     inCarSpeed = inCarSpeed - 0.1
  84.                     printStringNow("~r~InCar speed: ~w~"..inCarSpeed, 1000)
  85.                 end
  86.                 freezeCarPosition(handle, false)
  87.             end
  88.         end
  89.  
  90.     end
  91.  
  92.     wait(-1)
  93. end
  94.  
  95.  
  96. function getPlayerSeatId(handle)
  97.     if result and isCharInAnyCar(handle) then
  98.       local car = storeCarCharIsInNoSave(ped)
  99.       for i = 0, getMaximumNumberOfPassengers(car) do
  100.         if not isCarPassengerSeatFree(car, i) and getCharInCarPassengerSeat(car, i) == ped then
  101.           return i -- seat id
  102.         end
  103.       end
  104.     end
  105.     return nil
  106.   end
  107.  
  108. function setCharCoordinatesDontResetAnim(char, x, y, z)
  109.     if doesCharExist(char) then
  110.         local ptr = getCharPointer(char)
  111.         setEntityCoordinates(ptr, x, y, z)
  112.     end
  113. end
  114.  
  115. function setCarCoordinates(car, x, y, z)
  116.     local ptr = getCarPointer(car)
  117.     setEntityCoordinates(ptr, x, y, z)
  118. end
  119.  
  120. function setEntityCoordinates(entityPtr, x, y, z)
  121.     if entityPtr ~= 0 then
  122.         local matrixPtr = readMemory(entityPtr + 0x14, 4, false)
  123.         if matrixPtr ~= 0 then
  124.             local posPtr = matrixPtr + 0x30
  125.             writeMemory(posPtr + 0, 4, representFloatAsInt(x), false) --X
  126.             writeMemory(posPtr + 4, 4, representFloatAsInt(y), false) --Y
  127.             writeMemory(posPtr + 8, 4, representFloatAsInt(z), false) --Z
  128.         end
  129.     end
  130. end
  131.  
  132. function sampev.onSendUnoccupiedSync(data)
  133.     if flyActivated and isKeyDown(18) then
  134.         if data.vehicleId == id then
  135.             data.moveSpeed.z = -1.5;
  136.             data.turnSpeed = {x = 0.1, y = 0.1, z = 0.1}
  137.             data.roll = {x = 0.1, y = 0.1, z = 0.1}
  138.         end
  139.     end
  140. end
  141.  
  142.  
  143.  
  144. function FindRandomVehInSphere()
  145.     local x, y, z = getCharCoordinates(PLAYER_PED)
  146.     local res, veh = findAllRandomVehiclesInSphere(x, y, z, 5000.0, true, false)
  147.     if res then
  148.         local res, id = sampGetVehicleIdByCarHandle(veh)
  149.         if res then return id, x, y, z else return -1, x, y, z end
  150.     end
  151. end
  152.  
  153. function sampev.onSetPlayerPos()
  154.     if flyActivated then return false end
  155. end
  156. function sampev.onSetPlayerPosFindZ()
  157.     if flyActivated then return false end
  158. end
  159. function sampev.onApplyPlayerAnimation()
  160.     if flyActivated then return false end
  161. end
  162. function sampev.onClearPlayerAnimation()
  163.     if flyActivated then return false end
  164. end
  165.  
  166. function sampev.onSendPlayerSync(data)
  167.     if flyActivated then
  168.         data.animationId = 1538;
  169.         data.animationFlags = 32772;
  170.         if isKeyDown(18) then
  171.             data.moveSpeed.x = 0.1;
  172.             data.moveSpeed.y = 0.1;
  173.             data.moveSpeed.z = 0.135;
  174.             data.keysData = 0;
  175.            
  176.             local v_id, x, y, z = FindRandomVehInSphere()
  177.            
  178.             if v_id ~= -1 and v_id ~= nil then
  179.            
  180.                 onFootSpeed = 4.1
  181.            
  182.                 -- sampAddChatMessage(string.format('surfing veh = %d', v_id), -1)
  183.            
  184.                 data.surfingVehicleId = v_id
  185.            
  186.                 data.surfingOffsets = {x = x, y = y, z = z}
  187.            
  188.             else onFootSpeed = 2.5 end
  189.            
  190.            
  191.         end
  192.     end
  193. end
  194.  
  195. function sampev.onSendVehicleSync(data)
  196.     if flyActivated and isKeyDown(18) then
  197.         data.moveSpeed.z = -0.1;
  198.     end
  199.     if isKeyDown(16) and slapActivated then
  200.         local res, handle = sampGetCharHandleBySampPlayerId(target)
  201.         if res then
  202.             sampAddChatMessage("Ebanulo 1", -1)
  203.             local x1, y1, z1 = getCharCoordinates(handle)
  204.             data.position = {x = x1, y = y1, z = z1 + 1.0}
  205.             data.moveSpeed.x = -0.1
  206.             data.moveSpeed.z = -1.0
  207.         end
  208.     end
  209. end
  210.  
  211. function sampev.onSetVehicleVelocity()
  212.     if flyActivated then print("Noped"); return false end
  213. end
Add Comment
Please, Sign In to add comment