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: Also shouldnt this: Spring.SetUnitWeaponState (unitID, wi,{aimReady=2}) block the weapon too?
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.
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
Users browsing this forum: No registered users and 3 guests
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