Mod making

Everything about mods can be found here.

Moderator: Morax

Mod making

Postby StylisticSagi » 22 Aug 2016, 18:00

Hi guys,

I have made some mods for sc for quite a while but i have never been good at it (never posted a mod online either).

But now i have a question.
When i normally mod units i copy the entire unit files and change everything i want to unit per unit.
Is it possible to create this more easily with a single file if i want for example give all t1 units double health.
Or give an extra effect like all t2 units doe area of effect damage.
If think this is possible but how do i do this?
StylisticSagi
Crusader
 
Posts: 41
Joined: 22 Aug 2016, 17:53
Has liked: 1 time
Been liked: 1 time
FAF User Name: StylisticSagi

Re: Mod making

Postby Uveso » 22 Aug 2016, 21:50

Hello StylisticSagi,

there is always a way :)

you could make those general changes inside blueprint lua.

Create a file named Blueprint.lua inside your mod, using this folder structure:
Code: Select all
\Mods\YOURMODNAME\hook\lua\system\Blueprints.lua

then open Blueprints.lua and copy paste the following:
Code: Select all
-- Save the original function before we overwrite it with our own.
local OldModBlueprints = ModBlueprints
-- Overwrite the original ModBlueprints
function ModBlueprints(all_blueprints)
    -- first let us call the original ModBlueprints function
    OldModBlueprints(all_blueprints)
    -- now we loop over every UNIT blueprint
    for id,bp in all_blueprints.Unit do
        -- id = init ID. example: URL0103
        -- bp = the whole content of the file URL0103_unit.bp
        -- if we have Categories and MaxHealth > 0 inside the unit blueprint then...
        if bp.Categories and bp.Defense.MaxHealth and bp.Defense.MaxHealth > 0 then
            -- create an array where we can save the unit categories for easier access
            local Categories = {}
            -- loop over unit categories
            for _, cat in bp.Categories do
                -- example: Categories[TECH1] = true -> Categories.TECH1 == true
                Categories[cat] = true
            end
            -- Lets find out, if we have a tech 1 unit
            if Categories.TECH1 then
                -- now double the health value inside the blueprint
                bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2
                LOG('processing unit >>>'..id..'<<< ('..(bp.Description or 'Unknown')..') new healthvalue= "'..bp.Defense.MaxHealth..'"')
           end
        end
    end
end


Start the game and you will see many lines like this:
Code: Select all
INFO: processing unit >>>xsb1103<<< (<LOC xsb1103_desc>Mass Extractor) new healthvalue= "1200"


So all your T1 units have now double health.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Mod making

Postby StylisticSagi » 23 Aug 2016, 20:00

I really suck at writing own lines but i will spend some days trying to figure everything out.
In the example you adjusted for example the new health but can you also multiply a value lets say double something or so?
like a unit that has 300 health but after the mod has 600 and another unit affected by that same line has 1000 health and after the mod 2000?

In any case already thanks for the explanation!
StylisticSagi
Crusader
 
Posts: 41
Joined: 22 Aug 2016, 17:53
Has liked: 1 time
Been liked: 1 time
FAF User Name: StylisticSagi

Re: Mod making

Postby Uveso » 23 Aug 2016, 20:18

This is exacly what the function does, it will double the units health.

This happened in this line:
Code: Select all
bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2

bp = unitBlueprint
.Defence = the Defense array
.MaxHealth = value of the MaxHealth inside the defense array. (140)

Inside the blueprint we are modifying this array:
Code: Select all
    Defense = {
        AirThreatLevel = 0,
        ArmorType = 'Normal',
        EconomyThreatLevel = 0,
        Health = 140,
        MaxHealth = 140,
        RegenRate = 0,
        SubThreatLevel = 0,
        SurfaceThreatLevel = 1.5,
    },

so in this case
Code: Select all
bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2
will execute this:
Code: Select all
MaxHealth = 140*2


This will double the actual health of the unit.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Mod making

Postby StylisticSagi » 31 Aug 2016, 14:42

Thx i try to make it work. never had any lessons or programming so basicly annything i can get working is a victory.

