Guest User

Untitled

a guest
Nov 22nd, 2015
253
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using GTA;
  11. using GTA.Native;
  12. using GTA.Math;
  13.  
  14.  
  15. namespace ArrestWarrant
  16. {
  17.     public class ArrestWarrant : Script
  18.     {
  19.         private string _vehicleUsed;
  20.         private string _vehicleColor;
  21.         private string _vehiclePlate;
  22.         private Vehicle _vehicle;
  23.         private string _pedModel;
  24.         private int _lastDay;
  25.  
  26.         private Sprite gradientTimer;
  27.         private Sprite carSprite;
  28.         private Sprite pedSprite;
  29.         private UIText wantedHud;
  30.  
  31.         private bool _warrantActive;
  32.  
  33.         private Dictionary<int, float> wantedMultiplier = new Dictionary<int, float>();
  34.         private int lastWanted;
  35.  
  36.         private int[] drawablesArray = new int[15];
  37.         private int[] texturesArray = new int[15];
  38.  
  39.  
  40.         private Dictionary<int, Scaleform> _copBars = new Dictionary<int, Scaleform>();
  41.  
  42.         private float carPlateRecognisedMultiplier = 0.2f;
  43.         private float carColorRecognisedMultiplier = 0.2f;
  44.         private float carPlayerRecognisedMultiplier = 0.1f;
  45.         private float onFootPlayerRecognisedMultiplier = 0.3f;
  46.  
  47.  
  48.         public ArrestWarrant()
  49.         {
  50.             Tick += OnTick;
  51.             KeyDown += OnKeyDown;
  52.  
  53.             carSprite = new Sprite("mpinventory", "mp_specitem_car", new Point(UI.WIDTH - 200, UI.HEIGHT - 20), new Size(20, 20));
  54.             pedSprite = new Sprite("mpinventory", "mp_specitem_ped", new Point(UI.WIDTH - 180, UI.HEIGHT - 20), new Size(20, 20));
  55.  
  56.             gradientTimer = new Sprite("timerbars", "all_red_bg", new Point(UI.WIDTH - 890, UI.HEIGHT - 20), new Size(900, 20));
  57.             wantedHud = new UIText("~w~WARRANT ACTIVE", new Point(UI.WIDTH-155, UI.HEIGHT-20), 0.4f);
  58.  
  59.             ScriptSettings settings = ScriptSettings.Load("scripts\\ArrestWarrant.ini");
  60.             if (settings != null)
  61.             {
  62.                 carPlateRecognisedMultiplier = settings.GetValue("COP_MULTIPLIER", "carPlateRecognisedMultiplier", 0.2f);
  63.                 carColorRecognisedMultiplier = settings.GetValue("COP_MULTIPLIER", "carColorRecognisedMultiplier", 0.2f);
  64.                 carPlayerRecognisedMultiplier = settings.GetValue("COP_MULTIPLIER", "carPlayerRecognisedMultiplier", 0.1f);
  65.                 onFootPlayerRecognisedMultiplier = settings.GetValue("COP_MULTIPLIER", "onFootPlayerRecognisedMultiplier", 0.3f);
  66.             }
  67.         }
  68.  
  69.         void OnTick(object sender, EventArgs e)
  70.         {
  71.             Ped player = Game.Player.Character;
  72.             int currentWantedLevel = Game.Player.WantedLevel;
  73.  
  74.             if (_vehicle != null)
  75.                 if(player.IsInVehicle(_vehicle))
  76.                     _warrantActive = true;
  77.  
  78.             if(currentWantedLevel > 0)
  79.                 lastWanted = currentWantedLevel;
  80.  
  81.             if (_warrantActive)
  82.             {
  83.                 string name = Function.Call<String>((Hash)0x198D161F458ECC7F);
  84.                 wantedHud.Draw();
  85.                 gradientTimer.Draw();
  86.  
  87.                 if(!String.IsNullOrEmpty(_pedModel))
  88.                     pedSprite.Draw();
  89.  
  90.                 if (player.IsInVehicle())
  91.                 {
  92.                     if(player.CurrentVehicle == _vehicle)
  93.                         carSprite.Draw();
  94.                 }
  95.                    
  96.  
  97.                 int[] tmpDrawables = new int[15];
  98.                 int[] tmpTextures = new int[15];
  99.  
  100.                 for (int i = 0; i < drawablesArray.Length; i++)
  101.                 {
  102.                     tmpDrawables[i] = Function.Call<int>(Hash.GET_PED_DRAWABLE_VARIATION,
  103.                         new InputArgument(player), i);
  104.                     tmpTextures[i] = Function.Call<int>(Hash.GET_PED_TEXTURE_VARIATION,
  105.                         new InputArgument(player), i);
  106.                 }
  107.  
  108.                 if ((!tmpDrawables.SequenceEqual(drawablesArray) || !tmpTextures.SequenceEqual(texturesArray) || SplitCamelCase(((PedHash)player.Model.Hash).ToString()) != _pedModel) && currentWantedLevel == 0)
  109.                 {
  110.                     if (_vehicle == null)
  111.                     {
  112.                         _warrantActive = false;
  113.                         _pedModel = null;
  114.                     }
  115.                     else if (!player.IsInVehicle(_vehicle))
  116.                     {
  117.                         _warrantActive = false;
  118.                         _pedModel = null;
  119.                     }
  120.                 }
  121.                 if (player.IsDead || (Function.Call<int>(Hash.GET_TIME_SINCE_LAST_ARREST) < 10 && Function.Call<int>(Hash.GET_TIME_SINCE_LAST_ARREST) != -1))
  122.                 {
  123.                     _warrantActive = false;
  124.                     _pedModel = null;
  125.                     _vehicleUsed = null;
  126.                 }
  127.             }
  128.  
  129.            
  130.             if (currentWantedLevel > 0 && !_warrantActive)
  131.             {
  132.                 if (player.IsInVehicle())
  133.                 {
  134.                     string name = Function.Call<String>((Hash) 0x198D161F458ECC7F);
  135.                     string model = ((VehicleHash) player.CurrentVehicle.Model.Hash).ToString();
  136.                     string color = SplitCamelCase(player.CurrentVehicle.PrimaryColor.ToString());
  137.                     string plate = player.CurrentVehicle.NumberPlate;
  138.  
  139.                     string warrant2 =
  140.                         String.Format(
  141.                             "Vehicle description: Model ~b~{0}~w~, Color ~b~{1}~w~, License ~b~{2}~w~",
  142.                             SplitCamelCase(model), color, plate);
  143.                     PictureNotification("~r~WARRANT ISSUED", "", "Unidentified criminal escaping on vehicle.", 0);
  144.                     UI.Notify(warrant2);
  145.  
  146.                     _vehicleUsed = model;
  147.                     _vehicleColor = color;
  148.                     _vehiclePlate = plate;
  149.                     _vehicle = player.CurrentVehicle;
  150.  
  151.                     _warrantActive = true;
  152.                 }
  153.                 else
  154.                 {
  155.                     string name = Function.Call<String>((Hash) 0x198D161F458ECC7F);
  156.                     string pedModel = ((PedHash) player.Model.Hash).ToString();
  157.                     string warrant =
  158.                         String.Format("Criminal identified as {0}, escaping on foot.", SplitCamelCase(pedModel));
  159.                     PictureNotification("~r~ARREST WARRANT ISSUED", "", warrant, 0, pedModel == "Michael" ? "CHAR_MICHAEL" : pedModel == "Trevor" ? "CHAR_TREVOR" : pedModel == "Franklin" ? "CHAR_FRANKLIN" : "CHAR_DEFAULT");
  160.                     _pedModel = SplitCamelCase(pedModel);
  161.  
  162.                     for (int i = 0; i < drawablesArray.Length; i++)
  163.                     {
  164.                         drawablesArray[i] = Function.Call<int>(Hash.GET_PED_DRAWABLE_VARIATION,
  165.                             new InputArgument(player), i);
  166.                         texturesArray[i] = Function.Call<int>(Hash.GET_PED_TEXTURE_VARIATION,
  167.                             new InputArgument(player), i);
  168.                     }
  169.  
  170.                     _warrantActive = true;
  171.                 }
  172.             }
  173.             else if (currentWantedLevel == 0 && _warrantActive)
  174.             {
  175.                 int currentDay = Function.Call<int>(Hash.GET_CLOCK_DAY_OF_MONTH);
  176.                 if (currentDay % _lastDay > lastWanted && _lastDay != -1)
  177.                 {
  178.                     _warrantActive = false;
  179.                     _lastDay = -1;
  180.                     PictureNotification("~b~ARREST WARRANT RECALLED", "", "Your arrest warrant has been recalled.", 0, _pedModel == "Michael" ? "CHAR_MICHAEL" : _pedModel == "Trevor" ? "CHAR_TREVOR" : _pedModel == "Franklin" ? "CHAR_FRANKLIN" : "CHAR_DEFAULT");
  181.                 }
  182.                 Ped[] nearbyPeds = World.GetNearbyPeds(player, 80f);
  183.                 foreach (var nearbyPed in from nearbyPed in nearbyPeds let los = Function.Call<bool>(Hash.HAS_ENTITY_CLEAR_LOS_TO_ENTITY_IN_FRONT, nearbyPed, player) where IsPedCop(nearbyPed) where los select nearbyPed)
  184.                 {
  185.                     if (_copBars.ContainsKey(nearbyPed.Handle) && wantedMultiplier.ContainsKey(nearbyPed.Handle))
  186.                     {
  187.                         if (player.IsInVehicle())
  188.                         {
  189.                             float multiplier = 0.00f;
  190.                             if (SplitCamelCase(((VehicleHash) player.CurrentVehicle.Model.Hash).ToString()) ==
  191.                                 _vehicleUsed)
  192.                             {
  193.                                 if (player.CurrentVehicle.NumberPlate == _vehiclePlate)
  194.                                     multiplier += carPlateRecognisedMultiplier;
  195.                                 if (SplitCamelCase(player.CurrentVehicle.PrimaryColor.ToString()) ==
  196.                                     _vehicleColor)
  197.                                     multiplier += carColorRecognisedMultiplier;
  198.                             }
  199.                             if (SplitCamelCase(((PedHash) player.Model.Hash).ToString()) == _pedModel)
  200.                                 multiplier += carPlayerRecognisedMultiplier;
  201.                             wantedMultiplier[nearbyPed.Handle] += multiplier;
  202.                         }
  203.                         else
  204.                         {
  205.                             wantedMultiplier[nearbyPed.Handle] += onFootPlayerRecognisedMultiplier;
  206.                         }
  207.                         if (!Function.Call<bool>(Hash.IS_ENTITY_ON_SCREEN, new InputArgument(nearbyPed)))
  208.                             continue;
  209.                         _copBars[nearbyPed.Handle].CallFunction("SET_PLAYER_NAME",
  210.                             "Alertness: " + wantedMultiplier[nearbyPed.Handle].ToString("##"));
  211.                         Vector3 rotationVector = player.Position - nearbyPed.Position;
  212.                         float yaw = 57.2957795f * ((float)Math.Atan(rotationVector.X / rotationVector.Y));
  213.                         if (player.Position.X > nearbyPed.Position.X)
  214.                             yaw += 180f;
  215.                         if (player.Position.Y > nearbyPed.Position.Y)
  216.                             yaw += 180f;
  217.                         _copBars[nearbyPed.Handle].Render3D(nearbyPed.Position + new Vector3(0, 0, 2f),
  218.                             new Vector3(0, 0, Math.Abs(yaw)), new Vector3(6, 3, 1));
  219.                         if (wantedMultiplier[nearbyPed.Handle] > 100f)
  220.                         {
  221.                             Game.Player.WantedLevel = lastWanted;
  222.                         }
  223.                     }
  224.                     else
  225.                     {
  226.                         Scaleform floatingBar = new Scaleform(0);
  227.                         _copBars.Add(nearbyPed.Handle, floatingBar);
  228.                         wantedMultiplier.Add(nearbyPed.Handle, 1f);
  229.                         _copBars[nearbyPed.Handle].Load("PLAYER_NAME_01");
  230.                     }
  231.                 }
  232.                
  233.             }
  234.             if (Game.Player.WantedLevel != 0 && !Function.Call<bool>(Hash.ARE_PLAYER_STARS_GREYED_OUT, new InputArgument(Game.Player)))
  235.             {
  236.                 if (player.IsInVehicle())
  237.                 {
  238.                     string model = ((VehicleHash)player.CurrentVehicle.Model.Hash).ToString();
  239.                     string color = SplitCamelCase(player.CurrentVehicle.PrimaryColor.ToString());
  240.                     string plate = player.CurrentVehicle.NumberPlate;
  241.                     if (model != _vehicleUsed)
  242.                     {
  243.                         //car changed
  244.                         string warrant2 =
  245.                         String.Format(
  246.                             "Vehicle Model ~b~{0}~w~, Color ~b~{1}~w~, License ~b~{2}~w~",
  247.                             SplitCamelCase(model), color, plate);
  248.                         //UI.Notify(warrant2);
  249.                         PictureNotification("~r~ARREST WARRANT UPDATED", "", warrant2, 0);
  250.                     }
  251.                     _vehicleUsed = model;
  252.                     _vehicleColor = color;
  253.                     _vehiclePlate = plate;
  254.                     _vehicle = player.CurrentVehicle;
  255.                 }
  256.                 else
  257.                 {
  258.                     string pedModel = ((PedHash)player.Model.Hash).ToString();
  259.                     if (SplitCamelCase(pedModel) != _pedModel)
  260.                     {
  261.                         //identified
  262.                         string warrant = String.Format("Criminal has been identified as {0}, escaping on foot.", SplitCamelCase(pedModel));
  263.                         PictureNotification("~r~ARREST WARRANT UPDATED", "", warrant, 0, pedModel == "Michael" ? "CHAR_MICHAEL" : pedModel == "Trevor" ? "CHAR_TREVOR" : pedModel == "Franklin" ? "CHAR_FRANKLIN" : "CHAR_DEFAULT");
  264.                     }
  265.                     _pedModel = SplitCamelCase(pedModel);
  266.                 }
  267.                 _lastDay = Function.Call<int>(Hash.GET_CLOCK_DAY_OF_MONTH);
  268.             }
  269.            
  270.  
  271.         }
  272.  
  273.         bool IsPedCop(Ped ped)
  274.         {
  275.             Vector3 maxVector3 = ped.Position + new Vector3(2f, 2f, 2f);
  276.             Vector3 minVector3 = ped.Position - new Vector3(2f, 2f, 2f);
  277.             return Function.Call<bool>(Hash.IS_COP_PED_IN_AREA_3D, maxVector3.X, maxVector3.Y, maxVector3.Z, minVector3.X, minVector3.Y, minVector3.Z);
  278.         }
  279.  
  280.         //Blip sprites
  281.         //Garbage truck: 319
  282.         //Defaul cop: 3
  283.         //handcuffs 188
  284.  
  285.         void OnKeyDown(object sender, KeyEventArgs e)
  286.         {
  287.             Ped player = Game.Player.Character;
  288.         }
  289.  
  290.         string SplitCamelCase(string s)
  291.         {
  292.             return Regex.Replace(s, @"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1");
  293.         }
  294.  
  295.         private void PictureNotification(string sender, string subject, string text, int icon, string texture = "CHAR_DEFAULT")
  296.         {
  297.             Function.Call(Hash._SET_NOTIFICATION_TEXT_ENTRY, "STRING");
  298.             Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  299.             Function.Call(Hash._0x1CCD9A37359072CF, texture, texture, true, icon, sender, subject);
  300.         }
  301.  
  302.     }
  303. }
RAW Paste Data