Lua Function For Fewer Decimal Places - PetCharges

Language: JP EN DE FR
New Items
2023-11-19
users online
Forum » Windower » Support » Lua Function for fewer decimal places - PetCharges
Lua Function for fewer decimal places - PetCharges
 Quetzalcoatl.Xilkk
Offline
Server: Quetzalcoatl
Game: FFXI
user: Xilk
Posts: 1414
By Quetzalcoatl.Xilkk 2022-11-12 05:20:50
Link | Quote | Reply
 
I'm using Sammeh's Petcharges addon.
There is a small problem.
In the current version he displays a recast counter for Ready Charges.
It calculates fine, but it displays awful
It shows around 9 decimal places out on the seconds which causes the normal text to shift to the left and blink rapidly.

Can anyone show me how to use a function or limit the number of decimal places to 0 or 1 ?

below is the functions:
Code
windower.register_event('prerender', function()
    if self then
        if self.main_job == 'BST' then
            duration = windower.ffxi.get_ability_recasts()[102]
            if duration then 
                chargebase = (30 - merits - jobpoints - equip_reduction)
                charges = math.floor(((chargebase * 3) - duration) / chargebase)
                next_ready_recast = math.fmod(duration,chargebase)
                displayabilities()
            end
        end
    end
end)


Maybe its better to modify the abilty recast variable in the following function instead. I'm really not sure.
Code
function displayabilities()
  if pet then
    local list = "Charges: "..charges.." - "..next_ready_recast.."\n"
    for key,ability in pairs(abilitylist) do
        ability_en = res.job_abilities[ability].en
        ability_type = res.job_abilities[ability].type
        ability_targets = res.job_abilities[ability].targets
        ability_charges = res.job_abilities[ability].mp_cost
        if ability_targets.Self == true and ability_type == 'Monster' then
            if charges >= ability_charges then 
                list = list..'\\cs(0,255,0)'..ability_en..'\\cs(255,255,255)'..'\n'
            else
                list = list..'\\cs(255,255,255)'..ability_en..'\n'
            end
        end
    end
    abilities_list.value = list
    abilities_list:visible(true)
  else
    abilities_list:visible(false)
  end
end
 Bismarck.Tewl
Offline
Server: Bismarck
Game: FFXI
user: Tewl
Posts: 19
By Bismarck.Tewl 2022-11-12 06:13:29
Link | Quote | Reply
 
Quetzalcoatl.Xilkk said: »
Can anyone show me how to use a function or limit the number of decimal places to 0 or 1 ?

I don't know this addon but I'm assuming 'next_ready_recast' is the variable you want to reduce decimal place. Try this
Code
next_ready_recast = math.fmod(duration,chargebase)
next_ready_recast = math.floor(next_ready_recast * 10) / 10
 
Offline
Posts:
By 2022-11-12 06:14:13
 Undelete | Edit  | Link | Quote | Reply
 
Post deleted by User.
 Bahamut.Punishment
Offline
Server: Bahamut
Game: FFXI
Posts: 27
By Bahamut.Punishment 2022-11-14 18:11:52
Link | Quote | Reply
 
I just changed math.fmod to math.modf and it just counts down from 30 to zero now depending on how many charges I have left. Kind of a kludge fix but I don't have a lot of experience with this stuff beyond using basic gearswap. I kinda like it that way.
Log in to post.