-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectiveFire.cs
More file actions
238 lines (214 loc) · 12.8 KB
/
Copy pathSelectiveFire.cs
File metadata and controls
238 lines (214 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using GTA;
using GTA.Native;
using System;
using System.Windows.Forms;
using System.Drawing; //print external images on game
public class SelectiveFire : Script
{
//LOCAL VARIABLES for the whole script
private int fireMode = 1, //0=full auto, 1=semi-auto, 2=burst (3-shots), 3=burst (2-shots)
ammo, ammocount;
private bool capableWeapon = false, firemodechanged = false, showImg = false, stealth, stealthLaunchIfPlayerAiming = false, playerreloaded = false, breathshaking = false, aimshaking = false;
private string firemodeImgRoot = AppDomain.CurrentDomain.BaseDirectory + "\\SelectiveFire\\", firemodeImg;
private Weapon previousWeapon;
private Ped player;
private DateTime imgTimer;
//VARIABLES FROM INI CONFIG FILE
private ScriptSettings config;
private Keys ChangeFireModeHotkey_Keys;
private bool ActivateSelectiveFire, ShowImage, AutoHideImage, StealthIfPlayerAiming, StealthAutoDisable, WasteAmmo, ShowNotif, BreathAimMovement, ShakeWhenAim;
private int ShotsPerBurst, ImageShownTime, ImageWidth, ImageHeight, BreathMovementRate, ShakeWhenAimMovementRate;
public SelectiveFire()
{
Tick += OnTick;
KeyUp += OnKeyUp;
Interval = 10;
//Pick up configs from INI file
config = ScriptSettings.Load("scripts\\SelectiveFire.ini");
string ChangeFireModeHotkey_String = config.GetValue<string>("HOTKEYS", "ChangeFireMode", "N");
ActivateSelectiveFire = config.GetValue<bool>("SELECTIVEFIRE", "SelectiveFire", true);
ShotsPerBurst = config.GetValue<int>("SELECTIVEFIRE", "ShotsPerBurst", 3);
ShowImage = config.GetValue<bool>("NOTIFICATIONS", "ShowImage", true);
AutoHideImage = config.GetValue<bool>("NOTIFICATIONS", "AutoHideImage", true);
ImageShownTime = config.GetValue<int>("NOTIFICATIONS", "ImageShownTime", 3);
ShowNotif = config.GetValue<bool>("NOTIFICATIONS", "ShowNotif", true);
ImageWidth = config.GetValue<int>("NOTIFICATIONS", "ImageWidth", 136);
ImageHeight = config.GetValue<int>("NOTIFICATIONS", "ImageHeight", 27);
StealthIfPlayerAiming = config.GetValue<bool>("STEALTHMODE", "StealthIfPlayerAiming", false);
StealthAutoDisable = config.GetValue<bool>("STEALTHMODE", "StealthAutoDisable", true);
if (ShowNotif) {UI.Notify("SelectiveFire loaded."); }
WasteAmmo = config.GetValue<bool>("REALLISTICMAGS", "WasteAmmo", false);
BreathAimMovement = config.GetValue<bool>("REALLISTICAIMING", "BreathAimMovement", false);
BreathMovementRate = config.GetValue<int>("REALLISTICAIMING", "BreathMovementRate", 1);
ShakeWhenAim = config.GetValue<bool>("REALLISTICAIMING", "ShakeWhenAim", false);
ShakeWhenAimMovementRate = config.GetValue<int>("REALLISTICAIMING", "ShakeWhenAimMovementRate", 1);
//Hotkeys (String from INI to Enum-Keys)
Enum.TryParse(ChangeFireModeHotkey_String, out ChangeFireModeHotkey_Keys);
}
private void OnTick(object sender, EventArgs e)
{
player = Game.Player.Character;
Weapon actualWeapon = player.Weapons.Current;
if (ActivateSelectiveFire && (actualWeapon.Hash == GTA.Native.WeaponHash.AdvancedRifle || actualWeapon.Hash == GTA.Native.WeaponHash.APPistol || actualWeapon.Hash == GTA.Native.WeaponHash.AssaultRifle || actualWeapon.Hash == GTA.Native.WeaponHash.AssaultSMG || actualWeapon.Hash == GTA.Native.WeaponHash.BullpupRifle || actualWeapon.Hash == GTA.Native.WeaponHash.CarbineRifle || actualWeapon.Hash == GTA.Native.WeaponHash.CombatPDW || actualWeapon.Hash == GTA.Native.WeaponHash.Gusenberg || actualWeapon.Hash == GTA.Native.WeaponHash.MachinePistol || actualWeapon.Hash == GTA.Native.WeaponHash.MicroSMG || actualWeapon.Hash == GTA.Native.WeaponHash.SMG || actualWeapon.Hash == GTA.Native.WeaponHash.SpecialCarbine))
{ //just run if using an automatic weapon (from the upper "if" list)
ammo = Game.Player.Character.Weapons.Current.Ammo;
capableWeapon = true;
//LAUNCH Selective Fire Modes
if (fireMode == 1) {
firemodeImg = firemodeImgRoot + "fullauto.png";
}
else if (fireMode == 2) {
firemodeImg = firemodeImgRoot + "semiauto.png";
SemiAutoMode();
}
else if (fireMode == 3) {
firemodeImg = firemodeImgRoot + "burst3.png";
BurstMode(ShotsPerBurst);
}
//Draw on screen a image showing the actual fire mode for X seconds, if fire mode changed
if (ShowImage && AutoHideImage) { //if show image and autohide it
if (actualWeapon != previousWeapon) { //"fire mode changed" if weapon changed, too
firemodechanged = true;
}
if (firemodechanged) { //launch the startup timer
imgTimer = DateTime.Now; //take startup time
firemodechanged = false;
showImg = true;
}
if ((DateTime.Now - imgTimer).TotalSeconds > ImageShownTime) { //if X seconds passed, stop showing img
showImg = false;
}
if (showImg) {
UI.DrawTexture(firemodeImg, 1, 1, 100, new Point(1, 1), new Size(ImageWidth, ImageHeight));
}
}
if (ShowImage && !AutoHideImage) { //if always show the image (no autohide)
UI.DrawTexture(firemodeImg, 1, 1, 100, new Point(1, 1), new Size(ImageWidth, ImageHeight));
}
//Restart ammocount when player is reloading or has changed weapon (avoiding firing after that)
if (player.IsReloading || actualWeapon != previousWeapon) {
Game.Player.DisableFiringThisFrame();
ammocount = 0;
}
}
//END OF "IF USING AUTO WEAPON"
else { //if not using an automatic weapon from the list
capableWeapon = false;
}
//STEALTH MODULE
if (StealthIfPlayerAiming) {
stealth = GTA.Native.Function.Call<bool>(GTA.Native.Hash.GET_PED_STEALTH_MOVEMENT, player);
if (StealthIfPlayerAiming && !stealthLaunchIfPlayerAiming && Game.Player.IsAiming) {
StealthMode(true);
stealthLaunchIfPlayerAiming = true; //just launch stealth order once
}
else if (stealthLaunchIfPlayerAiming && !Game.Player.IsAiming) {
stealthLaunchIfPlayerAiming = false;
if (StealthAutoDisable && stealth) { //auto-disable stealth option
StealthMode(false);
}
}
}
//REALLISTIC MAGS MODULE
if (WasteAmmo && (actualWeapon.Hash == GTA.Native.WeaponHash.AdvancedRifle || actualWeapon.Hash == GTA.Native.WeaponHash.APPistol || actualWeapon.Hash == GTA.Native.WeaponHash.AssaultRifle || actualWeapon.Hash == GTA.Native.WeaponHash.AssaultSMG || actualWeapon.Hash == GTA.Native.WeaponHash.BullpupRifle || actualWeapon.Hash == GTA.Native.WeaponHash.CarbineRifle || actualWeapon.Hash == GTA.Native.WeaponHash.CombatMG || actualWeapon.Hash == GTA.Native.WeaponHash.CombatPDW || actualWeapon.Hash == GTA.Native.WeaponHash.CombatPistol || actualWeapon.Hash == GTA.Native.WeaponHash.CompactRifle || actualWeapon.Hash == GTA.Native.WeaponHash.GrenadeLauncher || actualWeapon.Hash == GTA.Native.WeaponHash.GrenadeLauncherSmoke || actualWeapon.Hash == GTA.Native.WeaponHash.Gusenberg || actualWeapon.Hash == GTA.Native.WeaponHash.HeavyPistol || actualWeapon.Hash == GTA.Native.WeaponHash.HeavyShotgun || actualWeapon.Hash == GTA.Native.WeaponHash.HeavySniper || actualWeapon.Hash == GTA.Native.WeaponHash.MachinePistol || actualWeapon.Hash == GTA.Native.WeaponHash.MarksmanRifle || actualWeapon.Hash == GTA.Native.WeaponHash.MG || actualWeapon.Hash == GTA.Native.WeaponHash.MicroSMG || actualWeapon.Hash == GTA.Native.WeaponHash.Pistol || actualWeapon.Hash == GTA.Native.WeaponHash.Pistol50 || actualWeapon.Hash == GTA.Native.WeaponHash.Revolver || actualWeapon.Hash == GTA.Native.WeaponHash.SMG || actualWeapon.Hash == GTA.Native.WeaponHash.SniperRifle || actualWeapon.Hash == GTA.Native.WeaponHash.SNSPistol || actualWeapon.Hash == GTA.Native.WeaponHash.SpecialCarbine || actualWeapon.Hash == GTA.Native.WeaponHash.VintagePistol || actualWeapon.Hash == GTA.Native.WeaponHash.AssaultShotgun))
{
if (player.IsReloading && !playerreloaded) {
playerreloaded = true;
if (player.Weapons.Current.AmmoInClip > 0) {
player.Weapons.Current.AmmoInClip = 0;
}
}
if (!player.IsReloading && player.Weapons.Current.AmmoInClip == player.Weapons.Current.DefaultClipSize) {
playerreloaded = false;
}
}
//REALLISTICAIMING MODULE
if (ShakeWhenAim && !BreathAimMovement)
{ //Shake "Jolt" effect - just applies when start aiming, moving the camera
if (Game.Player.IsAiming && !aimshaking) {
GameplayCamera.Shake(GTA.CameraShake.Jolt, (0.1f * ShakeWhenAimMovementRate));
aimshaking = true; //avoid shake function to run more than once
}
else if (!Game.Player.IsAiming) {
aimshaking = false;
}
}
if (BreathAimMovement && !ShakeWhenAim)
{ //Shake "Hand" effect - when you're aiming the camera moves like if breathing
if (Game.Player.IsAiming && !breathshaking) {
GameplayCamera.Shake(GTA.CameraShake.Hand, (0.1f * BreathMovementRate));
breathshaking = true; //avoid shake running more than once
}
else if (!Game.Player.IsAiming) {
GameplayCamera.StopShaking();
breathshaking = false;
}
}
if (BreathAimMovement && ShakeWhenAim)
{ //Both Shake effects
if (Game.Player.IsAiming) {
if (!aimshaking) { //apply aim shake only once
GameplayCamera.Shake(GTA.CameraShake.Jolt, (0.1f * ShakeWhenAimMovementRate));
aimshaking = true;
}
else if (!GameplayCamera.IsShaking) { //apply breath shake when breath shake finished
GameplayCamera.Shake(GTA.CameraShake.Hand, (0.1f * BreathMovementRate));
breathshaking = true;
}
}
else if (aimshaking || breathshaking) {
GameplayCamera.StopShaking();
aimshaking = false;
breathshaking = false;
}
}
previousWeapon = actualWeapon;
}
private void OnKeyUp(object sender, KeyEventArgs e)
{
//CHANGE FIRE MODE
if (capableWeapon && e.KeyCode == ChangeFireModeHotkey_Keys) {
if (fireMode == 1) { //FULL-AUTO to SEMI-AUTO
fireMode = 2;
if (ShowNotif) {UI.Notify("Fire mode: SEMI-AUTO");}
firemodechanged = true;
}
else if (fireMode == 2) { //SEMI-AUTO to BURST
fireMode = 3;
if (ShowNotif) {UI.Notify("Fire mode: BURST - x" + ShotsPerBurst);}
firemodechanged = true;
}
else if (fireMode == 3) { //BURST to FULL-AUTO
fireMode = 1;
if (ShowNotif) {UI.Notify("Fire mode: FULL-AUTO");}
firemodechanged = true;
}
}
}
private void BurstMode(int SpB)
{ //Script for Burst Fire Mode
if (player.IsShooting) {
ammocount++;
}
if (ammocount < SpB && ammocount > 0) {
Game.SetControlNormal(0, GTA.Control.Attack, 1.0f);
if (player.IsAimingFromCover) {
Game.SetControlNormal(0, GTA.Control.Aim, 1.0f);
}
}
if (ammocount == SpB) {
Game.Player.DisableFiringThisFrame();
if (GTA.Game.IsControlJustReleased(0, GTA.Control.Attack)) {
ammocount = 0;
}
}
}
private void SemiAutoMode()
{ //Script for Semi-Auto Fire Mode
if (GTA.Game.IsControlPressed(0, GTA.Control.Attack)) {
Game.Player.DisableFiringThisFrame();
}
}
private void StealthMode(bool sth)
{ GTA.Native.Function.Call(GTA.Native.Hash.SET_PED_STEALTH_MOVEMENT, player, sth, 0); }
}