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

Commit

Permalink
Merge pull request #85 from VP-EN/dev
Browse files Browse the repository at this point in the history
Infinite Ammo + No Reload toggle
  • Loading branch information
VP-EN authored Feb 14, 2021
2 parents f5b9b83 + 0718095 commit 4d954b9
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 70 deletions.
63 changes: 32 additions & 31 deletions mods/braindance_protocol/BD.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
local BraindanceProtocol = {
description = "",
description = "",
}

function BraindanceProtocol:new()
local BDScripts = {}

setmetatable(BDScripts, self)
self.__index = self


-- Load LUA modules into memory
BDScripts.Utilities = require("utility")
BDScripts.Player = require("player")
BDScripts.Inventory = require("inventory")
BDScripts.Vehicles = require("ai/vehicles")
BDScripts.Examples = require("examples/init")
BDScripts.Shopper = require("utility/shopper")
BDScripts.Saves = require("engine/saves")
BDScripts.Time = require("engine/time")

BDScripts.Cheats = {
Crafting = require("cheats/crafting"),
Johnny = require("cheats/johnny"),
Player = require("cheats/player"),
Legend = require("cheats/legend"),
Platform = require("cheats/platform"),
Modify = require("cheats/modify"),
ItemSets = require("cheats/itemsets"),
Cyberware = require("cheats/cyberware"),
Facts = require("cheats/facts"),
Teleport = require("cheats/teleport")
}

return BDScripts
local BDScripts = {}

setmetatable(BDScripts, self)
self.__index = self


-- Load LUA modules into memory
BDScripts.Utilities = require("utility")
BDScripts.Player = require("player")
BDScripts.Inventory = require("inventory")
BDScripts.Vehicles = require("ai/vehicles")
BDScripts.Examples = require("examples/init")
BDScripts.Shopper = require("utility/shopper")
BDScripts.Saves = require("engine/saves")
BDScripts.Time = require("engine/time")

BDScripts.Cheats = {
Crafting = require("cheats/crafting"),
Johnny = require("cheats/johnny"),
Player = require("cheats/player"),
Legend = require("cheats/legend"),
Platform = require("cheats/platform"),
Modify = require("cheats/modify"),
ItemSets = require("cheats/itemsets"),
Cyberware = require("cheats/cyberware"),
Facts = require("cheats/facts"),
Teleport = require("cheats/teleport"),
Ammo = require("cheats/ammo")
}

return BDScripts
end

local BD = BraindanceProtocol:new()
Expand Down
215 changes: 215 additions & 0 deletions mods/braindance_protocol/cheats/ammo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
local Ammo = {
counter = 0,
isInfiniteAmmo = false,
isInfiniteAmmoNoReload = false,
lastMagazineAmmoCount = 0,
lastActiveWeapon = nil
}

local Utilities = require("utility")
local Inventory = require("inventory")

-- All credits to Nexusmods user "TheBs65422" for the infinite ammo script
function Ammo.AddAmmo()
local moduleName = "Refill All Ammunition"
Utilities.StartProtocol(moduleName)

Game.AddToInventory("Ammo.HandgunAmmo", 1000)
Game.AddToInventory("Ammo.ShotgunAmmo", 1000)
Game.AddToInventory("Ammo.RifleAmmo", 1000)
Game.AddToInventory("Ammo.SniperRifleAmmo", 1000)
Game.AddToInventory("Ammo.Special", 1000)

Utilities.FinishProtocol(moduleName)
end

function Ammo.GetHashAndLength(itemID)
if itemID == nil then
return nil
end

local hash = tostring(itemID):match("= (%g+),")
local length = tostring(itemID):match("= (%g+) }")
local result = nil

if hash ~= nil and length ~= nil then
result = { hash, length }
end

return result
end

function Ammo.IsNewWeapon(weapon)
if weapon == nil then
return false
elseif Ammo.lastActiveWeapon == nil then
return true
else
local currentWeaponData = Ammo.GetHashAndLength(weapon:GetItemID())

if currentWeaponData == nil then
return false
end

local lastWeaponData = Ammo.GetHashAndLength(Ammo.lastActiveWeapon.itemID)

if lastWeaponData == nil then
return true
end

if currentWeaponData[1] ~= lastWeaponData[1] and currentWeaponData[2] ~= lastWeaponData[2] then
return true
else
return false
end
end
end

function Ammo.SetNewWeapon(weapon)
if weapon ~= nil and Game ~= nil then
local statsSystem = Game.GetStatsSystem()
local weaponItemData = weapon:GetItemData()

if statsSystem ~= nil and weaponItemData ~= nil then
local weaponStatsObjectID = weaponItemData:GetStatsObjectID()

