Skip to content

Instantly share code, notes, and snippets.

@Cvar1984
Created February 19, 2025 10:10
Show Gist options
  • Save Cvar1984/79b143c044313944b625f37d5d67cb84 to your computer and use it in GitHub Desktop.
Save Cvar1984/79b143c044313944b625f37d5d67cb84 to your computer and use it in GitHub Desktop.
Simulate and calculate terror of nowhere panthera weapon cost
-- Function to simulate enkephalin usage and calculate paralysis occurrences
local function simulatePanthera(userInputEnkephalin)
-- Constants for calculations
local percentage = 1 -- Percentage of total enkephalin used per hit
local base = 3 -- Base cost for each hit
local minimum = 5 -- Minimum cost for a hit
local totalEnkephalin = userInputEnkephalin -- Total enkephalin available
local hitCounter = 0 -- Counter for the number of hits made
local costCounter = 0 -- Counter for the total cost incurred
local paralizeCounter = 0 -- Counter for paralysis occurrences
local totalParalizeTimeCounter = 0 -- Total paralysis duration
local totalTimeElapsed = 0 -- Total time spent firing
math.randomseed(os.time()) -- Seed the random number generator for randomness
-- Loop until we run out of enkephalin
while totalEnkephalin >= minimum do
-- Calculate the cost of the next hit
local cost = (totalEnkephalin * percentage / 100) + base
cost = math.ceil(cost) -- Round up the cost to the nearest integer
-- Ensure the cost is not below the minimum value
if cost < minimum then
cost = minimum
end
-- Update counters
costCounter = costCounter + cost
totalEnkephalin = totalEnkephalin - cost
hitCounter = hitCounter + 1
totalTimeElapsed = totalTimeElapsed + 0.25 -- Each shot takes 0.25 seconds
-- Independent 10% chance per hit to trigger paralysis
if math.random(1, 10) == 1 then
paralizeCounter = paralizeCounter + 1
-- Simulate paralysis duration (1 to 3 seconds)
local paralizeDuration = math.random(1, 3) -- Random duration between 1 and 3 seconds
totalParalizeTimeCounter = totalParalizeTimeCounter + paralizeDuration
end
end
-- Calculate expected and actual paralysis occurrences
local expectedParalysis = hitCounter * 0.1 -- Expected paralysis based on hits
-- Estimate expected paralysis duration based on average duration
local averageParalizeDuration = 2 -- Average of 1 to 3 seconds
local expectedparalizeDuration = expectedParalysis * averageParalizeDuration -- Expected duration
-- Calculate paralysis rate
local paralysisRate = (paralizeCounter / hitCounter) * 100
return {
hitCounter = hitCounter,
costCounter = costCounter,
totalEnkephalin = totalEnkephalin,
paralysisCounter = paralizeCounter,
paralysisRate = paralysisRate,
expectedParalysis = expectedParalysis,
totalParalizeTimeCounter = totalParalizeTimeCounter,
expectedparalizeDuration = expectedparalizeDuration,
totalTimeElapsed = totalTimeElapsed
}
end
io.write("Enkephalin Earned: ")
local userInputEnkephalin = io.read("*n") -- Read in numerical
local results = simulatePanthera(userInputEnkephalin)
print("Total hit: " .. results.hitCounter .. "x")
print("Total cost: " .. results.costCounter .. " EPH")
print("Enkephalin left: " .. results.totalEnkephalin .. " EPH")
print("Bullet per chunk: " .. results.hitCounter / userInputEnkephalin .. " Hit")
print("Bullet per spent: " .. results.hitCounter / results.costCounter .. " Hit")
print("Actual Cost Per bullet: " .. results.costCounter / results.hitCounter .. " EPH")
print("Actual Paralysis Occurrences: " .. results.paralysisCounter .. "x")
print("Actual Paralysis Duration: " .. results.totalParalizeTimeCounter .. " seconds")
print("Expected Paralysis Occurrences: " .. string.format("%.1f", math.ceil(results.expectedParalysis)))
print("Expected Paralysis Duration: " .. string.format("%.2f", results.expectedparalizeDuration) .. " seconds")
print("Total Time Elapsed (Shooting Time): " .. string.format("%.2f", results.totalTimeElapsed) .. " seconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment