swag_k_dog Posted October 25, 2017 Share Posted October 25, 2017 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 Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 @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) 1 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 Sorry man, I was pissed because I couldn't script it by myself. I actually said "THANK YAA" in real life, wish you could hear it tho thank you again @IIYAMA 1 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 @IIYAMA how do you find the coordonates of the exhaust? like local x,y,z = getElementPosition(vehicle) but instead of vehicle, I want it to find the exhaust values. help :)? Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 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 1 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 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 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 @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 Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 (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 October 25, 2017 by IIYAMA 1 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 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. Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 DEBUG< I didn't add those lines for nothing. 1 Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 (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 October 25, 2017 by IIYAMA 1 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 @IIYAMA https://imgur.com/a/RBDrz here is the issue, the fire does not rotate and not placed on the exhaust Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 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 1 Link to comment
swag_k_dog Posted October 25, 2017 Author Share Posted October 25, 2017 @IIYAMA still doesnt work. allright :O it, is it possible to draw a png image at the back of the car? if yes, how? Link to comment
Moderators IIYAMA Posted October 25, 2017 Moderators Share Posted October 25, 2017 With this: https://wiki.multitheftauto.com/wiki/DxDrawMaterialLine3D Read the requirements, syntax and example very carefully. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now