Cambios

112 bytes añadidos ,  16:53 27 feb 2023
m
Margotbean trasladó la página Módulo:Test a Módulo:Calcedibility sin dejar una redirección: I think I've settled on its final name
Línea 1: Línea 1:  
local p = {}
 
local p = {}
   −
--ceh = calculate energy or health
+
--ceh = calculate edibility (energy/health)
function p.ceh(frame)
+
function p.ce(frame)
 
local item = string.lower(frame.args.im)
 
local item = string.lower(frame.args.im)
 
local edibility = tonumber(frame.args.ed)
 
local edibility = tonumber(frame.args.ed)
 
local quality = tonumber(frame.args.q)
 
local quality = tonumber(frame.args.q)
 
local ulang = string.upper(frame.args.ll)
 
local ulang = string.upper(frame.args.ll)
local formattedresult
+
local result, formattedresult, temp, length
    
if edibility == 0 then return 0 end
 
if edibility == 0 then return 0 end
    
if item == "energy" then
 
if item == "energy" then
formattedresult = mw.language.getContentLanguage():formatNum(calcenergy(edibility, quality))
+
result = math.floor(math.ceil(edibility*2.5) + edibility*quality)
 
else
 
else
formattedresult = mw.language.getContentLanguage():formatNum(calchealth(edibility, quality))
+
result = math.floor(math.floor(math.ceil(edibility*2.5) + edibility*quality)*0.45)
 
end
 
end
   −
if ulang == "ES" then
+
formattedresult = mw.language.getContentLanguage():formatNum(result)
--replace space with dot
+
 
local temp = {mw.ustring.gsub(formattedresult, "%s" , ".")}
+
if ((result < 1000) or (ulang ~= "ES")) then return formattedresult end
return temp[1]
+
 
 +
--replace space with dot
 +
--Problem: ES doesn't add a space for 4 digits, only for 5+
 +
 
 +
if (result < 10000) then
 +
length = #(tostring(result))
 +
temp = string.sub(tostring(result), -3)
 +
return string.sub(tostring(result), 1, (length-3)) .. "." .. temp
 
else
 
else
return formattedresult
+
temp = {mw.ustring.gsub(tostring(formattedresult), "%s" , ".")}
 +
return temp[1]
 
end
 
end
end
  −
  −
function calcenergy(edib, qualmult)
  −
return math.floor(math.ceil(edib*2.5) + edib*qualmult)
  −
end
  −
  −
function calchealth(edib, qualmult)
  −
return math.floor(math.floor(math.ceil(edib*2.5) + edib*qualmult) * 0.45)
   
end
 
end
    
return p
 
return p
105 900

ediciones