Strike27208 Posted November 25, 2016 Share Posted November 25, 2016 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
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 to check if localPlayer is the driver use getPedOccupiedVehicleSeat. If it does return 0, then localPlayer is the driver Link to comment
Strike27208 Posted November 25, 2016 Author Share Posted November 25, 2016 (edited) 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 November 25, 2016 by Strike27208 Link to comment
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 (edited) 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 November 25, 2016 by LoPollo Link to comment
Strike27208 Posted November 25, 2016 Author Share Posted November 25, 2016 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
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 mmm... try localPlayer:getOccupiedVehicleSeat() instead of localPlayer.vehicleSeat Link to comment
Strike27208 Posted November 25, 2016 Author Share Posted November 25, 2016 (edited) 3 minutes ago, LoPollo said: mmm... try localPlayer:getOccupiedVehicleSeat() instead of localPlayer.vehicleSeat Same Error. localPlayer:getOccupiedVehicleSeat(vehicle , 0 ) Edited November 25, 2016 by Strike27208 Link to comment
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 why do you put vehicle and 0 as arguments? that function does not require arguments. I'm going to test, wait a moment Link to comment
Strike27208 Posted November 25, 2016 Author Share Posted November 25, 2016 Ok , thanks. Link to comment
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 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 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
Strike27208 Posted November 25, 2016 Author Share Posted November 25, 2016 Thanks man , it's working , cheers Link to comment
Mr.Loki Posted November 26, 2016 Share Posted November 26, 2016 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. 1 Link to comment
LoPollo Posted November 26, 2016 Share Posted November 26, 2016 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 well i learn also by making error i hope 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