disabling weapons breaks reloadbar of healthbar widget

disabling weapons breaks reloadbar of healthbar widget

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

disabling weapons breaks reloadbar of healthbar widget

Post 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?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: disabling weapons breaks reloadbar of healthbar widget

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: disabling weapons breaks reloadbar of healthbar widget

Post by knorke »

ah thanks.
seems limited to xta...
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: disabling weapons breaks reloadbar of healthbar widget

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: disabling weapons breaks reloadbar of healthbar widget

Post 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 ;)
Post Reply

Return to “Lua Scripts”