edit:
i'm sorry to bother again but the line "bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2" i cannot find it in your first answer.
You explain allot but i know so little about starting a file myself that i can't see the threes beyond the forest.
For an example that would do me find is exactly how such a file would look like and how i can make lines for groups of units for example all t1 land units or all economic buildings or things like that. I need a start to get further :( .
StylisticSagi
Crusader
 
Posts: 41
Joined: 22 Aug 2016, 17:53
Has liked: 1 time
Been liked: 1 time
FAF User Name: StylisticSagi

Re: Mod making

Postby Uveso » 31 Aug 2016, 21:46

I know, the first start is most difficult.

I uploaded a small test mod for your start.

The changes to the units-health can be found in:
Code: Select all
Mods\StylisticSagi_1st_Mod\hook\lua\system\Blueprints.lua


Also when the mod is loaded, we have a small hook inside:
Code: Select all
Mods\StylisticSagi_1st_Mod\hook\lua\ui\game\gamemain.lua


This will start a function inside:
Code: Select all
Mods\StylisticSagi_1st_Mod\SagisLuaScripts\InitSagiMod.lua


Inside InitSagiMod.lua is also a line that includes a keybinding for the combination: [SHIFT]+[Q].
If you press it, it will execute the Hello World function and write something to the LogWindow.

Greetings, Uveso.
Attachments
StylisticSagi_1st_ModV1.zip
(30.09 KiB) Downloaded 93 times
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Mod making

Postby StylisticSagi » 02 Sep 2016, 07:36

Thanks!
All of these lines that are in those files are alle absolutly neccesary i presume?
It is still very hard to understand when what to type. Il need a few days to test things with it.
StylisticSagi
Crusader
 
Posts: 41
Joined: 22 Aug 2016, 17:53
Has liked: 1 time
Been liked: 1 time
FAF User Name: StylisticSagi

Re: Mod making

Postby StylisticSagi » 16 Oct 2016, 11:25

Okay so i wrote a few lines but some of them work and others do not. But i have no idea what i do diffrent in them...
Why does it not work? p.s. once again thx for helping me out.
most of the -- starting with broken are the lines that won't work.

Code: Select all
local OldModBlueprints = ModBlueprints
function ModBlueprints(all_blueprints)
    OldModBlueprints(all_blueprints)
   
    for id,bp in all_blueprints.Unit do
      local Categories = {}
      for _, cat in bp.Categories do
         Categories[cat] = true
      end
      
      --units Double health
      if Categories.LAND and not Categories.STRUCTURE and not Categories.EXPERIMENTAL then
         bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2.0
      end
         --land units double vision
            if Categories.LAND then
            bp.Intel.VisionRadius = bp.Intel.VisionRadius * 2.0
            end
--broken         --land units shield double health
         --if Categories.LAND and not Categories.STRUCTURE and not Categories.EXPERIMENTAL then
         --bp.Defense.Shield.ShieldMaxHealth = bp.Defense.Shield.ShieldMaxHealth * 2.0
         --end
      
      --tech 1 no mass
      if Categories.TECH1 and not Categories.STRUCTURE then
      bp.Economy.BuildCostMass = 0
      end
         --tech 2 half mass
         if Categories.TECH2 and Categories.LAND and not Categories.STRUCTURE then
         bp.Economy.BuildCostMass = bp.Economy.BuildCostMass * 0.5
         end
            --tech 3 double mass
            if Categories.TECH3 and not Categories.STRUCTURE then
            bp.Economy.BuildCostMass = bp.Economy.BuildCostMass * 2.0
            end
         --navel sail speed doubled
      local NavalSpeedScale = 20
--broken   --for id,bp in all_bps.Unit do
            -- if Categories.Naval then
            -- bp.Physics.CatchUpAcc = NavalSpeedScale
            -- end
               --if Categories.Naval and not Categories.STRUCTURE then
               --bp.Physics.MaxAcceleration = NavalSpeedScale
               --end
                  -- if Categories.Naval then
                  -- bp.Physics.MaxBrake = NavalSpeedScale
                  -- end
                     --if Categories.Naval and not Categories.STRUCTURE then
                     --bp.Physics.MaxSpeed = NavalSpeedScale
                     --end
                        -- if Categories.Naval then
                        -- bp.Physics.MaxSpeedReverse = NavalSpeedScale
                        -- end
                           -- if Categories.Naval then
                           -- bp.Physics.MaxSteerForce = NavalSpeedScale
                           -- end
         --end
      --remove structure death
--broken      --if Categories.ECONOMIC and not Categories.EXPERIMENTAL then
      --bp.Weapon.damage = 0
      --end
   end      
end
StylisticSagi
Crusader
 
Posts: 41
Joined: 22 Aug 2016, 17:53
Has liked: 1 time
Been liked: 1 time
FAF User Name: StylisticSagi

Re: Mod making

Postby Uveso » 17 Oct 2016, 00:04

I checked your code and found some issues.

If you change a value inside the blueprint, you should be sure, that the value exist.
So please validate everything before you change it:
Code: Select all
first validate that Intel.VisionRadius exist inside the blueprint, then change it.
if bp.Intel.VisionRadius then
    bp.Intel.VisionRadius = bp.Intel.VisionRadius * 2.0
end


Your naval stuff simply don't worked because of an Typo:
you asked for:
Code: Select all
Categories.Naval

but the word Naval should be in uppercase:
Code: Select all
Categories.NAVAL


I am not shure what you want to do with "--remove structure death"
In case you want all weapon damage from this unit reduced to 0, then you can use this:
Code: Select all
        -- Find a MOBILE EXPERIMENTAL unit and set all weapon-damage to "0", so the unit can't damage other units
        if Categories.MOBILE and Categories.EXPERIMENTAL then
            -- check first if we have a weapon array inside the unit blueprint
            if bp.Weapon then
                -- Loop over all Weaponss
                for _,weapon in bp.Weapon do
                    -- if we found a weapon, then check if we have a damage variable
                    if weapon.Damage then
                        LOG('processing >>>'..id..'<<< +MOBILE +EXPERIMENTAL : Weaponname: ('..(weapon.DisplayName or "Unknown")..') Changing damage from ('..(weapon.Damage)..') to "0"')
                        -- set the damage to 0
                        weapon.Damage = 0
                    end
                end
            end
        end


Or if you want to make the unit indestructible you can use this:
(Well, you cant make it really indestructible without changing the unitscript. But you can make a unit untargetable for other units)
Code: Select all
        -- Find a MOBILE EXPERIMENTAL unit and make it untargetable, so you can't destroy the unit.
        if Categories.MOBILE and Categories.EXPERIMENTAL then
            -- do we have a Category Array ?
            if bp.Categories then
                LOG('processing >>>'..id..'<<< +MOBILE +EXPERIMENTAL : Make the Unit indestructible, adding UNTARGETABLE to Categories.')
                -- add the line "UNTARGETABLE" to Categories:
                table.insert(bp.Categories, 'UNTARGETABLE')
            end
        end


You added a comment that "bp.Defense.Shield.ShieldMaxHealth" is not working. I checked this, but it is working.
Please check it again.


Here is the full code Copy & past ready for your blueprint.lua file:
I also added some debuglines for the Debug-log Window.

Code: Select all
local OldModBlueprints = ModBlueprints

function ModBlueprints(all_blueprints)
    OldModBlueprints(all_blueprints)
       
    for id,bp in all_blueprints.Unit do
         
        -- build Category Array for faster access like "Categories.LAND" or "Categories.EXPERIMENTAL"
        local Categories = {}
        for _, cat in bp.Categories do
            Categories[cat] = true
        end
         
        --units Double health
        if Categories.LAND and not Categories.STRUCTURE and not Categories.EXPERIMENTAL then
            if bp.Defense.MaxHealth then
                LOG('processing >>>'..id..'<<< +LAND -STRUCTURE -EXPERIMENTAL : Changing MaxHealth from ('..(bp.Defense.MaxHealth)..') to "'..(bp.Defense.MaxHealth * 2.0)..'"')
                bp.Defense.MaxHealth = bp.Defense.MaxHealth * 2.0
            end
        end

        --land units double vision
        if Categories.LAND then
            if bp.Intel.VisionRadius then
                LOG('processing >>>'..id..'<<< +LAND : Changing VisionRadius from ('..(bp.Intel.VisionRadius)..') to "'..(bp.Intel.VisionRadius * 2.0)..'"')
                bp.Intel.VisionRadius = bp.Intel.VisionRadius * 2.0
            end
        end
       
        --land units shield double health
        if Categories.LAND and not Categories.STRUCTURE and not Categories.EXPERIMENTAL then
            if bp.Defense.Shield.ShieldMaxHealth then
                LOG('processing >>>'..id..'<<< +LAND -STRUCTURE -EXPERIMENTAL : Changing ShieldMaxHealth from ('..(bp.Defense.Shield.ShieldMaxHealth)..') to "'..(bp.Defense.Shield.ShieldMaxHealth * 2.0)..'"')
                bp.Defense.Shield.ShieldMaxHealth = bp.Defense.Shield.ShieldMaxHealth * 2.0
            end
        end
         
        --tech 1 no mass
        if Categories.TECH1 and not Categories.STRUCTURE then
            if bp.Economy.BuildCostMass then
                LOG('processing >>>'..id..'<<< +TECH1 -STRUCTURE : Changing BuildCostMass from ('..(bp.Economy.BuildCostMass)..') to "0"')
                bp.Economy.BuildCostMass = 0
            end
        end

        --tech 2 half mass
        if Categories.TECH2 and Categories.LAND and not Categories.STRUCTURE then
            if bp.Economy.BuildCostMass then
                LOG('processing >>>'..id..'<<< +TECH2 +LAND -STRUCTURE : Changing BuildCostMass from ('..(bp.Economy.BuildCostMass)..') to "'..(bp.Economy.BuildCostMass * 0.5)..'"')
                bp.Economy.BuildCostMass = bp.Economy.BuildCostMass * 0.5
            end
        end
               
        --tech 3 double mass
        if Categories.TECH3 and not Categories.STRUCTURE then
            if bp.Economy.BuildCostMass then
                LOG('processing >>>'..id..'<<< +TECH3 -STRUCTURE : Changing BuildCostMass from ('..(bp.Economy.BuildCostMass)..') to "'..(bp.Economy.BuildCostMass * 2.0)..'"')
                bp.Economy.BuildCostMass = bp.Economy.BuildCostMass * 2.0
            end
        end
             
        --navel sail speed doubled
        local NavalSpeedScale = 20
   
        if Categories.NAVAL then
            if bp.Physics.CatchUpAcc then
                LOG('processing >>>'..id..'<<< +NAVAL : Changing CatchUpAcc from ('..(bp.Physics.CatchUpAcc)..') to "'..(NavalSpeedScale)..'"')
                bp.Physics.CatchUpAcc = NavalSpeedScale
            end
        end
        if Categories.NAVAL and not Categories.STRUCTURE then
            if bp.Physics.MaxAcceleration then
                LOG('processing >>>'..id..'<<< +NAVAL : Changing MaxAcceleration from ('..(bp.Physics.MaxAcceleration)..') to "'..(NavalSpeedScale)..'"')
                bp.Physics.MaxAcceleration = NavalSpeedScale
            end
        end
        if Categories.NAVAL then
            if bp.Physics.MaxBrake then
                LOG('processing >>>'..id..'<<< +NAVAL : Changing MaxBrake from ('..(bp.Physics.MaxBrake)..') to "'..(NavalSpeedScale)..'"')
                bp.Physics.MaxBrake = NavalSpeedScale
            end
        end
        if Categories.NAVAL and not Categories.STRUCTURE then
            if bp.Physics.MaxSpeed then
                LOG('processing >>>'..id..'<<< +NAVAL : Changing MaxSpeed from ('..(bp.Physics.MaxSpeed)..') to "'..(NavalSpeedScale)..'"')
                bp.Physics.MaxSpeed = NavalSpeedScale
            end
        end
        if Categories.NAVAL then
            if bp.Physics.MaxSpeedReverse then
                LOG('processing >>>'..id..'<<< +NAVAL : Changing MaxSpeedReverse from ('..(bp.Physics.MaxSpeedReverse)..') to "'..(NavalSpeedScale)..'"')
                bp.Physics.MaxSpeedReverse = NavalSpeedScale
            end
        end
        if Categories.NAVAL then
            if bp.Physics.MaxSteerForce then
                LOG('processing >>>'..id..'<<< +NAVAL : Changing MaxSteerForce from ('..(bp.Physics.MaxSteerForce)..') to "'..(NavalSpeedScale)..'"')
                bp.Physics.MaxSteerForce = NavalSpeedScale
            end
        end
         
        --remove structure death
        --broken
        --if Categories.ECONOMIC and not Categories.EXPERIMENTAL then
        --    if bp.Weapon.damage then
        --        LOG('broken >>>'..id..'<<< +Naval : Changing Weapon.damage from ('..(bp.Weapon.damage)..') to "0"')
        --        bp.Weapon.damage = 0
        --    end
        --end
       
        -- Find a MOBILE EXPERIMENTAL unit and set all weapon-damage to "0", so the unit can't damage other units
        if Categories.MOBILE and Categories.EXPERIMENTAL then
            -- check first if we have a weapon array inside the unit blueprint
            if bp.Weapon then
                -- Loop over all Weaponss
                for _,weapon in bp.Weapon do
                    -- if we found a weapon, then check if we have a damage variable
                    if weapon.Damage then
                        LOG('processing >>>'..id..'<<< +MOBILE +EXPERIMENTAL : Weaponname: ('..(weapon.DisplayName or "Unknown")..') Changing damage from ('..(weapon.Damage)..') to "0"')
                        -- set the damage to 0
                        weapon.Damage = 0
                    end
                end
            end
        end

        -- Find a MOBILE EXPERIMENTAL unit and make it untargetable, so you can't destroy the unit.
        if Categories.MOBILE and Categories.EXPERIMENTAL then
            -- do we have a Category Array ?
            if bp.Categories then
                LOG('processing >>>'..id..'<<< +MOBILE +EXPERIMENTAL : Make the Unit indestructible, adding UNTARGETABLE to Categories.')
                -- add the line "UNTARGETABLE" to Categories:
                table.insert(bp.Categories, 'UNTARGETABLE')
            end
        end
       
    end -- this end starts at : for id,bp in all_blueprints.Unit do
end --  this end starts at : function ModBlueprints(all_blueprints)
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Mod making

Postby StylisticSagi » 17 Oct 2016, 16:02

Thx alot!
While i was working i was already assuming that the problem could be that i have to specify the line if it exists.
Friends of mine warned me for the lack of using copy paste for typos haha.

I understand that it is confusing what i try to do with the 0 weapon damage but this is actually to remove all death damage (like when a power plant explodes everything else around it explodes as well) And since this is sepcified as a weapon i tried to remove all economic structures his weapon damage exept for the paragon, i have special plans for that one.

I am long not finisched with the tweaks that i want to do but at least now i'm getting somewhere.

The major thing i am struggling now is to make all the factories mass extractors radars shield aka every building that upgrades go very fast.
So as long as you have resources you could upgrade a t1 factory to t3 in less then 30 seconds. But i find it difficult to tag since i don't want every building to be fast build.

p.s. what is the purpuse of these lines?
LOG('processing >>>'..id..'<<< +LAND -STRUCTURE -EXPERIMENTAL : Changing MaxHealth from ('..(bp.Defense.MaxHealth)..') to "'..(bp.Defense.MaxHealth * 2.0)..'"')

p.s.2 i like to do something nice here but i don't know why it fails
Code: Select all
      --Hide full life bars
      if Categories.SELECTABLE then
         if bp.LifeBarSize and bp.Defense.MaxHealth and bp.Defense.Health then
            if bp.Defense.MaxHealth = bp.Defense.MaxHealth then
               bp.LifeBarSize = 0
            end
         end
      end


Apart from my poor programming skills are there any changes you think could make a nice change to the game?
If you play the game wich mods do you like?
StylisticSagi
Crusader
 
Posts: 41
Joined: 22 Aug 2016, 17:53
Has liked: 1 time
Been liked: 1 time
FAF User Name: StylisticSagi

Next

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest