Timiimit Posted January 27, 2012 Posted January 27, 2012 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!
GanJaRuleZ Posted January 27, 2012 Posted January 27, 2012 (edited) 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 January 27, 2012 by Guest
BriGhtx3 Posted January 27, 2012 Posted January 27, 2012 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 )
BriGhtx3 Posted January 27, 2012 Posted January 27, 2012 GanJa your code will not work. playerVehicle is a ped now
GanJaRuleZ Posted January 27, 2012 Posted January 27, 2012 xthepr0mise , ty , i forgot about the @getPedOccupiedVehicle And tiimiit , this is the whole script or just an part of it , cuz i don't see isLocked .. Tiimiit , just try my code
BriGhtx3 Posted January 27, 2012 Posted January 27, 2012 He defined isLocked after his bindKey But it wont work, cause its just a local variable €:GanJa you also forgot the source element in your bindKey as argument
GanJaRuleZ Posted January 27, 2012 Posted January 27, 2012 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
BriGhtx3 Posted January 27, 2012 Posted January 27, 2012 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
Timiimit Posted January 27, 2012 Author Posted January 27, 2012 ok working!!! Thx so much! I still need one more help im making topic.. name will be "Fixing help"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now