Strike27208

How to playSound only for seat 0 ?

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)

 

Share this post


Link to post
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

Share this post


Link to post

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

Share this post


Link to post
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 ? 

Share this post


Link to post
3 minutes ago, LoPollo said:

mmm... try  localPlayer:getOccupiedVehicleSeat() instead of  localPlayer.vehicleSeat

Same Error. 

localPlayer:getOccupiedVehicleSeat(vehicle , 0 )

 

Edited by Strike27208

Share this post


Link to post

why do you put vehicle and 0 as arguments? that function does not require arguments. I'm going to test, wait a moment

Share this post


Link to post

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)

 

Share this post


Link to post
3 hours ago, LoPollo said:

the other ways i posted return the error as you said, but i don't want to know why right now

I'm pretty sure it's because OOP was not enabled.

  • Like 1

Share this post


Link to post
19 hours ago, loki2143 said:

I'm pretty sure it's because OOP was not enabled.

Yes it is, but i don't want him to edit the meta... But i thought that someElement:someMethod() is not OOP xD well i learn also by making error i hope

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.