if weaponStatsObjectID ~= nil then
Ammo.lastActiveWeapon = {}

Ammo.lastActiveWeapon.statsObjectID = weaponStatsObjectID
Ammo.lastActiveWeapon.itemID = weapon:GetItemID()
Ammo.lastActiveWeapon.numShotsToFire = statsSystem:GetStatValue(weaponStatsObjectID, Game.EnumValueFromString("gamedataStatType", "NumShotsToFire"))
end
end
end
end

function Ammo.RestoreLastWeaponStats(isModifiedStats)
if Ammo.lastActiveWeapon ~= nil then
if isModifiedStats then
local statModifier = Game['gameRPGManager::CreateStatModifier;gamedataStatTypegameStatModifierTypeFloat'](Game.EnumValueFromString("gamedataStatType", "NumShotsToFire"), Game.EnumValueFromString("gameStatModifierType", "Additive"), Ammo.lastActiveWeapon.numShotsToFire)

if statModifier ~= nil then
local statsSystem = Game.GetStatsSystem()

if statsSystem ~= nil then
statsSystem:AddModifier(Ammo.lastActiveWeapon.statsObjectID, statModifier)
end
end
end

Ammo.lastActiveWeapon = nil
Ammo.lastMagazineAmmoCount = 0
end
end

function Ammo.RefillAmmo(weapon, amount)
if weapon ~= nil then
local ammoType = Game['gameweaponObject::GetAmmoType;WeaponObject'](weapon)

if ammoType ~= nil and Game ~= nil then
local transactionSystem = Game.GetTransactionSystem()
local player = Game.GetPlayer()

if transactionSystem ~= nil and player ~= nil then
transactionSystem:GiveItem(player, ammoType, amount)
end
end
end
end

function Ammo.InfiniteAmmoToggle()
local moduleName = "Auto Refill Ammo Toggle"
Utilities.StartProtocol(moduleName)

if Ammo.isInfiniteAmmo then
Ammo.RestoreLastWeaponStats(false)
end

Ammo.isInfiniteAmmo = not Ammo.isInfiniteAmmo

if Ammo.isInfiniteAmmo and Ammo.isInfiniteAmmoNoReload then
Ammo.InfiniteAmmoNoReloadToggle()
end
print("Auto Refill:", Ammo.isInfiniteAmmo)
Utilities.FinishProtocol(moduleName)
end

function Ammo.InfiniteAmmoNoReloadToggle()
local moduleName = "No Reload Toggle"
Utilities.StartProtocol(moduleName)

if Ammo.isInfiniteAmmoNoReload then
Ammo.RestoreLastWeaponStats(true)
end

Ammo.isInfiniteAmmoNoReload = not Ammo.isInfiniteAmmoNoReload

if Ammo.isInfiniteAmmoNoReload and Ammo.isInfiniteAmmo then
Ammo.InfiniteAmmoToggle()
end
print("No Reload:", Ammo.isInfiniteAmmoNoReload)
Utilities.FinishProtocol(moduleName)
end

function Ammo.OnUpdateAmmo(deltaTime)
if (Ammo.isInfiniteAmmo or Ammo.isInfiniteAmmoNoReload) and Game ~= nil then
Ammo.counter = Ammo.counter + deltaTime
if (Ammo.counter > 0.1) then
Ammo.counter = Ammo.counter - 0.1

local player = Game.GetPlayer()

if player ~= nil then
local activeWeapon = Game.GetTransactionSystem():GetItemInSlot(player, TweakDBID.new('AttachmentSlots.WeaponRight'))

if activeWeapon ~= nil and Game['gameweaponObject::IsRanged;ItemID'](activeWeapon:GetItemID()) then
if Ammo.isInfiniteAmmo then
Ammo.SetInfiniteAmmo(activeWeapon)
elseif Ammo.isInfiniteAmmoNoReload then
Ammo.SetInfiniteAmmoNoReload(activeWeapon)
end
end
end
end
end
end

function Ammo.SetInfiniteAmmo(weapon)
if weapon ~= nil and Game ~= nil then
if Ammo.IsNewWeapon(weapon) then
Ammo.RestoreLastWeaponStats(false)
Ammo.SetNewWeapon(weapon)
end

if Ammo.lastMagazineAmmoCount < 1 then
Ammo.lastMagazineAmmoCount = Game['gameweaponObject::GetMagazineCapacity;WeaponObject'](weapon)
end

local currentMagazineAmmoCount = Game['gameweaponObject::GetMagazineAmmoCount;WeaponObject'](weapon)

if currentMagazineAmmoCount < Ammo.lastMagazineAmmoCount then
Ammo.RefillAmmo(weapon, Ammo.lastMagazineAmmoCount - currentMagazineAmmoCount)

