General Information
Register Time: 7 May 2013, 17:21 PM
Last Visit Time: 13 Feb 2023, 05:57 AM
Broadcast: https://www.twitch.tv/janne252
Website: https://janne252.com
Twitter: @Jannev252
Youtube: Janne252
Xfire: Janne252
Steam: 76561198035243858
Residence: Finland
Nationality: Finland
Timezone: Europe/Helsinki
Game Name: Janne252
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. - --]]
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:
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.
NIS animations are the cinematic parts of the Singleplayer missions, where the footage is in-game. Some ToW mission ending camera movement is probably also implemented with NIS.
1. Export your map in the WorldBuilder 2. Start COH2, Publish your map to the WorkShop, exit COH2 3. Locate your exported .sga file in my games\company of heroes 2\mods\scenarios and make a copy of it to my games\company of heroes 2\mods\scenarios\subscriptions 4. Goto your recently published map WorkShop page and select "Share".
Copy the 9-digit number from the end of the url. Example result: http://steamcommunity.com/sharedfiles/filedetails/?id=279533345
5. Rename the copy of your map to #########.sga where ######### is the 9-digit number you just copied. 6. Launch COH2. You will now have 2 identical maps available in the map browser. Usually the one in the bottom of the list is the one from the WorkShop. You can just try in the lobby which map triggers the download icon for other players.
I've tested this with my laptop and desktop combination. Only Workshop maps created by others will start downloading at the laptop I join to my game.
The fact that the exported version of your map re-appears in C:\Users\Janne\Documents\my games\company of heroes 2\mods\scenarios most likely causes this, as it's not a Workshop map and thus has no encoded information or anything.
That's why any map located in C:\Users\Janne\Documents\my games\company of heroes 2\mods\scenarios\subscriptions can be hosted and will download for others. For some reason the one in scenarios folder overrides the Workshop version and it's treated as local map.
SOLVED!
How to host your own maps:
1. Export your map in the WorldBuilder 2. Publish it normally 3. Exit COH2 4. Change your map's name to something else so you can tell the difference between 2 copies of it, e.g. "mapname" -> "mapname 2" 5. Export that map again 6. Login to another Steam account which has COH2 or use family share OR ask your friend to do it. 7. Subscribe to your recently published map 8. Grab the downloaded .sga file ( it will be hard to know which one is it, as all Workshop maps have 9 numbers in their name. Look for one with (almost) identical file size as your recently exported map. Another method is to open the .sga file in notepad++ / hex editor, as you can locate readable text in the beginning of the file. Example:
9. Copy this map to your subscription folder. Subscribing to your own maps wont do this! 10. Host the new copied map. It should automatically download to other players! (Don't host the one with the new edited name. The map name was edited so that you can now tell whih one is the "offical" Workshop map.)
aerafield: @LimaOscarMike I would say nowadays is a decent time to try CoH3. If you loved CoH2 however, there is a solid chance you're gonna dislike CoH3 Yesterday, 17:04 PM
LimaOscarMike: My laptop can't even run COH3. Should I get them on my Series X or is it dead yet? Last Saturday, 05:10 AM
Rosbone: One of my last major gripes about Coh3. Price is still too high I feel for growth. But progress is always good. Last Saturday, 04:43 AM
Rosbone: I am not 100% sure but I think Relic actually fixed up the skirmish menus a little last patch. If so, thank you and keep it coming. Last Saturday, 04:39 AM
Lady Xenarra: Does anyone else think that USF needs buffs? It feels like they’re on life support sometimes 01 Apr 2025, 02:36 AM
Willy Pete: @Rosbone Ahh I missed that memo. I still think its a bad decision though. Adds frustration for players and isnt gonna make them that much money 27 Mar 2025, 15:46 PM
Rosbone: It is also good they left it free until after the free to play weekend. Points for that. 27 Mar 2025, 09:34 AM
Rosbone: But I agree, the cost to get a full decent Coh game pushing $115 US is not the best idea. Especially when it needs so much more work for casuals. 27 Mar 2025, 09:32 AM