supinus

convoy

Apr 6th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | Gaming | 0 0
  1. local player = ac.getCarState(1)
  2. local collisionTimeout = 0
  3. local cutTimeout = 0
  4. local minCollisionHeight = 0.27
  5. local toTeleportMaxSpeedThreshold = 500
  6. local isCarLockedForPlayer = false
  7.  
  8. local pitsCornerA = { x = 549.23, z = 1502.58 }
  9. local pitsCornerB = { x = 696.02, z = 1346.43 }
  10. local pitsMinX, pitsMaxX = math.min(pitsCornerA.x, pitsCornerB.x), math.max(pitsCornerA.x, pitsCornerB.x)
  11. local pitsMinZ, pitsMaxZ = math.min(pitsCornerA.z, pitsCornerB.z), math.max(pitsCornerA.z, pitsCornerB.z)
  12.  
  13. local function isWithinPits(currentPosition)
  14. return (currentPosition.x >= pitsMinX and currentPosition.x <= pitsMaxX) and
  15. (currentPosition.z >= pitsMinZ and currentPosition.z <= pitsMaxZ)
  16. end
  17.  
  18. local onCarLockedReceive = ac.OnlineEvent({
  19. ac.StructItem.key("lightspeedPointsCarLockedReceive"),
  20. isLocked = ac.StructItem.uint16(),
  21. }, function(sender, message)
  22. if sender ~= nil then return end
  23.  
  24. ac.debug("IsLocked", message.isLocked)
  25. if message.isLocked == 1 then
  26. isCarLockedForPlayer = true
  27. end
  28. end)
  29.  
  30. local onCollision = ac.OnlineEvent({
  31. ac.StructItem.key("lightspeedPointsEnvironmentCollision"),
  32. Speed = ac.StructItem.int32()
  33. })
  34. local onCut = ac.OnlineEvent({
  35. ac.StructItem.key("lightspeedPointsLapCut"),
  36. Speed = ac.StructItem.int32()
  37. })
  38. local onPitLeave = ac.OnlineEvent({
  39. ac.StructItem.key("lightspeedPointsPitLeave"),
  40. id = ac.StructItem.int32()
  41. })
  42. local onPitReEntry = ac.OnlineEvent({
  43. ac.StructItem.key("lightspeedPointsPitReEntry"),
  44. id = ac.StructItem.int32()
  45. })
  46. local onPitTeleport = ac.OnlineEvent({
  47. ac.StructItem.key("lightspeedPointsPitTeleport"),
  48. id = ac.StructItem.int32()
  49. })
  50. local onLapStart = ac.OnlineEvent({
  51. ac.StructItem.key("lightspeedPointsLapStart"),
  52. id = ac.StructItem.int32()
  53. })
  54. local onConvoyAlmostFinish = ac.OnlineEvent({
  55. ac.StructItem.key("lightspeedPointsConvoyAlmostFinish"),
  56. id = ac.StructItem.int32()
  57. })
  58. local onConvoyAtNorthTurn = ac.OnlineEvent({
  59. ac.StructItem.key("lightspeedPointsConvoyAtNorthTurn"),
  60. id = ac.StructItem.int32()
  61. })
  62. local onConvoyAtAirfield = ac.OnlineEvent({
  63. ac.StructItem.key("lightspeedPointsConvoyAtAirfield"),
  64. id = ac.StructItem.int32()
  65. })
  66. local onConvoyAtFoxhole = ac.OnlineEvent({
  67. ac.StructItem.key("lightspeedPointsConvoyAtFoxhole"),
  68. id = ac.StructItem.int32()
  69. })
  70. local onConvoyAtKallenForest = ac.OnlineEvent({
  71. ac.StructItem.key("lightspeedPointsConvoyAtKallenForest"),
  72. id = ac.StructItem.int32()
  73. })
  74. local onConvoyAtWaterMill = ac.OnlineEvent({
  75. ac.StructItem.key("lightspeedPointsConvoyAtWaterMill"),
  76. id = ac.StructItem.int32()
  77. })
  78. local onConvoyAtLittleValley = ac.OnlineEvent({
  79. ac.StructItem.key("lightspeedPointsConvoyAtLittleValley"),
  80. id = ac.StructItem.int32()
  81. })
  82. local onConvoyAtFirstCarousel = ac.OnlineEvent({
  83. ac.StructItem.key("lightspeedPointsConvoyAtFirstCarousel"),
  84. id = ac.StructItem.int32()
  85. })
  86. local onConvoyAtBrunnchen = ac.OnlineEvent({
  87. ac.StructItem.key("lightspeedPointsConvoyAtBrunnchen"),
  88. id = ac.StructItem.int32()
  89. })
  90. local onConvoyAtSecondCarousel = ac.OnlineEvent({
  91. ac.StructItem.key("lightspeedPointsConvoyAtSecondCarousel"),
  92. id = ac.StructItem.int32()
  93. })
  94.  
  95. local Checkpoint = class("Checkpoint")
  96. function Checkpoint:initialize(position, forward, radius)
  97. self.position = position
  98. self.normal = forward:normalize()
  99. self.radius = radius
  100. self.d = self.normal:dot(position)
  101. end
  102.  
  103. function Checkpoint:side(position)
  104. return self.normal:dot(position) - self.d > 0
  105. end
  106.  
  107. function Checkpoint:passed(previous, current)
  108. local previousSide = self:side(previous)
  109. local currentSide = self:side(current)
  110. return current:closerToThan(self.position, self.radius) and previousSide ~= currentSide and previousSide == false
  111. end
  112.  
  113. local pitExitCheckpoint = Checkpoint(vec3(585.79, 91.35, 1475.79), vec3(0, 0, 1), 12)
  114. local pitReEntryCheckpoint = Checkpoint(vec3(585.79, 91.35, 1475.79), vec3(0, 0, -1), 12)
  115. local lapStartCheckpoint = Checkpoint(vec3(170.46, 105.64, 1737.48), vec3(0, 0, 1), 20)
  116. local convoyNearFinishCheckpoint = Checkpoint(vec3(1986.75, 74.97, 374.93), vec3(1, 0, 0), 20)
  117. local convoyNorthTurnCheckpoint = Checkpoint(vec3(-625.59, 146.59, 2240.01), vec3(-1, 0, 0), 25) -- 2km - North Turn
  118. local convoyAirfieldCheckpoint = Checkpoint(vec3(-2177.44, 93.59, 1540.91), vec3(0, 0, -1), 20) -- 4km - Airfield
  119. local convoyFoxholeCheckpoint = Checkpoint(vec3(-2526.74, 37.83, -16.62), vec3(0, 0, -1), 20) -- 6km - Foxhole
  120. local convoyKallenForestCheckpoint = Checkpoint(vec3(-1589.83, -31.08, -1700.77), vec3(-1, 0, 0), 20) -- 8km - Kallen Forest
  121. local convoyWaterMillCheckpoint = Checkpoint(vec3(-110.40, -124.35, -2249.71), vec3(0, 0, -1), 20) -- 10km - Water Mill
  122. local convoyLittleValleyCheckpoint = Checkpoint(vec3(1196.56, -44.42, -1644.69), vec3(1, 0, 0), 20) -- 12km - Little Valley
  123. local convoyFirstCarouselCheckpoint = Checkpoint(vec3(2099.80, 75.73, -1407.64), vec3(0, 0, 1), 20) -- 14km - First Carousel
  124. local convoyBrunnchenCheckpoint = Checkpoint(vec3(3439.53, 67.56, -1219.93), vec3(1, 0, 0), 20) -- 16km - Brunnchen a.k.a Youtube Corner
  125. local convoySecondCarouselCheckpoint = Checkpoint(vec3(1721.88, 68.38, 178.33), vec3(0, 0, 1), 20) -- 19km - Second Carousel
  126.  
  127. local lastCarPositions = {}
  128.  
  129. function DoUpdate(dt)
  130. local carIndex = 0
  131. local car = ac.getCar(carIndex)
  132. local currentPosition = car.position
  133.  
  134. if isCarLockedForPlayer then
  135. physics.setCarNoInput(true)
  136. physics.setCarFuel(0, 0)
  137. physics.forceUserBrakesFor(60, 1)
  138. physics.forceUserClutchFor(60, 1)
  139. physics.engageGear(0, 1)
  140. return
  141. end
  142.  
  143. lastCarPositions[carIndex] = lastCarPositions[carIndex] or currentPosition:clone()
  144. local lastPosition = lastCarPositions[carIndex]
  145. local speed = ((currentPosition - lastPosition):length() / dt)
  146. if speed > toTeleportMaxSpeedThreshold and (isWithinPits(currentPosition)) then
  147. onPitTeleport { id = carIndex }
  148. end
  149.  
  150. local checkpoints = {
  151. { checkpoint = pitExitCheckpoint, event = onPitLeave },
  152. { checkpoint = pitReEntryCheckpoint, event = onPitReEntry },
  153. { checkpoint = lapStartCheckpoint, event = onLapStart },
  154. { checkpoint = convoyNearFinishCheckpoint, event = onConvoyAlmostFinish },
  155. { checkpoint = convoyNorthTurnCheckpoint, event = onConvoyAtNorthTurn },
  156. { checkpoint = convoyAirfieldCheckpoint, event = onConvoyAtAirfield },
  157. { checkpoint = convoyFoxholeCheckpoint, event = onConvoyAtFoxhole },
  158. { checkpoint = convoyKallenForestCheckpoint, event = onConvoyAtKallenForest },
  159. { checkpoint = convoyWaterMillCheckpoint, event = onConvoyAtWaterMill },
  160. { checkpoint = convoyLittleValleyCheckpoint, event = onConvoyAtLittleValley },
  161. { checkpoint = convoyFirstCarouselCheckpoint, event = onConvoyAtFirstCarousel },
  162. { checkpoint = convoyBrunnchenCheckpoint, event = onConvoyAtBrunnchen },
  163. { checkpoint = convoySecondCarouselCheckpoint, event = onConvoyAtSecondCarousel }
  164. }
  165. for _, item in ipairs(checkpoints) do
  166. if item.checkpoint:passed(lastPosition, currentPosition) then
  167. item.event { id = carIndex }
  168. end
  169. end
  170.  
  171. lastCarPositions[carIndex] = currentPosition:clone()
  172. end
  173.  
  174. function script.update(dt)
  175. if collisionTimeout > 0 then
  176. collisionTimeout = collisionTimeout - dt
  177. elseif player.speedKmh > 0 and player.collisionPosition.y > minCollisionHeight then
  178. if player.collidedWith >= 0 then
  179. onCollision { Speed = player.speedKmh }
  180. collisionTimeout = 1
  181. end
  182. end
  183.  
  184. if cutTimeout > 0 then
  185. cutTimeout = cutTimeout - dt
  186. elseif player.speedKmh > 1 and player.wheelsOutside > 3 then
  187. onCut { Speed = player.speedKmh }
  188. cutTimeout = 1
  189. end
  190.  
  191. DoUpdate(dt)
  192. end
  193.  
Tags: convoy
Add Comment
Please, Sign In to add comment