View topic - disabling weapons breaks reloadbar of healthbar widget



All times are UTC + 1 hour


Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 03 Aug 2011, 12:38 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
To disable all weapons of a unit I do:
Code:
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?


Top
 Offline Profile  
 
PostPosted: 03 Aug 2011, 13:50 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
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


Top
 Offline Profile  
 
PostPosted: 03 Aug 2011, 14:12 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
ah thanks.
seems limited to xta...


Top
 Offline Profile  
 
PostPosted: 04 Aug 2011, 05:57 
Moderator

Joined: 12 Oct 2007, 08:24
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:
function script.AimWeapon(num, heading, pitch)
   return (spGetUnitRulesParam(unitID, "cantfire") == 0)
end
And then just manipulate the UnitRulesParam 'cantfire' in the gadget.


Top
 Offline Profile  
 
PostPosted: 04 Aug 2011, 07:32 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
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 ;)


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.