Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

Commit 4d954b9

Browse files
author
VP-EN
authored
Merge pull request #85 from VP-EN/dev
Infinite Ammo + No Reload toggle
2 parents f5b9b83 + 0718095 commit 4d954b9

10 files changed

Lines changed: 327 additions & 70 deletions

File tree

mods/braindance_protocol/BD.lua

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
local BraindanceProtocol = {
2-
description = "",
2+
description = "",
33
}
44

55
function BraindanceProtocol:new()
6-
local BDScripts = {}
7-
8-
setmetatable(BDScripts, self)
9-
self.__index = self
10-
11-
12-
-- Load LUA modules into memory
13-
BDScripts.Utilities = require("utility")
14-
BDScripts.Player = require("player")
15-
BDScripts.Inventory = require("inventory")
16-
BDScripts.Vehicles = require("ai/vehicles")
17-
BDScripts.Examples = require("examples/init")
18-
BDScripts.Shopper = require("utility/shopper")
19-
BDScripts.Saves = require("engine/saves")
20-
BDScripts.Time = require("engine/time")
21-
22-
BDScripts.Cheats = {
23-
Crafting = require("cheats/crafting"),
24-
Johnny = require("cheats/johnny"),
25-
Player = require("cheats/player"),
26-
Legend = require("cheats/legend"),
27-
Platform = require("cheats/platform"),
28-
Modify = require("cheats/modify"),
29-
ItemSets = require("cheats/itemsets"),
30-
Cyberware = require("cheats/cyberware"),
31-
Facts = require("cheats/facts"),
32-
Teleport = require("cheats/teleport")
33-
}
34-
35-
return BDScripts
6+
local BDScripts = {}
7+
8+
setmetatable(BDScripts, self)
9+
self.__index = self
10+
11+
12+
-- Load LUA modules into memory
13+
BDScripts.Utilities = require("utility")
14+
BDScripts.Player = require("player")
15+
BDScripts.Inventory = require("inventory")
16+
BDScripts.Vehicles = require("ai/vehicles")
17+
BDScripts.Examples = require("examples/init")
18+
BDScripts.Shopper = require("utility/shopper")
19+
BDScripts.Saves = require("engine/saves")
20+
BDScripts.Time = require("engine/time")
21+
22+
BDScripts.Cheats = {
23+
Crafting = require("cheats/crafting"),
24+
Johnny = require("cheats/johnny"),
25+
Player = require("cheats/player"),
26+
Legend = require("cheats/legend"),
27+
Platform = require("cheats/platform"),
28+
Modify = require("cheats/modify"),
29+
ItemSets = require("cheats/itemsets"),
30+
Cyberware = require("cheats/cyberware"),
31+
Facts = require("cheats/facts"),
32+
Teleport = require("cheats/teleport"),
33+
Ammo = require("cheats/ammo")
34+
}
35+
36+
return BDScripts
3637
end
3738

