Advertisement
Guest User

paynspray.cs

a guest
Mar 5th, 2025
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.14 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("PaynSpray 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. // Create the icon (blip) on the map
  135. Blip blip = World.CreateBlip(point.Position);
  136. blip.Sprite = BlipSprite.LosSantosCustoms;
  137. blip.Color = BlipColor.Green;
  138. blip.IsShortRange = true;
  139. try { blip.Name = "Pay 'n' Spray"; } catch { }
  140. }
  141. catch
  142. {
  143. Notification.Show("Error loading a PaynSpray point.");
  144. }
  145. }
  146. }
  147. catch (Exception ex)
  148. {
  149. Notification.Show("Error loading paynspray.ini: " + ex.Message);
  150. }
  151. }
  152. }
  153.  
  154. // Create a new PaynSpray point
  155. private void CreatePaynSprayPoint()
  156. {
  157. if (Game.Player.Character.IsInVehicle())
  158. {
  159. Vector3 pos = Game.Player.Character.CurrentVehicle.Position;
  160.  
  161. // Check if there is already a nearby PaynSpray point (<10 units)
  162. if (paynSprayPoints.Any(p => p.Position.DistanceTo(pos) < 10))
  163. {
  164. Notification.Show("Position too close to another PaynSpray point.");
  165. return;
  166. }
  167.  
  168. // Add the new point to the list
  169. paynSprayPoints.Add(new PaynSprayPoint(pos, defaultCharge, "spray.ogg"));
  170.  
  171. // Save the point in the INI file with invariant formatting
  172. using (StreamWriter sw = new StreamWriter(pointsFilePath, true))
  173. {
  174. sw.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}, {1}, {2}, {3}, {4}", pos.X, pos.Y, pos.Z, defaultCharge, "spray.ogg"));
  175. }
  176.  
  177. Notification.Show("New PaynSpray point created!");
  178. }
  179. else
  180. {
  181. Notification.Show("You need to be in a vehicle to create a PaynSpray point.");
  182. }
  183. }
  184.  
  185. // On each tick, draw markers and check interactions
  186. private void OnTick(object sender, EventArgs e)
  187. {
  188. Vehicle playerVehicle = Game.Player.Character.CurrentVehicle;
  189. Vector3 playerPos = Game.Player.Character.Position;
  190.  
  191. // Draw the cylinder for points within 150 units of the player
  192. foreach (var point in paynSprayPoints)
  193. {
  194. if (playerPos.DistanceTo(point.Position) <= 150f)
  195. {
  196. World.DrawMarker(MarkerType.Cylinder, point.Position + new Vector3(0, 0, -1),
  197. Vector3.Zero, Vector3.Zero, new Vector3(3, 3, 1), System.Drawing.Color.Green);
  198. }
  199. }
  200.  
  201. // If the player is in a vehicle, check if they have entered a PaynSpray point
  202. if (playerVehicle == null) return;
  203. foreach (var point in paynSprayPoints)
  204. {
  205. if (playerVehicle.Position.DistanceTo(point.Position) < 5f)
  206. {
  207. if (!lastUseTime.ContainsKey(playerVehicle.Handle) || (DateTime.Now - lastUseTime[playerVehicle.Handle]).TotalSeconds > 10)
  208. {
  209. // Check if the player's vehicle is an emergency vehicle (cop cars and ambulances cannot be resprayed)
  210. if (playerVehicle.ClassType == VehicleClass.Emergency)
  211. {
  212. Notification.Show("Emergency vehicles cannot be resprayed.");
  213. continue;
  214. }
  215.  
  216. // Check if the player's wanted stars are solid (active pursuit).
  217. // ARE_WANTED_STARS_FLASHING is expected to return true when the stars are flashing (greyed-out).
  218. // If the player has a wanted level and the stars are not flashing, skip the PaynSpray action.
  219. if (Function.Call<bool>((Hash)0x9780872414DA43F8, Game.Player))
  220. {
  221. Notification.Show("Cannot use Pay 'n' Spray while under active pursuit.");
  222. continue;
  223. }
  224.  
  225. if (Game.Player.Money >= point.Charge)
  226. {
  227. Game.Player.Money -= (int)point.Charge;
  228.  
  229. string soundPath = "scripts/" + point.SoundFile;
  230. if (File.Exists(soundPath))
  231. {
  232. Function.Call(Hash.PLAY_SOUND_FROM_ENTITY, soundPath, playerVehicle.Handle);
  233. }
  234.  
  235. Random rand = new Random();
  236. playerVehicle.Mods.PrimaryColor = (VehicleColor)rand.Next(0, Enum.GetValues(typeof(VehicleColor)).Length);
  237. playerVehicle.Mods.SecondaryColor = (VehicleColor)rand.Next(0, Enum.GetValues(typeof(VehicleColor)).Length);
  238.  
  239. if (Game.Player.WantedLevel > 0)
  240. {
  241. Game.Player.WantedLevel = 0;
  242. }
  243.  
  244. Notification.Show("Thank you for using PaynSpray!");
  245. lastUseTime[playerVehicle.Handle] = DateTime.Now;
  246. }
  247. else
  248. {
  249. Notification.Show("Insufficient funds to use PaynSpray.");
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256.  
  257. public class PaynSprayPoint
  258. {
  259. public Vector3 Position { get; set; }
  260. public float Charge { get; set; }
  261. public string SoundFile { get; set; }
  262.  
  263. public PaynSprayPoint(Vector3 position, float charge, string soundFile)
  264. {
  265. Position = position;
  266. Charge = charge;
  267. SoundFile = soundFile;
  268. }
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement