-- server side:
addEventHandler ( "onPlayerJoin", root,
function ( )
bindKey ( source, "M", "down", turnEngine )
end
)
addEventHandler ( "onResourceStart", resourceRoot,
function ( )
for _, player in ipairs ( getElementsByType ( "player" ) ) do
bindKey ( player, "M", "down", turnEngine )
end
end
)
engineStarting = { }
function turnEngine ( thePlayer, key, keyState )
if ( key ~= "m" or keyState ~= "down" ) then
return
end
if ( not isPedInVehicle ( thePlayer ) ) then
return
end
local vehicle = getPedOccupiedVehicle ( thePlayer )
if ( thePlayer ~= getVehicleOccupant ( vehicle, 0 ) ) then
return
end
if ( engineStarting [ thePlayer ] ) then
return
end
if getVehicleEngineState ( vehicle ) then
setVehicleEngineState ( vehicle, false )
else
if ( getElementData ( vehicle, "tank" ) > 0.0 ) then
triggerClientEvent ( thePlayer, "playSound", thePlayer, 'engine.wav' )
engineStarting [ thePlayer ] = true
setTimer ( startEngine, 1500, 1, vehicle )
else
triggerClientEvent ( thePlayer, "playSound", thePlayer, 'engineNoFuel.wav' )
end
end
end
-- client side:
addEvent ( "playSound", true )
addEventHandler ( "playSound", root,
function ( path )
playSound ( path )
end
)