ScriptingExamples/VehicleBounceAndFixer: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Latest revision as of 07:56, 16 August 2018
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
Lua, Client-Side, GTAC versions 1.0.72 and newer:
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)