Sign in to follow this  
ByCash

[HELP] Changing Wheel Size

Recommended Posts

Spoiler

VQo70y.png

Hello dear friends, first of all, I am writing this text using translate. I apologize to everyone for my bad English. Forgive me if I put the issue in the wrong section. - I want to enlarge the wheels of the vehicles and make camber adjustments and I came across this content in the forum https://forum.mtasa.com/topic/92222-custom-wheel/ but the system in this content applies only to the front wheels and it goes underground when the wheel grows and how I will fix these errors from you I want your help, thank you very much in advance. :)

Client-Side

Spoiler

-- Table containing vehicles that have custom wheels
local createdCustomWheels = { }

--[[ /customwheels [ number tilt, number scale ]
	 Adds custom wheels to your currently occupied vehicle and optionally applies a tilt angle and wheel scale. ]]
addCommandHandler( 'customwheels',
	function( _, tilt, scale )
		-- Let's get our vehicle
		local vehicle = getPedOccupiedVehicle( localPlayer )

		-- Oh, we have a vehicle!
		if ( vehicle ) then
			-- Let's give it a wheel now
			addVehicleCustomWheel( vehicle, 1075, tilt, scale )
		end
	end
)

-- Let's bind that command to F2 as requested by OP
bindKey( 'f2', 'down', 'customwheels' )

--[[ void addVehicleCustomWheel ( vehicle vehicle, number model [ , number tilt, number scale ] )
	 Adds custom wheels to the vehicle. ]]
function addVehicleCustomWheel( vehicle, model, tilt, scale )
	-- If we've given the object's model number
	if ( tonumber( model ) ) then
		-- Let's delete any old ones
		for _, wheel in pairs( createdCustomWheels[ vehicle ] or { } ) do
			destroyElement( wheel.object )
		end

		-- And let's nil it to be clear
		createdCustomWheels[ vehicle ] = nil

		-- Let's set some component names we want to customize
		local wheels = { 'wheel_lf_dummy', 'wheel_rf_dummy' }

		-- Let's iterate through those components
		for i = 1, #wheels do
			-- Let's hide the existing component
			setVehicleComponentVisible( vehicle, wheels[ i ], false )

			-- Initialize our wheel table
			local wheel = {
				tilt = tonumber( tilt ) or 0, -- We'll default a non-number tilt angle to 0
				name = wheels[ i ], -- Let's store the component name
				object = createObject( model, Vector3( ) ) -- Let's make a new wheel object
			}

			-- Let's set the vehicle as the wheel object's parent
			setElementParent( wheel.object, vehicle )

			-- Let's make sure the wheel is not colliding with the vehicle
			setElementCollidableWith( wheel.object, vehicle, false )

			-- Let's change the scale
			setObjectScale( wheel.object, tonumber( scale ) or 0.7 )

			-- Let's update that original table
			wheels[ i ] = wheel
		end

		-- And let's store all of those wheels now
		createdCustomWheels[ vehicle ] = wheels
	end
end

--[[ void calculateVehicleWheelRotation ( vehicle vehicle, table wheel )
	 Let's calculate the wheel rotation for given wheel(s). ]]
function calculateVehicleWheelRotation( vehicle, wheel )
	-- If we have many wheels in the given argument
	if ( type( wheel ) == 'table' ) and ( #wheel > 0 ) then
		-- Let's iterate through them all
		for i = 1, #wheel do
			-- Let's call the method alone with just the iterator
			calculateVehicleWheelRotation( vehicle, wheel[ i ] )
		end

		-- Let's stop here now
		return
	end

	-- If we have an object
	if ( wheel.object ) then
		-- Let's get the rotation vector of the original component
		local rotation = Vector3( getVehicleComponentRotation( vehicle, wheel.name, 'world' ) )

		-- Let's set our tilt angle
		rotation.y = wheel.tilt

		-- Let's make sure the wheel is at the original component's position
		setElementPosition( wheel.object, Vector3( getVehicleComponentPosition( vehicle, wheel.name, 'world' ) ) )

		-- Let's finally set the rotation (in ZYX order, important!)
		setElementRotation( wheel.object, rotation, "ZYX" )
	end
end

-- Render-time!
addEventHandler( 'onClientPreRender', root,
	function( )
		-- Let's iterate through all the vehicles
		for vehicle, wheels in pairs( createdCustomWheels ) do
			-- If we have a vehicle, it's streamed in and it has wheels
			if ( vehicle ) and ( isElementStreamedIn( vehicle ) ) and ( #wheels > 0 ) then
				-- Let's calculate wheel rotation!
				calculateVehicleWheelRotation( vehicle, wheels )
			end
		end
	end
)

 

 


Share this post


Link to post

addCustomWheel(vehicle, 1075, "front")

Turkish:

burdaki front ön demek back dersen arkadaki tekerleri kastedersin

English:

If you say front here means front back, you mean the rear wheels

English text is translate.Sorry if I'm wrong.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.