Sign in to follow this  
jingzhi

Any pro to help me with these scripts?

Recommended Posts

Client side

addEvent("onvehiclelock",true) 
function playSoundLock() 
playSound3D("lock.wav",vehposx,vehposy,vehposz) 
outputChatBox("playsound") 
end 
addEventHandler("onvehiclelock",getRootElement(),playSoundLock) 
  
addEvent("onvehicleunlock",true) 
function playSoundUnlock() 
playSound3D("unlock.wav",vehposx,vehposy,vehposz) 
outputChatBox("playsound") 
end 
addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) 

Server side

function lockcar ( thePlayer ) 
    local vehicle = getPedOccupiedVehicle ( thePlayer )    
    if ( vehicle ) then                                
    vehposx,vehposy,vehposz = getElementPosition(vehicle) 
    if isVehicleLocked ( vehicle ) then   
    setVehicleLocked ( vehicle, false )         
    triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle) 
    outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) 
        else                                                  
        setVehicleLocked ( vehicle, true )      
        triggerClientEvent(getRootElement(),"onvehiclelock",vehicle) 
        outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) 
        end 
    end 
end 
  
addCommandHandler("lock",lockcar) 
  
function unlock(vehicle) 
    setVehicleLocked(vehicle, false) 
    triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle) 
end 
addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) 

I want to make the vehicle play a 3d sond when its locked/unlocked, but it always says the vector3 of play3dsound is nil, please help :|

Share this post


Link to post

Server-side and client-side variables are not synced, even if they're global. The position variables never get sent to the client.

Another problem you have is getRootElement in triggerClientEvent, this will play the sound for everyone in the server regardless of who triggered the event.

Server:

function lockcar ( thePlayer ) 
    local vehicle = getPedOccupiedVehicle ( thePlayer )   
    if ( vehicle ) then                               
    local vehposx,vehposy,vehposz = getElementPosition(vehicle) 
    if isVehicleLocked ( vehicle ) then   
    setVehicleLocked ( vehicle, false )         
    triggerClientEvent(thePlayer,"onvehicleunlock",vehicle, vehposx, vehposy, vehposz) 
    outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) 
        else                                                 
        setVehicleLocked ( vehicle, true )     
        triggerClientEvent(thePlayer,"onvehiclelock",vehicle, vehposx, vehposy, vehposz) 
        outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) 
        end 
    end 
end 
  
addCommandHandler("lock",lockcar) 
  
function unlock(vehicle) 
    setVehicleLocked(vehicle, false) 
    triggerClientEvent(source,"onvehicleunlock",vehicle) 
end 
addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) 

 

Client:

addEvent("onvehiclelock",true) 
function playSoundLock(vehposx, vehposy, vehposz) 
playSound3D("lock.wav",vehposx,vehposy,vehposz) 
outputChatBox("playsound") 
end 
addEventHandler("onvehiclelock",getRootElement(),playSoundLock) 
  
addEvent("onvehicleunlock",true) 
function playSoundUnlock(vehposx, vehposy, vehposz) 
playSound3D("unlock.wav",vehposx,vehposy,vehposz) 
outputChatBox("playsound") 
end 
addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) 

Share this post


Link to post
  
-- Client Side 
  
function playSoundLock(x,y,z) 
local sound = playSound3D("lock.wav",x,y,z) 
setSoundMaxDistance(sound, 100 ) 
end 
addEvent("onvehiclelock",true) 
addEventHandler("onvehiclelock",getRootElement(),playSoundLock) 
  
  
function playSoundUnlock(x,y,z) 
local sound = playSound3D("unlock.wav",x,y,z) 
setSoundMaxDistance(sound, 100 ) 
end 
addEvent("onvehicleunlock",true) 
addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) 
  
-- Server side 
function lockcar ( thePlayer ) 
    local vehicle = getPedOccupiedVehicle ( thePlayer )   
    if ( vehicle ) then                               
    vehposx,vehposy,vehposz = getElementPosition(vehicle) 
    if isVehicleLocked ( vehicle ) then   
    setVehicleLocked ( vehicle, false )         
    triggerClientEvent(thePlayer,"onvehicleunlock",thePlayer,vehposx,vehposy,vehposz) 
    outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) 
        else                                                 
        setVehicleLocked ( vehicle, true )     
        triggerClientEvent(thePlayer,"onvehiclelock",thePlayer,vehposx,vehposy,vehposz) 
        outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) 
        end 
    end 
end 
addCommandHandler("lock",lockcar) 

Share this post


Link to post
Server-side and client-side variables are not synced, even if they're global. The position variables never get sent to the client.

Another problem you have is getRootElement in triggerClientEvent, this will play the sound for everyone in the server regardless of who triggered the event.

Server:

function lockcar ( thePlayer ) 
    local vehicle = getPedOccupiedVehicle ( thePlayer )   
    if ( vehicle ) then                               
    local vehposx,vehposy,vehposz = getElementPosition(vehicle) 
    if isVehicleLocked ( vehicle ) then   
    setVehicleLocked ( vehicle, false )         
    triggerClientEvent(thePlayer,"onvehicleunlock",vehicle, vehposx, vehposy, vehposz) 
    outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) 
        else                                                 
        setVehicleLocked ( vehicle, true )     
        triggerClientEvent(thePlayer,"onvehiclelock",vehicle, vehposx, vehposy, vehposz) 
        outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) 
        end 
    end 
end 
  
addCommandHandler("lock",lockcar) 
  
function unlock(vehicle) 
    setVehicleLocked(vehicle, false) 
    triggerClientEvent(source,"onvehicleunlock",vehicle) 
end 
addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) 

 

Client:

addEvent("onvehiclelock",true) 
function playSoundLock(vehposx, vehposy, vehposz) 
playSound3D("lock.wav",vehposx,vehposy,vehposz) 
outputChatBox("playsound") 
end 
addEventHandler("onvehiclelock",getRootElement(),playSoundLock) 
  
addEvent("onvehicleunlock",true) 
function playSoundUnlock(vehposx, vehposy, vehposz) 
playSound3D("unlock.wav",vehposx,vehposy,vehposz) 
outputChatBox("playsound") 
end 
addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) 

Hey its still not working, I made it like you said :|

Server

function lockcar ( thePlayer ) 
    local vehicle = getPedOccupiedVehicle ( thePlayer )    
    if ( vehicle ) then                                
    local vehx,vehy,vehz = getElementPosition(vehicle) 
    if isVehicleLocked ( vehicle ) then   
    setVehicleLocked ( vehicle, false )         
    triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle, vehx,vehy,vehz) 
    outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) 
        else                                                  
        setVehicleLocked ( vehicle, true )      
        triggerClientEvent(getRootElement(),"onvehiclelock",vehicle,vehx,vehy,vehz) 
        outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) 
        end 
    end 
end 
  
addCommandHandler("lock",lockcar) 
  
function unlock(vehicle) 
    setVehicleLocked(vehicle, false) 
    triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle,vehx,vehy,vehz) 
end 
  
addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) 

Client

addEvent("onvehiclelock",true) 
function playSoundLock() 
playSound3D("lock.mp3",vehx,vehy,vehz) 
end 
addEventHandler("onvehiclelock",getRootElement(),playSoundLock) 
  
addEvent("onvehicleunlock",true) 
function playSoundUnlock() 
playSound3D("unlock.mp3",vehx,vehy,vehz) 
end 
addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) 

Share this post


Link to post

do it like this

-- Client side

function playSoundLock(x,y,z) 
local sound = playSound3D("lock.wav",x,y,z) 
setSoundMaxDistance(sound, 100 ) 
end 
addEvent("onvehiclelock",true) 
addEventHandler("onvehiclelock",getRootElement(),playSoundLock) 
  
  
function playSoundUnlock(x,y,z) 
local sound = playSound3D("unlock.wav",x,y,z) 
setSoundMaxDistance(sound, 100 ) 
end 
addEvent("onvehicleunlock",true) 
addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) 

-- server side

function lockcar ( thePlayer ) 
    local vehicle = getPedOccupiedVehicle ( thePlayer )   
    if ( vehicle ) then                               
    vehposx,vehposy,vehposz = getElementPosition(vehicle) 
    if isVehicleLocked ( vehicle ) then   
    setVehicleLocked ( vehicle, false )         
    triggerClientEvent(thePlayer,"onvehicleunlock",thePlayer,vehposx,vehposy,vehposz) 
    outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) 
        else                                                 
        setVehicleLocked ( vehicle, true )     
        triggerClientEvent(thePlayer,"onvehiclelock",thePlayer,vehposx,vehposy,vehposz) 
        outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) 
        end 
    end 
end 
addCommandHandler("lock",lockcar) 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.