Jump to content

Car alarm


Recommended Posts

Posted

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

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
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

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

._. can you fix my code please?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Working but what about unlocking?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Bump ._.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

So . .

If the the Vehicle is locked = play

If the the vehicle is unlocked = play other sound

True?

I reply with iPhone can't give example,anyway add the else.

Posted (edited)

xD i'm connected from iPhone too :D

Yes.

Edited by Guest

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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