SHARE
    TWEET
    supinus

    convoy

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

    AltStyle によって変換されたページ (->オリジナル) /