Advertisement
Guest User

paynspray.cs

a guest
Mar 6th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1. using GTA;
  2. using GTA.Math;
  3. using GTA.Native;
  4. using System;
  5. using System.IO;
  6. using System.Collections.Generic;
  7. using System.Windows.Forms;
  8. using System.Linq;
  9. using GTA.UI;
  10. using System.Globalization;
  11.  
  12. public class PaynSpray : Script
  13. {
  14. // List of PaynSpray points
  15. private List<PaynSprayPoint> paynSprayPoints = new List<PaynSprayPoint>();
  16.  
  17. // Configuration files
  18. private string pointsFilePath = "scripts/paynspray.ini";
  19. private string configFilePath = "scripts/paynspray.config";
  20.  
  21. // Customizable hotkeys
  22. private Keys createPointKey = Keys.E;
  23. private Keys reloadConfigKey = Keys.C;
  24.  
  25. // Default charge value for creating PaynSpray points
  26. private float defaultCharge = 100f;
  27.  
  28. // To manage the last interaction time with a PaynSpray point
  29. private Dictionary<int, DateTime> lastUseTime = new Dictionary<int, DateTime>();
  30.  
  31. public PaynSpray()
  32. {
  33. // Load configuration and points on startup
  34. LoadConfig();
  35. LoadPaynSprayPoints();
  36.  
  37. // Register events
  38. Tick += OnTick;
  39. KeyDown += OnKeyDown;
  40. }
  41.  
  42. // Event to detect key presses
  43. private void OnKeyDown(object sender, KeyEventArgs e)
  44. {
  45. if (e.Control && e.KeyCode == createPointKey) // Create new PaynSpray point
  46. {
  47. CreatePaynSprayPoint();
  48. }
  49. else if (e.Control && e.KeyCode == reloadConfigKey) // Reload configuration files
  50. {
  51. ReloadConfig();
  52. }
  53. }
  54.  
  55. // Reload configuration and points
  56. private void ReloadConfig()
  57. {
  58. LoadConfig();
  59. LoadPaynSprayPoints();
  60. Notification.Show("Pay 'n' Spray configurations and points reloaded.");
  61. }
  62.  
  63. // Load the configuration file
  64. private void LoadConfig()
  65. {
  66. if (File.Exists(configFilePath))
  67. {
  68. try
  69. {
  70. string[] lines = File.ReadAllLines(configFilePath);
  71. foreach (var line in lines)
  72. {
  73. if (line.StartsWith("createKey"))
  74. {
  75. string[] parts = line.Split('=');
  76. if (parts.Length == 2)
  77. {
  78. createPointKey = (Keys)Enum.Parse(typeof(Keys), parts[1].Trim());
  79. }
  80. }
  81. else if (line.StartsWith("reloadKey"))
  82. {
  83. string[] parts = line.Split('=');
  84. if (parts.Length == 2)
  85. {
  86. reloadConfigKey = (Keys)Enum.Parse(typeof(Keys), parts[1].Trim());
  87. }
  88. }
  89. else if (line.StartsWith("defaultCharge"))
  90. {
  91. string[] parts = line.Split('=');
  92. if (parts.Length == 2)
  93. {
  94. defaultCharge = float.Parse(parts[1].Trim(), CultureInfo.InvariantCulture);
  95. }
  96. }
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. Notification.Show("Error loading paynspray.config: " + ex.Message);
  102. }
  103. }
  104. }
  105.  
  106. // Load the PaynSpray points from the INI file
  107. private void LoadPaynSprayPoints()
  108. {
  109. paynSprayPoints.Clear();
  110. if (File.Exists(pointsFilePath))
  111. {
  112. try
  113. {
  114. string[] lines = File.ReadAllLines(pointsFilePath);
  115. foreach (var line in lines)
  116. {
  117. if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
  118. continue;
  119.  
  120. string[] data = line.Split(',');
  121. if (data.Length != 5) continue;
  122.  
  123. try
  124. {
  125. float x = float.Parse(data[0].Trim(), CultureInfo.InvariantCulture);
  126. float y = float.Parse(data[1].Trim(), CultureInfo.InvariantCulture);
  127. float z = float.Parse(data[2].Trim(), CultureInfo.InvariantCulture);
  128. float charge = float.Parse(data[3].Trim(), CultureInfo.InvariantCulture);
  129. string soundFile = data[4].Trim();
  130.  
  131. PaynSprayPoint point = new PaynSprayPoint(new Vector3(x, y, z), charge, soundFile);
  132. paynSprayPoints.Add(point);
  133. }
  134. catch
  135. {
  136. Notification.Show("Error loading a Pay 'n' Spray point.");
  137. }
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. Notification.Show("Error loading paynspray.ini: " + ex.Message);
  143. }
  144. }
  145. }
  146.  
  147. // Create a new PaynSpray point
  148. private void CreatePaynSprayPoint()
  149. {
  150. if (Game.Player.Character.IsInVehicle())
  151. {
  152. Vector3 pos = Game.Player.Character.CurrentVehicle.Position;
  153.  
  154. // Check if there is already a nearby PaynSpray point (<10 units)
  155. if (paynSprayPoints.Any(p => p.Position.DistanceTo(pos) < 10))
  156. {
  157. Notification.Show("Position too close to another Pay 'n' Spray point.");
  158. return;
  159. }
  160.  
  161. // Add the new point to the list
  162. paynSprayPoints.Add(new PaynSprayPoint(pos, defaultCharge, "spray.ogg"));
  163.  
  164. // Save the point in the INI file with invariant formatting
  165. using (StreamWriter sw = new StreamWriter(pointsFilePath, true))
  166. {
  167. sw.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}, {1}, {2}, {3}, {4}", pos.X, pos.Y, pos.Z, defaultCharge, "spray.ogg"));
  168. }
  169.  
  170. Notification.Show("New Pay 'n' Spray point created!");
  171. }
  172. else
  173. {
  174. Notification.Show("You need to be in a vehicle to create a Pay 'n' Spray point.");
  175. }
  176. }
  177.  
  178. // On each tick, draw markers and check interactions
  179. private void OnTick(object sender, EventArgs e)
  180. {
  181. Vehicle playerVehicle = Game.Player.Character.CurrentVehicle;
  182. Vector3 playerPos = Game.Player.Character.Position;
  183.  
  184. // Draw the cylinder for points within 150 units of the player
  185. foreach (var point in paynSprayPoints)
  186. {
  187. if (playerPos.DistanceTo(point.Position) <= 150f)
  188. {
  189. World.DrawMarker(MarkerType.Cylinder, point.Position + new Vector3(0, 0, -1),
  190. Vector3.Zero, Vector3.Zero, new Vector3(3, 3, 1), System.Drawing.Color.Green);
  191. }
  192. }
  193.  
  194. // If the player is in a vehicle, check if they have entered a PaynSpray point
  195. if (playerVehicle == null) return;
  196. foreach (var point in paynSprayPoints)
  197. {
  198. if (playerVehicle.Position.DistanceTo(point.Position) < 5f)
  199. {
  200. if (!lastUseTime.ContainsKey(playerVehicle.Handle) || (DateTime.Now - lastUseTime[playerVehicle.Handle]).TotalSeconds > 10)
  201. {
  202. // Check if the player's vehicle is stopped
  203. if (!Function.Call<bool>((Hash)0x1CE980E99A2A6FB6, playerVehicle.Handle))
  204. {
  205. continue;
  206. }
  207.  
  208. // Check if the player's vehicle is an emergency vehicle (cop cars and ambulances cannot be resprayed)
  209. if (playerVehicle.ClassType == VehicleClass.Emergency)
  210. {
  211. Notification.Show("Emergency vehicles cannot be resprayed.");
  212. continue;
  213. }
  214.  
  215. // Check if the player's wanted stars are solid (active pursuit).
  216. if (Function.Call<bool>((Hash)0x9780872414DA43F8, Game.Player))
  217. {
  218. Notification.Show("Cannot use Pay 'n' Spray while under active pursuit.");
  219. continue;
  220. }
  221.  
  222. if (Game.Player.Money >= point.Charge)
  223. {
  224. // Fade to black for 1 second
  225. Function.Call(Hash.DO_SCREEN_FADE_OUT, 1000);
  226. while (!Function.Call<bool>(Hash.IS_SCREEN_FADED_OUT))
  227. {
  228. Wait(0);
  229. }
  230.  
  231. Game.Player.Money -= (int)point.Charge;
  232.  
  233. string soundPath = "scripts/" + point.SoundFile;
  234. if (File.Exists(soundPath))
  235. {
  236. Function.Call(Hash.PLAY_SOUND_FROM_ENTITY, soundPath, playerVehicle.Handle);
  237. }
  238.  
  239. Random rand = new Random();
  240. playerVehicle.Mods.PrimaryColor = (VehicleColor)rand.Next(0, Enum.GetValues(typeof(VehicleColor)).Length);
  241. playerVehicle.Mods.SecondaryColor = (VehicleColor)rand.Next(0, Enum.GetValues(typeof(VehicleColor)).Length);
  242.  
  243. if (Game.Player.WantedLevel > 0)
  244. {
  245. Game.Player.WantedLevel = 0;
  246. }
  247.  
  248. // Fade back in for 1 second
  249. Function.Call(Hash.DO_SCREEN_FADE_IN, 1000);
  250. while (!Function.Call<bool>(Hash.IS_SCREEN_FADED_IN))
  251. {
  252. Wait(0);
  253. }
  254.  
  255. Notification.Show("Thank you for using Pay 'n' Spray!");
  256. lastUseTime[playerVehicle.Handle] = DateTime.Now;
  257. }
  258. else
  259. {
  260. Notification.Show("Insufficient funds to use Pay 'n' Spray.");
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267.  
  268. public class PaynSprayPoint
  269. {
  270. public Vector3 Position { get; set; }
  271. public float Charge { get; set; }
  272. public string SoundFile { get; set; }
  273.  
  274. public PaynSprayPoint(Vector3 position, float charge, string soundFile)
  275. {
  276. Position = position;
  277. Charge = charge;
  278. SoundFile = soundFile;
  279. }
  280. }
  281.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement