A while ago I was getting into modding and wanted to try something reasonably simple. Since then I've been working on other projects, but I thought I might as well post up what I had done, in case anyone else was working along a similar line and could use an example. I figured that adding a toggle button to a unit would be a nice test-case mod just to get the feel of things.
Unfortunately I never got it to succeed.
-----
The idea was to add a button to T2 artillery that would change the emplacement from shooting low arc to high arc, while keeping the stats of the weapon the same.
All work was done on the UEF version of the unit, since it would be easy enough to port over once it was functional.
Investigation revealed that the standard procedure for SupCom units with multiple weapons/upgrades was to stat up all variations of the weapon as individual weapons, and then leave all but the one that is wanted set to disabled.
As such, the first step was to test if the weapon functioned in high-arc mode, and indeed it did. When the string in the units weapon stat block was changed from low to high the unit functioned correctly in game, aiming high into the air and finally succeeding in not shooting the cliff in front of its face.
The next step was getting two weapons on the unit, and disabling one. This was where I began to run into problems. I copied the code from the Cybran cruiser and cybran t1 mobile AA units, intending to use their ground/air toggle as a placeholder while I got the system working. The code copied across well enough with only minor edits, but didn't function properly. Everything seemed to be in place, but the button never appeared.
Furthermore, when both weapons are on the unit, even when one is disabled, some odd behaviour happens. The turret aims as if trying to use the high-arc weapon, even when the low-arc weapon is the one active, and then makes the shooting noise, yet no projectile is spawned.
This is about as far as I got before various life things came and pulled me away, and I haven't progressed with the mod beforehand.
I did have a few leads, though:
- There seems to be an empty bit that is used for the toggle that isn't ever tied into anything. It would make sense to me for the unit to check the state of this bit to check which weapon it has active, but that doesn't seem to be how it functions, and nothing ever seems to toggle it. It's simply there.
- There was mention in another thread, over here, of people having similar problems. It might be that the unit needs to be told that it has a toggle button somewhere other than in its blueprint.
----
I am unlikely to continue work on this, so if anyone wants to use what I have, then by all means do. However I suspect it'd be quicker to re-do it yourself, since then you wouldn't have any erroneous bits hanging around that you didn't know about.
Also, the T2 artillery is actually listed as a T3 unit by its code designation, which is slightly disconcerting when you're trying to spawn it in with the cheat menu.