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 DDDX » 09 Mar 2018, 23:17

I thought so too, however I tested Uveso's code and it does indeed work - I created a t1 pgen, with pathetic vision radius. That means the original blueprint in UNITS.scd has been altered by the map's lua script. I see no reason why if it works on vision, it would not work on other unit attributes.
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 Uveso » 09 Mar 2018, 23:55

Hello DDDX,

UnitID's are lowercase ;)

But also with lower case ID its not working.

This would be the right syntax for the function (maybe you can use it outside a map script file):
Code: Select all
function EditBlueprints(self)
    for UnitID, UnitBlueprint in __blueprints do
       if (UnitID == 'xsb2401') then -- Yolona Oss
            UnitBlueprint.Intel.VisionRadius = 5
            UnitBlueprint.Defense.Health = 22000
            UnitBlueprint.Defense.MaxHealth = 22000
        end
    end
end


Also not working from a map file, but if you only want to change a singe blueprint, then you can access it with the unitID:
Code: Select all
__blueprints['xsb2401'].Defense.Health = 22000
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 » 10 Mar 2018, 00:42

Does not work via map script.lua :(
But why?
It your prior code was able to edit vision radius of units (and i saw for myself that it does, on a lonely pgen t1) then obviously it can be done from a map script... blueprint got edited

anyways, thank you for your reply. At least u tried :(
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 Ghoustaq » 10 Mar 2018, 18:23

@Sprouto

Hello Sprouto,

Do you know what is the right code to get current capcost and to reset capcost in the game?

CurrentCapCost = GetArmyUnitCapCost(INDEX)?

and

SetArmyUnitCapCost(INDEX, NewCapCost)?

I'm not sure whether the both are correct or not. They haven't work via my mapscript so far. :?
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 » 10 Mar 2018, 20:48

Ghostaq !

To obtain the overall unit cap of the map use this;

local initialCap = tonumber(ScenarioInfo.Options.UnitCap)

This will give you the initial unit cap that all players will be using. It should be available during the map script.

You've got the right code for setting an army's unit cap but I'm not sure if the armies are initialized at the time of map script execution. However, if the function to set individual armies unit cap is unavailable, then perhaps your script could adjust the ScenarioInfo value before the normal code gets hold of it - that way you could enforce a unit cap of your choice on the map. Try it and see.

In the LOUD project, we use it to increase an armies unit cap as they attain veterancy and it works well - allowing games that have fairly low starting unit caps. We've had some discussions in the past about tying unit cap to the ownership of mass points as a tool for encouraging players to play the entire map (and de-emphasize turtling) - but as of yet we have not attempted to implement it. Having said that, we do feel it could be an effective 'nudge' in that regard. Let us know how your own work progresses.
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 Uveso » 11 Mar 2018, 02:46

@Ghoustaq:

I am a little bit confused. You wrote it was working:
viewtopic.php?f=53&t=15932&p=161202#p161202

BTW, there was no command like this:
Code: Select all
GetArmyUnitCapCost()

This is the right command (no "cost" word at the end):
Code: Select all
GetArmyUnitCap()

Also the second command is wrong:
Code: Select all
SetArmyUnitCapCost()

This is the correct one:
Code: Select all
SetArmyUnitCap()


ScenarioInfo.Options.UnitCap is a game option set by host before the game starts.

If you change the cap with SetArmyUnitCapCost(), then ScenarioInfo.Options.UnitCap has still the old start value stored, not the new unitcap.

So you can reset the unitcap to default with this:
Code: Select all
SetArmyUnitCap( brain:GetArmyIndex() , ScenarioInfo.Options.UnitCap )
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 » 11 Mar 2018, 09:27

@Uveso:
I'm sorry. I think I didn't make it clear.

I know that unitcap means the Maximum quantity of units which I can own. If I have a unitcap of 100, that means I can own 100 units at most.

I personally define unitcapcost as the cost of unitcap for all units I have owned. If I have built 30 units, that means I must cost 30 unitcap to build units, so the unitcapcost is 30, but I can still build 70 units at most,'cause unitcap which have not been cost remains 70(100-30=70). Though I'm not sure whether the concept of unitcapcost does exist or not.

unitcap can be altered for sure, by the codes that you offered to me. Now I wonder if unitcapcost can be alterd too?

In general, one unit costs 1 unitcap. What I want is that every Tech1unit costs 1 unitcap, Tech2unit costs 2, Tech3unit costs 3, experimentalunit costs 10, like this.
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 speed2 » 11 Mar 2018, 09:51

These are all the engine functions available http://supcom.wikia.com/wiki/LUADOC_1.5.3599

I wrote bit of documentation for some of them here https://github.com/FAForever/fa/tree/develop/engine
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 Ghoustaq » 11 Mar 2018, 10:32

speed2 wrote:These are all the engine functions available http://supcom.wikia.com/wiki/LUADOC_1.5.3599

I wrote bit of documentation for some of them here https://github.com/FAForever/fa/tree/develop/engine

Those are what I need. Thank you very much. :D
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 » 12 Mar 2018, 16:33

@speed2
Hello!speed2:

I am tring to create a damagearea where all mobile units will suffer damage over time until they get out. The following are the whole codes that I modified from yours. Can you check them and find out the reason for not-working?

Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')

function OnPopulate()
   ScenarioUtils.InitializeArmies()
   ScenarioFramework.SetPlayableArea('AREA_1', false)


local oldDamageArea = DamageArea
local radius = 25
local self = import('/lua/sim/Entity.lua').Entity()
local damage = 30
   for k = 1, 1 do
      local DAMAGEAREAName = 'DAMAGEAREA_' .. k
      local location = ScenarioUtils.MarkerToPosition(DAMAGEAREAName)
           local px, py, pz = unpack(location)
        end
end




DamageArea = function(instigator, location, radius, damage, type, damageAllies, damageSelf, brain, army)
    local army = ListArmies()
    local rect = Rect(px-radius, pz-radius, px+radius, pz+radius)
    local units = GetUnitsInRect(rect) or {}
    local damageAllies = true
    local damageSelf = true   
    for _, u in units do
        if table.find(u:GetBlueprint().Categories,'MOBILE') then
           continue
        end
        if VDist3(u:GetPosition(), location) > radius then
           continue
        end
        if instigator == u then
            if damageSelf then
                local vector = import('/lua/utilities.lua').GetDirectionVector(location, u:GetPosition())
                -- need this ugliness due to Damage() refuse to damage when instigator == u
                instigator:OnDamage(instigator, damage, vector, 'Reclaimed')
            end
        elseif damageAllies or not IsAlly(army, u:GetArmy()) then
            Damage(instigator, location, u, damage, 'Reclaimed')
        end
    end

    local reclaim = GetReclaimablesInRect(rect) or {}
    for _, r in reclaim do
        if IsProp(r) and VDist3(r:GetPosition(), location) <= radius then
            Damage(instigator, location, r, damage, 'Reclaimed')
        end
    end

     -- Get rid of trees
     oldDamageArea(instigator, location, radius, 1, 'Reclaimed', false, false)
    end


function OnStart(self)
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

PreviousNext

Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest