Project Zomboid

Project Zomboid

奔跑换弹 [B42]
Not run if you have out of breath+ moodle
I was messing with the lua file and check the functions, they have easy reading names so, I was able to add a way to make it so you aren't able to run if you have any type of exertion moodle, even out of breath! so if anyone is intersted here is the code, just go into:
steamapps\workshop\content\108600\3397207461\mods\RunAndReload\42\media\lua\client\RunAndReload_Lua and open the variables.lua file and paste this:
引用自 pumpkerino
--Made by SportXAI
local function SetAllowReloading(player)
-- Get player's stamina
local stats = player:getStats()
local stamina = stats and stats:getEndurance() or 1.0
local staminaThreshold = 0.75 -- adjust this (0.0–1.0); lower = more forgiving

-- If stamina too low, disallow running + reloading
if stamina < staminaThreshold then
player:setVariable("RunAndReload_IsAllowed", false)
player:setVariable("RunAndReload_Enable", false)
player:setAllowRun(false)
return
end

-- Original logic
if not player:getVariableBoolean("RunAndReload_IsAllowed") then
player:setVariable("RunAndReload_IsAllowed", true)

if getCore():isToggleToRun() and (player:isRunning() or player:isSprinting()) then
player:setRunning(false)
player:setForceRun(false)
player:setVariable("RunAndReload_Enable", true)
end
end
end

local function SetVariable(player)
local actions = player:getCharacterActions()

for index = 0, actions:size()-1 do
local action = actions:get(index)
local actionName = action:getMetaType()

if math.abs(player:getVariableFloat("WalkInjury", 0)) > 0.1 then
player:setVariable("RunAndReload_Enable", false)
player:setVariable("RunAndReload_IsAllowed", false)
return
end
--Cancel running + reloading if stamina drops below threshold
local stats = player:getStats()
local stamina = stats and stats:getEndurance() or 1.0
local staminaThreshold = 0.75
if stamina < staminaThreshold then
player:setVariable("RunAndReload_Enable", false)
player:setVariable("RunAndReload_IsAllowed", false)
player:setAllowRun(false)
player:setRunning(false)
player:setForceRun(false)
return
end

--Load bullets into magazine
if actionName == "ISLoadBulletsInMagazine" then
SetAllowReloading(player)

--Unload bullets from firearm
elseif actionName == "ISUnloadBulletsFromFirearm" then
SetAllowReloading(player)

--Unload bullets from magazine
elseif actionName == "ISUnloadBulletsFromMagazine" then
SetAllowReloading(player)

--Is racking firearm
elseif actionName == "ISRackFirearm" then
SetAllowReloading(player)
--[[local weapon = player:getPrimaryHandItem()
if weapon ~= nil then
if weapon:isRanged() then
if not weapon:haveChamber() then
weapon:setHaveChamber(true)
end
end
end--]]

--Insert magazine
elseif actionName == "ISInsertMagazine" then
SetAllowReloading(player)

--Reload weapon action
elseif actionName == "ISReloadWeaponAction" then
SetAllowReloading(player)

--Eject magazine
elseif actionName == "ISEjectMagazine" then
SetAllowReloading(player)
end
end

--Settings for player
local key = getCore():getKey("Run")
if not getCore():isToggleToRun() then
if player:getVariableBoolean("RunAndReload_IsAllowed") then
player:setAllowRun(false)

if GameKeyboard.isKeyDown(key) then
player:setVariable("RunAndReload_Enable",true)
else
player:setVariable("RunAndReload_Enable",false)
end

if isJoypadConnected(0) then
if isJoypadRTPressed(0) then
player:setVariable("RunAndReload_Enable",true)
else
player:setVariable("RunAndReload_Enable",false)
end
end
else
player:setAllowRun(true)
end
end

if not player:hasTimedActions() then
if player:getVariableBoolean("RunAndReload_IsAllowed") then
if not getCore():isToggleToRun() then
player:setVariable("RunAndReload_Enable",false)
player:setVariable("RunAndReload_IsAllowed",false)
else --Toggle to run
if player:getVariableBoolean("RunAndReload_Enable") then
player:setRunning(true)
player:setForceRun(true)
player:setVariable("RunAndReload_Enable",false)
player:setVariable("RunAndReload_IsAllowed",false)
end
end
end
end
end

Events.OnPlayerUpdate.Add(SetVariable)