3839
local BD = BraindanceProtocol:new()
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
local Ammo = {
2+
counter = 0,
3+
isInfiniteAmmo = false,
4+
isInfiniteAmmoNoReload = false,
5+
lastMagazineAmmoCount = 0,
6+
lastActiveWeapon = nil
7+
}
8+
9+
local Utilities = require("utility")
10+
local Inventory = require("inventory")
11+
12+
-- All credits to Nexusmods user "TheBs65422" for the infinite ammo script
13+
function Ammo.AddAmmo()
14+
local moduleName = "Refill All Ammunition"
15+
Utilities.StartProtocol(moduleName)
16+
17+
Game.AddToInventory("Ammo.HandgunAmmo", 1000)
18+
Game.AddToInventory("Ammo.ShotgunAmmo", 1000)
19+
Game.AddToInventory("Ammo.RifleAmmo", 1000)
20+
Game.AddToInventory("Ammo.SniperRifleAmmo", 1000)
21+
Game.AddToInventory("Ammo.Special", 1000)
22+
23+
Utilities.FinishProtocol(moduleName)
24+
end
25+
26+
function Ammo.GetHashAndLength(itemID)
27+
if itemID == nil then
28+
return nil
29+
end
30+
31+
local hash = tostring(itemID):match("= (%g+),")
32+
local length = tostring(itemID):match("= (%g+) }")
33+
local result = nil
34+
35+
if hash ~= nil and length ~= nil then
36+
result = { hash, length }
37+
end
38+
39+
return result
40+
end
41+
42+
function Ammo.IsNewWeapon(weapon)
43+
if weapon == nil then
44+
return false
45+
elseif Ammo.lastActiveWeapon == nil then
46+
return true
47+
else
48+
local currentWeaponData = Ammo.GetHashAndLength(weapon:GetItemID())
49+
50+
if currentWeaponData == nil then
51+
return false
52+
end
53+
54+
local lastWeaponData = Ammo.GetHashAndLength(Ammo.lastActiveWeapon.itemID)
55+
56+
if lastWeaponData == nil then
57+
return true
58+
end
59+
60+
if currentWeaponData[1] ~= lastWeaponData[1] and currentWeaponData[2] ~= lastWeaponData[2] then
61+
return true
62+
else
63+
return false
64+
end
65+
end
66+
end
67+
68+
function Ammo.SetNewWeapon(weapon)
69+
if weapon ~= nil and Game ~= nil then
70+
local statsSystem = Game.GetStatsSystem()
71+
local weaponItemData = weapon:GetItemData()
72+
73+
if statsSystem ~= nil and weaponItemData ~= nil then
74+
local weaponStatsObjectID = weaponItemData:GetStatsObjectID()
75+
76+
if weaponStatsObjectID ~= nil then
77+
Ammo.lastActiveWeapon = {}
78+
79+
Ammo.lastActiveWeapon.statsObjectID = weaponStatsObjectID
80+
Ammo.lastActiveWeapon.itemID = weapon:GetItemID()
81+
Ammo.lastActiveWeapon.numShotsToFire = statsSystem:GetStatValue(weaponStatsObjectID, Game.EnumValueFromString("gamedataStatType", "NumShotsToFire"))
82+
end
83+
end
84+
end
85+
end
86+
87+
function Ammo.RestoreLastWeaponStats(isModifiedStats)
88+
if Ammo.lastActiveWeapon ~= nil then
89+
if isModifiedStats then
90+
local statModifier = Game['gameRPGManager::CreateStatModifier;gamedataStatTypegameStatModifierTypeFloat'](Game.EnumValueFromString("gamedataStatType", "NumShotsToFire"), Game.EnumValueFromString("gameStatModifierType", "Additive"), Ammo.lastActiveWeapon.numShotsToFire)
91+
92+
if statModifier ~= nil then
93+
local statsSystem = Game.GetStatsSystem()
94+
95+
if statsSystem ~= nil then
96+
statsSystem:AddModifier(Ammo.lastActiveWeapon.statsObjectID, statModifier)
97+
end
98+
end
99+
end
100+
101+
Ammo.lastActiveWeapon = nil
102+
Ammo.lastMagazineAmmoCount = 0
103+
end
104+
end
105+
106+
function Ammo.RefillAmmo(weapon, amount)
107+
if weapon ~= nil then
108+
local ammoType = Game['gameweaponObject::GetAmmoType;WeaponObject'](weapon)
109+
110+
if ammoType ~= nil and Game ~= nil then
111+
local transactionSystem = Game.GetTransactionSystem()
112+
local player = Game.GetPlayer()
113+
114+
if transactionSystem ~= nil and player ~= nil then
115+
transactionSystem:GiveItem(player, ammoType, amount)
116+
end
117+
end
118+
end
119+
end
120+
121+
function Ammo.InfiniteAmmoToggle()
122+
local moduleName = "Auto Refill Ammo Toggle"
123+
Utilities.StartProtocol(moduleName)
124+
125+
if Ammo.isInfiniteAmmo then
126+
Ammo.RestoreLastWeaponStats(false)
127+
end
128+
129+
Ammo.isInfiniteAmmo = not Ammo.isInfiniteAmmo
130+
131+
if Ammo.isInfiniteAmmo and Ammo.isInfiniteAmmoNoReload then
132+
Ammo.InfiniteAmmoNoReloadToggle()
133+
end
134+
print("Auto Refill:", Ammo.isInfiniteAmmo)
135+
Utilities.FinishProtocol(moduleName)
136+
end
137+
138+
function Ammo.InfiniteAmmoNoReloadToggle()
139+
local moduleName = "No Reload Toggle"
140+
Utilities.StartProtocol(moduleName)
141+
142+
if Ammo.isInfiniteAmmoNoReload then
143+
Ammo.RestoreLastWeaponStats(true)
144+
end
145+
146+
Ammo.isInfiniteAmmoNoReload = not Ammo.isInfiniteAmmoNoReload
147+
148+
if Ammo.isInfiniteAmmoNoReload and Ammo.isInfiniteAmmo then
149+
Ammo.InfiniteAmmoToggle()
150+
end
151+
print("No Reload:", Ammo.isInfiniteAmmoNoReload)
152+
Utilities.FinishProtocol(moduleName)
153+
end
154+
155+
function Ammo.OnUpdateAmmo(deltaTime)
156+
if (Ammo.isInfiniteAmmo or Ammo.isInfiniteAmmoNoReload) and Game ~= nil then
157+
Ammo.counter = Ammo.counter + deltaTime
158+
if (Ammo.counter > 0.1) then
159+
Ammo.counter = Ammo.counter - 0.1
160+
161+
local player = Game.GetPlayer()
162+
163+
if player ~= nil then
164+
local activeWeapon = Game.GetTransactionSystem():GetItemInSlot(player, TweakDBID.new('AttachmentSlots.WeaponRight'))
165+
166+
if activeWeapon ~= nil and Game['gameweaponObject::IsRanged;ItemID'](activeWeapon:GetItemID()) then
167+
if Ammo.isInfiniteAmmo then
168+
Ammo.SetInfiniteAmmo(activeWeapon)
169+
elseif Ammo.isInfiniteAmmoNoReload then
170+
Ammo.SetInfiniteAmmoNoReload(activeWeapon)
171+
end
172+
end
173+
end
174+
end
175+
end
176+
end
177+
178+
function Ammo.SetInfiniteAmmo(weapon)
179+
if weapon ~= nil and Game ~= nil then
180+
if Ammo.IsNewWeapon(weapon) then
181+
Ammo.RestoreLastWeaponStats(false)
182+
Ammo.SetNewWeapon(weapon)
183+
end
184+
185+
if Ammo.lastMagazineAmmoCount < 1 then
186+
Ammo.lastMagazineAmmoCount = Game['gameweaponObject::GetMagazineCapacity;WeaponObject'](weapon)
187+
end
188+
189+
local currentMagazineAmmoCount = Game['gameweaponObject::GetMagazineAmmoCount;WeaponObject'](weapon)
190+
191+
if currentMagazineAmmoCount < Ammo.lastMagazineAmmoCount then
192+
Ammo.RefillAmmo(weapon, Ammo.lastMagazineAmmoCount - currentMagazineAmmoCount)
193+
194+
Ammo.lastMagazineAmmoCount = currentMagazineAmmoCount
195+
end
196+
end
197+
end
198+
199+
function Ammo.SetInfiniteAmmoNoReload(weapon)
200+
if weapon ~= nil and Ammo.IsNewWeapon(weapon) and Game ~= nil then
201+
Ammo.RestoreLastWeaponStats(true)
202+
Ammo.SetNewWeapon(weapon)
203+
204+
if Ammo.lastActiveWeapon ~= nil then
205+
local statModifier = Game['gameRPGManager::CreateStatModifier;gamedataStatTypegameStatModifierTypeFloat'](Game.EnumValueFromString("gamedataStatType", "NumShotsToFire"), Game.EnumValueFromString("gameStatModifierType", "Additive"), -Ammo.lastActiveWeapon.numShotsToFire)
206+
local statsSystem = Game.GetStatsSystem()
207+
208+
if statModifier ~= nil and statsSystem ~= nil then
209+
statsSystem:AddModifier(Ammo.lastActiveWeapon.statsObjectID, statModifier)
210+
end
211+
end
212+
end
213+
end
214+
215+
return Ammo

