Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using GTA;
- using GTA.Native;
- using GTA.Math;
- using Font = GTA.Font;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- public partial class SafeCrack : Script
- {
- private ScriptSettings KeysData;
- List<SafeCracker> Safe_Cracker = new List<SafeCracker>();
- List<Vector3> Safe_Locations = new List<Vector3>();
- List<float> Safe_Rotations = new List<float>();
- int Safe_Cracker_Intervel = 0;
- int Safe_Cracker_Time_of_Success = 0;
- int Safe_Cracker_Cooldown = 30000;
- int MinCash = 0;
- int MaxCash = 0;
- bool LoadOptionalSafes = true;
- bool LoadSafes = true;
- bool PadShake = true;
- int WantedLevel = 0;
- public SafeCrack()
- {
- Safe_Locations.Add(new Vector3(1735.22f, 6420.86f, 34.80502f)); // coords for safes
- Safe_Locations.Add(new Vector3(1959.45f, 3749.25f, 32.10276f));
- Safe_Locations.Add(new Vector3(2672.7f, 3287.05f, 55.00016f));
- Safe_Locations.Add(new Vector3(546.1f, 2662.55f, 41.9243f));
- Safe_Locations.Add(new Vector3(-3250.259f, 1004.763f, 12.59851f));
- Safe_Locations.Add(new Vector3(-3048.12f, 585.9f, 7.6724f));
- Safe_Locations.Add(new Vector3(378.55f, 333.4986f, 103.3342f));
- Safe_Locations.Add(new Vector3(2549.05f, 385.23f, 108.3908f));
- Safe_Locations.Add(new Vector3(28.54f, -1338.98f, 29.26483f));
- Safe_Locations.Add(new Vector3(1708.3f, 4920.4f, 41.83146f));
- Safe_Locations.Add(new Vector3(-1829.558f, 798.8604f, 137.945f));
- Safe_Locations.Add(new Vector3(1159.254f, -313.7326f, 68.97286f));
- Safe_Locations.Add(new Vector3(-710.0f, -903.8f, 18.98339f));
- Safe_Locations.Add(new Vector3(-43.4f, -1747.95f, 29.18881f));
- Safe_Rotations.Add(334.6f); // safe heading
- Safe_Rotations.Add(30.0f);
- Safe_Rotations.Add(59.0f);
- Safe_Rotations.Add(187.0f);
- Safe_Rotations.Add(84.81945f);
- Safe_Rotations.Add(108.5598f);
- Safe_Rotations.Add(346.2444f);
- Safe_Rotations.Add(88.7537f);
- Safe_Rotations.Add(0.0f);
- Safe_Rotations.Add(324.9322f);
- Safe_Rotations.Add(131.5848f);
- Safe_Rotations.Add(98.38525f);
- Safe_Rotations.Add(90.58581f);
- Safe_Rotations.Add(50.60119f);
- KeysData = ScriptSettings.Load("scripts//SafeCracker.ini");
- Safe_Cracker_Cooldown = KeysData.GetValue<int>("settings", "CoolDown", 30000);
- MinCash = KeysData.GetValue<int>("settings", "MinCash", 500);
- MaxCash = KeysData.GetValue<int>("settings", "MaxCash", 5000);
- LoadOptionalSafes = KeysData.GetValue<bool>("settings", "LoadOptionalSafes", true);
- PadShake = KeysData.GetValue<bool>("settings", "PadShake", true);
- WantedLevel = KeysData.GetValue<int>("settings", "WantedLevel", 0);
- Tick += OnTick;
- KeyUp += OnKeyUp;
- Safe_Cracker_Intervel = (int)Game.GameTime;
- }
- public void OnTick(object o, EventArgs e)
- {
- if (LoadSafes)
- {
- Startup();
- LoadSafes = false;
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_JUST_PRESSED, 2, 174)) // start if dpad left
- {
- if (Safe_Cracker_Time_of_Success < (int)Game.GameTime - Safe_Cracker_Cooldown) // cool down time before player can start after death
- {
- if (Safe_Cracker.Count < 1)
- {
- Prop[] tmp = World.GetNearbyProps(Game.Player.Character.Position, 2.9f); // get props
- if (tmp.Count() > 0)
- {
- for (int i = 0; i < tmp.Count(); i++)
- {
- if (tmp[i].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i].Model.Hash == -1346995970) // if safe door
- {
- SafeCracker safe = new SafeCracker(); // create new safecracker
- Safe_Cracker.Add(safe); // add to list
- }
- }
- }
- }
- }
- }
- if (Function.Call<int>(Hash.GET_TIME_SINCE_LAST_DEATH) < Safe_Cracker_Cooldown & Function.Call<int>(Hash.GET_TIME_SINCE_LAST_DEATH) != -1)// if player dies
- {
- if (Safe_Cracker.Count > 0) // check if safecracker is present
- {
- if (Safe_Cracker[0].CashPickup != null) // if cash prop exists then door is open
- {
- Prop[] tmp = World.GetNearbyProps(Safe_Cracker[0].CashPickup.Position, 2.0f);
- for (int i = 0; i < tmp.Count(); i++)
- {
- tmp[i].Rotation = new Vector3(tmp[i].Rotation.X, tmp[i].Rotation.Y, tmp[i].Rotation.Z - 90.0f); // close door
- }
- Safe_Cracker[0].CashPickup.Delete(); // delete cash prop
- }
- Safe_Cracker[0].RemoveSafeCracker(); // delete safecracker
- Safe_Cracker.RemoveAt(0);
- }
- }
- if (Safe_Cracker.Count > 0)
- {
- float sclX = .3f;
- float sclY = sclX;
- float pozX = .5f;
- float pozY = .5f;
- float aspect = Function.Call<float>(Hash._GET_SCREEN_ASPECT_RATIO, true);
- sclY = sclY * aspect; // set x and y scale to reflect the screen aspect ratio
- if (!Safe_Cracker[0].Running) // if not running it has finnished dislay all locks open
- {
- if (Safe_Cracker[0].Pin_one == true && Safe_Cracker[0].Pin_two == true && Safe_Cracker[0].Pin_three == true)
- {
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .4f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .5f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .6f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- }
- }
- if (Safe_Cracker[0].Running)
- {
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 9) && Safe_Cracker[0].DirectionRight == true) // if rotating wrong way reset wheel
- {
- Function.Call(Hash._PLAY_AMBIENT_SPEECH1, Game.Player.Character, "GENERIC_CURSE_MED", "SPEECH_PARAMS_FORCE", 1);
- Safe_Cracker[0].ResetSafe();
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 34) && Safe_Cracker[0].DirectionRight == false) // if rotating wrong way reset wheel
- {
- Function.Call(Hash._PLAY_AMBIENT_SPEECH1, Game.Player.Character, "GENERIC_CURSE_MED", "SPEECH_PARAMS_FORCE", 1);
- Safe_Cracker[0].ResetSafe();
- }
- if (!Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 9) || !Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 34)) // if not terning wheel play idle animation
- {
- if (!Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Game.Player.Character, "mini@safe_cracking", "idle_look_around", 3))
- {
- Game.Player.Character.Task.ClearAnimation("mini@safe_cracking", "dial_turn_clock_fast");
- Game.Player.Character.Task.ClearAnimation("mini@safe_cracking", "dial_turn_anti_fast");
- Function.Call(Hash.TASK_PLAY_ANIM, Game.Player.Character, "mini@safe_cracking", "idle_look_around", 1.0f, .1f, 2000, 0, .0f, 1, 1, 1);
- }
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 9)) // if left input play dial_turn_anti_fast animation
- {
- Game.Player.Character.Task.ClearAnimation("mini@safe_cracking", "idle_look_around");
- Game.Player.Character.Task.ClearAnimation("mini@safe_cracking", "dial_turn_clock_fast");
- if (!Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Game.Player.Character, "mini@safe_cracking", "dial_turn_anti_fast", 3))
- {
- Function.Call(Hash.TASK_PLAY_ANIM, Game.Player.Character, "mini@safe_cracking", "dial_turn_anti_fast", 1.0f, .1f, 1000, 0, .0f, 1, 1, 1); // 64
- }
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 34)) // if right input play dial_turn_clock_fast animation
- {
- Game.Player.Character.Task.ClearAnimation("mini@safe_cracking", "idle_look_around");
- Game.Player.Character.Task.ClearAnimation("mini@safe_cracking", "dial_turn_anti_fast");
- if (!Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Game.Player.Character, "mini@safe_cracking", "dial_turn_clock_fast", 3))
- {
- Function.Call(Hash.TASK_PLAY_ANIM, Game.Player.Character, "mini@safe_cracking", "dial_turn_clock_fast", 1.0f, .1f, 1000, 0, .0f, 1, 1, 1); // 64
- }
- }
- if (!Safe_Cracker[0].Pin_one) // if pin one not set
- {
- Function.Call(Hash.DRAW_SPRITE, "GolfPutting", "PuttingMarker", .48f, .3f, sclX * .2f, sclY * .1f, 90.0f, 0, 255, 0, 255); // display help arrow left
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One - 5).ToString("F2") && Safe_Cracker[0].DirectionRight == true) // if wheel posiyion 5 away
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4995, .5005); // set wheel position random position (shake)
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4995, .5005);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 90);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One - 4).ToString("F2") && Safe_Cracker[0].DirectionRight == true) // if wheel posiyion 4 away
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .499, .501);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .499, .501);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 100);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One - 3).ToString("F2") && Safe_Cracker[0].DirectionRight == true) // if wheel posiyion 3 away
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4985, .5015);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4985, .5015);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 112);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One - 2).ToString("F2") && Safe_Cracker[0].DirectionRight == true) // if wheel posiyion 2 away
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .498, .502);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .498, .502);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 130);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One - 1).ToString("F2") && Safe_Cracker[0].DirectionRight == true) // if wheel posiyion 1 away
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4975, .5025);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4975, .5025);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 180);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One).ToString("F2")) // if pin one and rotation / 3.6 are same we are at the correct position
- {
- Wait(80); // added this or it wont detect can change this to make harder to crack
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_One).ToString("F2")) // if pin one and rotation / 3.6 are same we are still at the correct position
- {
- Safe_Cracker[0].Pin_one = true; // set first pin to true
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "TUMBLER_PIN_FALL", "SAFE_CRACK_SOUNDSET", 1);
- Safe_Cracker[0].DirectionRight = false; // set direction to set the next pin. If continue turning now its wrong direction and will reset dial to 0.
- }
- else
- {
- Safe_Cracker[0].ResetSafe();
- }
- }
- }
- if (Safe_Cracker[0].Pin_one && !Safe_Cracker[0].Pin_two) // if pin one set and pin two not set
- {
- Function.Call(Hash.DRAW_SPRITE, "GolfPutting", "PuttingMarker", .52f, .3f, sclX * .2f, sclY * .1f, 270.0f, 0, 255, 0, 255); // display help arrow right
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two + 5).ToString("F2") && Safe_Cracker[0].DirectionRight == false)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4995, .5005);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4995, .5005);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 90);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two + 4).ToString("F2") && Safe_Cracker[0].DirectionRight == false)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .499, .501);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .499, .501);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 100);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two + 3).ToString("F2") && Safe_Cracker[0].DirectionRight == false)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4985, .5015);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4985, .5015);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 112);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two + 2).ToString("F2") && Safe_Cracker[0].DirectionRight == false)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .498, .502);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .498, .502);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 130);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two + 1).ToString("F2") && Safe_Cracker[0].DirectionRight == false)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4975, .5025);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4975, .5025);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 180);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two).ToString("F2"))
- {
- Wait(80);
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Two).ToString("F2"))
- {
- Safe_Cracker[0].Pin_two = true;
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "TUMBLER_PIN_FALL", "SAFE_CRACK_SOUNDSET", 1);
- Safe_Cracker[0].DirectionRight = true;
- }
- else
- {
- Safe_Cracker[0].ResetSafe();
- }
- }
- }
- if (Safe_Cracker[0].Pin_one && Safe_Cracker[0].Pin_two && !Safe_Cracker[0].Pin_three) // if pin one and two are set and three is not
- {
- Function.Call(Hash.DRAW_SPRITE, "GolfPutting", "PuttingMarker", .48f, .3f, sclX * .2f, sclY * .1f, 90.0f, 0, 255, 0, 255); // display help arrow left
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three - 5).ToString("F2") && Safe_Cracker[0].DirectionRight == true)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4995, .5005);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4995, .5005);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 90);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three - 4).ToString("F2") && Safe_Cracker[0].DirectionRight == true)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .499, .501);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .499, .501);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 100);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three - 3).ToString("F2") && Safe_Cracker[0].DirectionRight == true)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4985, .5015);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4985, .5015);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 112);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three - 2).ToString("F2") && Safe_Cracker[0].DirectionRight == true)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .498, .502);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .498, .502);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 130);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three - 1).ToString("F2") && Safe_Cracker[0].DirectionRight == true)
- {
- pozX = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4975, .5025);
- pozY = Function.Call<float>(Hash.GET_RANDOM_FLOAT_IN_RANGE, .4975, .5025);
- if (PadShake)
- {
- Function.Call(Hash.SET_PAD_SHAKE, 0, 300, 180);
- }
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three).ToString("F2")) // if last pin done
- {
- Wait(80);
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 34)) // if still turning dial reset to 0.
- {
- Safe_Cracker[0].ResetSafe();
- }
- if ((Safe_Cracker[0].Rotation / 3.6).ToString("F2") == (Safe_Cracker[0].Number_Three).ToString("F2")) // if still dial and pin are same
- {
- Safe_Cracker[0].Pin_three = true;
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "TUMBLER_PIN_FALL_FINAL", "SAFE_CRACK_SOUNDSET", 1);
- Safe_Cracker[0].DirectionRight = false;
- Function.Call(Hash.TASK_PLAY_ANIM, Game.Player.Character, "mini@safe_cracking", "door_open_succeed_stand", 1.0f, .1f, 1000, 0, .0f, 1, 1, 1); // 64
- Wait(2400); // wait for task so it looks like door is opening by player
- Prop[] tmp = World.GetNearbyProps(Game.Player.Character.Position, 2.0f); // get near props
- if (tmp.Count() > 0)
- {
- for (int i = 0; i < tmp.Count(); i++)
- {
- if (tmp[i].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i].Model.Hash == -1346995970) // check if is safe door
- {
- Game.Player.Character.FreezePosition = false; // Unfreeze player
- tmp[i].Rotation = new Vector3(tmp[i].Rotation.X, tmp[i].Rotation.Y, tmp[i].Rotation.Z + 90.0f); // set door open
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "SAFE_DOOR_OPEN", "SAFE_CRACK_SOUNDSET", 1);
- Game.Player.Character.Position = Game.Player.Character.Position + Game.Player.Character.ForwardVector * -.05f + Game.Player.Character.UpVector * -.7f; // move player back
- //Wait(1000);
- var model = new Model("prop_money_bag_01");
- model.Request(250);
- if (model.IsInCdImage && model.IsValid)
- {
- while (!model.IsLoaded) Script.Wait(50);
- Prop pickup = World.CreateProp(model, Game.Player.Character.Position + Game.Player.Character.ForwardVector * .8f + Game.Player.Character.RightVector * .15f + Game.Player.Character.UpVector * -.4f, new Vector3(0.0f, 0.0f, 0.0f), false, false); // create money prop
- Wait(1000);
- Safe_Cracker[0].CashPickup = pickup; // set to safecracker cash pickup (prop)
- }
- model.MarkAsNoLongerNeeded();
- Game.Player.Character.FreezePosition = false; // give back control to player
- Function.Call(Hash.SET_PED_CAN_SWITCH_WEAPON, true);
- }
- }
- }
- Safe_Cracker[0].Running = false; // now all locks open can be displayed
- }
- }
- }
- if (Safe_Cracker[0].Running == true) // displays dial and locks when running
- {
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "Dial_BG", pozX, pozY, sclX, sclY, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash._SET_2D_LAYER, 4);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "Dial", pozX, pozY, sclX * .5f, sclY * .5f, 0 - Safe_Cracker[0].Rotation, 255, 255, 255, 255);
- // lock_closed lock_closed_dark lock_open lock_open_dark
- if (Safe_Cracker[0].Pin_one == false && Safe_Cracker[0].Pin_two == false && Safe_Cracker[0].Pin_three == false)
- {
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_closed", .4f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_closed", .5f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_closed", .6f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- }
- if (Safe_Cracker[0].Pin_one == true && Safe_Cracker[0].Pin_two == false && Safe_Cracker[0].Pin_three == false)
- {
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .4f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_closed", .5f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_closed", .6f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- }
- if (Safe_Cracker[0].Pin_one == true && Safe_Cracker[0].Pin_two == true && Safe_Cracker[0].Pin_three == false)
- {
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .4f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .5f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_closed", .6f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- }
- if (Safe_Cracker[0].Pin_one == true && Safe_Cracker[0].Pin_two == true && Safe_Cracker[0].Pin_three == true)
- {
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .4f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .5f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- Function.Call(Hash.DRAW_SPRITE, "MPSafeCracking", "lock_open", .6f, .8f, sclX * .2f, sclY * .2f, 0.0f, 255, 255, 255, 255);
- }
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_JUST_PRESSED, 2, 34)) // sets speed that wheel can turn
- {
- Safe_Cracker[0].RotateAntiClock();
- Safe_Cracker_Intervel = (int)Game.GameTime;
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_JUST_PRESSED, 2, 9))
- {
- Safe_Cracker[0].RotateClock();
- Safe_Cracker_Intervel = (int)Game.GameTime;
- }
- if (Safe_Cracker_Intervel < (int)Game.GameTime - 250) // sets speed that wheel can turn
- {
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 34))
- {
- Safe_Cracker[0].RotateAntiClock();
- }
- if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 2, 9))
- {
- Safe_Cracker[0].RotateClock();
- }
- }
- }
- if (Safe_Cracker.Count > 0) // check if player collected moneybag
- {
- if (Safe_Cracker[0].Running == false) // all pins are true cracking done
- {
- if (Safe_Cracker[0].CashPickup != null) // if cash pickup exists
- {
- float dis = World.GetDistance(Game.Player.Character.Position, Safe_Cracker[0].CashPickup.Position);
- Prop[] tmp = World.GetNearbyProps(Game.Player.Character.Position, 2.0f);
- if (dis < 1.2f) // check distance from pickup
- {
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 2, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
- Game.Player.Money += Function.Call<int>(Hash.GET_RANDOM_INT_IN_RANGE, MinCash, MaxCash); // give player cash
- Safe_Cracker[0].CashPickup.Delete();
- Safe_Cracker[0].RemoveSafeCracker();
- Safe_Cracker.RemoveAt(0);
- Wait(1500);
- for (int i = 0; i < tmp.Count(); i++)
- {
- if (tmp[i].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i].Model.Hash == -1346995970)
- {
- tmp[i].Rotation = new Vector3(tmp[i].Rotation.X, tmp[i].Rotation.Y, tmp[i].Rotation.Z - 90.0f);// close door
- }
- }
- if ( WantedLevel > 0)
- {
- if (Game.Player.WantedLevel <= WantedLevel)
- {
- Game.Player.WantedLevel = WantedLevel;
- }
- }
- Safe_Cracker_Time_of_Success = (int)Game.GameTime;
- }
- }
- }
- }
- if (Safe_Cracker.Count > 0) // check if user wants to quit
- {
- if (Safe_Cracker[0].Pin_three == false)
- {
- bool D_Pad_Right = Function.Call<bool>(Hash.IS_DISABLED_CONTROL_PRESSED, 2, 74);
- bool key_Right = Function.Call<bool>(Hash.IS_DISABLED_CONTROL_PRESSED, 2, 175);
- DisplayHelpTextThisFrame("select ~INPUT_FRONTEND_RIGHT~ to quit");
- if (D_Pad_Right || key_Right && !Safe_Cracker[0].Pin_three)
- {
- if (Safe_Cracker.Count > 0)
- {
- if (Safe_Cracker[0].CashPickup != null)
- {
- Safe_Cracker[0].CashPickup.Delete();
- }
- Safe_Cracker[0].RemoveSafeCracker();
- Safe_Cracker.RemoveAt(0);
- }
- }
- }
- }
- }
- //Game.Player.WantedLevel = 0; // used during testing
- }
- public void OnKeyUp(object o, KeyEventArgs e)
- {
- KeysData = ScriptSettings.Load("scripts//SafeCracker.ini");
- Keys StartKey = KeysData.GetValue<Keys>("settings", "StartKey", Keys.U);
- //if (e.KeyCode == Keys.Y) // used during testing
- //{
- // if (Safe_Cracker.Count > 0)
- // {
- // if (Safe_Cracker[0].CashPickup != null)
- // {
- // Prop[] tmp = World.GetNearbyProps(Safe_Cracker[0].CashPickup.Position, 2.0f);
- // for (int i = 0; i < tmp.Count(); i++)
- // {
- // tmp[i].Rotation = new Vector3(tmp[i].Rotation.X, tmp[i].Rotation.Y, tmp[i].Rotation.Z - 90.0f);
- // }
- // Safe_Cracker[0].CashPickup.Delete();
- // }
- // Safe_Cracker[0].RemoveSafeCracker();
- // Safe_Cracker.RemoveAt(0);
- // }
- //}
- if (e.KeyCode == StartKey)
- {
- if (Safe_Cracker_Time_of_Success < (int)Game.GameTime - Safe_Cracker_Cooldown) // cool down time before player can start after death
- {
- if (Safe_Cracker.Count < 1)
- {
- Prop[] tmp = World.GetNearbyProps(Game.Player.Character.Position, 2.9f); // get props
- if (tmp.Count() > 0)
- {
- for (int i = 0; i < tmp.Count(); i++)
- {
- if (tmp[i].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i].Model.Hash == -1346995970) // if safe door
- {
- SafeCracker safe = new SafeCracker(); // create new safecracker
- Safe_Cracker.Add(safe); // add to list
- }
- }
- }
- }
- }
- }
- //if (e.KeyCode == Keys.O) // used during testing
- //{
- // Prop[] tmp = World.GetNearbyProps(Game.Player.Character.Position, 2.0f);
- // if (tmp.Count() > 0)
- // {
- // for (int i = 0; i < tmp.Count(); i++)
- // {
- // if (tmp[i].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i].Model.Hash == -1346995970)
- // {
- // tmp[i].Rotation = new Vector3(tmp[i].Rotation.X, tmp[i].Rotation.Y, tmp[i].Rotation.Z - 90.0f);
- // }
- // }
- // }
- //}
- }
- public class SafeCracker
- {
- public SafeCracker()
- {
- Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, "GolfPutting", 0); // request images and animations
- Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, "MPSafeCracking", false);
- Function.Call(Hash.REQUEST_ANIM_DICT, "mini@safe_cracking");
- while (!Function.Call<bool>(Hash.HAS_ANIM_DICT_LOADED, "mini@safe_cracking") && // wait for all to load
- !Function.Call<bool>(Hash.REQUEST_AMBIENT_AUDIO_BANK, "SAFE_CRACK", 0, 0) &&
- !Function.Call<bool>(Hash.REQUEST_AMBIENT_AUDIO_BANK, "DLC_Biker_Cracked_Sounds", 0, 1) &&
- !Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, "mini@safe_cracking") &&
- !Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, "GolfPutting"))
- {
- Wait(0);
- }
- this.Running = true; // sets to check pin positions
- this.DirectionRight = true; // used so can only turn right for first number
- this.Rotation = 0.0f; // used to set dial position to zero
- this.Pin_one = false; // set all three pins to false
- this.Pin_two = false;
- this.Pin_three = false;
- this.Number_One = Function.Call<int>(Hash.GET_RANDOM_INT_IN_RANGE, 10, 90); // set all three pin numbers to random 10 - 90
- this.Number_Two = Function.Call<int>(Hash.GET_RANDOM_INT_IN_RANGE, 10, 90);
- this.Number_Three = Function.Call<int>(Hash.GET_RANDOM_INT_IN_RANGE, 10, 90);
- //this.Number_One = 10; // for testing
- //this.Number_Two = 90;
- //this.Number_Three = 10;
- Game.Player.Character.Weapons.Give(WeaponHash.Unarmed, 0, true, true);
- //Function.Call(Hash.SET_FOLLOW_PED_CAM_VIEW_MODE, 1);
- Function.Call(Hash.SET_PED_CAN_SWITCH_WEAPON, false);
- Prop[] tmp = World.GetNearbyProps(Game.Player.Character.Position, 3.0f); // get nerby props to get the door to set player position in front and facing safe
- if (tmp.Count() > 0)
- {
- for (int i = 0; i < tmp.Count(); i++)
- {
- if (tmp[i].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i].Model.Hash == -1346995970)
- {
- Game.Player.Character.FreezePosition = true;
- // optional points the camara at safe not used anymore
- //var cam = World.CreateCamera(tmp[i].Position + tmp[i].ForwardVector * -2.0f + tmp[i].RightVector * -.22f + tmp[i].UpVector * +.5f, new Vector3(0.0f, 0.0f, 0.0f), 60f);
- //cam.Shake(CameraShake.Hand, 1.0f);
- //cam.PointAt(tmp[i].Position + tmp[i].UpVector * .1f);
- //Camera camcur = Function.Call<Camera>(Hash.GET_RENDERING_CAM);
- //Function.Call(Hash.SET_CAM_ACTIVE_WITH_INTERP, cam, camcur, 1500, false, false);
- //Function.Call(Hash.RENDER_SCRIPT_CAMS, 1, 1, cam, 1, 1);
- Game.Player.Character.Position = tmp[i].Position + tmp[i].ForwardVector * -.5f + tmp[i].RightVector * -.66f + tmp[i].UpVector * -.8f; // set player position in front of safe
- Game.Player.Character.Heading = tmp[i].Heading - 10.0f;
- //Wait(1000);
- }
- }
- for (int i = 0; i < tmp.Count(); i++)
- {
- if (tmp[i].Model.Hash == 1785922871 || tmp[i].Model.Hash == -170500011) // remove props phone an coffee from inside safe
- {
- tmp[i].Delete();
- }
- }
- }
- }
- public Prop CashPickup; // veriable to hold moneybag prop
- public bool Running;
- public bool DirectionRight;
- public bool Pin_one;
- public bool Pin_two;
- public bool Pin_three;
- public int Number_One;
- public int Number_Two;
- public int Number_Three;
- public float Rotation;
- public void RotateClock() // funtion to rotate wheel
- {
- if (Rotation > 0.0f)
- {
- Rotation -= 3.6f;
- }
- else
- {
- Rotation = 356.4f;
- }
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "TUMBLER_TURN", "SAFE_CRACK_SOUNDSET", 1);
- }
- public void RotateAntiClock() // funtion to rotate wheel cc
- {
- if (Rotation < 356.4f)
- {
- Rotation += 3.6f;
- }
- else
- {
- Rotation = 0.0f;
- }
- Function.Call(Hash.PLAY_SOUND_FRONTEND, 0, "TUMBLER_TURN", "SAFE_CRACK_SOUNDSET", 1);
- }
- public void RemoveSafeCracker() // funtion to remove when canciling or complete
- {
- Function.Call(Hash.SET_STREAMED_TEXTURE_DICT_AS_NO_LONGER_NEEDED, "GolfPutting");
- Function.Call(Hash.SET_STREAMED_TEXTURE_DICT_AS_NO_LONGER_NEEDED, "MPSafeCracking");
- Function.Call(Hash.REMOVE_ANIM_DICT, "mini@safe_cracking");
- Function.Call(Hash.RELEASE_NAMED_SCRIPT_AUDIO_BANK, "SAFE_CRACK");
- Function.Call(Hash.RELEASE_NAMED_SCRIPT_AUDIO_BANK, "DLC_Biker_Cracked_Sounds");
- Function.Call(Hash.STOP_SOUND, -1);
- Function.Call(Hash.RELEASE_SOUND_ID, -1);
- Game.Player.Character.FreezePosition = false;
- Function.Call(Hash.SET_PED_CAN_SWITCH_WEAPON, true);
- Game.Player.Character.Task.ClearAllImmediately();
- //World.DestroyAllCameras(); // not needed anymore
- World.RenderingCamera = null;
- }
- public void ResetSafe() // resets safe called when turning wrong way
- {
- this.Rotation = 0.0f;
- this.DirectionRight = true;
- this.Pin_one = false;
- this.Pin_two = false;
- this.Pin_three = false;
- Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "TUMBLER_RESET", "SAFE_CRACK_SOUNDSET", 1);
- }
- }
- void Startup()
- {
- for (int i = 0; i < Safe_Locations.Count; i++)// check at each location if a safe or door exists delete them so we dont spawn more than we need if scripts are reloaded
- {
- Prop[] tmp = World.GetNearbyProps(Safe_Locations[i], 2.0f);
- for (int i2 = 0; i2 < tmp.Count(); i2++)
- {
- if (tmp[i2].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafedoor") || tmp[i2].Model.Hash == Function.Call<int>(Hash.GET_HASH_KEY, "v_ilev_gangsafe"))
- {
- tmp[i2].Delete();
- }
- }
- }
- if (LoadOptionalSafes)
- {
- for (int i = 0; i < Safe_Locations.Count; i++) // spawn a safe and door at each location
- {
- var model = new Model("v_ilev_gangsafe");
- model.Request(250);
- if (model.IsInCdImage && model.IsValid)
- {
- while (!model.IsLoaded) Script.Wait(50);
- Prop myprop = World.CreateProp(model, new Vector3(Safe_Locations[i].X, Safe_Locations[i].Y, Safe_Locations[i].Z - .8f), new Vector3(0.0f, 0.0f, Safe_Rotations[i]), false, false);
- Function.Call(Hash.SET_ENTITY_LOAD_COLLISION_FLAG, myprop.Handle, true);
- myprop.LodDistance = 10;
- myprop.IsPersistent = true;
- model.MarkAsNoLongerNeeded();
- var model2 = new Model("v_ilev_gangsafedoor");
- model2.Request(250);
- if (model2.IsInCdImage && model2.IsValid)
- {
- while (!model2.IsLoaded) Script.Wait(50);
- Prop myprop2 = World.CreateProp(model2, new Vector3(myprop.Position.X, myprop.Position.Y, myprop.Position.Z - .68f), new Vector3(0.0f, 0.0f, myprop.Heading), false, false);
- Function.Call(Hash.SET_ENTITY_LOAD_COLLISION_FLAG, myprop2.Handle, true);
- myprop.LodDistance = 10;
- myprop.IsPersistent = true;
- myprop2.HasCollision = true;
- model2.MarkAsNoLongerNeeded();
- }
- }
- }
- }
- }
- void DisplayHelpTextThisFrame(string text) // used to display quit message. credit jedijosh920 for this function
- {
- Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
- Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement