Cambios

133 bytes eliminados ,  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 tonumber(formattedresult) < 1000 then return formattedresult end
+
formattedresult = mw.language.getContentLanguage():formatNum(result)
if ulang ~= "ES" then return formattedresult end
+
 
 +
if ((result < 1000) or (ulang ~= "ES")) then return formattedresult end
    
--replace space with dot
 
--replace space with dot
--Problem: ES doesn't add a space for 4 digits
+
--Problem: ES doesn't add a space for 4 digits, only for 5+
local temp = {mw.ustring.gsub(tostring(formattedresult), "%s" , "")}
  −
temp2 = string.sub(tostring(temp[1]), -3)
  −
return string.sub(tostring(formattedresult), 1, #formattedresult-3) .. "." .. temp2
  −
  −
  −
  −
--end
  −
end
     −
function calcenergy(edib, qualmult)
+
if (result < 10000) then
return math.floor(math.ceil(edib*2.5) + edib*qualmult)
+
length = #(tostring(result))
end
+
temp = string.sub(tostring(result), -3)
 
+
return string.sub(tostring(result), 1, (length-3)) .. "." .. temp
function calchealth(edib, qualmult)
+
else
return math.floor(math.floor(math.ceil(edib*2.5) + edib*qualmult) * 0.45)
+
temp = {mw.ustring.gsub(tostring(formattedresult), "%s" , ".")}
 +
return temp[1]
 +
end
 
end
 
end
    
return p
 
return p
105 900

ediciones