Einheit-101 Posted October 18, 2010 Share Posted October 18, 2010 Hello Community, i am new in this Forum and i hope that you will help me better then the German Community I have made this script with help from Wiki and codeparts from other resources. But it does not work. The script should check if a player is in a Hydra and play the sound "knall.mp3" if the Hydra is faster than 230 mph. Hope for help. local vehSpeed = getVehicleSpeed() function planeEnter ( theVehicle, seat, jacked ) id = getElementModel ( theVehicle ) if id == 520 then if (speed >= 230) then local sound = playSound(files/knall.mp3) setSoundVolume(sound, 1) end end end addEventHandler ( "onClientVehicleEnter", getRootElement(), planeEnter ) function getVehicleSpeed() if isPedInVehicle(source) then local vx, vy, vz = getElementVelocity(getPedOccupiedVehicle(source)) return math.sqrt(vx^2 + vy^2 + vz^2) * 161 end return 0 end addEventHandler ( "onClientVehicleEnter", getRootElement(), getVehicleSpeed ) mfg Einheit Link to comment
Castillo Posted October 18, 2010 Share Posted October 18, 2010 you are using the event when he enters the hydra, the hydra won't get 230 of speed when you enter on it.. Link to comment
Deltanic Posted October 18, 2010 Share Posted October 18, 2010 (edited) local localPlayer = getLocalPlayer ( ) local isSoundPlayed = false addEventHandler ( "onClientRender", getRootElement ( ), function ( ) if isPedInVehicle ( localPlayer ) and getVehicleType ( getPedOccupiedVehicle ( localPlayer ) ) == "Plane" then if getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 and isSoundPlayed == false then local sound = playSound ( "files/knall.mp3" ) isSoundPlayed = true --You can add here some more stuff if you reached 230 KM/H. else if isSoundPlayed == true then isSoundPlayed = false end end end end ) function getVehicleSpeed ( vehicle ) local vx, vy, vz = getElementVelocity ( vehicle ) return math.sqrt ( vx^2 + vy^2 + vz^2 ) * 161 end I didnt test that, but it should work. Besides that, you script was totally wrong Too much to explain so early in the morning Edited October 18, 2010 by Guest Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 this is not the best way to do that (you can save some cpu adding handler when player enters vehicle and its hydra and removing when player leaves) but should work Link to comment
Einheit-101 Posted October 18, 2010 Author Share Posted October 18, 2010 !!!WOW!!! RESPECT!! You have answered me! So you have done something the German Community has never done! Thanks! I will test it now and try to learn from you, Remi-x. @ varez Maybe its not the best way, but i am lucky if it works anyway and i dont like so much "gefuschels" because it doesnt work if i make it Edit1: What will happen if I delete the"IsSoundPlayed == true" or add a Timer which sets it to false again because i want the sound to play again when your plane is faster than 230 mph again. Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 if plane will slow down isSoundPlayed will be changed back to false - so if plane accelerate again to 230km/h - the sound will be played again. its all ok. or maybe you mean to make sound loopped while speed > 230? then do it in this way: if getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 and isSoundPlayed == false then sound = playSound ( "files/knall.mp3", true ) isSoundPlayed=true else if isElement(sound) then stopSound(sound) isSoundPlayed = false end end Link to comment
Einheit-101 Posted October 18, 2010 Author Share Posted October 18, 2010 EDIT2: It plays the sound strange. If i am faster than 230 mph it make bööööööööööööö[...]öm until i am slower than 230 mph. Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 can you send me the audio file? and explain what exactly do you need? Link to comment
Deltanic Posted October 18, 2010 Share Posted October 18, 2010 (edited) !!!WOW!!! RESPECT!! You have answered me! So you have done something the German Community has never done! Thanks! I will test it now and try to learn from you, Remi-x. Edit1:What will happen if I delete the"IsSoundPlayed == true" or add a Timer which sets it to false again because i want the sound to play again when your plane is faster than 230 mph again. You don't need to do that, because that's already what I've made. Explanation: On the top of the script we got isSoundPlayer = false, this will mean when a player joins, he doesn't have to hear the sound. After flying and get a speed higher than 230 units (Which we check here: getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 ), we are looking to that boolean again if it's still false: if (...) isSoundPlayed == false then If it's still false, the script will be passed. There will the sound be played, and the boolean will be set to true, which means we played the sound. isSoundPlayed = true If the player is flying less than 230 units, we would pass the "else" statement, and that will check if the boolean we used is set to true. If so, we set it to false. And since this event is triggered everytime your game renders ( Amount of renders in 1 second = FPS, that may sound familiar ), we are checking your speed also enough times. EDIT2: It plays the sound strange. If i am faster than 230 mph it make bööööööööööööö[...]öm until i am slower than 230 mph. You should do what varez said, stopping the sound. I never worked with sounds, so that's the reason why I forgot that to place in the script I've made And I'm bored at the moment, so here it is all ready: local localPlayer = getLocalPlayer ( ) local isSoundPlayed = false local knallSound = nil --nil means literally "nothing", or "empty". addEventHandler ( "onClientRender", getRootElement ( ), function ( ) if isPedInVehicle ( localPlayer ) and getVehicleType ( getPedOccupiedVehicle ( localPlayer ) ) == "Plane" then if getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 and isSoundPlayed == false then knallSound = playSound ( "files/knall.mp3" ) isSoundPlayed = true --You can add here some more stuff if you reached 230 KM/H. else if isSoundPlayed == true and isElement ( knallSound ) then isSoundPlayed = false stopSound ( knallSound ) end end end end ) function getVehicleSpeed ( vehicle ) local vx, vy, vz = getElementVelocity ( vehicle ) return math.sqrt ( vx^2 + vy^2 + vz^2 ) * 161 end Should really give no problems. @ varez below: solved. Edited October 18, 2010 by Guest Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 stopSound( knallSound ) you cant do that if you created local on line 10 Link to comment
Einheit-101 Posted October 18, 2010 Author Share Posted October 18, 2010 Yes. it says ERROR in uberschall/ psound.lua: CRC Mismatch @varez how can i send you the resource? I can describe what i want: A sonic boom! The sound file/knall.mp3 is a self-made BOOOOM! Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 sendspace.com mediafire.com zip it and send Link to comment
Einheit-101 Posted October 18, 2010 Author Share Posted October 18, 2010 http://www.sendspace.com/file/whumq3 Bidde! Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 tested, working.. hydra is a bit noisy vehicle so its hard to hear that sound, but script is working ;p local pl = getLocalPlayer() local mycar = nil local t = nil addEventHandler("onClientPlayerVehicleEnter",pl, function(veh) if getElementModel(veh) == 520 then mycar = veh if (not isTimer(t)) then t = setTimer(check, 100, 0) end end end) addEventHandler("onClientPlayerVehicleExit",pl, function() mycar = nil if (isTimer(t)) then killTimer(t) end end) local above = false function check() local speed = getVehicleSpeed(mycar) if (not above and speed>225) then --outputChatBox("b") above = true playSound ("file/knall.mp3") elseif (above and speed<225) then above = false end end function getVehicleSpeed ( vehicle ) local vx, vy, vz = getElementVelocity ( vehicle ) return math.sqrt ( vx^2 + vy^2 + vz^2 ) * 161 end Link to comment
Einheit-101 Posted October 29, 2010 Author Share Posted October 29, 2010 Thanx varez! It works! I will upload this resource to community.multitheftauto.com with credits to you! I improved the sound. ******TOPIC CAN GET CLOSED****** Link to comment
Recommended Posts