How to alter values of unitweights by scripting?

Interesting mapping tools and mapping help.

Moderator: Morax

Re: How to alter values of unitweights by scripting?

Postby Ghoustaq » 04 Mar 2018, 15:55

Sprouto wrote: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
Yes, I was. Could CapCost be altered in mapscript? I am unwilling to modify any file in gamedata.
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 » 04 Mar 2018, 17:25

@Sprouto
Hello Sprouto:
I wrote some codes as below. Can you check them for me? They haven't worked yet.I don't know why :roll:
Code: Select all
for UnitID, Intel in __unit.bp do
        if Intel.General.VisionRadius then
            LOG('Unit '..UnitID..' has a value of '..Intel.General.VisionRadius..' as VisionRadius')
            if Intel.CategoriesHash.MASSEXTRACTION * (CategoriesHash.TECH1) then
                LOG('Unit '..UnitID..' is a TECH1 unit. Seting VisionRadius to 25')
                Intel.General.VisionRadius = 25
            end
            if Intel.CategoriesHash.MASSEXTRACTION * (CategoriesHash.TECH2) then
                LOG('Unit '..UnitID..' is a TECH2 unit. Seting VisionRadius to 35')
                Intel.General.VisionRadius = 35
            end
            if Intel.CategoriesHash.MASSEXTRACTION * (CategoriesHash.TECH3) then
                LOG('Unit '..UnitID..' is a TECH3 unit. Seting VisionRadius to 45')
                Intel.General.VisionRadius = 45
            end
            if Intel.CategoriesHash.HYDROCARBON then
                LOG('Unit '..UnitID..' is a TECH1 unit. Seting VisionRadius to 55')
                Intel.General.VisionRadius = 55
            end
        else
            LOG('Unit '..UnitID..' don\'t has a VisionRadius')
        end
    end
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, 19:27

Your code looks good - but - to my knowledge - it won't work in a map script - this would be best used in blueprints.lua

The question is, and I'm not clear to answer this one, is -- are the unit blueprints registered before the map script is run ? If not - then it might be possible for the script to execute as part of the map. If the blueprints are already registered (and I think they are before the map script is even considered) then you can't do it from the map script.
Sprouto
Priest
 
Posts: 366
Joined: 08 Sep 2012, 05:40
Has liked: 54 times
Been liked: 74 times
FAF User Name: Sprouto

Re: How to alter values of unitweights by scripting?

Postby speed2 » 04 Mar 2018, 19:34

Code: Select all
-- ==========================================================================================
-- * File       : lua/simInit.lua
-- * Authors    : Gas Powered Games, FAF Community, HUSSAR
-- * Summary    : This is the sim-specific top-level lua initialization file. It is run at initialization time to set up all lua state for the sim.
-- * Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
-- ==========================================================================================
-- Initialization order within the sim:
--   1. __blueprints is filled in from preloaded data
--   2. simInit.lua [this file] runs. It sets up infrastructure necessary to make Lua classes work etc.
--   if starting a new session:
--     3a. ScenarioInfo is setup with info about the scenario
--     4a. SetupSession() is called
--     5a. Armies, brains, recon databases, and other underlying game facilities are created
--     6a. BeginSession() is called, which loads the actual scenario data and starts the game
--   otherwise (loading a old session):
--     3b. The saved lua state is deserialized
-- ==========================================================================================

map script is used in BeginSession() so that is too late to change bps
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: How to alter values of unitweights by scripting?

Postby Sprouto » 04 Mar 2018, 19:44

That pretty much confirms it. Which only leaves with a few options - either a blueprints.lua that will temporarily change the blueprint values at game start - or a blueprint merge for each of the affected units which would alter their stats before the blueprints are registered for the game.
Sprouto
Priest
 
Posts: 366
Joined: 08 Sep 2012, 05:40
Has liked: 54 times
Been liked: 74 times
FAF User Name: Sprouto

Re: How to alter values of unitweights by scripting?

Postby Ghoustaq » 05 Mar 2018, 14:08

Sprouto wrote:That pretty much confirms it. Which only leaves with a few options - either a blueprints.lua that will temporarily change the blueprint values at game start - or a blueprint merge for each of the affected units which would alter their stats before the blueprints are registered for the game.

OK, I got it. the conclusion is that it's very hard to change variables which have been set in _Unit.bps by the means of map-scripting.
Last edited by Ghoustaq on 06 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 Uveso » 05 Mar 2018, 18:31

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


