Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------
- -- Advanced Control Mod 0.8.1
- -- https://www.nexusmods.com/cyberpunk2077/mods/1902
- ----------------------------------------------------------------
- -- Settings
- disableAutoCover = false
- disableFirstEquip = false
- -- Vars
- isWalking = false
- isLeanLeft = false
- isLeanRight = false
- firstEquip = false
- CurrentGrenade = 0
- Grenades = {}
- timer = 0.0
- -- Init
- registerForEvent('onInit', function()
- setupWalk()
- setupFirstEquip()
- setupDisableAutoCover()
- end)
- -- Shutdown
- registerForEvent('onShutdown', function()
- setupWalk(false)
- end)
- -- Update
- registerForEvent('onUpdate', function(delta)
- if timer > 0.0 then
- timer = timer + delta
- end
- if not isLeanLeft and not isLeanRight then
- return
- end
- if not IsPlayerAiming() then
- isLeanLeft = false
- isLeanRight = false
- local player = Game.GetPlayer()
- local event = PlayerCoverStatusChangedEvent.new()
- event.fullyBehindCover = false
- player:QueueEvent(event)
- end
- end)
- -- Lean Left (Toggle)
- registerInput('advanced_control_lean_left', 'Lean Left (Toggle)', function(key)
- if not key or IsPlayerInMenu() or not IsPlayerAiming() then
- return
- end
- -- Cover + Aim
- if IsPlayerCover() then
- local coverDirection = getCoverDirection()
- if coverDirection.value == 'Left' then
- leanToLeft() -- center
- leanToLeft() -- force left
- isLeanLeft = true
- isLeanRight = false
- elseif coverDirection.value == 'Right' then
- leanToRight(true) -- center
- isLeanLeft = false
- isLeanRight = false
- else
- leanToLeft()
- isLeanLeft = true
- isLeanRight = false
- end
- -- Aim
- else
- if isLeanLeft then
- leanToRight(true)
- isLeanLeft = false
- isLeanRight = false
- elseif isLeanRight then
- leanToLeft(true)
- isLeanLeft = false
- isLeanRight = false
- else
- leanToLeft()
- isLeanLeft = true
- isLeanRight = false
- end
- end
- end)
- -- Lean Right (Toggle)
- registerInput('advanced_control_lean_right', 'Lean Right (Toggle)', function(key)
- if not key or IsPlayerInMenu() or not IsPlayerAiming() then
- return
- end
- -- Cover + Aim
- if IsPlayerCover() then
- local coverDirection = getCoverDirection()
- if coverDirection.value == 'Right' then
- leanToRight() -- center
- leanToRight() -- force right
- isLeanLeft = false
- isLeanRight = true
- elseif coverDirection.value == 'Left' then
- leanToLeft(true) -- center
- isLeanLeft = false
- isLeanRight = false
- else
- leanToRight()
- isLeanLeft = false
- isLeanRight = true
- end
- -- Aim
- else
- if isLeanRight then
- leanToLeft(true)
- isLeanLeft = false
- isLeanRight = false
- elseif isLeanLeft then
- leanToRight(true)
- isLeanLeft = false
- isLeanRight = false
- else
- leanToRight()
- isLeanLeft = false
- isLeanRight = true
- end
- end
- end)
- -- Lean Left (Hold)
- registerInput('advanced_control_lean_left_hold', 'Lean Left (Hold)', function(key)
- if IsPlayerInMenu() or not IsPlayerAiming() then
- return
- end
- if key then
- if IsPlayerCover() then
- leanToLeft() -- center
- leanToLeft() -- force left
- isLeanLeft = true
- isLeanRight = false
- else
- leanToLeft()
- isLeanLeft = true
- isLeanRight = false
- end
- else
- if isLeanLeft then
- leanToRight(true)
- isLeanLeft = false
- isLeanRight = false
- end
- end
- end)
- -- Lean Right (Hold)
- registerInput('advanced_control_lean_right_hold', 'Lean Right (Hold)', function(key)
- if IsPlayerInMenu() or not IsPlayerAiming() then
- return
- end
- if key then
- if IsPlayerCover() then
- leanToRight() -- center
- leanToRight() -- force right
- isLeanRight = true
- isLeanLeft = false
- else
- leanToRight()
- isLeanRight = true
- isLeanLeft = false
- end
- else
- if isLeanRight then
- leanToLeft(true)
- isLeanRight = false
- isLeanLeft = false
- end
- end
- end)
- -- Walk
- registerHotkey('advanced_control_walk', 'Walk', function()
- if IsPlayerInMenu() then
- return
- end
- if not isWalking then
- enableWalk()
- else
- disableWalk()
- end
- end)
- -- Walk (Hold)
- registerInput('advanced_control_walk_hold', 'Walk (Hold)', function(key)
- if IsPlayerInMenu() then
- return
- end
- if key then
- enableWalk()
- else
- disableWalk()
- end
- end)
- -- Grenade Next
- registerHotkey('advanced_control_grenade_next', 'Cycle Grenade Next', function()
- if IsPlayerInMenu() or IsPlayerScanner() then
- return
- end
- syncGrenades()
- local equipmentSystem = Game.GetScriptableSystemsContainer():Get('EquipmentSystem')
- local equipmentSystemPlayer = equipmentSystem:GetPlayerData(Game.GetPlayer())
- if CurrentGrenade == #Grenades then
- equipmentSystemPlayer:EquipItem(Grenades[ #Grenades ].ID, false)
- CurrentGrenade = 0
- else
- CurrentGrenade = CurrentGrenade + 1
- equipmentSystemPlayer:EquipItem(Grenades[ CurrentGrenade ].ID, false)
- end
- end)
- -- Grenade Prev
- registerHotkey('advanced_control_grenade_prev', 'Cycle Grenade Previous', function()
- if IsPlayerInMenu() or IsPlayerScanner() then
- return
- end
- syncGrenades()
- local equipmentSystem = Game.GetScriptableSystemsContainer():Get('EquipmentSystem')
- local equipmentSystemPlayer = equipmentSystem:GetPlayerData(Game.GetPlayer())
- if CurrentGrenade < 1 then
- CurrentGrenade = #Grenades
- else
- CurrentGrenade = CurrentGrenade - 1
- end
- equipmentSystemPlayer:EquipItem(Grenades[ CurrentGrenade ].ID, false)
- end)
- -- Holster
- registerHotkey('advanced_control_holster', 'Toggle Holster', function()
- if IsPlayerInMenu() then
- return
- end
- local Player = Game.GetPlayer()
- local QuickSlotsManager = Player:GetQuickSlotsManager()
- local Transaction = Game.GetTransactionSystem()
- local Equipment = Game.GetScriptableSystemsContainer():Get('EquipmentSystem')
- local PlayerEquipmentData = Equipment:GetPlayerData(Player)
- local Weapon = Transaction:GetItemInSlot(Player, TweakDBID.new("AttachmentSlots.WeaponRight"))
- if Weapon then
- QuickSlotsManager:HideWeapon()
- else
- QuickSlotsManager:RequestWeaponEquip(PlayerEquipmentData:GetActiveWeapon())
- end
- end)
- -- Untrack Quest
- registerHotkey('advanced_control_untrack', 'Untrack Quest', function()
- Game.untrack()
- local blackboard = Game.GetBlackboardSystem()
- local blackboardDefs = Game.GetAllBlackboardDefs()
- blackboard:Get(blackboardDefs.UI_System):SignalBool(blackboardDefs.UI_System.IsInMenu)
- end)
- function setupWalk(enable)
- local enable = (enable ~= false)
- -- PlayerSystem
- local PlayerSystem = Game.GetPlayerSystem()
- if not PlayerSystem then return end
- -- Player
- local Player = PlayerSystem:GetLocalPlayerMainGameObject()
- if not Player then return end
- -- StatSystem
- local StatSystem = Game.GetStatsSystem()
- if not StatSystem then return end
- if enable then
- WalkEffect = Game['gameRPGManager::CreateStatModifier;gamedataStatTypegameStatModifierTypeFloat']('MaxSpeed', 'Multiplier', 0.4)
- else
- StatSystem:RemoveModifier(Player:GetEntityID(), WalkEffect)
- end
- end
- function setupFirstEquip()
- if (disableFirstEquip) then
- return
- end
- Observe('PlayerPuppet', 'OnAction', function(self, action)
- -- bail early if player in menu or scanner
- if IsPlayerInMenu() or IsPlayerScanner() then
- return
- end
- local actionName = Game.NameToString(action:GetName(action)) -- Reload
- local actionType = action:GetType(action).value -- BUTTON_PRESSED | BUTTON_RELEASED
- local actionValue = action:GetValue(action) -- 0 | 1
- -- bail early if reload button not pressed
- if actionName ~= 'Reload' then
- return
- end
- if actionType == 'BUTTON_PRESSED' then
- timer = timer + 1.0
- return
- end
- if actionType == 'BUTTON_RELEASED' and timer < 1.3 then
- timer = 0.0
- return
- end
- timer = 0.0
- local Player = Game.GetPlayer()
- local Transaction = Game.GetTransactionSystem()
- local Weapon = Transaction:GetItemInSlot(Player, TweakDBID.new("AttachmentSlots.WeaponRight"))
- -- bail early if no weapon
- if not Weapon then
- return
- end
- local ItemID = Weapon:GetItemID()
- local canReload = Game['gameweaponObject::CanReload;WeaponObject'](Weapon)
- -- bail early if player can reload
- if canReload then
- return
- end
- local EquipmentSystem = Game.GetScriptableSystemsContainer():Get('EquipmentSystem')
- local EquipmentSystemPlayer = EquipmentSystem:GetPlayerData(Player)
- -- set marker
- firstEquip = true
- -- unequip + equip again
- EquipmentSystemPlayer:UnequipItem(ItemID)
- EquipmentSystemPlayer:EquipItem(ItemID, false)
- end)
- Observe('PlayerPuppet', 'OnWeaponEquipEvent', function(self, event)
- -- bail early if no marker
- if not firstEquip then
- return
- end
- -- first equip
- firstEquip = false
- event.animFeature.firstEquip = true
- end)
- end
- function setupDisableAutoCover()
- if not disableAutoCover then
- return
- end
- Observe('ActivateCoverEvents', 'OnUpdate', function(self)
- local coverDirection = getCoverDirection()
- if coverDirection.value == 'Left' then
- leanToLeft()
- elseif coverDirection.value == 'Right' then
- leanToRight()
- end
- end)
- end
- function enableWalk()
- Game.GetStatsSystem():AddModifier(Game.GetPlayer():GetEntityID(), WalkEffect)
- isWalking = true
- end
- function disableWalk()
- Game.GetStatsSystem():RemoveModifier(Game.GetPlayer():GetEntityID(), WalkEffect)
- isWalking = false
- end
- function syncGrenades()
- local equipmentSystem = Game.GetScriptableSystemsContainer():Get('EquipmentSystem')
- local equipmentSystemPlayer = equipmentSystem:GetPlayerData(Game.GetPlayer())
- local inventoryDataManager = equipmentSystemPlayer:GetInventoryManager()
- local items = inventoryDataManager['GetPlayerInventoryData;gamedataEquipmentAreaBoolarray<ItemModParams>'](inventoryDataManager, 'QuickSlot', true, {})
- if #Grenades == 0 then
- for i, item in ipairs(items) do
- local itemHash = item.ID.id.hash
- local itemID = item.ID
- local temp = {}
- temp.hash = itemHash
- temp.ID = itemID
- table.insert(Grenades, temp)
- end
- else
- for i, item in ipairs(items) do
- local itemHash = item.ID.id.hash
- local itemID = item.ID
- local found = false
- local temp = {}
- temp.hash = itemHash
- temp.ID = itemID
- for _, grenade in ipairs(Grenades) do
- if grenade.hash == itemHash then
- found = true
- end
- if equipmentSystemPlayer:HasItemInInventory(grenade.ID) == false then
- CurrentGrenade = 0
- Grenades = {}
- syncGrenades()
- return
- end
- end
- if found == false then
- table.insert(Grenades, temp)
- end
- end
- end
- end
- function IsPlayerAiming()
- local GetPlayer = Game.GetPlayer()
- if GetPlayer == nil then
- return false
- end
- local GetEntityID = GetPlayer:GetEntityID()
- local blackboard = Game.GetBlackboardSystem()
- local blackboardDefs = Game.GetAllBlackboardDefs()
- local blackboardPSM = blackboardDefs.PlayerStateMachine
- return blackboard:GetLocalInstanced(GetEntityID, blackboardPSM):GetInt(blackboardPSM.UpperBody) == 6
- end
- function IsPlayerCover()
- local GetPlayer = Game.GetPlayer()
- if GetPlayer == nil then
- return false
- end
- local GetEntityID = GetPlayer:GetEntityID()
- local blackboard = Game.GetBlackboardSystem()
- local blackboardDefs = Game.GetAllBlackboardDefs()
- local blackboardPSM = blackboardDefs.PlayerStateMachine
- return blackboard:GetLocalInstanced(GetEntityID, blackboardPSM):GetBool(blackboardPSM.UsingCover)
- end
- function IsPlayerScanner()
- local blackboard = Game.GetBlackboardSystem()
- local blackboardDefs = Game.GetAllBlackboardDefs()
- return blackboard:Get(blackboardDefs.UI_Scanner):GetBool(blackboardDefs.UI_Scanner.UIVisible)
- end
- function IsPlayerInMenu()
- local blackboard = Game.GetBlackboardSystem()
- local blackboardDefs = Game.GetAllBlackboardDefs()
- local uiSystem = blackboard:Get(blackboardDefs.UI_System)
- if (not uiSystem) then
- return true
- end
- return uiSystem:GetBool(blackboardDefs.UI_System.IsInMenu) or GetSingleton('inkMenuScenario'):GetSystemRequestsHandler():IsPreGame()
- end
- function leanToLeft(reset)
- local reset = reset or false
- local player = Game.GetPlayer()
- Game.GetSpatialQueriesSystem():GetPlayerObstacleSystem():ManualLeanRight(player)
- local event = PlayerCoverStatusChangedEvent.new()
- if not reset then
- event.direction = 1
- end
- event.fullyBehindCover = false
- player:QueueEvent(event)
- end
- function leanToRight(reset)
- local reset = reset or false
- local player = Game.GetPlayer()
- Game.GetSpatialQueriesSystem():GetPlayerObstacleSystem():ManualLeanLeft(player)
- local event = PlayerCoverStatusChangedEvent.new()
- if not reset then
- event.direction = 2
- end
- event.fullyBehindCover = false
- player:QueueEvent(event)
- end
- function getCoverDirection()
- return Game.GetSpatialQueriesSystem():GetPlayerObstacleSystem():GetCoverDirection(Game.GetPlayer())
- end
Advertisement
Add Comment
Please, Sign In to add comment