Page 1 of 1

disabling weapons breaks reloadbar of healthbar widget

Posted: 03 Aug 2011, 13:38
by knorke
To disable all weapons of a unit I do:

Code: Select all

function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
	if (wallActive and blockWeapons) then
		local n = #UnitDefs[unitDefID].weapons
		Spring.Echo ("n="..n)
		for wi=0,n-1,1 do
			Spring.SetUnitWeaponState (unitID, wi,{reloadFrame = 99999, reloadState =  9999})
		end
	end
which works. Can unblock weapons by setting reloadFrame=0
But on some few units like XTA commander or Merl (T2 rocket launcher vehicle) it breaks the reloadbar of the healthbars:
Image
Also shouldnt this:
Spring.SetUnitWeaponState (unitID, wi,{aimReady=2})
block the weapon too?

Re: disabling weapons breaks reloadbar of healthbar widget

Posted: 03 Aug 2011, 14:50
by FLOZi
S44 ammo gadget does it the same way, we have a modified healthbars widget to fix it

http://spring1944.svn.sourceforge.net/v ... iew=markup

Re: disabling weapons breaks reloadbar of healthbar widget

Posted: 03 Aug 2011, 15:12
by knorke
ah thanks.
seems limited to xta...

Re: disabling weapons breaks reloadbar of healthbar widget

Posted: 04 Aug 2011, 06:57
by Google_Frog
How to fix breaking healthbars:
  • You know lua
  • The widget is well written (followable, modular)
  • Modify healthbars until it suits your needs.
Of course that is assuming the "games have their own UI" paradigm.

Now I'm going to criticise your weapon handling.

Firstly according to the wiki reloadFrame and reloadState are synonyms. The behaviour is undefined when you set one to 99999 and the other to 9999 with the same function.

The larger problem is to do with your system and how reloadFrame work (which I think work really well). reloadFrame sets when the unit will next be able to fire. The frame 99999 is about 55.5 minutes into the game. Sure you could just use a larger number but that's really really inelegant.

Here is my solution. In the unit script do this:

Code: Select all

function script.AimWeapon(num, heading, pitch)
   return (spGetUnitRulesParam(unitID, "cantfire") == 0)
end
And then just manipulate the UnitRulesParam 'cantfire' in the gadget.

Re: disabling weapons breaks reloadbar of healthbar widget

Posted: 04 Aug 2011, 08:32
by knorke
hp widget probally just needs some if something < 0 then dont draw or something. was not sure if it was really the widgets fault though.

yes, 99999 looks a bit stupid but math.huge has no effect.
But I think instead setting of it to 99999 I could set it to the frame when all weapons will be unlocked again. (so AIs or whatever can read reload time and in theory react on it. ie retreat reloading units like some AIs do)
What happens in a unit script is not "visible" to the outside.
Can not modify the unit scripts anyway as it is for a map ;)