Jump to content

Car Engine


Khalil

Recommended Posts

Well guys, I just started lua scripting and I made a few "beginner" scripts. Anyway, I made an engine resource that start/stops vehicle engines when you do /engine. I just wanted to add sound effects to it. When someone does /engine in a vehicle, a certain sound goes off.

PS. I don't want someone to do it for me, I just need a little help with it.

Thanks

Link to comment

Whats wrong with this?

function switchEngine ( playerSource ) 
    local theVehicle = getPedOccupiedVehicle ( playerSource ) 
  
    -- Check if the player is in any vehicle and if he is the driver 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
        playSound ( sound.mp3, [ bool looped = false ] ) 
    end 
end 
addCommandHandler ( "engine", switchEngine ) 

Link to comment
function switchEngine(player) 
     local theVehicle = getPedOccupiedVehicle(player) 
     if theVehicle and getVehicleController(theVehicle) == player then 
          setVehicleEngineState(theVehicle, not getVehicleEngineState(theVehicle)) 
          playSound("sound.mp3") 
     end 
end 
addCommandHandler("engine", switchEngine) 

Link to comment

Error: engine\script.lua:5: attempt to call global 'playsound'

If it helps, maybe there's something wrong with my meta.xml:

     "Khalil" type="script" name="engine" description="engine script" /> 
     

When I do /engine it works fine but the sound doesn't play..

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