Jump to content

How to playSound only for seat 0 ?


Strike27208

Recommended Posts

Hey , how i can to play sound for driver only ? this is my code , i tried to make but i failed and i need some help : 

function helicopter ()
if ( isPedInVehicle ( localPlayer ) == false ) then return false end
local vehicle = getPedOccupiedVehicle(getLocalPlayer())
if vehicle then 
    if ( policeVehicles[getElementModel ( vehicle )] ) then 
    local maxfuel = tonumber(getElementData(vehicle, "maxfuel")) or 0;
    local fuels = math.floor(tonumber(getElementData(getElementData(vehicle, "parent"), "fuel"))) or 0;
        if fuels <=5 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
end
aMyTimer = setTimer( helicopter, 5000,0)

 

Link to comment
21 minutes ago, LoPollo said:

to check if localPlayer is the driver use getPedOccupiedVehicleSeat. If it does return 0, then localPlayer is the driver

I used this and didn't work : 

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

 

Edited by Strike27208
Link to comment

You make the function end if there's any player at seat 1-2-3, but i guess that's not what you want

You are checking if the drivers exists. That's also not what you are looking for. You want to know if the driver is the localPlayer

if localPlayer.vehicleSeat == 0 then
Spoiler

function helicopter ()
	if ( isPedInVehicle ( localPlayer ) == false ) then return false end
	local vehicle = getPedOccupiedVehicle(getLocalPlayer())
	if vehicle then 
		if ( policeVehicles[getElementModel ( vehicle )] ) then 
			local maxfuel = tonumber(getElementData(vehicle, "maxfuel")) or 0;
			local fuels = math.floor(tonumber(getElementData(getElementData(vehicle, "parent"), "fuel"))) or 0;
			if fuels <=5 then
				if localPlayer.vehicleSeat == 0 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
	end
end
aMyTimer = setTimer( helicopter, 5000,0)

 

 

Edited by LoPollo
Link to comment
2 minutes ago, LoPollo said:

You make the function end if there's any player at seat 1-2-3, but i guess that's not what you want

You are checking if the drivers exists. That's also not what you are looking for. You want to know if the driver is the localPlayer


if localPlayer.vehicleSeat == 0 then

 

attempt to index a global "localPlayer" a userdata value , hmmmm ? 

Link to comment

Use the "classic" style: getPedOccupiedVehicleSeat(localPlayer)

the other ways i posted return the error as you said, but i don't want to know why right now xD let me know if this helps

function helicopter ()
	if ( isPedInVehicle ( localPlayer ) == false ) then return false end
	local vehicle = getPedOccupiedVehicle(getLocalPlayer())
	if vehicle then 
		if ( policeVehicles[getElementModel ( vehicle )] ) then 
			local maxfuel = tonumber(getElementData(vehicle, "maxfuel")) or 0;
			local fuels = math.floor(tonumber(getElementData(getElementData(vehicle, "parent"), "fuel"))) or 0;
			if fuels <=5 then
				if getPedOccupiedVehicleSeat(localPlayer) == 0 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
	end
end
aMyTimer = setTimer( helicopter, 5000,0)

 

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