Strike27208 Posted November 21, 2016 Share Posted November 21, 2016 Hey i make this script when you have low fuel to start a sound alarm but i don't know how to make to check this when you are in helicopter : function helicopter () if ( isPedInVehicle ( localPlayer ) == false ) then return false end ---------------------------Parts----------------------- local veh = getPedOccupiedVehicle(getLocalPlayer()); local maxfuel = ---myStuff--; local fuel = ---myStuff----------; if (isElement(veh) and getElementModel(veh) == 487 or 497 or 417 or 563 ) then if fuel <= 5 then sound = playSound("sound/beep.mp3" , true) setSoundVolume(sound, 0.2) outputChatBox ( "#FF0000Alarm ! #FFFFFFLow fuel ! Press ' Z ' to stop the alarm.", 255, 255, 255, true ) bindKey ( "Z", "down", stopMySoundV ) addEventHandler ( "onClientVehicleExit", root, stopMySound ) killTimer(tm) end end end tm = setTimer (helicopter , 5000 , 0) addEventHandler ( "onClientResourceStart", root, helicopter ) function stopMySound() stopSound ( sound ) unbindKey ( "Z", "down", stopMySoundV ) end function stopMySoundV() stopSound ( sound ) removeEventHandler( "onClientVehicleExit", root, stopMySound ) end This all work , but when he kill the timer i can't use ' resetTimer ' because he killed it , so how to make to reset that timer when he leave the vehicle ? this work first time , but when i enter again in vehicle he wont verify again. Link to comment
iPrestege Posted November 22, 2016 Share Posted November 22, 2016 You can use isTimer to check if the timer exists or no and set the timer again something like this : if not isTimer ( aMyTimer ) then aMyTimer = setTimer( function theFunction, int timeInterval, int timesToExecute, [ var arguments... ] ) end 1 Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 (edited) Thanks man it's work , now i made a sistem like only driver to hear the sound , this work but when i want exit from vehicle the sound are not stopping and i get an warnging in debugscript like this : My code : function stopMySoundV() local veh = getPedOccupiedVehicle(getLocalPlayer()) local driver = getVehicleOccupant(veh, 0) local p1 = getVehicleOccupant(veh, 1) local p2 = getVehicleOccupant(veh, 2) local p3 = getVehicleOccupant(veh, 3) if p1 or p2 or p3 then return false end if driver then stopSound (sound) unbindKey ( "Z", "down", stopMySoundB ) removeEventHandler( "onClientVehicleExit", root, stopMySoundV ) if not isTimer ( Check ) then Check = setTimer( helicopter, 5000,0) end end end Edited November 22, 2016 by Strike27208 Link to comment
iPrestege Posted November 22, 2016 Share Posted November 22, 2016 @Strike27208 You can do some check 'if' to make sure that's the thing you want to get exists and no errors for that. You can try to do this : if veh then driver = getVehicleController( vehicle theVehicle ); if driver then -- stuff's Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 (edited) Hmm i tried but still not work function stopMySoundV() local veh = getPedOccupiedVehicle(getLocalPlayer()) if veh then local driver = getVehicleController(veh , getLocalPlayer()) if driver then local drivers = getVehicleOccupant(veh, 0) local p1 = getVehicleOccupant(veh, 1) local p2 = getVehicleOccupant(veh, 2) local p3 = getVehicleOccupant(veh, 3) if p1 or p2 or p3 then return false end if drivers then stopSound (sound) unbindKey ( "Z", "down", stopMySoundB ) removeEventHandler( "onClientVehicleExit", root, stopMySoundV ) if not isTimer ( aMyTimer ) then aMyTimer = setTimer( helicopter, 5000,0) end end end end end Tell me if i am wrong. Edited November 22, 2016 by Strike27208 Link to comment
iPrestege Posted November 22, 2016 Share Posted November 22, 2016 (edited) Try this and make sure to not use 'local' when making the sound played. function stopMySoundV ( ) local veh = getPedOccupiedVehicle( getLocalPlayer ( ) ) if veh then local driver = getVehicleController ( veh ) if driver then if sound then stopSound ( sound ) unbindKey ( "Z", "down", stopMySoundB ) removeEventHandler( "onClientVehicleExit", root, stopMySoundV ) if not isTimer ( aMyTimer ) then aMyTimer = setTimer( helicopter, 5000,0) end end end end end Edited just now! Edited November 22, 2016 by iPrestege Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 (edited) Nope , i don't use local , still not working , but thanks for help man , i appreciate. No warrnings or erros in debugscript. I used this to play sound only for driver seat and it's working , when i tried to use for that function he give that warrning , can you tell me why ? local driver = getVehicleOccupant(veh, 0) local p1 = getVehicleOccupant(veh, 1) local p2 = getVehicleOccupant(veh, 2) local p3 = getVehicleOccupant(veh, 3) if fuel1 <= 6 then if p1 or p2 or p3 then return false end if driver then sound = playSound("sound/beep.mp3" , true) setSoundVolume(sound, 0.2) Edited November 22, 2016 by Strike27208 Link to comment
iPrestege Posted November 22, 2016 Share Posted November 22, 2016 function stopMySoundV ( plr ) if plr == localPlayer then driver = getVehicleController ( source ) if driver then if sound then stopSound ( sound ) unbindKey ( "Z", "down", stopMySoundB ) removeEventHandler( "onClientVehicleExit", root, stopMySoundV ) if not isTimer ( aMyTimer ) then aMyTimer = setTimer( helicopter, 5000,0) end end end end end Just noticed that you have attached this function to on vehicle exit event ;d . or if that didn't work you can try this : function stopMySoundV ( plr,seat ) if plr == localPlayer and seat == 0 then if sound then stopSound ( sound ) unbindKey ( "Z", "down", stopMySoundB ) removeEventHandler( "onClientVehicleExit", root, stopMySoundV ) if not isTimer ( aMyTimer ) then aMyTimer = setTimer( helicopter, 5000,0) end end end end Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 (edited) I have the event attached. This is server part ? Edited November 22, 2016 by Strike27208 Link to comment
iPrestege Posted November 22, 2016 Share Posted November 22, 2016 no it's a client side also i've added another code check my post again. Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 Oh man thank you very much , it's working , thaaaaaaanks !!!!! Last code are working. Link to comment
iPrestege Posted November 22, 2016 Share Posted November 22, 2016 You are welcome also i didn't get it that you are using the 'onClientVehicleExit'.Event so i've edited using event source. Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 I use to activate my function if driver then sound = playSound("sound/beep.mp3" , true) setSoundVolume(sound, 0.2) outputChatBox ( "#FF0000Alarm ! #FFFFFFLow fuel ! Press ' Z ' to stop the alarm.", 255, 255, 255, true ) bindKey ( "Z", "down", stopMySoundB ) addEventHandler ( "onClientVehicleExit", root, stopMySoundV ) killTimer(aMyTimer) end Link to comment
Strike27208 Posted November 22, 2016 Author Share Posted November 22, 2016 Hey , i come back here because i find a new bug :)) , if i'm with other player in vehicle the alarm won't start , this is my code : local driver = getVehicleOccupant(veh, 0) local p1 = getVehicleOccupant(veh, 1) local p2 = getVehicleOccupant(veh, 2) local p3 = getVehicleOccupant(veh, 3) if fuel <=5 then if p1 or p2 or p3 then return false end if driver then sound = playSound("sound/beep.mp3" , true) setSoundVolume(sound, 0.1) setSoundSpeed ( sound, 0.9 ) outputChatBox ( "#FF0000Alarm ! #FFFFFFLow fuel ! Press ' Z ' to stop the alarm.", 255, 255, 255, true ) bindKey ( "Z", "down", stopMySoundB ) addEventHandler ( "onClientVehicleExit", root, stopMySoundV ) killTimer(aMyTimer) end end end 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