ScriptingExamples/VehicleBounceAndFixer: Difference between revisions

From GTA Connected
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
Line 5: Line 5:


== Code ==
== Code ==
'''Lua, Client-Side, GTAC versions 1.0.72 and newer:'''
{{LuaCode|caption=Lua, Client-Side, GTAC versions 1.0.72 and newer:|1=function polarToCartesian(pos, rad, radius)
{{LuaCode|1=function polarToCartesian(pos, rad, radius)
--rad = rad + math.pi / 2
--rad = rad + math.pi / 2
pos.x = pos.x + radius * math.cos(rad)
pos.x = pos.x + radius * math.cos(rad)

Latest revision as of 10:58, 1 September 2025

Description

This code fixes the local player's vehicle and also bounces the front of the vehicle up, every 10th of a second, if the player has typed /bounce.
Typing /bounce will toggle vehicle bouncing on or off for the local player.

Code

function polarToCartesian(pos, rad, radius) --rad = rad + math.pi / 2 pos.x = pos.x + radius * math.cos(rad) pos.y = pos.y + radius * math.sin(rad) return pos end

addCommandHandler('bounce', function(cmd,args) if bounceTimer then clearInterval(bounceTimer) bounceTimer = nil boundTimer2Used = nil else local function boundCallback() if not localPlayer.vehicle then return end localPlayer.vehicle:fix() local t = localPlayer.vehicle.turnVelocity if not localPlayer.vehicle.flipped and t.x >= -0.03 and t.x <= 0.03 and t.y >= -0.03 and t.y <= 0.03 then local y = tonumber(args) or math.random(26, 32)/100.0 localPlayer.vehicle.turnVelocity = polarToCartesian(t, localPlayer.vehicle.heading, y) boundTimer2Used = nil clearInterval(bounceTimer) bounceTimer = setInterval(boundCallback, 1200) elseif not boundTimer2Used then boundTimer2Used = true clearInterval(bounceTimer) bounceTimer = setInterval(boundCallback, 500) end end bounceTimer = setInterval(boundCallback, 1200) end end)