# SafePoints Version 1.3 [Source Code]

Nov 25th, 2021 (edited)
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //
2. //
3. // SAFEPOINTS - LOSE YOUR WANTED STARS v1.3 [C#]
5. //
6. // THIS IS MY VERY FIRST MOD SO THE SOURCE CODE IS ACCORDINGLY NOT HIGH QUALITY.
7. // I HAVE LEFT COMMENTS EVERYWHERE IN THE CODE SO THAT BEGINNERS CAN FIND THEIR WAY AROUND BETTER.
8. // HAVE FUN EXPERIMENTING AROUND
9. //
10. // PERMISSION:
11. // ANYONE CAN USE THIS SOURCE CODE TO WRITE THEIR OWN MOD. IF YOU DECIDE TO UPLOAD THIS, PLEASE GIVE ME CREDITS.
12. //
13. //
14. using System;
15. using GTA;              //Install "ScriptHookV2" via NuGet
16. using GTA.Math;         //Otherwise you dont need any further references
17. using GTA.Native;
18.
19. namespace SafePoints
20. {
21.     public class SafePoints : Script
22.     {
23.         // The coordinates of the individual points are each stored in a variable
24.         // Simply copy paste a cwXCoord and fill it with the coordinates of a point you have chosen.
25.         Vector3 cw1Coord = new Vector3(135f, -1050f, 28f), //Pillbox Hill
26.             cw2Coord = new Vector3(964f, -1856f, 30f), //San Andreas
27.             cw3Coord = new Vector3(-676f, 902f, 230f), //Vinewood Mid
28.             cw4Coord = new Vector3(147f, 320f, 111f), //Vinewoods Hills
29.             cw5Coord = new Vector3(259f, 2587f, 44f), //Harmony
30.             cw6Coord = new Vector3(-1359f, -757f, 21f), //Del Perro
31.             cw7Coord = new Vector3(-459f, -2283f, 6.600f), //Elysian Island
32.             cw8Coord = new Vector3(1341.673f, 4319.541f, 37f), //Galilee
33.             cw9Coord = new Vector3(3804f, 4440f, 3f), //San-Chianski / Catfish View
34.             cw10Coord = new Vector3(280f, 6801f, 14.715f), //Paleto Bay
35.             cw11Coord = new Vector3(-1133f, 4964f, 220f), //Chiliad-Mountain
36.             cw12Coord = new Vector3(-2353f, 263f, 164f); //Pacific Bluffs
37.
38.         // These are the integer where we will store the amount of money you specify in the .ini file
39.         readonly int moneyToTake, moneyToTake2, moneyToTake3, moneyToTake4, moneyToTake5;
40.
41.         // Here we declare the config file (.ini)
42.         ScriptSettings config;
43.
44.         // Here we declare the blips (the round things on the map)
45.         Blip loc1Blip, loc2Blip, loc3Blip, loc4Blip, loc5Blip, loc6Blip, loc7Blip, loc8Blip, loc9Blip, loc10Blip, loc11Blip, loc12Blip;
46.         readonly int checkpoint1, checkpoint2, checkpoint3, checkpoint4, checkpoint5, checkpoint6, checkpoint7, checkpoint8,
47.         checkpoint9, checkpoint10, checkpoint11, checkpoint12;
48.
49.
50.         public SafePoints()
51.         {
52.             // Here we call the config file and save the data in our money integer
54.             moneyToTake = Settings.GetValue<int>("SETTINGS", "MONEY_WANTED_1", 2000);
55.             moneyToTake2 = Settings.GetValue<int>("SETTINGS", "MONEY_WANTED_2", 3000);
56.             moneyToTake3 = Settings.GetValue<int>("SETTINGS", "MONEY_WANTED_3", 5000);
57.             moneyToTake4 = Settings.GetValue<int>("SETTINGS", "MONEY_WANTED_4", 7500);
58.             moneyToTake5 = Settings.GetValue<int>("SETTINGS", "MONEY_WANTED_5", 10000);
59.
60.             // Here you create and configure the blips to be displayed on the map
61.                 loc1Blip = World.CreateBlip(cw1Coord);
62.                 loc2Blip = World.CreateBlip(cw2Coord);
63.                 loc3Blip = World.CreateBlip(cw3Coord);
64.                 loc4Blip = World.CreateBlip(cw4Coord);
65.                 loc5Blip = World.CreateBlip(cw5Coord);
66.                 loc6Blip = World.CreateBlip(cw6Coord);
67.                 loc7Blip = World.CreateBlip(cw7Coord);
68.                 loc8Blip = World.CreateBlip(cw8Coord);
69.                 loc9Blip = World.CreateBlip(cw9Coord);
70.                 loc10Blip = World.CreateBlip(cw10Coord);
71.                 loc11Blip = World.CreateBlip(cw11Coord);
72.                 loc12Blip = World.CreateBlip(cw12Coord);
73.
74.                 loc1Blip.Scale = 1f;
75.                 loc2Blip.Scale = 1f;
76.                 loc3Blip.Scale = 1f;
77.                 loc4Blip.Scale = 1f;
78.                 loc5Blip.Scale = 1f;
79.                 loc6Blip.Scale = 1f;
80.                 loc7Blip.Scale = 1f;
81.                 loc8Blip.Scale = 1f;
82.                 loc9Blip.Scale = 1f;
83.                 loc10Blip.Scale = 1f;
84.                 loc11Blip.Scale = 1f;
85.                 loc12Blip.Scale = 1f;
86.
87.                 loc1Blip.Sprite = BlipSprite.PolicePlayer;
88.                 loc2Blip.Sprite = BlipSprite.PolicePlayer;
89.                 loc3Blip.Sprite = BlipSprite.PolicePlayer;
90.                 loc4Blip.Sprite = BlipSprite.PolicePlayer;
91.                 loc5Blip.Sprite = BlipSprite.PolicePlayer;
92.                 loc6Blip.Sprite = BlipSprite.PolicePlayer;
93.                 loc7Blip.Sprite = BlipSprite.PolicePlayer;
94.                 loc8Blip.Sprite = BlipSprite.PolicePlayer;
95.                 loc9Blip.Sprite = BlipSprite.PolicePlayer;
96.                 loc10Blip.Sprite = BlipSprite.PolicePlayer;
97.                 loc11Blip.Sprite = BlipSprite.PolicePlayer;
98.                 loc12Blip.Sprite = BlipSprite.PolicePlayer;
99.
100.                 loc1Blip.IsShortRange = true;
101.                 loc2Blip.IsShortRange = true;
102.                 loc3Blip.IsShortRange = true;
103.                 loc4Blip.IsShortRange = true;
104.                 loc5Blip.IsShortRange = true;
105.                 loc6Blip.IsShortRange = true;
106.                 loc7Blip.IsShortRange = true;
107.                 loc8Blip.IsShortRange = true;
108.                 loc9Blip.IsShortRange = true;
109.                 loc10Blip.IsShortRange = true;
110.                 loc11Blip.IsShortRange = true;
111.                 loc12Blip.IsShortRange = true;
112.
113.                 loc1Blip.Name = "SafePoint";
114.                 loc2Blip.Name = "SafePoint";
115.                 loc3Blip.Name = "SafePoint";
116.                 loc4Blip.Name = "SafePoint";
117.                 loc5Blip.Name = "SafePoint";
118.                 loc6Blip.Name = "SafePoint";
119.                 loc7Blip.Name = "SafePoint";
120.                 loc8Blip.Name = "SafePoint";
121.                 loc9Blip.Name = "SafePoint";
122.                 loc10Blip.Name = "SafePoint";
123.                 loc11Blip.Name = "SafePoint";
124.                 loc12Blip.Name = "SafePoint";
125.
126.     // Here we create the cylinders into which you must enter/drive to lose your wanted level (each with the individual coordinates)
127.             checkpoint1 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw1Coord.X, cw1Coord.Y, cw1Coord.Z, cw1Coord.X, cw1Coord.Y,
128.             cw1Coord.Z, 1.0, 255, 255, 0, 150, 0);
129.             checkpoint2 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw2Coord.X, cw2Coord.Y, cw2Coord.Z, cw2Coord.X, cw2Coord.Y,
130.             cw2Coord.Z, 1.0, 255, 255, 0, 150, 0);
131.             checkpoint3 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw3Coord.X, cw3Coord.Y, cw3Coord.Z, cw3Coord.X, cw3Coord.Y,
132.             cw3Coord.Z, 1.0, 255, 255, 0, 150, 0);
133.             checkpoint4 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw4Coord.X, cw4Coord.Y, cw4Coord.Z, cw4Coord.X, cw4Coord.Y,
134.             cw4Coord.Z, 1.0, 255, 255, 0, 150, 0);
135.             checkpoint5 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw5Coord.X, cw5Coord.Y, cw5Coord.Z, cw5Coord.X, cw5Coord.Y,
136.             cw5Coord.Z, 1.0, 255, 255, 0, 150, 0);
137.             checkpoint6 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw6Coord.X, cw6Coord.Y, cw6Coord.Z, cw6Coord.X, cw6Coord.Y,
138.             cw6Coord.Z, 1.0, 255, 255, 0, 150, 0);
139.             checkpoint7 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw7Coord.X, cw7Coord.Y, cw7Coord.Z, cw7Coord.X, cw7Coord.Y,
140.             cw7Coord.Z, 1.0, 255, 255, 0, 150, 0);
141.             checkpoint8 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw8Coord.X, cw8Coord.Y, cw8Coord.Z, cw8Coord.X, cw8Coord.Y,
142.             cw8Coord.Z, 1.0, 255, 255, 0, 150, 0);
143.             checkpoint9 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw9Coord.X, cw9Coord.Y, cw9Coord.Z, cw9Coord.X, cw9Coord.Y,
144.             cw9Coord.Z, 1.0, 255, 255, 0, 150, 0);
145.             checkpoint10 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw10Coord.X, cw10Coord.Y, cw10Coord.Z, cw10Coord.X,
146.             cw10Coord.Y, cw10Coord.Z, 1.0, 255, 255, 0, 150, 0);
147.             checkpoint11 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw11Coord.X, cw11Coord.Y, cw11Coord.Z, cw11Coord.X,
148.             cw11Coord.Y, cw11Coord.Z, 1.0, 255, 255, 0, 150, 0);
149.             checkpoint12 = Function.Call<int>(Hash.CREATE_CHECKPOINT, 45, cw12Coord.X, cw12Coord.Y, cw12Coord.Z, cw12Coord.X,
150.             cw12Coord.Y, cw12Coord.Z, 1.0, 255, 255, 0, 150, 0);
151.
152.             // Here we set the height and width of the cylinder
153.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint1, 1f, 1f, 1f);
154.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint2, 1f, 1f, 1f);
155.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint3, 1f, 1f, 1f);
156.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint4, 1f, 1f, 1f);
157.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint5, 1f, 1f, 1f);
158.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint6, 1f, 1f, 1f);
159.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint7, 1f, 1f, 1f);
160.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint8, 1f, 1f, 1f);
161.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint9, 1f, 1f, 1f);
162.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint10, 1f, 1f, 1f);
163.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint11, 1f, 1f, 1f);
164.             Function.Call(Hash.SET_CHECKPOINT_CYLINDER_HEIGHT, checkpoint12, 1f, 1f, 1f);
165.
166.             Interval = 0;
167.             Tick += SafePoint_Tick;
168.         }
169.
170.
171.         // Here we check if the player is 2f away from one of the cylinders. (Can be set to any distance)
172.         private bool IsCoordNearStation(Vector3 coords)
173.         {
174.             return coords.DistanceTo(cw1Coord) < 2f || coords.DistanceTo(cw2Coord) < 2f || coords.DistanceTo(cw3Coord) < 2f ||
175.             coords.DistanceTo(cw4Coord) < 2f || coords.DistanceTo(cw5Coord) < 2f || coords.DistanceTo(cw6Coord) < 2f ||
176.             coords.DistanceTo(cw7Coord) < 2f || coords.DistanceTo(cw8Coord) < 2f || coords.DistanceTo(cw9Coord) < 2f ||
177.             coords.DistanceTo(cw10Coord) < 2f || coords.DistanceTo(cw11Coord) < 2f || coords.DistanceTo(cw12Coord) < 2f;
178.         }
179.
180.
181.         private void SafePoint_Tick(object sender, EventArgs e)
182.         {
183.             // Here we declare the game character and its position
184.             Player plr = Game.Player;
185.             Ped plrPed = plr.Character;
186.             Vector3 plrPedCoords = plrPed.Position;
187.
188.             // Here it is checked whether the game character is near a cylinder. If yes then:
189.             if (IsCoordNearStation(plrPedCoords))
190.             {
191.                 // The script checks which wanted level it has and executes the appropriate if loop
192.                 if (plr.WantedLevel == 0)
193.                 {
194.
195.                 }
196.                 else
197.                 {
198.                     if (plr.Money >= moneyToTake) // Here is checked if the game character has enough money
199.                     {
200.                         if (plr.WantedLevel == 0)
201.                         {
202.
203.                         }
204.                         else
205.                         {
206.                             if (plr.WantedLevel == 1)
207.                             {
208.                                 Game.FadeScreenOut(1500); // Here the screen goes black in 1500 milliseconds
209.                                 Wait(2500); // The script waits 2500 milliseconds
210.                                 Function.Call(Hash.ADD_TO_CLOCK_TIME, 0, 20, 0); // 20 minutes are added to the in game time
211.                                 plr.WantedLevel = 0; //Wanted level is set to 0
212.                                 plr.Money -= moneyToTake; // The game character will have the money taken from the account
214.                                 Function.Call(Hash.PLAY_MISSION_COMPLETE_AUDIO, "FRANKLIN_BIG_01"); // An in-game audio file is played
215.                                 UI.Notify("Wanted level cleared!"); // A pop up message is displayed to the player
216.                                 Wait(10); // The script waits 10 milliseconds
217.                             }
218.                             else
219.                             {
220.                                 if (plr.WantedLevel == 2)
221.                                 {
223.                                     Wait(2500);
225.                                     plr.WantedLevel = 0;
226.                                     plr.Money -= moneyToTake2;
228.                                     Function.Call(Hash.PLAY_MISSION_COMPLETE_AUDIO, "FRANKLIN_BIG_01");
229.                                     UI.Notify("Wanted level cleared!");
230.                                     Wait(10);
231.                                 }
232.                                 else
233.                                 {
234.                                     if (plr.WantedLevel == 3)
235.                                     {
237.                                         Wait(2500);
239.                                         plr.WantedLevel = 0;
240.                                         plr.Money -= moneyToTake3;
242.                                         Function.Call(Hash.PLAY_MISSION_COMPLETE_AUDIO, "FRANKLIN_BIG_01");
243.                                         UI.Notify("Wanted level cleared!");
244.                                         Wait(10);
245.                                     }
246.                                     else
247.                                     {
248.                                         if (plr.WantedLevel == 4)
249.                                         {
251.                                             Wait(2500);
253.                                             plr.WantedLevel = 0;
254.                                             plr.Money -= moneyToTake4;
256.                                             Function.Call(Hash.PLAY_MISSION_COMPLETE_AUDIO, "FRANKLIN_BIG_01");
257.                                             UI.Notify("Wanted level cleared!");
258.                                             Wait(10);
259.                                         }
260.                                         else
261.                                         {
262.                                             if (plr.WantedLevel == 5)
263.                                             {
265.                                                 Wait(2500);
267.                                                 plr.WantedLevel = 0;
268.                                                 plr.Money -= moneyToTake5;
270.                                                 Function.Call(Hash.PLAY_MISSION_COMPLETE_AUDIO, "FRANKLIN_BIG_01");
271.                                                 UI.Notify("Wanted level cleared!");
272.                                                 Wait(10);
273.                                             }
274.                                         }
275.                                     }
276.                                 }
277.                             }
278.
279.                         }
280.                     }
281.                     else
282.                     {
283.                         // This pop up message is displayed to the player when the game character does not have enough money
284.                         UI.Notify("You dont have enough cash. Have fun with the police!");
285.                     }
286.                 }
287.             }
288.         }
289.     }
290. }
RAW Paste Data