How to alter values of unitweights by scripting?

Interesting mapping tools and mapping help.

Moderator: Morax

How to alter values of unitweights by scripting?

Postby Ghoustaq » 01 Mar 2018, 11:35

I have a new problem now.That is I want to alter the values of unitweights of some units, for example, tech2 units take 2 unitweights and tech3 units take 3. Do you know how to do by scripting? I konw that it's easier to reach this goal by rewriting the units.bp files in the gamedata folder , even so I would rather scripting.
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Re: How to alter values of unitweights by scripting?

Postby Ghoustaq » 01 Mar 2018, 11:37

Here's the answer from Uveso,

Well, you can't change the unitweights without changing the unit-blueprint.
Unitweight is controlled by the c-engine of the game, not from LUA side.

And you have to change the unit-blueprint before the game starts.
Changing the bluprint after gamestart will instantly desync multiplayer games.

I don't know if this works, but if you can modify blueprints from the mapscript, then try it with this:
Code: Select all
    for UnitID, UnitBlueprint in __blueprints do
        if UnitBlueprint.General.UnitWeight then
            LOG('Unit '..UnitID..' has a value of '..UnitBlueprint.General.UnitWeight..' as UnitWeight')
            if UnitBlueprint.CategoriesHash.TECH1 then
                LOG('Unit '..UnitID..' is a TECH1 unit. Seting UnitWeight to 1')
                UnitBlueprint.General.UnitWeight = 1
            end
            if UnitBlueprint.CategoriesHash.TECH2 then
                LOG('Unit '..UnitID..' is a TECH2 unit. Seting UnitWeight to 2')
                UnitBlueprint.General.UnitWeight = 2
            end
            if UnitBlueprint.CategoriesHash.TECH3 then
                LOG('Unit '..UnitID..' is a TECH3 unit. Seting UnitWeight to 3')
                UnitBlueprint.General.UnitWeight = 3
            end
            if UnitBlueprint.CategoriesHash.EXPERIMENTAL then
                LOG('Unit '..UnitID..' is a EXPERIMENTAL unit. Seting UnitWeight to 4')
                UnitBlueprint.General.UnitWeight = 4
            end
        else
            LOG('Unit '..UnitID..' don\'t has a UnitWeight')
        end
    end
Last edited by Ghoustaq on 02 Mar 2018, 18:19, edited 1 time in total.
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Re: How to alter values of unitweights by scripting?

Postby Franck83 » 01 Mar 2018, 19:26

Try this by hooking blueprints.lua :

Code: Select all
local overridden = ModBlueprints
    function ModBlueprints(blueprints)
       overridden(blueprints)   
        for id,bp in blueprints.Unit do
         if bp.General.UnitWeight then
            if table.find(bp.Categories, 'TECH1') then
               bp.General.UnitWeight = 1
            elseif table.find(bp.Categories, 'TECH2') then
               bp.General.UnitWeight = 2
            elseif table.find(bp.Categories, 'TECH3') then
               bp.General.UnitWeight = 3    
            elseif table.find(bp.Categories, 'EXPERIMENTAL') then
               bp.General.UnitWeight = 4
            end
         end
        end
    end
end
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: How to alter values of unitweights by scripting?

Postby Uveso » 01 Mar 2018, 20:53

@Franck83:

are you sure you can run this from a MAP_script.lua ?
It's a MAP not a MOD! :)


@Ghoustaq:

if you post code here, mark the code with your mouse and then press the "Code" button.
This will crate a [code] tag. This way you will get a nice code-textbox inside the normal text.
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: How to alter values of unitweights by scripting?

Postby Franck83 » 01 Mar 2018, 23:12

Oups sorry :D !

I looked at it too fast :)
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: How to alter values of unitweights by scripting?

Postby Uveso » 02 Mar 2018, 02:35

@Ghoustaq:

Just a idea;

You could make a mod with this Mex/Cap ratio function.
This way we could play all maps with Mex/Cap ratio.

But it's also ok, if you make it only for your maps :)

BTW, is it working ?

Nasty question; Did you test this with an AI ? :mrgreen:
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: How to alter values of unitweights by scripting?

Postby Ghoustaq » 02 Mar 2018, 18:30

@Uveso

not yet. I'm a little busy with my job in recent days. But I will test it at this weekends. :)
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Re: How to alter values of unitweights by scripting?

Postby Uveso » 04 Mar 2018, 03:47

No hurry Ghoustaq :)

I am just interested.
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: How to alter values of unitweights by scripting?

Postby Ghoustaq » 04 Mar 2018, 07:17

@Uveso

hello, Uveso :

the Mex/Cap ratio function works well just in FA, I cannot run it in vanilla.

I faild to alter unitweight, but it doesn't matter.

Now, I'm trying to broaden visionradius of max-extratcors. But I find no visionradius in the _unit.bp of max-extractors, it's really strange!

Do you know what variable defines the visionradius of a max-extratcor?
Last edited by Ghoustaq on 04 Mar 2018, 16:06, edited 2 times in total.
User avatar
Ghoustaq
Avatar-of-War
 
Posts: 65
Joined: 25 Dec 2017, 13:54
Has liked: 10 times
Been liked: 0 time
FAF User Name: Ghoustaq

Re: How to alter values of unitweights by scripting?

Postby Sprouto » 04 Mar 2018, 08:43

Ghoustaq - were you using unitwieght to control unit caps ? If so, the proper variable is CapCost.

The mass extractors vision radius can be found in the Intel section - and it is VisionRadius - if it's not there - then it may be being defaulted.
Sprouto
Priest
 
Posts: 366
Joined: 08 Sep 2012, 05:40
Has liked: 54 times
Been liked: 74 times
FAF User Name: Sprouto

Next

Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest