Jump to content

How to make to check non-stop ?


Strike27208

Recommended Posts

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

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 : 

Ue50AFg.png 

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 by Strike27208
Link to comment

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 by Strike27208
Link to comment

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 by iPrestege
Link to comment

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 by Strike27208
Link to comment
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

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

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

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...