Page 1 of 1

MainHand durability

Posted: Wed Oct 27, 2021 5:11 am
by ThulsaDoom
Before I was using this code to check main hand dura, then depending on result, to fo for repair.

Code: Select all

			local dura = inventory:getMainHandDurability()
			printf("Durability:%s\n", dura);
			if ( 99 > dura ) then
				__WPL:setWaypointIndex(__WPL:findWaypointTag("repair"));
			else
				__WPL:setWaypointIndex(__WPL:findWaypointTag("direct"));
			end
Now is not working anymore.
The function "inventory:getMainHandDurability()" returns a value that is not correct: -269446252, in the case of a 104 dura in mainhand.

Do I need to call in diferent way the function or is an address problem?

Many thnaks

Re: MainHand durability

Posted: Wed Oct 27, 2021 4:19 pm
by Administrator
This wasn't a mistake on your end. I've provided an update that should resolve this issue. It isn't always accurate (some items have the durability available on the item struct, while others have a seemingly random value and use a durability of 80 -- exactly what determines which value to use is unknown) but should be good enough.

If you update your scripts, things should be working.

Re: MainHand durability

Posted: Sat Oct 30, 2021 5:04 am
by ThulsaDoom
thanks, it works as before!

Re: MainHand durability

Posted: Wed Jun 15, 2022 6:22 am
by ThulsaDoom
It seems "inventory:getMainHandDurability()" It does not return a correct value.
Please, cannyou have a look?

Thanks a lot.

Re: MainHand durability

Posted: Thu Jun 16, 2022 3:34 pm
by Administrator
Could I get some more information? It seems to be having acceptably to me.
My mainhand has a durability of 76/100.
inventory:getMainHandDurability()
returns
76.15


If I had to guess, one thing that could be causing issues for you is that the max durability for items isn't reliably stored with the item itself. In other words, sometimes the "max durability" of an item in the game's memory is actually the durability, and sometimes it is just "0" even though the item does indeed have some max durability; it would need to be read from somewhere else. As a cheat, I've added some pretty dumb logic to cover for those cases and take a best guess at what the max durability of an item should be.

Re: MainHand durability

Posted: Sun Jun 19, 2022 4:06 am
by ThulsaDoom
Before it was getting 0.
Now it's getting a number that seems to be a ratio, the ratio of maximum durability to current durability.
This number is never equal to Durability and varies based on the maximum Durability of the weapon.

For each character and weapon, I have identified the number that the function returns when the durability is negative.
Use the following function to determine if the character's maihand weapon has no durability

Code: Select all

function checkDura()
		local dura = inventory:getMainHandDurability()
		local nodura = false 
		repeat myClass=RoMScript("UnitClass('player')"); until myClass
			if player.Name=="pj1" then
				if ( 94 > dura ) then
				 	nodura = true
				end	
			elseif player.Name=="pj2" then
				if myClass=="Rogue" then
					if ( 98 > dura ) then
				 		nodura = true
					end
				end
			elseif player.Name=="pj3" then
				if myClass=="Rogue" then
					if ( 99 > dura ) then
				 		nodura = true
					end
				elseif myClass=="Kinght" then
				 		nodura = true
				end
			elseif player.Name=="pj4" then
				if myClass=="Druid" then
					if ( 88 > dura ) then
				 		nodura = true 
					end
				end
			elseif player.Name=="pj5" then
				if myClass=="Warden" then
					if ( 98 > dura ) then
				 		nodura = true 
					end
				end
			end		
		return nodura
	end
So for now the function works fine for me.
Thank you

Re: MainHand durability

Posted: Sun Jun 19, 2022 6:40 am
by Administrator
Indeed,
getMainHandDurability()
and
getDurability()
actually return the percentage. It's goofy, but it was what I found when I had to pick up maintaining the scripts and didn't want to break compatibility.

It looks like you should be able to get the real (non-percentage) durability with:

Code: Select all

equipment.BagSlot[15]:update()
local dura = equipment.BagSlot[15].Durability
Where `15` is the index for main hand in equipment, `16` for offhand, and `10` for ranged.

Re: MainHand durability

Posted: Mon Jun 20, 2022 2:53 pm
by ThulsaDoom
Tested, worked perfectly, getting the real Durability.
Thank you