Jump to content

no sound when driving


swag_k_dog

Recommended Posts

Posted
local gVehicle = getPedOccupiedVehicle(localPlayer) 
local lastGear
addEventHandler("onClientRender", root,
function()
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if vehicle then
		local gear = getVehicleCurrentGear(vehicle)
		if gear ~= lastGear then
			triggerEvent("onClientVehicleGearChange", vehicle, gear)
			lastGear = gear
			            local x,y,z = getElementPosition(gVehicle) 
						local sound = playSound3D("untitled.mp3", x, y, z, true)
						setSoundVolume(sound, 1)
						setSoundMaxDistance(sound, 100)
						outputChatBox("test")
						

		end
	end
end)

-- prevent the trigger to activate after entering a vehicle.
addEventHandler("onClientPlayerVehicleEnter", localPlayer,
function (vehicle)
	lastGear = getVehicleCurrentGear(vehicle)
end)

The "test" text works but the playsound3D does not  work, pls help! it should play everytime the car changes gears at the car's position

the car must have a player inside

  • Moderators
Posted

@swag_k_dog

Why creating a new topic for only this?

And you didn't even say thank you for my help, are you that inhuman or what?

 

    local lastGear
    addEventHandler("onClientRender", root,
    function()
    	local vehicle = getPedOccupiedVehicle(localPlayer)
    	if vehicle then
    		local gear = getVehicleCurrentGear(vehicle)
    		if gear ~= lastGear then
    			triggerEvent("onClientVehicleGearChange", vehicle, gear)
    			lastGear = gear
				local x,y,z = getElementPosition(vehicle) 
				local sound = playSound3D("untitled.mp3", x, y, z, true)
				setSoundVolume(sound, 1)
				setSoundMaxDistance(sound, 100)
				outputChatBox("test")
    		end
    	end
    end)

    -- prevent the trigger to activate after entering a vehicle.
    addEventHandler("onClientPlayerVehicleEnter", localPlayer,
    function (vehicle)
    	lastGear = getVehicleCurrentGear(vehicle)
    end)

 

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

hmm

local x,y,z
if getVehicleComponents(vehicle).exhaust_ok then
	x,y,z = getVehicleComponentPosition ( vehicle, "exhaust_ok", "world" )
	iprint("found exhaust_ok component on vehicle")-- debug
else
	x,y,z = getElementPosition(vehicle)
	iprint("can't find exhaust_ok component on vehicle")-- debug
end

 

OR (get the back of the vehicle)

 

--local x,y,z = getElementPosition(vehicle)

local x0, y0, z0, x1, y1, z1 = getElementBoundingBox ( vehicle )

-- test which one is ~ correct.
x,y,z = getPositionFromElementOffset(vehicle, (x0 + x1) / 2, y0, z0)
-- or
x,y,z = getPositionFromElementOffset(vehicle, (x0 + x1) / 2, y1, z1)
-- or
x,y,z = getPositionFromElementOffset(vehicle, x0, (y0 + y1) / 2, z0)
-- or
x,y,z = getPositionFromElementOffset(vehicle, x1, (y0 + y1) / 2, z1)

 

 

function getPositionFromElementOffset(element,offX,offY,offZ)
    local m = getElementMatrix ( element )  -- Get the matrix
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
    return x, y, z                               -- Return the transformed point
end

 

 

 

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
4 minutes ago, IIYAMA said:

hmm


local x,y,z
if getVehicleComponents(vehicle).exhaust_ok then
	x,y,z = getVehicleComponentPosition ( vehicle, "exhaust_ok", "world" )
	iprint("found exhaust_ok component on vehicle")-- debug
else
	x,y,z = getElementPosition(vehicle)
	iprint("can't find exhaust_ok component on vehicle")-- debug
end

 

OR (get the back of the vehicle)

 


--local x,y,z = getElementPosition(vehicle)

local x0, y0, z0, x1, y1, z1 = getElementBoundingBox ( vehicle )

-- test which one is ~ correct.
x,y,z = getPositionFromElementOffset(vehicle, (x0 + x1) / 2, y0, z0)
-- or
x,y,z = getPositionFromElementOffset(vehicle, (x0 + x1) / 2, y1, z1)
-- or
x,y,z = getPositionFromElementOffset(vehicle, x0, (y0 + y1) / 2, z0)
-- or
x,y,z = getPositionFromElementOffset(vehicle, x1, (y0 + y1) / 2, z1)

 

 


function getPositionFromElementOffset(element,offX,offY,offZ)
    local m = getElementMatrix ( element )  -- Get the matrix
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
    return x, y, z                               -- Return the transformed point
end

 

 

 

 

thank you, I'll try it right now

Posted

@IIYAMA I tried those and still dont know where to put the code or how to make it work.

basically I need to shoot fire at my exhaust.

				local x,y,z = getElementPosition(vehicle) 
				   fxAddGunshot(x, y+0.5, z+1, -10, 0, 0, true)
				   fxAddSparks(x, y+0.5, z+1, -10, 0, 0)
				   fxAddBulletImpact(x, y+0.5, z+1, -10, 0, 0, 2, 15, 5)
				   fxAddTankFire(x, y, z, -10, 0, 0)

