|
 |
| Author |
Message |
|
BulletMagnet
|
Posted: 28 Feb, 2010
|
|
Joined: 05 Oct, 2007 Posts: 16425 Location: camping near the biggest power-up
|
Come one, come all; to the Gas Powered Community developer toolbox for Supreme Commander 2. Here, discerning modders will find snippets of code to help them make mods in a timely fashion.
Rules: [1] make a thread in this forum. [2] post a link here, with a short summary of what you've accomplished. [3] keep chatter out; put it in the respective thread.
Here, I'll start;
Blueprint types available from the ModBlueprints() function.
WARN() logging function does nothing.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
RCIX
|
Posted: 31 Mar, 2010
|
|
Joined: 19 Mar, 2010 Posts: 144
|
|
| Top |
|
 |
|
Greatheart
|
Posted: 14 Aug, 2010
|
|
Joined: 03 Aug, 2010 Posts: 64
|
|
| Top |
|
 |
|
Mithy
|
Posted: 22 Feb, 2011
|
|
Joined: 19 Jul, 2009 Posts: 2972
|
Re-introduce 'non-existent global variable' error messages from FA/DemigodIf you replace the globalsmeta table in config.lua line 69 with this, the log will display warnings for non-existent global variable accesses complete with ghetto stack traceback, akin to an actual error message, but without the hard stop: Code: local globalsmeta = { __index = function(table, key) -- No error here because we don't care! -- (The prefetcherscenarios is a global table that may not have certain keys)
--Mithy: error message re-added, but no error thrown --This is an attempt to approximate the format and information given by a standard error stack traceback, --however the function name is often unavailable. Fortunately the line number is almost always present. LOG("*** WARNING: access to nonexistent global variable "..repr(key)) LOG("stack traceback:") for i=2, 999 do local t = debug.getinfo(i) if t then local msg = "\t" if t.short_src then msg = msg..t.short_src else msg = msg..string.sub(t.source,2) end if t.currentline and t.currentline > 0 then msg = msg..":"..t.currentline end if t.name then msg = msg.." in function '"..t.name.."'" elseif t.func then msg = msg.." in "..repr(t.func) end LOG(msg) else break end end end } It's not perfect, and won't show up as orange in the log window, but at least it gives source filenames and line numbers. Yes, the filenames all start with E:\Work\etc etc, that's also the case for the actual error messages. Unfortunately, DiskToLocal doesn't work with these paths, since they aren't 'real' paths on the host system, but if you can get this working then you can probably figure out the relative paths just fine. I experimented with pcall(error) to get a full error report, but it still halts the thread back to the previous pcall, which usually freezes the game (it seems as though they left quite a few non-existent variable accesses in some of the core sim code). Also, if you already have a mod lua.scd installed, you can make this (and some other file overrides) work by putting it into My Documents\My Games\Gas Powered Games\Supreme Commander 2\mods\DLC1\shadow\lua. The game does actually look for mod folders in this path, and will mount them, allowing you to use a shadow directory there to override any file not already found in the z_lua_dlc1.scd's /mods/dlc1/shadow path (any files in that .scd will take precedence). As far as I know, this won't desync the game, so it shouldn't need to be removed for multiplayer. But I haven't tested that.
|
|
| Top |
|
 |
|
Mithy
|
Posted: 25 Feb, 2011
|
|
Joined: 19 Jul, 2009 Posts: 2972
|
|
Easier Mod Creation and Testing
SC2 mounts anything in \gamedata with an .scd extension. This includes ordinary folders, which means that you can more quickly make and test changes to your mod by using a folder with an .scd extension.
This eliminates the need to drag files out, modify, and drag back in, saving a ton of time. As well, if you use a tabbed editor or one with a project system, this allows you to keep all of your mod's files open or accessible within the project directory instead of having to manually unpack, edit, and repack each file every time you want to make a change.
Packaging the mod for release is then as simple as selecting all of the subfolders it contains and adding them to an uncompressed .scd, just as you normally would. You can even release the mod in folder form, if you'd like - there's no particular reason it has to be packaged into an actual .scd.
liveordie reminded me to mention that the /EnableDiskWatch command line switch works for folders mounted this way, the same way as it does actual .scds. For all intents and purposes, it's the same as using packed .scd file.
Last edited by Mithy on 02 Mar, 2011, edited 1 time in total.
|
|
| Top |
|
 |
