Login

russian armor

[Scar Script] Pre-built tech buildings / unlocks

4 Jul 2014, 18:06 PM
#1
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

Ever wanted to have pre-built tech tree buildings in your maps, for example T1 for all players? With this script you can achieve that!

Start by preparing a .scar file for your map. Open notepad and paste in the following code:

Code
function InstantTech_Init()
InstantTech_SystemInit()
end

Scar_AddInit(InstantTech_Init)

function InstantTech_SystemInit()
local instantTechConfig = {
factions = {
[0] = { -- Wehrmacht
tiers = {
[1] = {ebp = EBP.GERMAN.BEREICH_FESTUNG_MP},
[2] = {ebp = EBP.GERMAN.DOLCH_AKTIONEN_MP, ubp = UPG.GERMAN.BATTLE_PHASE_2_MP},
[3] = {ebp = EBP.GERMAN.HINTERE_PANZERWERK_MP, ubp = UPG.GERMAN.BATTLE_PHASE_3_MP},
[4] = {ebp = EBP.GERMAN.SCHWERES_KRIEGSWERK_MP, ubp = UPG.GERMAN.BATTLE_PHASE_4_MP},
},
},
[1] = { -- Soviet
tiers = {
[1] = {ebp = EBP.SOVIET.BARRACKS_MP},
[2] = {ebp = EBP.SOVIET.WEAPON_SUPPORT_CENTER_MP},
[3] = {ebp = EBP.SOVIET.MOTORPOOL_MP},
[4] = {ebp = EBP.SOVIET.TANK_DEPOT_MP},
},
},
[2] = { -- Oberkommando West
tiers = {
-- T1 for OKW is a bit different than for others because of T1 and T2 are pretty much the same.
-- If you set globalTechLevel to 1, OKW will get T1 OR T2 truck setup for free. If T1 is setup, T2 setup cost modifier will be removed.
[1] = {ebp = EBP.WEST_GERMAN.HEAVY_ARMOR_SUPPORT_MP, additional_ebp = EBP.WEST_GERMAN.LIGHT_ARMOR_SUPPORT_MP},
[2] = {ebp = EBP.WEST_GERMAN.LIGHT_ARMOR_SUPPORT_MP},
[3] = {ebp = EBP.WEST_GERMAN.INFANTRY_SUPPORT_MP},
},
},
[3] = { -- US Forces
tiers = {
[1] = {ubp = UPG.AEF.LIEUTENANT_DISPATCHED_UPGRADE_MP, sbp = SBP.AEF.LIEUTENANT_SQUAD_MP},
[2] = {ubp = UPG.AEF.CAPTAIN_DISPATCHED_UPGRADE_MP, sbp = SBP.AEF.CAPTAIN_SQUAD_MP},
[3] = {ubp = UPG.AEF.MAJOR_DISPATCHED_UPGRADE_MP, sbp = SBP.AEF.MAJOR_SQUAD_MP},
},
},
},
}


--[[
- For US Forces and Oberkommando West, 1 will be substracted from this value.
- For example globalTechLevel of 4 is 3 for US Forces and Oberkommando West.
- You can adjust this in the config as well.
- If setupTrucks is set to false, OKW will get the number of trucks matching the globalTechLevel, with the possible WFASubtract.
-
--]]

local instantTechConfigMap = {
globalTechLevel = 3,
WFASubtract = 1,
setupTrucks = false,
spawnOfficers = false,
applyToHumans = true,
applyToAis = true,
}

g_okw_truck_setup_modifier = {}

g_resource_type_okw_truck_setup = {
RT_Manpower, RT_Fuel,
}

eg_all_instant_tech = EGroup_CreateIfNotFound("eg_all_instant_tech")
sg_all_instant_tech = SGroup_CreateIfNotFound("sg_all_instant_tech")

Players_ForEeach(function(idx, pid, player)
if (Player_IsHuman(player) and instantTechConfigMap.applyToHumans) or (not Player_IsHuman(player) and instantTechConfigMap.applyToAis) then
local pos = Player_GetStartingPosition(player)
local building_positions = InstantTech_GenerateBuildingPositions(pos)
local race = Player_GetRaceIndex(player)
if instantTechConfig.factions[race] then
local config = instantTechConfig.factions[race]
local _globalTechLevel = instantTechConfigMap.globalTechLevel
if race == 2 then
_globalTechLevel = _globalTechLevel - instantTechConfigMap.WFASubtract
if _globalTechLevel < 1 then _globalTechLevel = 1 end
end

for key, tier in pairs(config.tiers) do
if _globalTechLevel >= key then
if tier.ebp then
if race ~= 2 or instantTechConfigMap.setupTrucks then
local spawn_pos = InstantTech_GetAvailableBuildingSpawnPosition(building_positions)
local heading = Util_GetRandomPosition(pos, 30)
local entity = Entity_CreateAndSpawnToward(tier.ebp, player, spawn_pos.pos, heading)
elseif race == 2 and not instantTechConfigMap.setupTrucks then
local spawn_pos = InstantTech_GetAvailableBuildingSpawnPosition(building_positions)
local heading = Util_GetRandomPosition(pos, 30)
local squad = Squad_CreateAndSpawnToward(SBP.WEST_GERMAN.SWS_HALFTRACK_SQUAD_MP, player, 1, spawn_pos.pos, heading)

for key2, resource_type in ipairs(g_resource_type_okw_truck_setup) do
local modifier = Modify_EntityCostExpanded(player, tier.ebp, resource_type, 0)
table.insert(g_okw_truck_setup_modifier, {modifier = modifier, ebp = tier.ebp, player = player })

if tier.additional_ebp then
local modifier = Modify_EntityCostExpanded(player, tier.additional_ebp, resource_type, 0)
table.insert(g_okw_truck_setup_modifier, {modifier = modifier, ebp = tier.ebp, player = player })
end
end

local modifier = Modify_EntityBuildTime(player, tier.ebp, 0.15)
table.insert(g_okw_truck_setup_modifier, {modifier = modifier, ebp = tier.ebp, player = player })
end
end
if tier.ubp then
Player_CompleteUpgrade(player, tier.ubp)
end
if tier.sbp and not instantTechConfigMap.spawnOfficers then
SGroup_Clear(sg_all_instant_tech)
Player_GetAll(player, sg_all_instant_tech)
SGroup_Filter(sg_all_instant_tech, tier.sbp, FILTER_KEEP)
SGroup_DestroyAllSquads(sg_all_instant_tech)
end
end
end
end
end
end)

Rule_Add(InstantTech_MonitorOKWTrucks)
end

function InstantTech_MonitorOKWTrucks()
for key, truck_modifier in ipairs(g_okw_truck_setup_modifier) do
local player = truck_modifier.player
EGroup_Clear(eg_all_instant_tech)
Player_GetAll(player, eg_all_instant_tech)
EGroup_Filter(eg_all_instant_tech, truck_modifier.ebp, FILTER_KEEP)

EGroup_ForEach(eg_all_instant_tech, function(egid, idx, entity)
Modifier_Remove(truck_modifier.modifier)
table.remove(truck_modifier, key)
end)
end

if table.getn(g_okw_truck_setup_modifier) == 0 then
Rule_RemoveMe()
end
end

function InstantTech_GenerateBuildingPositions(pos)
local t_offsets = {OFFSET_FRONT, OFFSET_RIGHT, OFFSET_BACK, OFFSET_LEFT}
local result = {}
for key, offset in ipairs(t_offsets) do
table.insert(result, {pos = Util_GetOffsetPosition(pos, offset, 15), used = false})
end

return result
end

function InstantTech_GetAvailableBuildingSpawnPosition(pos_list)
for key, pos in ipairs(pos_list) do
if not pos.used then
pos.used = true
return pos
end
end
return World_Pos(0, 0, 0)
end

function Entity_CreateAndSpawnToward(ebp, player, pos, toward)
local entity

if player then
entity = Entity_Create(ebp, player, pos, toward)
else
entity = Entity_CreateENV(ebp, pos, toward)
end
Entity_Spawn(entity)
Entity_ForceConstruct(entity)
return entity
end

function Players_ForEeach(f)
for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
f(Player_GetID(player), i, player)
end
end

function Modify_EntityCostExpanded(playerid, blueprint, resource, addition, mathtype)
local modifiertype = ""
mathtype = mathtype or MUT_Multiplication

if (resource == RT_Manpower) then
modifiertype = "modifiers\\cost_manpower_modifier.lua"
elseif (resource == RT_Munition) then
modifiertype = "modifiers\\cost_munition_modifier.lua"
elseif (resource == RT_Fuel) then
modifiertype = "modifiers\\cost_fuel_modifier.lua"
elseif (resource == RT_Action) then
modifiertype = "modifiers\\cost_action_modifier.lua"
end

local modifier = Modifier_Create(MAT_EntityType, modifiertype, mathtype, false, addition, blueprint)

return {Modifier_ApplyToPlayer(modifier, playerid)}
end

function Player_GetRaceIndex(player)
local racename = Player_GetRaceName(player)

if racename == "german" then
return 0
elseif racename == "soviet" then
return 1
elseif racename == "west_german" then
return 2
elseif racename == "aef" then
return 3
else
return -1
end
end


.. and save the current file to your map's folder as <yourmapname>.scar where <yourmapname> is the name of your map's .sgb file.


Run "Export Package" in WorldBuilder and you are ready to test it!

Configuration


By default the configuration for this script is the following:
Code
local instantTechConfigMap = {
globalTechLevel = 3,
WFASubtract = 1,
setupTrucks = false,
spawnOfficers = false,
applyToHumans = true,
applyToAis = true,
}

You should edit this config in the script to match your needs. Information about the parameters is listed below:

globalTechLevel = desired tech level
WFASubtract = amount of levels to subtract for WFA armies. (Because of WFA armies only got 3 logical tiers)
setupTrucks = Whether or not to instant-setup OKW truck around their HQ. By default this is set to false and mobile trucks are spawned instead, with one-time free building convert. If globalTechLevel is set to 1, OKW can setup either Battlegroup HQ (healing) or Mechanized Regiment (Conversion + Repair pios) for free.
spawnOfficers = Whether or not US Forces players should receive the officers from the instant tech unlocks.
applyToHumans = Apply instant teching to all human players.
applyToAis = Apply instant teching to all AI players.

Example screenshots:


Config used for these screenshots


Wehrmacht


Soviet


Oberkommando West


US Forces
14 Jun 2015, 15:52 PM
#2
avatar of GSamu

Posts: 32

I can't believe what I see!!!
It works!!!

Master Janne, my admiration for your work and thank you for your time.


Regards.
1 user is browsing this thread: 1 guest

Ladders Top 10

  • #
    Steam Alias
    W
    L
    %
    Streak
Data provided by Relic Relic Entertainment

Replay highlight

VS
  • U.S. Forces flag cblanco ★
  • The British Forces flag 보드카 중대
  • Oberkommando West flag VonManteuffel
  • Ostheer flag Heartless Jäger
uploaded by XXxxHeartlessxxXX

Board Info

292 users are online: 292 guests
2 posts in the last 24h
39 posts in the last week
140 posts in the last month
Registered members: 44901
Welcome our newest member, otorusqvip
Most online: 2043 users on 29 Oct 2023, 01:04 AM