I made this but, the fire appears above or inside the car, and always faces one direction. the fire does not rotate when the car does. help? sorry i am bad at scripting

  • Moderators
Posted (edited)
local lastGear
addEventHandler("onClientRender", root,
function()
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if vehicle then
		local gear = getVehicleCurrentGear(vehicle)
		if gear ~= lastGear then
			iprint("gear isn't the same as last gear")
			
			triggerEvent("onClientVehicleGearChange", vehicle, gear)
			lastGear = gear
			
			local x,y,z
			if getVehicleComponents(vehicle).exhaust_ok then
				x,y,z = getVehicleComponentPosition ( vehicle, "exhaust_ok", "world" )
				iprint("found exhaust_ok component on vehicle")-- debug
			else
				x,y,z = getElementPosition(vehicle)
				iprint("can't find exhaust_ok component on vehicle")-- debug
			end
			
			fxAddGunshot(x, y+0.5, z+1, -10, 0, 0, true)
			fxAddSparks(x, y+0.5, z+1, -10, 0, 0)
			fxAddBulletImpact(x, y+0.5, z+1, -10, 0, 0, 2, 15, 5)
			fxAddTankFire(x, y, z, -10, 0, 0)
			
			local sound = playSound3D("untitled.mp3", x, y, z, true)
			setSoundVolume(sound, 1)
			setSoundMaxDistance(sound, 100)
			
		end
	end
end)

-- prevent the trigger to activate after entering a vehicle.
addEventHandler("onClientPlayerVehicleEnter", localPlayer,
function (vehicle)
	lastGear = getVehicleCurrentGear(vehicle)
end)

Untested, if it doesn't work, please debug properly.

You could have guessed it... As it is just a language like English, with different rules.

 

 

 

Edited by IIYAMA

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
6 minutes ago, IIYAMA said:

local lastGear
addEventHandler("onClientRender", root,
function()
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if vehicle then
		local gear = getVehicleCurrentGear(vehicle)
		if gear ~= lastGear then
			iprint("gear isn't the same as last gear")
			
			triggerEvent("onClientVehicleGearChange", vehicle, gear)
			lastGear = gear
			
			local x,y,z
			if getVehicleComponents(vehicle).exhaust_ok then
				x,y,z = getVehicleComponentPosition ( vehicle, "exhaust_ok", "world" )
				iprint("found exhaust_ok component on vehicle")-- debug
			else
				x,y,z = getElementPosition(vehicle)
				iprint("can't find exhaust_ok component on vehicle")-- debug
			end
			
			fxAddGunshot(x, y+0.5, z+1, -10, 0, 0, true)
			fxAddSparks(x, y+0.5, z+1, -10, 0, 0)
			fxAddBulletImpact(x, y+0.5, z+1, -10, 0, 0, 2, 15, 5)
			fxAddTankFire(x, y, z, -10, 0, 0)
			
			local sound = playSound3D("untitled.mp3", x, y, z, true)
			setSoundVolume(sound, 1)
			setSoundMaxDistance(sound, 100)
			
		end
	end
end)

-- prevent the trigger to activate after entering a vehicle.
addEventHandler("onClientPlayerVehicleEnter", localPlayer,
function (vehicle)
	lastGear = getVehicleCurrentGear(vehicle)
end)

Untested, if it doesn't work, please debug properly.

You could have guessed it... As it is just a language like English, with different rules.

 

 

 

well thank you but it works exactly as before.

the fire particles are above the car and they do not rotate.

  • Moderators
Posted

DEBUG< I didn't add those lines for nothing.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted (edited)

So it is actually working.

fxAddGunshot(x, y, z, -10, 0, 0, true)
fxAddSparks(x, y, z, -10, 0, 0)
fxAddBulletImpact(x, y, z, -10, 0, 0, 2, 15, 5)
fxAddTankFire(x, y, z, -10, 0, 0)

Set all offsets to 0. And adjust them little by little.

1 unit is A LOT. (1.5/2 units is ~ the height of a ped)

So use small steps like: 0.1 or 0.05

 

Rotating particles, I am not going to do that for you, because it takes me too much time for me to get it right. Sorry.

Edited by IIYAMA

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

Hmm strange, should be placed correctly according to wiki.

 

And if you replace the getVehicleComponentPosition line with these two lines:

local offsetX, offsetY, offsetZ = getVehicleComponentPosition ( vehicle, "exhaust_ok", "root" )
x,y,z = getPositionFromElementOffset(vehicle, offsetX, offsetY, offsetZ)

 

And add this at the bottom


    function getPositionFromElementOffset(element,offX,offY,offZ)
        local m = getElementMatrix ( element )  -- Get the matrix
        local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform
        local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
        local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
        return x, y, z                               -- Return the transformed point
    end

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

With this:

https://wiki.multitheftauto.com/wiki/DxDrawMaterialLine3D

 

Read the requirements, syntax and example very carefully.

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...