Jump to content

How do you put multiple units in the same group to limit the number of units?


Why would you want to reduce the number of units?

Also you mean creating squads or just increasing the unit count in a single "armada"?

 

Spoiler

dsasdaads.PNG.bc2ce9947079cbd3bd9893235e

sdadssad.PNG.5ba5c7adce4a585a235e382818c

 

There are also other way more complex ways.

Edited by RideR2
medal medal medal medal

Share this post


Link to post
Share on other sites

Spoiler

    customRules{
      name:t="sharedPool"

      teams{
        teamA{
          playerMaxSpawns:i=400
          spawnLimit:i=400

          limitedUnits{
            a-20g:i=4
            b_25j_20:i=4
            p-47d-28:i=4
            p-51d-5:i=4
            p-51d-10:i=4
            p-51d-20-na:i=4
            us_m10:i=52
            us_m4a1_76w_sherman:i=52
            us_m4a2_76w_sherman:i=52
            us_m4a3e8_76w_sherman:i=52
            us_m5a1_stuart:i=52
            us_halftrack_m16:i=16
          }

          unlimitedUnits{
          }
        }

        teamB{
          playerMaxSpawns:i=400
          spawnLimit:i=400

          limitedUnits{
            bf-109g-6:i=8
            fw-190a-5_u2:i=4
            fw-190a-8:i=4
            germ_pzkpfw_IV_ausf_F2:i=52
            germ_pzkpfw_IV_ausf_H:i=52
            germ_pzkpfw_V_ausf_g_panther:i=16
            germ_pzkpfw_V_ausf_a_panther:i=16
            germ_stuh_III_ausf_G:i=52
            germ_pzkpfw_38t_Marder_III:i=52
            germ_flakpanzer_38t_Gepard:i=8
            germ_sdkfz_6_2_flak36:i=8
            germ_sdkfz_9_flak37:i=8
          }

          unlimitedUnits{
          }
        }
      }

I know that this method can limit the number of vehicles used in combat.  But I'd like to know how to get different vehicles to share the same quantity limit.

For example, let the total number of Shermans be limited to 52, instead of setting a separate limit for each Sherman and having them add up to 52.

Share this post


Link to post
Share on other sites

8 minutes ago, SaratogaCV60 said:
Reveal hidden contents

    customRules{
      name:t="sharedPool"

      teams{
        teamA{
          playerMaxSpawns:i=400
          spawnLimit:i=400

          limitedUnits{
            a-20g:i=4
            b_25j_20:i=4
            p-47d-28:i=4
            p-51d-5:i=4
            p-51d-10:i=4
            p-51d-20-na:i=4
            us_m10:i=52
            us_m4a1_76w_sherman:i=52
            us_m4a2_76w_sherman:i=52
            us_m4a3e8_76w_sherman:i=52
            us_m5a1_stuart:i=52
            us_halftrack_m16:i=16
          }

          unlimitedUnits{
          }
        }

        teamB{
          playerMaxSpawns:i=400
          spawnLimit:i=400

          limitedUnits{
            bf-109g-6:i=8
            fw-190a-5_u2:i=4
            fw-190a-8:i=4
            germ_pzkpfw_IV_ausf_F2:i=52
            germ_pzkpfw_IV_ausf_H:i=52
            germ_pzkpfw_V_ausf_g_panther:i=16
            germ_pzkpfw_V_ausf_a_panther:i=16
            germ_stuh_III_ausf_G:i=52
            germ_pzkpfw_38t_Marder_III:i=52
            germ_flakpanzer_38t_Gepard:i=8
            germ_sdkfz_6_2_flak36:i=8
            germ_sdkfz_9_flak37:i=8
          }

          unlimitedUnits{
          }
        }
      }

I know that this method can limit the number of vehicles used in combat.  But I'd like to know how to get different vehicles to share the same quantity limit.

For example, let the total number of Shermans be limited to 52, instead of setting a separate limit for each Sherman and having them add up to 52.

Oh, I see what you mean.

 

11 hours ago, SaratogaCV60 said:

In World War mode, many different vehicles can be assigned to the same group to limit the total number.  How is this done?  I didn't find anything like this in the Missions editor.

I want to see a screenshot or video of that (from the WWM mode) then to confirm something, then I'll do some datamining.

Edited by RideR2
medal medal medal medal

Share this post


Link to post
Share on other sites

Well then, I did some datamining and couldn't get anything to work, but I found something interesting, it's possible to make it so there are only three active heavy tanks at the same time and people won't be able to spawn more.

So for example people will spawn three Tigers tanks and it even if you set them to unlimited it won't be possible to spawn more until someone dies.

 

I'm also afraid that groups are available only in the WWM's version of this script.

I did find the name, but I don't know how to apply them.

 

Here's the code that can be used:

https://wiki.warthunder.com/Multiplayer_mission_creation#Limiting_amount_and_type_of_units_available_for_respawn

There's also limitedActiveClasses which works like Classes (I just added it to the wiki page), but adds the active units limits that I mentioned.

 

The code of those groups from WWM is:

breakthrough_tank

infantry_tank

cruiser_tank

light_tank_destroyer

medium_tank_destroyer

heavy_tank_destroyer

germ_pzkpfw_II

germ_pzkpfw_III_kurz

germ_pzkpfw_III_lang

germ_pzkpfw_IV

germ_pzkpfw_IV_kurz

germ_pzkpfw_IV_lang

germ_pzkpfw_V_panther

germ_pzkpfw_VI_tiger

us_m4_sherman_75mm

us_m4_sherman_76mm

mbt

afv

 

But as I said I have no idea how to apply it.

 

This is the sharedPool script:

Spoiler
from "%scripts/dagui_library.nut" import *

//checked for explicitness
#no-root-fallback
#explicit-this

let { getUnitClassTypeByExpClass } = require("%scripts/unit/unitClassType.nut")
let unitTypes = require("%scripts/unit/unitTypesList.nut")

::mission_rules.SharedPool <- class extends ::mission_rules.Base
{
  function getMaxRespawns()
  {
    return getTblValue("playerMaxSpawns", this.getMyTeamDataBlk(), ::RESPAWNS_UNLIMITED)
  }

  function getLeftRespawns()
  {
    let maxRespawns = this.getMaxRespawns()
    if (maxRespawns == ::RESPAWNS_UNLIMITED)
      return ::RESPAWNS_UNLIMITED

    let spawnsBlk = getTblValue("spawns", this.getMisStateBlk())
    let usedSpawns = getTblValue(::my_user_id_str, spawnsBlk, 0)
    return max(0, maxRespawns - usedSpawns)
  }

  function getRespawnInfoTextForUnit(unit)
  {
    let res = base.getRespawnInfoTextForUnit(unit)
    if (!unit)
      return res

    let limitText = this.getExpClassLimitTextByUnit(unit)
    return res + ((res.len() && limitText.len()) ? loc("ui/comma") : "") + limitText
  }

  function getSpecialCantRespawnMessage(unit)
  {
    let expClassName = unit.expClass.getExpClass()
    let activeAtOnce = this.getActiveAtOnceExpClass(expClassName)
    if (activeAtOnce != ::RESPAWNS_UNLIMITED
        && activeAtOnce <= this.getCurActiveExpClassAmount(expClassName))
      return loc("multiplayer/cant_spawn/all_active_at_once",
                   {
                     name = colorize("activeTextColor", unit.expClass.getName())
                     amountText = this.getExpClassLimitTextByUnit(unit)
                   })

    let leftRespawns = this.getUnitLeftRespawns(unit)
    if (!leftRespawns)
      return loc("multiplayer/noTeamUnitLeft", { unitName = colorize("userlogColoredText", ::getUnitName(unit)) })

    return null
  }

  function getExpClassLimitTextByUnit(unit)
  {
    let expClassName = unit.expClass.getExpClass()
    let activeAtOnce = this.getActiveAtOnceExpClass(expClassName)
    if (activeAtOnce == ::RESPAWNS_UNLIMITED)
      return ""

    let limit = ::g_unit_limit_classes.ActiveLimitByUnitExpClass(
                    expClassName,
                    activeAtOnce,
                    { distributed = this.getCurActiveExpClassAmount(expClassName) }
                 )
    return limit.getText()
  }

  function hasCustomUnitRespawns()
  {
    let myTeamDataBlk = this.getMyTeamDataBlk()
    return "limitedUnits" in myTeamDataBlk || "unlimitedUnits" in myTeamDataBlk
           || "limitedClasses" in myTeamDataBlk || "limitedTags" in myTeamDataBlk
           || "limitedActiveClasses" in myTeamDataBlk
  }

  function getUnitLeftRespawnsByTeamDataBlk(unit, teamDataBlk)
  {
    if (!unit)
      return 0

    local res = ::RESPAWNS_UNLIMITED
    let limitedClasses = getTblValue("limitedClasses", teamDataBlk)
    if (::u.isDataBlock(limitedClasses))
    {
      let total = limitedClasses.paramCount()
      for(local i = 0; i < total; i++)
      {
        let expClassName = limitedClasses.getParamName(i)
        let expClass = getUnitClassTypeByExpClass(expClassName)
        if (expClass != unit.expClass)
          continue

        res = limitedClasses.getParamValue(i)
        break
      }
    }

    let limitedTags = getTblValue("limitedTags", teamDataBlk)
    if (::u.isDataBlock(limitedTags))
    {
      let total = limitedTags.paramCount()
      for(local i = 0; i < total; i++)
        if (isInArray(limitedTags.getParamName(i), unit.tags))
          res = this.minRespawns(res, limitedTags.getParamValue(i))
    }

    let limitedUnits = getTblValue("limitedUnits", teamDataBlk)
    res = this.minRespawns(res, getTblValue(unit.name, limitedUnits, ::RESPAWNS_UNLIMITED))

    if (res != ::RESPAWNS_UNLIMITED)
      return res

    let unlimitedUnits = getTblValue("unlimitedUnits", teamDataBlk)
    if (unlimitedUnits && !(unit.name in unlimitedUnits))
      res = 0
    return res
  }

  function calcFullUnitLimitsData(_isTeamMine = true)
  {
    let res = base.calcFullUnitLimitsData()

    let myTeamDataBlk = this.getMyTeamDataBlk()
    res.defaultUnitRespawnsLeft = "unlimitedUnits" in myTeamDataBlk ? 0 : ::RESPAWNS_UNLIMITED

    let limitedClasses = getTblValue("limitedClasses", myTeamDataBlk)
    if (::u.isDataBlock(limitedClasses))
    {
      let total = limitedClasses.paramCount()
      for(local i = 0; i < total; i++)
      {
        let expClassName = limitedClasses.getParamName(i)
        if (getUnitClassTypeByExpClass(expClassName).isValid())
          res.unitLimits.append(::g_unit_limit_classes.LimitByUnitExpClass(expClassName, limitedClasses.getParamValue(i)))
      }
    }

    let limitedTags = getTblValue("limitedTags", myTeamDataBlk)
    if (::u.isDataBlock(limitedTags))
    {
      let total = limitedTags.paramCount()
      for(local i = 0; i < total; i++)
      {
        let tag = limitedTags.getParamName(i)
        let respLeft = limitedTags.getParamValue(i)

        let unitType = unitTypes.getByTag(tag)
        if (unitType != unitTypes.INVALID)
        {
          res.unitLimits.append(::g_unit_limit_classes.LimitByUnitType(unitType.typeName, respLeft))
          continue
        }

        let role = ::g_string.cutPrefix(tag, "type_", null)
        if (role)
          res.unitLimits.append(::g_unit_limit_classes.LimitByUnitRole(role, respLeft))
      }
    }

    let unitsGroups = this.getUnitsGroups()
    local blk = getTblValue("limitedUnits", myTeamDataBlk)
    if (::u.isDataBlock(blk))
      for(local i = 0; i < blk.paramCount(); i++)
        res.unitLimits.append(::g_unit_limit_classes.LimitByUnitName(blk.getParamName(i), blk.getParamValue(i),
          { nameLocId = unitsGroups?[blk.getParamName(i)] }))

    blk = getTblValue("unlimitedUnits", myTeamDataBlk)
    if (::u.isDataBlock(blk))
      for(local i = 0; i < blk.paramCount(); i++)
        res.unitLimits.append(::g_unit_limit_classes.LimitByUnitName(blk.getParamName(i), ::RESPAWNS_UNLIMITED,
          { nameLocId = unitsGroups?[blk.getParamName(i)] }))

    let activeLimitsBlk = getTblValue("limitedActiveClasses", myTeamDataBlk)
    if (::u.isDataBlock(activeLimitsBlk))
    {
      let limitByExpClassName = {}
      let total = activeLimitsBlk.paramCount()
      for(local i = 0; i < total; i++)
      {
        local value = activeLimitsBlk.getParamValue(i)
        local expClassName = activeLimitsBlk.getParamName(i)
        if (::g_string.endsWith(expClassName, "_perc"))
        {
          value = this.getAmountByTeamPercent(value)
          expClassName = expClassName.slice(0, expClassName.len() - 5)
        }
        if (expClassName in limitByExpClassName)
          limitByExpClassName[expClassName] = min(value, limitByExpClassName[expClassName])
        else
          limitByExpClassName[expClassName] <- value
      }

      let activeBlk = getTblValue("activeClasses", myTeamDataBlk)
      foreach(expClassName, maxAmount in limitByExpClassName)
        res.unitLimits.append(
          ::g_unit_limit_classes.ActiveLimitByUnitExpClass(
            expClassName,
            maxAmount,
            { distributed = activeBlk?[expClassName] ?? 0 }
          )
        )
    }

    return res
  }

  function getAmountByTeamPercent(percent)
  {
    return ((percent * ::get_mplayers_count(::get_mp_local_team(), false)) / 100).tointeger()
  }

  function getActiveAtOnceExpClass(expClassName)
  {
    local res = ::RESPAWNS_UNLIMITED
    let activeLimitsBlk = getTblValue("limitedActiveClasses", this.getMyTeamDataBlk())
    if (!activeLimitsBlk)
      return res

    res = this.minRespawns(res, getTblValue(expClassName, activeLimitsBlk, ::RESPAWNS_UNLIMITED))
    let percent = getTblValue(expClassName + "_perc", activeLimitsBlk, -1)
    if (percent >= 0)
      res = this.minRespawns(res, this.getAmountByTeamPercent(percent))
    return res
  }

  function getCurActiveExpClassAmount(expClassName)
  {
    let activeBlk = getTblValue("activeClasses", this.getMyTeamDataBlk())
    return getTblValue(expClassName, activeBlk, 0)
  }
}

 

 

Also as you know that's the code of this script:

name:t="sharedPool"

 

There also other available scripts like:

missioncustomstate

rulebase

ruleenduringconfrontation

rulenumspawnsbyunittype

ruleunitsdeck

unitlimit

 

But I'm not sure if they are even related to missions.

 

Anyway, try experimenting with that stuff yourself.

Edited by RideR2
  • Thanks 1
medal medal medal medal

Share this post


Link to post
Share on other sites

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...