profileshame

Untitled

Apr 28th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. namespace LockDoors//name of your script or library
  2. {
  3.     //here you state what libraries of code you are using
  4.     //these are namespaces
  5.     using System;
  6.     using System.Windows.Forms;
  7.     using GTA;
  8.  
  9.     //this is the beginning of your script or class
  10.     public class LockDoors : Script
  11.     {
  12.         //here u can state variable u would like to use
  13.         //you are not using any so dont worry now
  14.         //look at some other people's source and u see
  15.  
  16.         //this is the constructor and code runs on script load
  17.         public LockDoors()
  18.         {
  19.             //you are hooking a KeyDown event here, it will look in the method
  20.             //in this case the method's name is LockDoors_KeyDown
  21.             KeyDown += new GTA.KeyEventHandler(LockDoors_KeyDown);
  22.         }
  23.  
  24.         //this is what u hooked and allows pc to look for key presses
  25.         void LockDoors_KeyDown(object sender, GTA.KeyEventArgs e)
  26.         {
  27.             if (e.Key == Keys.Delete)//so if u press delete then code inside runs
  28.             {
  29.                 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
  30.                 {
  31.                     if (Player.Character.CurrentVehicle.DoorLock == DoorLock.ImpossibleToOpen)// u check if door is locked here to see how u want key to react
  32.                     {
  33.                         //here the door is locked so your key unlocks
  34.                         Game.DisplayText("Door is Unlocked");
  35.                         Player.Character.CurrentVehicle.DoorLock = DoorLock.None;
  36.                     }
  37.                     else
  38.                     {
  39.                         //here your door is unlocked so the key locks
  40.                         Game.DisplayText("Door is Locked");
  41.                         Player.Character.CurrentVehicle.DoorLock = DoorLock.ImpossibleToOpen;
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment