Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace LockDoors//name of your script or library
- {
- //here you state what libraries of code you are using
- //these are namespaces
- using System;
- using System.Windows.Forms;
- using GTA;
- //this is the beginning of your script or class
- public class LockDoors : Script
- {
- //here u can state variable u would like to use
- //you are not using any so dont worry now
- //look at some other people's source and u see
- //this is the constructor and code runs on script load
- public LockDoors()
- {
- //you are hooking a KeyDown event here, it will look in the method
- //in this case the method's name is LockDoors_KeyDown
- KeyDown += new GTA.KeyEventHandler(LockDoors_KeyDown);
- }
- //this is what u hooked and allows pc to look for key presses
- void LockDoors_KeyDown(object sender, GTA.KeyEventArgs e)
- {
- if (e.Key == Keys.Delete)//so if u press delete then code inside runs
- {
- if (Game.Exists(Player.Character.CurrentVehicle))//this makes sure car exists so u dont do stuff with a null value because your script will crash if something is null
- {
- if (Player.Character.CurrentVehicle.DoorLock == DoorLock.ImpossibleToOpen)// u check if door is locked here to see how u want key to react
- {
- //here the door is locked so your key unlocks
- Game.DisplayText("Door is Unlocked");
- Player.Character.CurrentVehicle.DoorLock = DoorLock.None;
- }
- else
- {
- //here your door is unlocked so the key locks
- Game.DisplayText("Door is Locked");
- Player.Character.CurrentVehicle.DoorLock = DoorLock.ImpossibleToOpen;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment