Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 KB | None | 0 0
  1. local RCCar = {}
  2.  
  3. RegisterCommand("rc", function()
  4. RCCar.Start()
  5. end)
  6.  
  7. RCCar.Start = function()
  8.  
  9. if DoesEntityExist(RCCar.Entity) then return end
  10. RCCar.Spawn()
  11.  
  12. RCCar.Tablet(true)
  13.  
  14. while DoesEntityExist(RCCar.Entity) and DoesEntityExist(RCCar.Driver) do
  15. Citizen.Wait(5)
  16.  
  17. local distanceCheck = GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), GetEntityCoords(RCCar.Entity), true)
  18.  
  19. RCCar.DrawInstructions(distanceCheck)
  20. RCCar.HandleKeys(distanceCheck)
  21.  
  22. if distanceCheck <= Config.LoseConnectionDistance then
  23. if not NetworkHasControlOfEntity(RCCar.Driver) then
  24. NetworkRequestControlOfEntity(RCCar.Driver)
  25. elseif not NetworkHasControlOfEntity(RCCar.Entity) then
  26. NetworkRequestControlOfEntity(RCCar.Entity)
  27. end
  28. else
  29. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 6, 2500)
  30. end
  31. end
  32. end
  33.  
  34. RCCar.HandleKeys = function(distanceCheck)
  35. if IsControlJustReleased(0, 47) then
  36. if IsCamRendering(RCCar.Camera) then
  37. RCCar.ToggleCamera(false)
  38. else
  39. RCCar.ToggleCamera(true)
  40. end
  41. end
  42.  
  43. if distanceCheck <= 1.5 then
  44. if IsControlJustPressed(0, 38) then
  45. RCCar.Attach("pick")
  46. end
  47. end
  48.  
  49. if distanceCheck < Config.LoseConnectionDistance then
  50. if IsControlPressed(0, 172) and not IsControlPressed(0, 173) then
  51. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 9, 1)
  52. end
  53.  
  54. if IsControlJustReleased(0, 172) or IsControlJustReleased(0, 173) then
  55. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 6, 2500)
  56. end
  57.  
  58. if IsControlPressed(0, 173) and not IsControlPressed(0, 172) then
  59. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 22, 1)
  60. end
  61.  
  62. if IsControlPressed(0, 174) and IsControlPressed(0, 173) then
  63. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 13, 1)
  64. end
  65.  
  66. if IsControlPressed(0, 175) and IsControlPressed(0, 173) then
  67. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 14, 1)
  68. end
  69.  
  70. if IsControlPressed(0, 172) and IsControlPressed(0, 173) then
  71. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 30, 100)
  72. end
  73.  
  74. if IsControlPressed(0, 174) and IsControlPressed(0, 172) then
  75. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 7, 1)
  76. end
  77.  
  78. if IsControlPressed(0, 175) and IsControlPressed(0, 172) then
  79. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 8, 1)
  80. end
  81.  
  82. if IsControlPressed(0, 174) and not IsControlPressed(0, 172) and not IsControlPressed(0, 173) then
  83. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 4, 1)
  84. end
  85.  
  86. if IsControlPressed(0, 175) and not IsControlPressed(0, 172) and not IsControlPressed(0, 173) then
  87. TaskVehicleTempAction(RCCar.Driver, RCCar.Entity, 5, 1)
  88. end
  89. end
  90. end
  91.  
  92. RCCar.DrawInstructions = function(distanceCheck)
  93. local steeringButtons = {
  94. {
  95. ["label"] = "Höger",
  96. ["button"] = "~INPUT_CELLPHONE_RIGHT~"
  97. },
  98. {
  99. ["label"] = "Fram",
  100. ["button"] = "~INPUT_CELLPHONE_UP~"
  101. },
  102. {
  103. ["label"] = "Bak",
  104. ["button"] = "~INPUT_CELLPHONE_DOWN~"
  105. },
  106. {
  107. ["label"] = "Vänster",
  108. ["button"] = "~INPUT_CELLPHONE_LEFT~"
  109. }
  110. }
  111.  
  112. local pickupButton = {
  113. ["label"] = "Ta upp",
  114. ["button"] = "~INPUT_CONTEXT~"
  115. }
  116.  
  117. local buttonsToDraw = {
  118. {
  119. ["label"] = "Sätt På/Av kamera",
  120. ["button"] = "~INPUT_DETONATE~"
  121. }
  122. }
  123.  
  124. if distanceCheck <= Config.LoseConnectionDistance then
  125. for buttonIndex = 1, #steeringButtons do
  126. local steeringButton = steeringButtons[buttonIndex]
  127.  
  128. table.insert(buttonsToDraw, steeringButton)
  129. end
  130.  
  131. if distanceCheck <= 1.5 then
  132. table.insert(buttonsToDraw, pickupButton)
  133. end
  134. end
  135.  
  136. Citizen.CreateThread(function()
  137. local instructionScaleform = RequestScaleformMovie("instructional_buttons")
  138.  
  139. while not HasScaleformMovieLoaded(instructionScaleform) do
  140. Wait(0)
  141. end
  142.  
  143. PushScaleformMovieFunction(instructionScaleform, "CLEAR_ALL")
  144. PushScaleformMovieFunction(instructionScaleform, "TOGGLE_MOUSE_BUTTONS")
  145. PushScaleformMovieFunctionParameterBool(0)
  146. PopScaleformMovieFunctionVoid()
  147.  
  148. for buttonIndex, buttonValues in ipairs(buttonsToDraw) do
  149. PushScaleformMovieFunction(instructionScaleform, "SET_DATA_SLOT")
  150. PushScaleformMovieFunctionParameterInt(buttonIndex - 1)
  151.  
  152. PushScaleformMovieMethodParameterButtonName(buttonValues["button"])
  153. PushScaleformMovieFunctionParameterString(buttonValues["label"])
  154. PopScaleformMovieFunctionVoid()
  155. end
  156.  
  157. PushScaleformMovieFunction(instructionScaleform, "DRAW_INSTRUCTIONAL_BUTTONS")
  158. PushScaleformMovieFunctionParameterInt(-1)
  159. PopScaleformMovieFunctionVoid()
  160. DrawScaleformMovieFullscreen(instructionScaleform, 255, 255, 255, 255)
  161. end)
  162. end
  163.  
  164. RCCar.Spawn = function()
  165. RCCar.LoadModels({ GetHashKey("rcbandito"), 68070371 })
  166.  
  167. local spawnCoords, spawnHeading = GetEntityCoords(PlayerPedId()) + GetEntityForwardVector(PlayerPedId()) * 2.0, GetEntityHeading(PlayerPedId())
  168.  
  169. RCCar.Entity = CreateVehicle(GetHashKey("rcbandito"), spawnCoords, spawnHeading, true)
  170.  
  171. while not DoesEntityExist(RCCar.Entity) do
  172. Citizen.Wait(5)
  173. end
  174.  
  175. RCCar.Driver = CreatePed(5, 68070371, spawnCoords, spawnHeading, true)
  176.  
  177. SetEntityInvincible(RCCar.Driver, true)
  178. SetEntityVisible(RCCar.Driver, false)
  179. FreezeEntityPosition(RCCar.Driver, true)
  180. SetPedAlertness(RCCar.Driver, 0.0)
  181.  
  182. TaskWarpPedIntoVehicle(RCCar.Driver, RCCar.Entity, -1)
  183.  
  184. while not IsPedInVehicle(RCCar.Driver, RCCar.Entity) do
  185. Citizen.Wait(0)
  186. end
  187.  
  188. RCCar.Attach("place")
  189. end
  190.  
  191. RCCar.Attach = function(param)
  192. if not DoesEntityExist(RCCar.Entity) then
  193. return
  194. end
  195.  
  196. RCCar.LoadModels({ "pickup_object" })
  197.  
  198. if param == "place" then
  199. AttachEntityToEntity(RCCar.Entity, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 28422), -0.1, 0.0, -0.2, 70.0, 0.0, 270.0, 1, 1, 0, 0, 2, 1)
  200.  
  201. TaskPlayAnim(PlayerPedId(), "pickup_object", "pickup_low", 8.0, -8.0, -1, 0, 0, false, false, false)
  202.  
  203. Citizen.Wait(800)
  204.  
  205. DetachEntity(RCCar.Entity, false, true)
  206.  
  207. PlaceObjectOnGroundProperly(RCCar.Entity)
  208. elseif param == "pick" then
  209. if DoesCamExist(RCCar.Camera) then
  210. RCCar.ToggleCamera(false)
  211. end
  212.  
  213. RCCar.Tablet(false)
  214.  
  215. Citizen.Wait(100)
  216.  
  217. TaskPlayAnim(PlayerPedId(), "pickup_object", "pickup_low", 8.0, -8.0, -1, 0, 0, false, false, false)
  218.  
  219. Citizen.Wait(600)
  220.  
  221. AttachEntityToEntity(RCCar.Entity, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 28422), -0.1, 0.0, -0.2, 70.0, 0.0, 270.0, 1, 1, 0, 0, 2, 1)
  222.  
  223. Citizen.Wait(900)
  224.  
  225. DetachEntity(RCCar.Entity)
  226.  
  227. DeleteVehicle(RCCar.Entity)
  228. DeleteEntity(RCCar.Driver)
  229.  
  230. RCCar.UnloadModels()
  231. end
  232. end
  233.  
  234. RCCar.Tablet = function(boolean)
  235. if boolean then
  236. RCCar.LoadModels({ GetHashKey("prop_cs_tablet") })
  237.  
  238. RCCar.TabletEntity = CreateObject(GetHashKey("prop_cs_tablet"), GetEntityCoords(PlayerPedId()), true)
  239.  
  240. AttachEntityToEntity(RCCar.TabletEntity, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 28422), -0.03, 0.0, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
  241.  
  242. RCCar.LoadModels({ "amb@code_human_in_bus_passenger_idles@female@tablet@idle_a" })
  243.  
  244. TaskPlayAnim(PlayerPedId(), "amb@code_human_in_bus_passenger_idles@female@tablet@idle_a", "idle_a", 3.0, -8, -1, 63, 0, 0, 0, 0 )
  245.  
  246. Citizen.CreateThread(function()
  247. while DoesEntityExist(RCCar.TabletEntity) do
  248. Citizen.Wait(5)
  249.  
  250. if not IsEntityPlayingAnim(PlayerPedId(), "amb@code_human_in_bus_passenger_idles@female@tablet@idle_a", "idle_a", 3) then
  251. TaskPlayAnim(PlayerPedId(), "amb@code_human_in_bus_passenger_idles@female@tablet@idle_a", "idle_a", 3.0, -8, -1, 63, 0, 0, 0, 0 )
  252. end
  253. end
  254.  
  255. ClearPedTasks(PlayerPedId())
  256. end)
  257. else
  258. DeleteEntity(RCCar.TabletEntity)
  259. end
  260. end
  261.  
  262. RCCar.ToggleCamera = function(boolean)
  263. if not Config.Camera then return end
  264.  
  265. if boolean then
  266. if not DoesEntityExist(RCCar.Entity) then return end
  267. if DoesCamExist(RCCar.Camera) then DestroyCam(RCCar.Camera) end
  268.  
  269. RCCar.Camera = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
  270.  
  271. AttachCamToEntity(RCCar.Camera, RCCar.Entity, 0.0, 0.0, 0.4, true)
  272.  
  273. Citizen.CreateThread(function()
  274. while DoesCamExist(RCCar.Camera) do
  275. Citizen.Wait(5)
  276.  
  277. SetCamRot(RCCar.Camera, GetEntityRotation(RCCar.Entity))
  278. end
  279. end)
  280.  
  281. local easeTime = 500 * math.ceil(GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), GetEntityCoords(RCCar.Entity), true) / 10)
  282.  
  283. RenderScriptCams(1, 1, easeTime, 1, 1)
  284.  
  285. Citizen.Wait(easeTime)
  286.  
  287. SetTimecycleModifier("scanline_cam_cheap")
  288. SetTimecycleModifierStrength(2.0)
  289. else
  290. local easeTime = 500 * math.ceil(GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), GetEntityCoords(RCCar.Entity), true) / 10)
  291.  
  292. RenderScriptCams(0, 1, easeTime, 1, 0)
  293.  
  294. Citizen.Wait(easeTime)
  295.  
  296. ClearTimecycleModifier()
  297.  
  298. DestroyCam(RCCar.Camera)
  299. end
  300. end
  301.  
  302. RCCar.LoadModels = function(models)
  303. for modelIndex = 1, #models do
  304. local model = models[modelIndex]
  305.  
  306. if not RCCar.CachedModels then
  307. RCCar.CachedModels = {}
  308. end
  309.  
  310. table.insert(RCCar.CachedModels, model)
  311.  
  312. if IsModelValid(model) then
  313. while not HasModelLoaded(model) do
  314. RequestModel(model)
  315.  
  316. Citizen.Wait(10)
  317. end
  318. else
  319. while not HasAnimDictLoaded(model) do
  320. RequestAnimDict(model)
  321.  
  322. Citizen.Wait(10)
  323. end
  324. end
  325. end
  326. end
  327.  
  328. RCCar.UnloadModels = function()
  329. for modelIndex = 1, #RCCar.CachedModels do
  330. local model = RCCar.CachedModels[modelIndex]
  331.  
  332. if IsModelValid(model) then
  333. SetModelAsNoLongerNeeded(model)
  334. else
  335. RemoveAnimDict(model)
  336. end
  337. end
  338. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement