Jump to content

Car alarm


Recommended Posts

Hello i have this vehicle car lock system, and i want to locate the file when vehicle is locked it will play "files/lock.mp3"& when unlocked it will play "files/unlock.mp3" here is the code

client side:

-- Car Locks ( client ) 
  
-- local player 
localPlayer = getLocalPlayer ( ) 
  
-- playSoundNearElement 
addEvent ( "onPlaySoundNearElement", true ) 
function playSoundNearElement ( theElement, sound ) 
--  local sound = 5 
    local maxdist = 15.0 
    -- valid element 
    if ( theElement ) then 
        local x,y,z = getElementPosition ( theElement ) 
        local x2,y2,z2 = getElementPosition ( localPlayer ) 
        local dist = getDistanceBetweenPoints3D ( x, y, z, x2, y2, z2 )  
        -- distance is less than parameter maxdist 
        if ( dist < maxdist ) then 
            -- play parameter sound  
            playSoundFrontEnd ( 5 ) 
        --  outputChatBox ( "sound should play" ) 
        else 
        --  outputChatBox ( "not in range" ) 
        end 
    else 
        -- outputChatBox ( "invalid element" ) 
    end 
end 
addEventHandler ( "onPlaySoundNearElement", getRootElement(), playSoundNearElement ) 
  

server side

-- Car Locks ( client ) 
  
-- local player 
localPlayer = getLocalPlayer ( ) 
  
-- playSoundNearElement 
addEvent ( "onPlaySoundNearElement", true ) 
function playSoundNearElement ( theElement, sound ) 
--  local sound = 5 
    local maxdist = 15.0 
    -- valid element 
    if ( theElement ) then 
        local x,y,z = getElementPosition ( theElement ) 
        local x2,y2,z2 = getElementPosition ( localPlayer ) 
        local dist = getDistanceBetweenPoints3D ( x, y, z, x2, y2, z2 )  
        -- distance is less than parameter maxdist 
        if ( dist < maxdist ) then 
            -- play parameter sound  
            playSoundFrontEnd ( 5 ) 
        --  outputChatBox ( "sound should play" ) 
        else 
        --  outputChatBox ( "not in range" ) 
        end 
    else 
        -- outputChatBox ( "invalid element" ) 
    end 
end 
addEventHandler ( "onPlaySoundNearElement", getRootElement(), playSoundNearElement ) 
  

thanks for helping

Link to comment
function playLockingSound(vehicle) 
    if vehicle then 
    source = vehicle 
    end 
local x,y,z = getElementPosition(source) 
local lockSound = playSound3D("files/lock.mp3", x, y, z) 
setSoundMaxDistance(lockSound, 50) 
attachElements(lockSound, source) 
beep(source) 
end 
addEvent("onClientVehicleLock", true) 
addEventHandler("onClientVehicleLock", root, playLockingSound) 
  
function playUnlockingSound() 
stopVehicleAlarm(source) 
local x,y,z = getElementPosition(source) 
local unlockSound = playSound3D("files/unlock.mp3", x, y, z) 
setSoundMaxDistance(unlockSound, 50) 
attachElements(unlockSound, source) 
beep(source) 
setTimer(beep, 200, 1, source) 
end 
addEvent("onClientVehicleUnlock", true) 
addEventHandler("onClientVehicleUnlock", root, playUnlockingSound) 
  

i tried not working

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