Ammo.lastMagazineAmmoCount = currentMagazineAmmoCount
end
end
end

function Ammo.SetInfiniteAmmoNoReload(weapon)
if weapon ~= nil and Ammo.IsNewWeapon(weapon) and Game ~= nil then
Ammo.RestoreLastWeaponStats(true)
Ammo.SetNewWeapon(weapon)

if Ammo.lastActiveWeapon ~= nil then
local statModifier = Game['gameRPGManager::CreateStatModifier;gamedataStatTypegameStatModifierTypeFloat'](Game.EnumValueFromString("gamedataStatType", "NumShotsToFire"), Game.EnumValueFromString("gameStatModifierType", "Additive"), -Ammo.lastActiveWeapon.numShotsToFire)
local statsSystem = Game.GetStatsSystem()

if statModifier ~= nil and statsSystem ~= nil then
statsSystem:AddModifier(Ammo.lastActiveWeapon.statsObjectID, statModifier)
end
end
end
end

return Ammo
19 changes: 3 additions & 16 deletions mods/braindance_protocol/cheats/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ function Player.AddMoney(quantity)
Utilities.FinishProtocol(moduleName)
end

function Player.AddAmmo()
local moduleName = "Refill All Ammunition"
Utilities.StartProtocol(moduleName)

Game.AddToInventory("Ammo.HandgunAmmo", 1000)
Game.AddToInventory("Ammo.ShotgunAmmo", 1000)
Game.AddToInventory("Ammo.RifleAmmo", 1000)
Game.AddToInventory("Ammo.SniperRifleAmmo", 1000)
Game.AddToInventory("Ammo.Special", 1000)

Utilities.FinishProtocol(moduleName)
end


function Player.MaxOut()
local skills =
Expand Down Expand Up @@ -144,7 +131,7 @@ function Player.GodModeToggle()
Utilities.StartProtocol(moduleName)

Player.godMode = not Player.godMode
if (Player.godMode) then
if (Player.godMode) then
Game.GetGodModeSystem():EnableOverride(Game.GetPlayer():GetEntityID(), "Invulnerable", CName.new("SecondHeart"))
if Game.GetWorkspotSystem():IsActorInWorkspot(Game.GetPlayer()) then
veh = Game['GetMountedVehicle;GameObject'](Game.GetPlayer())
Expand Down Expand Up @@ -174,7 +161,7 @@ function Player.GodModeToggle()
end
end
end
print("Status:", Player.godMode)
Utilities.FinishProtocol(moduleName)
end
Expand Down Expand Up @@ -300,4 +287,4 @@ function Player.AddMaxMovementSpeed(quantity)
Utilities.FinishProtocol(moduleName)
end

return Player
return Player
32 changes: 27 additions & 5 deletions mods/braindance_protocol/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,40 @@ registerHotkey("braindance_protocol_interface", "Open Protocol Interface", funct
drawWindow = not drawWindow
end)

-- A Few Hotkeys
registerHotkey("braindance_protocol_addMoney", "Add Some Money", function()
BD.Cheats.Player.AddMoney(10000)
-- Hotkeys
registerHotkey("braindance_protocol_godMode", "God Mode Toggle", function()
BD.Cheats.Player.GodModeToggle()
end)

registerHotkey("braindance_protocol_infStamina", "Infinite Stamina Toggle", function()
BD.Cheats.Player.InfiniteStaminaToggle()
end)

registerHotkey("braindance_protocol_slowMo", "Slow Motion Toggle", function()
BD.Cheats.Player.SlowMotionToggle()
end)

registerHotkey("braindance_protocol_addAmmo", "Refill Ammunition", function()
BD.Cheats.Player.AddAmmo()
BD.Cheats.Ammo.AddAmmo()
end)

registerHotkey("braindance_protocol_infAmmo", "Infinite Ammunition Toggle", function()
BD.Cheats.Ammo.InfiniteAmmoToggle()
end)

registerHotkey("braindance_protocol_noReload", "No Reload Toggle", function()
BD.Cheats.Ammo.InfiniteAmmoNoReloadToggle()
end)

registerHotkey("braindance_protocol_addMoney", "Add Some Money", function()
BD.Cheats.Player.AddMoney(10000)
end)

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

registerForEvent("onUpdate", function()
registerForEvent("onUpdate", function(deltaTime)
for l in pairs(languages) do
if languages[l].selLang then
setLang(languages[l].id)
Expand All @@ -63,6 +83,8 @@ registerForEvent("onUpdate", function()
end
end
end
-- Ammo OnUpdate
BD.Cheats.Ammo.OnUpdateAmmo(deltaTime)
end)

registerForEvent("onDraw", function()
Expand Down
Loading

0 comments on commit 4d954b9

Please sign in to comment.