mods/braindance_protocol/cheats/player.lua

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ function Player.AddMoney(quantity)
2727
Utilities.FinishProtocol(moduleName)
2828
end
2929

30-
function Player.AddAmmo()
31-
local moduleName = "Refill All Ammunition"
32-
Utilities.StartProtocol(moduleName)
33-
34-
Game.AddToInventory("Ammo.HandgunAmmo", 1000)
35-
Game.AddToInventory("Ammo.ShotgunAmmo", 1000)
36-
Game.AddToInventory("Ammo.RifleAmmo", 1000)
37-
Game.AddToInventory("Ammo.SniperRifleAmmo", 1000)
38-
Game.AddToInventory("Ammo.Special", 1000)
39-
40-
Utilities.FinishProtocol(moduleName)
41-
end
42-
4330

4431
function Player.MaxOut()
4532
local skills =
@@ -144,7 +131,7 @@ function Player.GodModeToggle()
144131
Utilities.StartProtocol(moduleName)
145132

146133
Player.godMode = not Player.godMode
147-
if (Player.godMode) then
134+
if (Player.godMode) then
148135
Game.GetGodModeSystem():EnableOverride(Game.GetPlayer():GetEntityID(), "Invulnerable", CName.new("SecondHeart"))
149136
if Game.GetWorkspotSystem():IsActorInWorkspot(Game.GetPlayer()) then
150137
veh = Game['GetMountedVehicle;GameObject'](Game.GetPlayer())
@@ -174,7 +161,7 @@ function Player.GodModeToggle()
174161
end
175162
end
176163
end
177-
164+
178165
print("Status:", Player.godMode)
179166
Utilities.FinishProtocol(moduleName)
180167
end
@@ -300,4 +287,4 @@ function Player.AddMaxMovementSpeed(quantity)
300287
Utilities.FinishProtocol(moduleName)
301288
end
302289