|
madface
|
Posted: 27 Feb, 2011
|
|
Joined: 01 Jan, 2011 Posts: 1025
|
|
| Top |
|
 |
|
Mithy
|
Posted: 27 Feb, 2011
|
|
Joined: 19 Jul, 2009 Posts: 2972
|
You can non-destructively hook ModBlueprints from within a .bp file.This means that simple 2x resource-style ModBlueprints mods can be made compatible with each other and with any other possible mod, including those that shadow or replace Blueprints.lua. For SC2 modders unfamiliar with this function, it allows you access to every single blueprint in the game in one place, allowing you to make sweeping, procedural changes with any kind of conditions or filters you want. HowCreate a .bp file in a relevant location-- /units, /mods/DLC1, the load order doesn't really matter since you're hooking a function, not modding a bp directly-- and hook ModBlueprints as you would in a normal FA Blueprints.lua hook. Since this is pretty much the only time you need to know how to hook a function to mod SC2, I'll give you a simple example of how to do this, along with some examples of how to use ModBlueprints to make huge changes with a few lines of code. This is a basic non-destructive function hook, that is, any number of these can co-exist and will all run in sequence when the function is called, each performing their changes without directly overriding or breaking one another: Code: --Save the existing ModBlueprints function to a local local prevModBlueprints = ModBlueprints
--Redefine ModBlueprints function ModBlueprints(all_bps) --Call the saved copy that includes any other hooks prevModBlueprints(all_bps)
--Do whatever you'd like with all_bps; see Blueprints.lua --lines 67-91 for a list of all of the blueprint type subtables --We'll use unit blueprints (all_bps.Unit) in this example for id, bp in all_bps.Unit do --Example 1, doubling all unit hitpoints: if bp.Defense and bp.Defense.MaxHealth then bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2 bp.Defense.Health = bp.Defense.Health * 2 end --Example 2, doubling only mex output if bp.Categories and table.find(bp.Categories, 'MASSEXTRACTION') then if bp.Economy and bp.Economy.ProductionPerSecondMass then bp.Economy.ProductionPerSecondMass = bp.Economy.ProductionPerSecondMass * 2 end end --Example 3, doubling all experimental weapon damage --By the time unit blueprints reach ModBlueprints, their --weapon bps have been extracted into all_bps.Weapon, leaving --only their bpid/key within that table inside Weapons if bp.Categories and table.find(bp.Categories, 'EXPERIMENTAL') then if bp.Weapons then for k, wepid in bp.Weapons do local wepbp = all_bps.Weapons[wepbp] if wepbp and wepbp.Damage then wepbp.Damage = wepbp.Damage * 2 end end end end end end Be aware that it is quite possible to break the game horribly and/or cause crashes with this function, further complicated by SC2 not being very forthcoming with error messages. So be prepared for some trial and error, and start out with one or two simple changes, graduating to more complicated changes once you have those working. Also note how in my example, I check for absolutely every value I modify, and every sub-table that contains that value. This is the surest way to prevent crashes. Never assume that a unit blueprint will always contain a particular value or table, even something important like Categories. Even when all stock units have it, other mods can add units that may lack these values, causing a crash when combined with your mod.
|
|
| Top |
|
 |
|
Mithy
|
Posted: 01 Mar, 2011
|
|
Joined: 19 Jul, 2009 Posts: 2972
|
(Almost) Full File Hooking and Multi-Mod CompatibilityAs usual, this was deceptively simple to achieve, and takes nothing more than 7 lines of code in one shadowed file, totally eliminating the need for any mods to replace .scds, and allowing any number of mods to operate simultaneously. See the thread for details and download: viewtopic.php?f=19&t=50454(The 'almost' part is that it does not give access to local variables within hooked files, but all global variables are accessible)
|
|
| Top |
|
 |
