void OnKeyDown(object sender, GTA.KeyEventArgs args) { if (args.Key == Keys.LShiftKey) { lastClickTime = Game.GameTime; } }
private void NativeCallExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.L) { return; } GTA.Native.Pointer PedPointer = typeof(Ped); GTA.Native.Function.Call("GET_PLAYER_CHAR", Player, PedPointer); Ped PlayerChar = PedPointer; if (!GTA.Native.Function.Call <bool>("IS_CHAR_IN_ANY_CAR", PlayerChar)) { Game.DisplayText("Not in a car!"); return; } GTA.Native.Pointer CarPointer = typeof(Vehicle); GTA.Native.Function.Call("GET_CAR_CHAR_IS_USING", PlayerChar, CarPointer); GTA.Native.Pointer ModelPointer = typeof(Model); GTA.Native.Function.Call("GET_CAR_MODEL", CarPointer.ToInputParameter(), ModelPointer); String name = GTA.Native.Function.Call <String>("GET_DISPLAY_NAME_FROM_VEHICLE_MODEL", ModelPointer.ToInputParameter()); Game.DisplayText("Car name: " + name); }
// KeyDown returns the pressed key. // but there is no need to check it when your script watches only this one key private void BasicKeyExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key == Keys.M) { Player.Money += 10000; } }
private void PositionScript_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key == Keys.Home) { Game.DisplayText(Player.Character.Position.ToString()); } }
private void Quicksave_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key == Settings.GetValueKey("Key", Keys.F5)) { Game.DoAutoSave(); } if (e.Key == Settings.GetValueKey("Key", Keys.F5) && e.Alt) { Game.ShowSaveMenu(); } }
private void TaskSequenceExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.K) { return; } Ped p = World.CreatePed(Player.Character.Position.Around(3.0F)); p.CurrentRoom = Player.Character.CurrentRoom; p.Weapons.Glock.Ammo = 1000; p.Task.PerformSequence(FleeTask); }
private void AnimationExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.J) { return; } if (bSmoking) { StopSmoking(); } else { StartSmoking(); } }
private void eventOnKeyUp(object sender, GTA.KeyEventArgs e) { if (lastKeyUp != null && lastKeyUp == (int)e.Key) { return; } if (client.currentState == ClientState.Connected) { var bpf = new BinaryPacketFormatter(Commands.Keys_up); bpf.Add((int)e.Key); client.serverConnection.write(bpf.getBytes()); } lastKeyUp = (int)e.Key; lastKeyDown = 0; }
private void ConfigurableTeleportScript_KeyDown(object sender, GTA.KeyEventArgs e) { if (!isKeyPressed(Keys.End)) { return; // isKeyPressed works also on keys not watched by the script } Vector3 Target = GetPositionForKey(e.Key); if (Target.Length() == 0.0F) { return; // vector is empty } Game.FadeScreenOut(1000, true); Player.Character.Position = Target; World.LoadEnvironmentNow(Target); Game.FadeScreenIn(2000); }
private void PoliceScript_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.O) { return; } bNoPolice = !bNoPolice; if (bNoPolice) { Player.WantedLevel = 0; Game.WantedMultiplier = 0.0F; Game.DisplayText("Police will ignore you!"); } else { Game.WantedMultiplier = 1.0F; Game.DisplayText("Police will NOT ignore you!"); } }
public static void OnKeyDown(object sender, GTA.KeyEventArgs e) { switch (e.Key) { case Keys.G: Vehicle NearestVehicle = World.GetClosestVehicle(Game.LocalPlayer.Character.Position, 10.0f); if (NearestVehicle != null && NearestVehicle.Exists()) { VehicleSeat FreeSeat = NearestVehicle.GetFreePassengerSeat(); if (FreeSeat != VehicleSeat.None) { Game.LocalPlayer.Character.Task.EnterVehicle(NearestVehicle, FreeSeat); } } break; default: break; } }
private void BodyguardScript_KeyDown(object sender, GTA.KeyEventArgs e) { switch (e.Key) { case Keys.Insert: if (group.MemberCount < 3) // limit to 3 members, to make sure that all fit in a car { Ped p = World.CreatePed(PedModel, Player.Character.Position.Around(3.0F), RelationshipGroup.Player); AddToGroup(p); } break; case Keys.Delete: foreach (Ped member in group) { member.Weapons.RemoveAll(); member.Die(); } group.RemoveAllMembers(); break; } }
private void AnyTaxiScript_KeyDown(object sender, GTA.KeyEventArgs e) { switch (e.Key) { case Keys.N: switch (state) { case eState.Off: SelectedCar = World.GetClosestVehicle(Player.Character.Position, 5.0F); if (!Exists(SelectedCar)) { return; } SelectedDriver = SelectedCar.GetPedOnSeat(VehicleSeat.Driver); if (!Exists(SelectedDriver)) { SelectedDriver = SelectedCar.CreatePedOnSeat(VehicleSeat.Driver); if (!Exists(SelectedDriver)) { SelectedCar = null; return; } } else if (SelectedDriver == Player) { SelectedCar = null; SelectedDriver = null; return; } // force the game to load all path nodes, or he wouldn't be able to find the way to distant locations Game.LoadAllPathNodes = true; SelectedCar.DoorLock = 0; SelectedCar.MakeProofTo(false, false, false, true, false); // make the car collision proof, or it will blow up pretty fast // make sure that the driver won't die from his miserable driving skills SelectedDriver.Invincible = true; SelectedDriver.WillFlyThroughWindscreen = false; SelectedDriver.CanBeKnockedOffBike = false; // make sure that he will focus on his task SelectedDriver.BlockPermanentEvents = true; SelectedDriver.ChangeRelationship(RelationshipGroup.Player, Relationship.Respect); SelectedDriver.Task.ClearAll(); SelectedDriver.Task.AlwaysKeepTask = true; SelectedDriver.Task.Wait(-1); // wait until we clear the tasks again if (Player.Group.MemberCount > 0) { // Group.EnterVehicle will make sure that only members closeby try to enter the vehicle Player.Group.EnterVehicle(SelectedCar, true, true); } else { Player.Character.Task.EnterVehicle(SelectedCar, SelectedCar.GetFreePassengerSeat()); } state = eState.WaitingForPlayer; break; case eState.WaitingForPlayer: TurnDriverToNormal(); state = eState.Off; break; case eState.Driving: // Change Route case eState.ReachedTarget: if (SetDestination()) { // give the new task to the driver SelectedDriver.BlockPermanentEvents = true; SelectedDriver.Task.ClearAll(); SelectedDriver.Task.AlwaysKeepTask = true; SelectedDriver.Task.DriveTo(SelectedCar, Destination, Speed, false); state = eState.Driving; } break; } break; case Keys.M: if (state == eState.Driving) // Accelerate time when M is pressed while driving { ChangedTimescale = !ChangedTimescale; if (ChangedTimescale) { Game.TimeScale = 4.0F; } else { Game.TimeScale = 1.0F; } } break; } }
private void eventOnKeyDown(object sender, GTA.KeyEventArgs e) { if (lastKeyDown != null && lastKeyDown == (int)e.Key) { return; } if (!inKeyboardTypingMode && e.Key == System.Windows.Forms.Keys.T) { inKeyboardTypingMode = true; cursorpos = 0; historyIndex = 0; client.getPlayer().CanControlCharacter = false; } else if (inKeyboardTypingMode) { if (e.Key == System.Windows.Forms.Keys.Enter) { if (client.chatController.currentTypedText.Length > 0) { commandHistory.Add(client.chatController.currentTypedText); if (commandHistory.Count > 100) { commandHistory = commandHistory.Skip(commandHistory.Count - 100).ToList(); } var bpf = new BinaryPacketFormatter(Commands.Chat_sendMessage); bpf.Add(client.chatController.currentTypedText); client.serverConnection.write(bpf.getBytes()); } client.chatController.currentTypedText = ""; cursorpos = 0; inKeyboardTypingMode = false; client.getPlayer().CanControlCharacter = true; } else if (e.Key == System.Windows.Forms.Keys.Escape) { client.chatController.currentTypedText = ""; cursorpos = 0; inKeyboardTypingMode = false; } else if (e.Key == System.Windows.Forms.Keys.Left) { cursorpos = cursorpos > 0 ? cursorpos - 1 : cursorpos; } else if (e.Key == System.Windows.Forms.Keys.Down) { if (commandHistory.Count > 0) { if (historyIndex <= 1) { client.chatController.currentTypedText = commandHistory[commandHistory.Count - 1]; cursorpos = 0; } else { historyIndex--; if (historyIndex < 0) { historyIndex = 0; } client.chatController.currentTypedText = commandHistory[commandHistory.Count - historyIndex]; cursorpos = client.chatController.currentTypedText.Length; } } } else if (e.Key == System.Windows.Forms.Keys.Up) { if (commandHistory.Count > 0) { historyIndex++; if (historyIndex > commandHistory.Count) { historyIndex = commandHistory.Count; } client.chatController.currentTypedText = commandHistory[commandHistory.Count - historyIndex]; cursorpos = client.chatController.currentTypedText.Length; } } else if (e.Key == System.Windows.Forms.Keys.Right) { cursorpos = cursorpos >= client.chatController.currentTypedText.Length ? client.chatController.currentTypedText.Length : cursorpos + 1; } else if (e.Key == System.Windows.Forms.Keys.Back) { if (cursorpos > 0) { string leftcut = cursorpos > 0 ? client.chatController.currentTypedText.Substring(0, cursorpos - 1) : client.chatController.currentTypedText; string rightcut = client.chatController.currentTypedText.Substring(cursorpos, client.chatController.currentTypedText.Length - cursorpos); client.chatController.currentTypedText = leftcut + rightcut; cursorpos = cursorpos > 0 ? cursorpos - 1 : cursorpos; } } else { string leftcut = client.chatController.currentTypedText.Substring(0, cursorpos); string rightcut = cursorpos >= client.chatController.currentTypedText.Length ? "" : client.chatController.currentTypedText.Substring(cursorpos, client.chatController.currentTypedText.Length - cursorpos); string newstr = keyboardUS.ParseKey((int)e.Key, e.Shift, e.Control, e.Alt); client.chatController.currentTypedText = leftcut + newstr + rightcut; cursorpos += newstr.Length; } return; } if (e.Key == System.Windows.Forms.Keys.G) { Vehicle veh = World.GetClosestVehicle(client.getPlayerPed().Position, 20.0f); if (veh != null && veh.Exists()) { VehicleSeat seat = veh.GetFreePassengerSeat(); client.getPlayerPed().Task.EnterVehicle(veh, seat); } } if (client.currentState == ClientState.Connected) { var bpf = new BinaryPacketFormatter(Commands.Keys_down); bpf.Add((int)e.Key); client.serverConnection.write(bpf.getBytes()); } lastKeyDown = (int)e.Key; lastKeyUp = 0; }
/// <summary> /// Handles the KeyDown event of the BombScript control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GTA.KeyEventArgs"/> instance containing the event data.</param> private void GTAScript_KeyDown(object sender, GTA.KeyEventArgs e) { }