Lua help.

I’m trying to make a simple script, that detects when a car has no player in and if takes damage, emits a car alarm, I just finish making the car alarms sound right.

We’re should I start, I have 3 sounds, a horn like sound, a truck alarm and a normal car sound (please +rep my MSN account for those great descriptions).

So we’re should I start?

Thanks

I’d say use

GM/EntityTakeDamage and check if

Vehicle:GetDriver is equal to NULL, and then do something like

Entity:EmitSound to play the alarm sound

[editline]28th February 2016[/editline]

E.g.



hook.Add( 'EntityTakeDamage', 'DoAlarmSound', function( target, dmginfo ) -- hook into the EntityTakeDamage function
    if ( IsValid( target ) ) and ( target:IsVehicle() ) and ( target:GetDriver() == NULL ) then -- Check if the damage target is a vehicle and there's no driver and it's a valid entity
        target:EmitSound( 'some/sound.wav', 100, 100, 1, CHAN_AUTO ) -- play the sound from the car
    end
end )


[editline]28th February 2016[/editline]

I guess if you wanted the cars to have individual sounds then you could check the model to play the appropriate sound or something, you’ll probably know what to do

Also, that example above will probably make airboats and seats and stuff make alarm sounds as well since they’re considered vehicles, but you could fix that by checking the model or something like that

[editline]28th February 2016[/editline]

If you wanted the alarm to loop, you could wrap this timer around the EmitSound bit:



timer.Create( tostring( target:GetCreationID() ), SoundDuration( "some/sound.wav" ), 0, function() -- make a timer with infinite repetitions so when the alarm sound ends a new one plays
    if IsValid( target ) then -- make sure the vehicle didn't get removed before playing the sound
        target:EmitSound( 'some/sound.wav', 100, 100, 1, CHAN_AUTO ) -- play the sound from the car
    end
end )


Mpan1, you seem to be very helpful and fast at responding. +1

Wow that was a great response thanks for the help :slight_smile:

[editline]28th February 2016[/editline]

And code I use


 GM:PlayerLeaveVehicle( Player ply, Vehicle veh ) 

to play the sound of the engine making that tingling sound, I recently was able to get the sound out of GTA.