|
Bastilean
|
Posted: 04 Mar, 2011
|
|
Joined: 25 Mar, 2010 Posts: 1495
|
Mithy wrote a description How to Use Blue Print Merges. This is an excellent place to start for new modders that will help form good habits for sharing mod files and benefit their own by being merge ready for existing content. In a thread created by Nephilim, Mithy explains that you can use create Ability Merges as well. ShadowLord wrote a Tutorial how to Port FA units to SupCom2.
_________________ Yeah Toast!
|
|
| Top |
|
 |
|
doug4knfpu
|
Posted: 24 Jul, 2012
|
|
Joined: 20 Jul, 2012 Posts: 1
|
Mithy wrote: You can non-destructively hook ModBlueprints from within a .bp file.This means that simple 2x resource-style ModBlueprints mods can be made compatible with each other and with any other possible mod, including those that shadow or replace Blueprints.lua. For SC2 modders unfamiliar with this function, it allows you access to every single blueprint in the game in one place, allowing you to make sweeping, procedural changes with any kind of conditions or filters you want. HowCreate a .bp file in a relevant location-- /units, /mods/DLC1, the load order doesn't really matter since you're hooking a function, not modding a bp directly-- and hook ModBlueprints as you would in a normal FA Blueprints.lua hook. Since this is pretty much the only time you need to know how to hook a function to mod SC2, I'll give you a simple example of how to do this, along with some examples of how to use ModBlueprints to make huge changes with a few lines of code. This is a basic non-destructive function hook, that is, any number of these can co-exist and will all run in sequence when the function is called, each performing their changes without directly overriding or breaking one another: Code: --Save the existing ModBlueprints function to a local local prevModBlueprints = ModBlueprints
--Redefine ModBlueprints function ModBlueprints(all_bps) --Call the saved copy that includes any other hooks prevModBlueprints(all_bps)
--Do whatever you'd like with all_bps; see Blueprints.lua --lines 67-91 for a list of all of the blueprint type subtables --We'll use unit blueprints (all_bps.Unit) in this example for id, bp in all_bps.Unit do --Example 1, doubling all unit hitpoints: if bp.Defense and bp.Defense.MaxHealth then bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2 bp.Defense.Health = bp.Defense.Health * 2 end --Example 2, doubling only mex output if bp.Categories and table.find(bp.Categories, 'MASSEXTRACTION') then if bp.Economy and bp.Economy.ProductionPerSecondMass then bp.Economy.ProductionPerSecondMass = bp.Economy.ProductionPerSecondMass * 2 end end --Example 3, doubling all experimental weapon damage --By the time unit blueprints reach ModBlueprints, their --weapon bps have been extracted into all_bps.Weapon, leaving --only their bpid/key within that table inside Weapons if bp.Categories and table.find(bp.Categories, 'EXPERIMENTAL') then if bp.Weapons then for k, wepid in bp.Weapons do local wepbp = all_bps.Weapons[wepbp] if wepbp and wepbp.Damage then wepbp.Damage = wepbp.Damage * 2 end end end end end end Be aware that it is quite possible to break the game horribly and/or cause crashes with this function, further complicated by SC2 not being very forthcoming with error messages. So be prepared for some trial and error, and start out with one or two simple changes, graduating to more complicated changes once you have those working. Also note how in my example, I check for absolutely every value I modify, and every sub-table that contains that value. This is the surest way to prevent crashes. Never assume that a unit blueprint will always contain a particular value or table, even something important like Categories. Even when all stock units have it, other mods can add units that may lack these values, causing a crash when combined with your mod. hello, can you help me i'm trying to do this and im lost. can you send me a private message or something describing everything in a little more details or something. ___________________________________ http://calistacyinaz.com
|
|
| Top |
|
 |
 |
 |
|