using GTA; using GTA.Math; using GTA.Native; using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; public class GateLock : Script { Keys toggleKey; float radius; Model[] gateModels; bool lockInPos; public GateLock() { toggleKey = Settings.GetValue("Settings", "ToggleKey", Keys.L); radius = Settings.GetValue("Settings", "Radius", 20f); lockInPos = Settings.GetValue("Settings", "DefaultLocked", true); ReadModels(); Interval = 100; Tick += OnTick; KeyDown += OnKeyDown; } private void OnTick(object sender, EventArgs e) { LockGates(); } private void OnKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == toggleKey && AnyModelsNearby(Game.Player.Character.Position)) { lockInPos = !lockInPos; if (lockInPos) GTA.UI.Screen.ShowSubtitle("LOCKED IN PLACE"); else GTA.UI.Screen.ShowSubtitle("UNLOCKED"); } } private bool AnyModelsNearby(Vector3 pos) { foreach (Model model in gateModels) { if (Function.Call(Hash.DOES_OBJECT_OF_TYPE_EXIST_AT_COORDS, pos.X, pos.Y, pos.Z, radius, model.Hash, 0)) { return true; } } return false; } private void ReadModels() { if (File.Exists("./scripts/Gates.txt")) { List models = new List(); string[] strArrModels = File.ReadAllLines("./scripts/Gates.txt"); foreach (string strModel in strArrModels) { Model model = new Model(strModel.Trim()); if (model.IsValid) { models.Add(model); } } if (models.Count > 0) { gateModels = models.ToArray(); } } } private void LockGates() { Vector3 pos = Game.Player.Character.Position; foreach (Model model in gateModels) { if (Function.Call(Hash.DOES_OBJECT_OF_TYPE_EXIST_AT_COORDS, pos.X, pos.Y, pos.Z, radius, model.Hash, 0)) { Prop prop = (Prop)Entity.FromHandle(Function.Call(Hash.GET_CLOSEST_OBJECT_OF_TYPE, pos.X, pos.Y, pos.Z, radius, model.Hash, false, 0, 0)); if (prop.Exists()) { prop.IsPositionFrozen = lockInPos; } } } } }