Module:Get body in set

From Final Fantasy XIV Online Wiki
Jump to navigation Jump to search

This module takes in input number of the format x.y and returns 2.y. Used for finding the body piece in an armor set, where the input is the armor of interest's sortkey (specified by Property:Has sortkey) and the output is the body armor of interest's sortkey (2.y). If the input is a whole number or anything but a decimal of the format x.y, this module returns 0.

Usage: {{#invoke:Get body in set|convert|<number>}}.



local p = {}

function p.convert(frame)
    -- Get the input from the frame (either direct argument or parent frame)
    local input = frame.args[1] or frame:getParent().args[1]
    
    -- Check if input exists
    if not input or input == '' then
        return "0"
    end
    
    -- Convert to string and trim whitespace
    input = tostring(input):match("^%s*(.-)%s*$")
    
    -- Convert to number to validate
    local num = tonumber(input)
    if not num then
        return "0"
    end
    
    -- Extract the decimal part
    local whole, decimal = input:match("^([^%.]+)%.(.+)$")
    
    -- If there's no decimal part, return 0
    if not decimal then
        return "0"
    end
    
    -- Return 2 with the original decimal part
    return "2." .. decimal
end

return p