303-
return Player
290+
return Player

mods/braindance_protocol/init.lua

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,40 @@ registerHotkey("braindance_protocol_interface", "Open Protocol Interface", funct
3434
drawWindow = not drawWindow
3535
end)
3636

37-
-- A Few Hotkeys
38-
registerHotkey("braindance_protocol_addMoney", "Add Some Money", function()
39-
BD.Cheats.Player.AddMoney(10000)
37+
-- Hotkeys
38+
registerHotkey("braindance_protocol_godMode", "God Mode Toggle", function()
39+
BD.Cheats.Player.GodModeToggle()
40+
end)
41+
42+
registerHotkey("braindance_protocol_infStamina", "Infinite Stamina Toggle", function()
43+
BD.Cheats.Player.InfiniteStaminaToggle()
44+
end)
45+
46+
registerHotkey("braindance_protocol_slowMo", "Slow Motion Toggle", function()
47+
BD.Cheats.Player.SlowMotionToggle()
4048
end)
4149

4250
registerHotkey("braindance_protocol_addAmmo", "Refill Ammunition", function()
43-
BD.Cheats.Player.AddAmmo()
51+
BD.Cheats.Ammo.AddAmmo()
52+
end)
53+
54+
registerHotkey("braindance_protocol_infAmmo", "Infinite Ammunition Toggle", function()
55+
BD.Cheats.Ammo.InfiniteAmmoToggle()
56+
end)
57+
58+
registerHotkey("braindance_protocol_noReload", "No Reload Toggle", function()
59+
BD.Cheats.Ammo.InfiniteAmmoNoReloadToggle()
60+
end)
61+
62+
registerHotkey("braindance_protocol_addMoney", "Add Some Money", function()
63+
BD.Cheats.Player.AddMoney(10000)
4464
end)
4565

4666
registerHotkey("braindance_protocol_forceKillNPC", "Force Kill NPC", function()
4767
BD.Cheats.Player.ForceNPCDeath()
4868
end)
4969

50-
registerForEvent("onUpdate", function()
70+
registerForEvent("onUpdate", function(deltaTime)
5171
for l in pairs(languages) do
5272
if languages[l].selLang then
5373
setLang(languages[l].id)
@@ -63,6 +83,8 @@ registerForEvent("onUpdate", function()
6383
end
6484
end
6585
end
86+
-- Ammo OnUpdate
87+
BD.Cheats.Ammo.OnUpdateAmmo(deltaTime)
6688
end)
6789

6890
registerForEvent("onDraw", function()

0 commit comments

Comments
 (0)