Jump to content

Lock Help!


Timiimit

Recommended Posts

Hi!

I am making a script that will lock vehicle when you enter it and press 'L' and to unlock it press 'L' again.

what i have:

  
function lockcar ( thePlayer ) 
    playerVehicle = getVehicleOccupant ( thePlayer ) 
  
    if ( playerVehicle ) then 
    if isLocked == false then 
    setVehicleLocked ( playerVehicle, true ) 
    outputChatBox( "Vehicle locked!", thePlayer, 255, 50, 0)  
    else 
    setVehicleLocked ( playerVehicle, false ) 
    outputChatBox( "Vehicle unlocked!", thePlayer, 0, 255, 0)  
    end 
end 
  
function bindLockOnSpawn ( theSpawnpoint ) 
    bindKey ( source, "l", "down", lockcar ) 
    local isLocked = false 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) 
  

Please help because it is not working!

Link to comment
function lockcar ( thePlayer ) 
    local  playerVehicle = getPedOccupiedVehicle(thePlayer) 
    if ( playerVehicle ) then 
         if isVehicleLocked ( playerVehicle ) == false then 
         setVehicleLocked ( playerVehicle, true ) 
         outputChatBox( "Vehicle locked!", thePlayer, 255, 50, 0)  
         else 
         setVehicleLocked ( playerVehicle, false ) 
         outputChatBox( "Vehicle unlocked!", thePlayer, 0, 255, 0)  
         end 
    end 
end 
  
function bindLockOnSpawn ( theSpawnpoint ) 
    bindKey ( source, "l", "down", lockcar ) 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) 

isLocked isn't a function :) , hope it works ! :)

EDIT : You forgot an 'end'

Edited by Guest
Link to comment
  
function lockcar ( thePlayer  ) 
    playerVehicle = getPedOccupiedVehicle(thePlayer) 
    local isLocked = isVehicleLocked ( playerVehicle ) 
    if ( playerVehicle ) then 
        if isLocked == false then 
            setVehicleLocked ( playerVehicle, true ) 
            outputChatBox( "Vehicle locked!", thePlayer, 255, 50, 0) 
            isLocked = true 
        else 
            setVehicleLocked ( playerVehicle, false ) 
            outputChatBox( "Vehicle unlocked!", thePlayer, 0, 255, 0) 
            isLocked = false 
        end 
    end 
end 
  
function bindLockOnSpawn ( theSpawnpoint ) 
    bindKey ( source, "l", "down", lockcar, source ) 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) 

Link to comment
  
function lockcar () 
    local  playerVehicle = getPedOccupiedVehicle( source ) 
    if ( playerVehicle ) then 
         if isVehicleLocked ( playerVehicle ) == false then 
         setVehicleLocked ( playerVehicle, true ) 
         outputChatBox( "Vehicle locked!", source, 255, 50, 0)  
         else 
         setVehicleLocked ( playerVehicle, false ) 
         outputChatBox( "Vehicle unlocked!", source, 0, 255, 0)  
         end 
    end 
end 
  
function bindLockOnSpawn () 
    bindKey ( source, "l", "down", lockcar ) 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) 

Hmm , test it :)

Link to comment
  
function lockcar ( thePlayer  ) 
    playerVehicle = getPedOccupiedVehicle(thePlayer) 
    local isLocked = isVehicleLocked ( playerVehicle ) 
    if ( playerVehicle ) then 
        if isLocked == false then 
            setVehicleLocked ( playerVehicle, true ) 
            outputChatBox( "Vehicle locked!", thePlayer, 255, 50, 0) 
            isLocked = true 
        else 
            setVehicleLocked ( playerVehicle, false ) 
            outputChatBox( "Vehicle unlocked!", thePlayer, 0, 255, 0) 
            isLocked = false 
        end 
    end 
end 
  
function bindLockOnSpawn ( theSpawnpoint ) 
    bindKey ( source, "l", "down", lockcar) 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) 

This will definitly work

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