Yes, my fault :)

Only FAF has a CategoriesHash (thanks to Hussar)

Use this to create a CategoriesHash for the blueprint:

Code: Select all
            for _, cat in uBP.Categories do
                UnitBlueprint.CategoriesHash[cat] = true
            end
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 Uveso » 08 Mar 2018, 04:08

Hello Ghoustaq,

i viewed your script with intel radius and found 1-2 errors :)

Here is a copy & paste ready script for your MAP_script.lua:
(Vision radius is set to 1 for tech 1 units etc, just for testing)
Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')

function OnPopulate()
    ScenarioUtils.InitializeArmies()
end

function OnStart(self)
    EditBlueprints(self)
end

function EditBlueprints(self)
    for UnitID, UnitBlueprint in __blueprints do
        -- If we have no Categories then skip this unit and continue with the next unit
        if not UnitBlueprint.Categories then
            continue
        end
        -- Generate the CategoriesHash for non FAF game
        UnitBlueprint.CategoriesHash = {}
        for _, cat in UnitBlueprint.Categories do
            UnitBlueprint.CategoriesHash[cat] = true
        end
        -- fist check if we have a UnitBlueprint.Intel table, then check if we have a VisionRadius table inside UnitBlueprint.Intel
        if UnitBlueprint.Intel and UnitBlueprint.Intel.VisionRadius then
            LOG('Unit '..UnitID..' has a value of '..UnitBlueprint.Intel.VisionRadius..' as VisionRadius')
            if UnitBlueprint.CategoriesHash.TECH1 then
                LOG('Unit '..UnitID..' is a TECH1 unit. Seting VisionRadius to 1')
                UnitBlueprint.Intel.VisionRadius = 1
            end
            if UnitBlueprint.CategoriesHash.TECH2 then
                LOG('Unit '..UnitID..' is a TECH2 unit. Seting VisionRadius to 2')
                UnitBlueprint.Intel.VisionRadius = 2
            end
            if UnitBlueprint.CategoriesHash.TECH3 then
                LOG('Unit '..UnitID..' is a TECH3 unit. Seting VisionRadius to 3')
                UnitBlueprint.Intel.VisionRadius = 3
            end
            if UnitBlueprint.CategoriesHash.HYDROCARBON then
                LOG('Unit '..UnitID..' is a HYDROCARBON unit. Seting VisionRadius to 5')
                UnitBlueprint.Intel.VisionRadius = 5
            end
        else
            LOG('Unit '..UnitID..' don\'t has a VisionRadius')
        end
    end
end


I tested this also in multiplayer with 2 PC and it is NOT desyncing the game.
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 DDDX » 09 Mar 2018, 21:35

If you can lend a hand once more, Uveso:
How would one go about changing specific unit stats? Let's say I wanted, for example, Yolo to have 10k more hp.
What's missing from this code?

Code: Select all
function OnStart(self)

LOG("----- Survival MOD: Initializing game start sequence...");
   ForkThread(Survival_Tick);

   EditBlueprints(self)
end

function EditBlueprints(self)

    for UnitID, UnitBlueprint in __blueprints do

       if (UnitID == 'XSB2401') then      -- Yolona

             XSB2401_unit.bp.Defense.Health = 22000;  -- tried with UnitBlueprint.Defense.Health etc, nope
             XSB2401_unit.bp.Defense.MaxHealth = 22000;
       end           
    end
end


I bet it's something very simple, tried to figure it out by myself from your vision-by-tech-level example, but am not knowlegeable enough to do it :(
Much obliged!!!!!
Check out my 2 maps: "Survival_Mayhem&BO_3d_v1" "Survival_Mayhem&BO_3d_RPG"
as well as my mod: "Survival Mayhem&BO balance"
-- let me know of any bugs or issues regarding those 3.
DDDX
Avatar-of-War
 
Posts: 170
Joined: 21 Mar 2016, 16:13
Has liked: 18 times
Been liked: 16 times
FAF User Name: DDDX

Re: How to alter values of unitweights by scripting?

Postby Sprouto » 09 Mar 2018, 23:10

As I believe, by the time you get to your OnStart function, all of the blueprints have already been registered and can no longer be altered. Map loading, and any scripts associated with them always happen after the unit blueprints are locked in stone.
Sprouto
Priest
 
Posts: 366
Joined: 08 Sep 2012, 05:40
Has liked: 54 times
Been liked: 74 times
FAF User Name: Sprouto

PreviousNext

Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest