Thursday, April 19, 2012

Tweaking Enhancments. (FA)

Ellos, I was wondering, you know that when you have an Enhancment and switch to another one (Going from Cooling Upgrade, to the T2/T3 Contruction upgrade) You have to replace one, with the other instead of stacking them?
I was wondering, if there was a way to disable that. So you can have more then just 1 Upgrade for each slot. Like say, For the Cybran ACU, On LCH, theres the T2/T3 Upgrades, as well as the cooling Upgrades, how can I get the two to be used at the same time?
This way, The user could get ALL the upgrades on a ACU instead of just 3 seperate kinds...|||Yeah, you can do that. I've seen some code (maybe in Unit.lua) that makes sure the old enhancement is removed. You should be able to replace that function with something simpler and it should work.|||BulletMagnet|||take whatever the code is that checks if there is an existing enhancement and removes it, and then change/remove the code|||I dont even know which parts to remove, and what to change it with X-x|||Dude, quit posting all of these request threads and drop the pretense of being anything but a mashup modder if you're not gonna learn to read and write basic lua. We'll gladly help you out if you try something and it doesn't work, but nobody's interested in doing all the work for you.|||Mithy|||...I think I was just pwned on a epic level...
Im sorry for making so many threads... Its just I got a few things to take care of... And I tried reading over Unit.lua, but most of it doesnt make sense to me...|||Well no ****, it's a 4000 line file that's dependent on or acting as a base for about 500 other files, including every other core global sim file and every other unit script. You can't just look over it once and expect something to click, it takes time to learn how the game's structure all fits together, and to get familiar with the most of the engine methods that the lua calls and what they do and how to use them.
But you have to start somewhere. If you just get frustrated and give up every time it doesn't instantly make sense, of course you'll never get anywhere. Everyone who posts on these forums who knows anything about the game started at zero some time or another. Google search mod support and look at some of the dumb questions myself or DeadMG or BulletMagnet posted 2-3 years ago if you don't believe me.

When you have little existing knowledge about the game, and you want to learn how to do something in it, start with what you do know and work your way out from there by searching the lua for keywords. If you don't understand how the next function or file you come across works any more than the current one, keep going, keep piecing together the chain of calls that makes the thing you're inquiring about happen, until it does start to make sense.
In this case, you (should) know that a function called CreateEnhancement gets run every time an enhancement is added to a unit, because this is what does all of the enhancement-specific work in each unit script. Search for this function in Unit.lua, and see what it does. No, you won't automatically understand it, but it's gonna call some other functions and/or reference some other tables. Search for those in the lua, find where they are, what they do, and so on so forth.
5 minutes ago, this function was really the only part of the enhancement process that I was familiar with. After 5 minutes of searching and tracing, it was pretty easy to account for the entire chain of functioncalls that adding an enhancement takes, as it only really spans about 6 files, 4 of which have any meaningful code:
- /lua/ui/game/construction.lua for the UI portion, which passes a ScriptTask command to the engine
- /lua/sim/tasks/EnhanceTask.lua, which the engine calls on the sim side as a result of the enhancement order. This takes care of the economy portion of the enhancement using Unit.lua.OnWorkBegin, and Unit.lua.WorkingState.OnWorkEnd to finish and call CreateEnhancement.
- /lua/sim/Unit.lua.CreateEnhancement, which you should already know about. This is called by OnWorkEnd in WorkingState, and individual unit scripts use this to do unique work for each enhancement. The Unit.lua instance of the function calls global functions AddUnitEnhancement and RemoveUnitEnhancement in schook SimSync to handle sim-side enhancement tracking.
- /schook/lua/SimSync.lua, which stores the enhancement in a global table keyed by entityid and slot, and passes the new enhancement data into the Sync table so that the UI is informed of the enhancement addition, completing the circle.
From this, I can tell you that it should be possible, but not necessarily simple to make 'slotless' enhancements. You'll need to override the construction.lua portion so it understands that not all enhancements are slot-exclusive, and you'll have to expand the Sim/UserSync tables and functions to key enhancements by something other than slot, so that multiple enhancements in each UI slot can be used at once.|||/me gives milthy a round of applause... now take a bow pal... that was awesome lol.

No comments:

Post a Comment