I have to start off with an apology, I said i'd reply back when the script is finished and now I am replying back with an unfinished script.
I also have to apologise for how long I have been abscent since my last post. I have been trying to put in as much work on the script as I can but my full-time education has priority.
And I can't forget the MOTM nomination from USS Sovereign. :eek No emoticon available can express the surprise that hit me when I got the PM from JimmyB76. All I can say is it's very flattering but I don't consider myself ellegable given: the script was generously given to me by Defiant and I have done very little of the work by myself.
------------------------------------------------------------
Now moving onto the script.
(The script and a ConsoleTrackerDump.txt are attached)
I have made, what I consider to be, some big leaps since my last post and now. I have put down the all-important conditional statements logic that determines what shield generator is currently active and what shield generator is going to take over (if any), or turn off the shields altogether.
I have also worked out the FOR loop that goes through the players shields and stores and/or applies the new shield values (if necessary) when generators become operational/disabled.
To be straight to the point and try not draw out the post to an essay (a habit of mine) I will hand out the reasons and problems for why the script is ready for use.
WARNING: The script is quite messy since I threw in print statements all over the place to find out what's going on. I've also constructed quite a tree of IF ELSE IF ... statements, although hopefully the comments will keep you on track.
PROBLEMS WITH THE SCRIPT:1) Innaccurate shield values being assigned due to incorrect ShieldPercentage value.When a generator goes offline I store the values of all it's shields so they can be loaded and applied when (IF) that generator comes back online. In order to do this however I have to store the current values and NOT the maximum HP file values.
First I need the percentage strength of the current shield being worked on in the FOR loop. I do this differently depending on whether the script is running for the first time or not.
For the first run I get it on line 146 with:
ShieldPercentage = ShieldGenerators[0].GetSingleShieldPercentage(Shield)
After the first run I get it on line 163 with:
ShieldPercentage = pShields.GetSingleShieldPercentage(Shield)
Then I take this percentage value and use it to calculate the current strength of the current shield.
I do this on lines:
173 (storing current secondary generator shield values)
pSecondaryShieldVals[Shield] = pSecondaryGen.GetMaxShields(Shield) / 100 * ShieldPercentage * 100
186 (storing current primary generator shield values)
pPrimaryShieldVals[Shield] = pDisabledObject.GetMaxShields(Shield) / 100 * ShieldPercentage * 100
As you can see I am using the standard mathematical percentage formula: ((number / 100) * percentage) to work out what the real strength of the current shield is based on the current percentage value stored in variable
ShieldPercentage.
The
ShieldPercentage variable isn't very reliable. If you look at line 317 of ConsoleTrackerDump.txt you will see that in the scenario the shield generator is being disabled because both fake generators are offline; the primary generator has just been disabled and secondary is also offline.
The script should be using
ShieldPercentage to calcualte the current strength of the current shield and store it, instead though because
ShieldPercentage is 1.0 (100%) the maximum shield strength is being stored instead of it's current ingame damaged strength.
1a) Tactical display not correct. The ingame strength of all shields is shown as 100%, even when the correct values are loaded.I put this down as 1A because it's tied in with the
ShieldPercentage problem. Most of the time you will find, if you ran the script and looked at the log from Console Tracker, that the current strength of the shield is being calculated, recorded, loaded and applied correctly.
However you will go back ingame and see that the shield display gives all shields in GREEN status, implying 100% strength when in fact they are just as weak or strong as when the generator was disabled. Having downloaded Defiants
ShieldPercentages mod I have double confirmation of this as every shield gives it's percentage value at 100%
I wonder, can I calcualte the current percentage strength value of the shield as well as the shield strength values? If so could I use it to manually set the SingleShieldPercentage value and thus force the tactical display to show the correct percentage strength?
There is a:
pShields.GetSingleShieldPercentage(Shield)
but is there?
pShields.
SetSingleShieldPercentage(ShieldPercentage)
IMPROVEMENTS & TO-DO:2) Expand the scope of the script through the use of dictionaries and objectIDs, allowing it to work with an unlimited number of ships & shield generators in QB.I will need a data structure something such as:
[allShips]
[ship]
[primaryGenVals]
[secondaryGenVals]
[ship]
[primaryGenVals]
[secondaryGenVals]
[ship]
[primaryGenVals]
[secondaryGenVals]
[ship]
[primaryGenVals]
[secondaryGenVals]
I would then need to access it in a way similar to:
allShips[shipID[primaryGenVals]]
allShips[shipID[secondaryGenVals]]
How can I possibly write the script to manage a potentially unlimited amount of ships, and further more, continue to accurately decide what generators on each ship are ON/OFF and take appropraite action?
Bear in mind that the script is called when: player gets a new ship, a (any) subsystem is disabled or operational.
(MAYBE) TO-DOs3) Cover the CTRL + SHIFT + R scenario.Do I need to reset shield strengths for both generators or it's gonna trip over when they force repair both generators at the same time. How do I know if the player hits those three keys?
4) Add a delay value that is accessible through the Foundation plugin so the user can choose how long it takes for the shields to switchover.
I simply have no idea how to add a real-world time delay to a script.
What if an insanely large amount of time is given for the switchover?
What if during the delay between switchover a generator is repaired or disabled? Such as primary getting disabled, a delay of N seconds starting then the primary comes back online - OR the secondary (which is all set to takeover) is disabled?
It's nice to open up the script a bit and allow some room for configuration. I personally think that there should be absolutely no delay between switchover because you will be in a warzone and it'd be a serious design flaw for there to be a delay between generator switch-overs.
5) Foundation technologies?Will shield modifiers work or will it have problems working on ships that use Primary and Secondary shields?
Can I allow users to apply different technologies to different generators? E.G: Regenerative shields when primary is active but normal shields for secondary?