Search the Community
Showing results for tags 'onvehicleenter'.
-
So, i have a problem, im making a script for replacing sounds of cars, the first car i enter works nice, when i change engine state the sound goes off and on but when left a car on with the replaced sound and try to enter to another car and start the engine, it plays the sound on the last car, so if you do this with more cars, the first car plays a lot of sounds. Sorry my english is a bit :~ty cause im spanish. Heres some lua code, server side local wayfarerenginestate = 0 local timerwayfarersound = {} function OnEnterVehicle ( thePlayer, seat, jacked ) if getElementModel( source ) == 586 then local texture2 local sourcetxt = tostring(source) if string.match(sourcetxt, " ") then local extracted = sourcetxt:match("% .+") texture2 = extracted:gsub("% ","") end outputChatBox( texture2 ) if getElementData( source, "timer") == false then outputChatBox ( "Timer started", thePlayer ) timerwayfarersound[texture2] = setTimer( checkwayfarerenginestate, 500, 0, source, texture2 ) setElementData( source, "timer", true) end end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnterVehicle ) function checkwayfarerenginestate (source, texture2) if getVehicleEngineState( source ) == true and wayfarerenginestate == 0 then triggerClientEvent( "wayfarersoundcevent", resourceRoot, source, texture2) wayfarerenginestate = 1 elseif getVehicleEngineState( source ) == false and wayfarerenginestate == 1 then triggerClientEvent( "wayfarersounddcevent", resourceRoot, texture2) wayfarerenginestate = 0 end end Client side: local wayfarerenginestate = 0 local wayfarersound = {} function wayfarersoundf ( veh, texture2 ) local x, y, z = getElementPosition( veh ) wayfarersound[texture2] = playSound3D( "sounds/wayfarersound.mp3", x, y, z, true ) setSoundVolume( wayfarersound[texture2], 0.45 ) setSoundMaxDistance( wayfarersound[texture2], 100 ) attachElements( wayfarersound[texture2], veh) end addEvent( "wayfarersoundcevent", true ) addEventHandler( "wayfarersoundcevent", resourceRoot, wayfarersoundf ) function wayfarersounddf (texture2) destroyElement( wayfarersound[texture2] ) end addEvent( "wayfarersounddcevent", true ) addEventHandler( "wayfarersounddcevent", resourceRoot, wayfarersounddf ) What is the problem? Which 1 vehicle it works nice but, which more than 1 it bugs