Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GTA;
- using GTA.Math;
- using GTA.Native;
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Linq;
- using GTA.UI;
- using System.Globalization;
- public class PaynSpray : Script
- {
- // List of PaynSpray points
- private List<PaynSprayPoint> paynSprayPoints = new List<PaynSprayPoint>();
- // Configuration files
- private string pointsFilePath = "scripts/paynspray.ini";
- private string configFilePath = "scripts/paynspray.config";
- // Customizable hotkeys
- private Keys createPointKey = Keys.E;
- private Keys reloadConfigKey = Keys.C;
- // Default charge value for creating PaynSpray points
- private float defaultCharge = 100f;
- // To manage the last interaction time with a PaynSpray point
- private Dictionary<int, DateTime> lastUseTime = new Dictionary<int, DateTime>();
- public PaynSpray()
- {
- // Load configuration and points on startup
- LoadConfig();
- LoadPaynSprayPoints();
- // Register events
- Tick += OnTick;
- KeyDown += OnKeyDown;
- }
- // Event to detect key presses
- private void OnKeyDown(object sender, KeyEventArgs e)
- {
- if (e.Control && e.KeyCode == createPointKey) // Create new PaynSpray point
- {
- CreatePaynSprayPoint();
- }
- else if (e.Control && e.KeyCode == reloadConfigKey) // Reload configuration files
- {
- ReloadConfig();
- }
- }
- // Reload configuration and points
- private void ReloadConfig()
- {
- LoadConfig();
- LoadPaynSprayPoints();
- Notification.Show("Pay 'n' Spray configurations and points reloaded.");
- }
- // Load the configuration file
- private void LoadConfig()
- {
- if (File.Exists(configFilePath))
- {
- try
- {
- string[] lines = File.ReadAllLines(configFilePath);
- foreach (var line in lines)
- {
- if (line.StartsWith("createKey"))
- {
- string[] parts = line.Split('=');
- if (parts.Length == 2)
- {
- createPointKey = (Keys)Enum.Parse(typeof(Keys), parts[1].Trim());
- }
- }
- else if (line.StartsWith("reloadKey"))
- {
- string[] parts = line.Split('=');
- if (parts.Length == 2)
- {
- reloadConfigKey = (Keys)Enum.Parse(typeof(Keys), parts[1].Trim());
- }
- }
- else if (line.StartsWith("defaultCharge"))
- {
- string[] parts = line.Split('=');
- if (parts.Length == 2)
- {
- defaultCharge = float.Parse(parts[1].Trim(), CultureInfo.InvariantCulture);
- }
- }
- }
- }
- catch (Exception ex)
- {
- Notification.Show("Error loading paynspray.config: " + ex.Message);
- }
- }
- }
- // Load the PaynSpray points from the INI file
- private void LoadPaynSprayPoints()
- {
- paynSprayPoints.Clear();
- if (File.Exists(pointsFilePath))
- {
- try
- {
- string[] lines = File.ReadAllLines(pointsFilePath);
- foreach (var line in lines)
- {
- if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
- continue;
- string[] data = line.Split(',');
- if (data.Length != 5) continue;
- try
- {
- float x = float.Parse(data[0].Trim(), CultureInfo.InvariantCulture);
- float y = float.Parse(data[1].Trim(), CultureInfo.InvariantCulture);
- float z = float.Parse(data[2].Trim(), CultureInfo.InvariantCulture);
- float charge = float.Parse(data[3].Trim(), CultureInfo.InvariantCulture);
- string soundFile = data[4].Trim();
- PaynSprayPoint point = new PaynSprayPoint(new Vector3(x, y, z), charge, soundFile);
- paynSprayPoints.Add(point);
- }
- catch
- {
- Notification.Show("Error loading a Pay 'n' Spray point.");
- }
- }
- }
- catch (Exception ex)
- {
- Notification.Show("Error loading paynspray.ini: " + ex.Message);
- }
- }
- }
- // Create a new PaynSpray point
- private void CreatePaynSprayPoint()
- {
- if (Game.Player.Character.IsInVehicle())
- {
- Vector3 pos = Game.Player.Character.CurrentVehicle.Position;
- // Check if there is already a nearby PaynSpray point (<10 units)
- if (paynSprayPoints.Any(p => p.Position.DistanceTo(pos) < 10))
- {
- Notification.Show("Position too close to another Pay 'n' Spray point.");
- return;
- }
- // Add the new point to the list
- paynSprayPoints.Add(new PaynSprayPoint(pos, defaultCharge, "spray.ogg"));
- // Save the point in the INI file with invariant formatting
- using (StreamWriter sw = new StreamWriter(pointsFilePath, true))
- {
- sw.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}, {1}, {2}, {3}, {4}", pos.X, pos.Y, pos.Z, defaultCharge, "spray.ogg"));
- }
- Notification.Show("New Pay 'n' Spray point created!");
- }
- else
- {
- Notification.Show("You need to be in a vehicle to create a Pay 'n' Spray point.");
- }
- }
- // On each tick, draw markers and check interactions
- private void OnTick(object sender, EventArgs e)
- {
- Vehicle playerVehicle = Game.Player.Character.CurrentVehicle;
- Vector3 playerPos = Game.Player.Character.Position;
- // Draw the cylinder for points within 150 units of the player
- foreach (var point in paynSprayPoints)
- {
- if (playerPos.DistanceTo(point.Position) <= 150f)
- {
- World.DrawMarker(MarkerType.Cylinder, point.Position + new Vector3(0, 0, -1),
- Vector3.Zero, Vector3.Zero, new Vector3(3, 3, 1), System.Drawing.Color.Green);
- }
- }
- // If the player is in a vehicle, check if they have entered a PaynSpray point
- if (playerVehicle == null) return;
- foreach (var point in paynSprayPoints)
- {
- if (playerVehicle.Position.DistanceTo(point.Position) < 5f)
- {
- if (!lastUseTime.ContainsKey(playerVehicle.Handle) || (DateTime.Now - lastUseTime[playerVehicle.Handle]).TotalSeconds > 10)
- {
- // Check if the player's vehicle is stopped
- if (!Function.Call<bool>((Hash)0x1CE980E99A2A6FB6, playerVehicle.Handle))
- {
- continue;
- }
- // Check if the player's vehicle is an emergency vehicle (cop cars and ambulances cannot be resprayed)
- if (playerVehicle.ClassType == VehicleClass.Emergency)
- {
- Notification.Show("Emergency vehicles cannot be resprayed.");
- continue;
- }
- // Check if the player's wanted stars are solid (active pursuit).
- if (Function.Call<bool>((Hash)0x9780872414DA43F8, Game.Player))
- {
- Notification.Show("Cannot use Pay 'n' Spray while under active pursuit.");
- continue;
- }
- if (Game.Player.Money >= point.Charge)
- {
- // Fade to black for 1 second
- Function.Call(Hash.DO_SCREEN_FADE_OUT, 1000);
- while (!Function.Call<bool>(Hash.IS_SCREEN_FADED_OUT))
- {
- Wait(0);
- }
- Game.Player.Money -= (int)point.Charge;
- string soundPath = "scripts/" + point.SoundFile;
- if (File.Exists(soundPath))
- {
- Function.Call(Hash.PLAY_SOUND_FROM_ENTITY, soundPath, playerVehicle.Handle);
- }
- Random rand = new Random();
- playerVehicle.Mods.PrimaryColor = (VehicleColor)rand.Next(0, Enum.GetValues(typeof(VehicleColor)).Length);
- playerVehicle.Mods.SecondaryColor = (VehicleColor)rand.Next(0, Enum.GetValues(typeof(VehicleColor)).Length);
- if (Game.Player.WantedLevel > 0)
- {
- Game.Player.WantedLevel = 0;
- }
- // Fade back in for 1 second
- Function.Call(Hash.DO_SCREEN_FADE_IN, 1000);
- while (!Function.Call<bool>(Hash.IS_SCREEN_FADED_IN))
- {
- Wait(0);
- }
- Notification.Show("Thank you for using Pay 'n' Spray!");
- lastUseTime[playerVehicle.Handle] = DateTime.Now;
- }
- else
- {
- Notification.Show("Insufficient funds to use Pay 'n' Spray.");
- }
- }
- }
- }
- }
- }
- public class PaynSprayPoint
- {
- public Vector3 Position { get; set; }
- public float Charge { get; set; }
- public string SoundFile { get; set; }
- public PaynSprayPoint(Vector3 position, float charge, string soundFile)
- {
- Position = position;
- Charge = charge;
- SoundFile = soundFile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement