Module:ItemEconomy: Difference between revisions

m
Replace Shared module with Number module
m (Fix nil exceptions)
m (Replace Shared module with Number module)
Line 1: Line 1:
local number = require('Module:Number')
local p = {}
local p = {}
local function clamp(value, min, max)
    return math.min(math.max(value, min), max)
end


--
--
Line 18: Line 16:


-- Clamp values and turn them into decimals
-- Clamp values and turn them into decimals
     local preservationP = clamp(preservationChance, 0, 80) / 100
     local preservationP = number.clamp(preservationChance, 0, 80) / 100
     local duplicationP = clamp(duplicationChance, 0, 100) / 100
     local duplicationP = number.clamp(duplicationChance, 0, 100) / 100
     local extraItemP = math.max(extraItemChance, 0) / 100
     local extraItemP = math.max(extraItemChance, 0) / 100
      
      
Line 42: Line 40:
     extraItemChance = extraItemChance or 0
     extraItemChance = extraItemChance or 0


     local preservationP = clamp(preservationChance, 0, 80) / 100
     local preservationP = number.clamp(preservationChance, 0, 80) / 100
     local duplicationP = clamp(duplicationChance, 0, 100) / 100
     local duplicationP = number.clamp(duplicationChance, 0, 100) / 100
     local extraItemP = math.max(extraItemChance, 0) / 100
     local extraItemP = math.max(extraItemChance, 0) / 100
      
      
2,875

edits