Jump to content

Locking the car script


Recommended Posts

hey, it wont lock the car, please help. I have added some settings, can you please help me then explain why it doesnt work.

Server:

local lockcolourfirst = get('lockcolorfirst') 
local lockcoloursecond = get('lockcolorsecond') 
local enable = get('enablecarlocking') 
local exitunlock = get('unlockingonexit') 
local lockcommand = get('commandforlocking') 
function lock(thePlayer) 
    if enable == "true" then 
    playervehicle=getPlayerOccupiedVehicle(thePlayer) 
    if(playervehicle) then 
        if(isVehicleLocked(playervehicle)) then 
            setVehicleLocked(playervehicle,false) 
            outputChatBox(lockcolourfirst.."Your vehicle has been "..lockcoloursecond.."UNLOCKED!",thePlayer,255,255,255,true) 
 else 
            setVehicleLocked ( playervehicle, true ) 
            outputChatBox(lockcolourfirst.."Your vehicle has been "..lockcoloursecond.."LOCKED!",thePlayer,255,0,0,true) 
        end 
    end 
    elseif enable == "false" then 
  
    end 
end 
  
function binding() 
bindKey ( thePlayer, "L", "down", lock) 
end 
addEventHandler('onResourceStart', getRootElement(), binding) 
  
function leave(player,seat,jacked) 
if exitunlock == "true" then 
    if(isVehicleLocked(source)) then 
        setVehicleLocked(source,false) 
        outputChatBox(lockcolourfirst.."Your vehical has been "..lockcoloursecond.."UNLOCKED!",thePlayer,255,0,0, true) 
    end 
elseif exitunlock == "false" then 
  
end 
end 
  
addCommandHandler("lock",lock) 
addEventHandler("onVehicleExit",getRootElement(),leave) 
  

Meta:

    "[EGL]Chris" version="1.0" type="script" name="Stats System" description="This systems adds a fancy gui on screen with stats about the player, and the weapon, and the vehicle. We also have included a vehical management system, meaning locking of the vehicle, lights, engine, repairing of the vehical." /> 
    

Link to comment

line 24 you say?

  
function binding() 
for i,thePlayer in ipairs(getElementsByType('player')) do  
bindKey ( thePlayer, "L", "down", lock) 
end 
end 
addEventHandler('onResourceStart', getRootElement(), binding) 

now thePlayer is actually defined :P

and what about late joiners? L is only assigned to people who are in the server when you start the resource.

I suggest binding the key onPlayerJoin too, or whatever

oh and 1 more thing i noticed.

getPlayerOccupiedVehicle is deprecated.

Use getPedOccupiedVehicle instead

and post further errors and say exactly where the script fails. I mean does it say anything in the chatbox when you use the script?

Link to comment
use :
  
--- Client Side 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()), 
function() 
bindKey ( "l", "down", lock) 
end ) 
  

Why are you confusing him even more?

What you're saying means using clientside code, while his 'lock' function is clearly serverside..

'lock' is not defined as a client function so binding a key on it won't 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...