Login  Register
 



Post new topicReply to topic
 
Author Message
 PostPosted: 28 Feb, 2010 
 

Joined: 05 Oct, 2007
Posts: 16425
Location: camping near the biggest power-up
Offline
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.
help wrote:
Does anyone know how to use air transports? I cant get them to pick up troops.


Top
 Profile  
 PostPosted: 31 Mar, 2010 
 

Joined: 19 Mar, 2010
Posts: 144
Offline
I wrote up a post about the research system. I plan to expand it soon.


Top
 Profile  
 PostPosted: 14 Aug, 2010 
 

Joined: 03 Aug, 2010
Posts: 64
Offline
I made a tutorial for adding a new unit to SupCom 2. Extremely long but hopefully simple enough for anyone to be able to do. You can find it here:
viewtopic.php?f=19&p=829443#p829443

_________________
**spacing***My SC2 Mods*
*My tutorial on how to add units to SC2*


Top
 Profile  
 PostPosted: 22 Feb, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
Re-introduce 'non-existent global variable' error messages from FA/Demigod

If 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
 Profile  
 PostPosted: 25 Feb, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
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
 Profile  
 PostPosted: 27 Feb, 2011 
 

Joined: 01 Jan, 2011
Posts: 1025
Offline
A guide I'm writing on how to mod the SupCom 2 Tech Tree: http://forums.gaspowered.com/viewtopic.php?f=19&t=50389.

_________________
Image


Top
 Profile  
 PostPosted: 27 Feb, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
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.

How
Create 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
 Profile  
 PostPosted: 01 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
(Almost) Full File Hooking and Multi-Mod Compatibility

As 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
 Profile  
 PostPosted: 04 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
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
 Profile  
 PostPosted: 24 Jul, 2012 
 

Joined: 20 Jul, 2012
Posts: 1
Offline
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.

How
Create 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
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic



Quick Tools

Search for:
Jump to:  

© 2002-2010 Gas Powered Games Corp. All Rights Reserved. Gas Powered Games is the exclusive trademark of Gas Powered Games Corp.
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
 
Home| Games | Company | News & Press | Support
  Terms of Use   |    Copyright Information   |    Privacy Policy