Login

russian armor

How-to: Custom Starting Resources & Income rate

27 Dec 2013, 23:02 PM
#1
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

How-To: Custom Starting Resources



Basics



In this tutorial you will learn how to set custom starting resources for your map. To do this, you will need a basic text editor. Microsoft Notepad is suitable for this job and you already have it. In case you'd like to consider getting a bit better tool for this, I would recommend using notepad++, which you can download from notepad-plus-plus.org


The Script File



All maps can be shipped with a custom script file. This file is always named as <mapname>.scar, where <mapname> is same as the name of your map's .sgb file. You can create this file by opening notepad or notepad++, and by saving a new blank document as <mapname>.scar to your map folder.

Adding code to override default starting resources



Open <mapname>.scar in notepad / notepad++ if you have closed it.

Copy and paste in the following code:
Alternatively you can also download this .zip archive, which contains a pre-made scar file with the following code. Extract it and move the .scar file to your map's folder and rename the .scar file to match your .sbg file name!

Code

function CustomStartingResources_Init()
--[[
CustomStartingResource System created by Janne252. Visit COH2.ORG for more. Please do not remove this note.

Some information about income_modifier table and how to use it:
- All resource income modifiers affect the # per minute value.
- By default all resource income modifiers are set to 1 (value = 1, math_type = MUT_Multiplication). As you know, anything * 1 is the same value.
- MUT_Multiplication multiplies the income rate and MUT_Addition adds to it. Here are some examples of that:
- Let's say manpower income is 294 manpower per minute. With value = 10, math_type = MUT_Multiplication we will get 2940 manpower per minute,
since 294 * 10 = 2940.
Let's say manpower income is still 294 manpower per minute. With value = 10, math_type = MUT_Addition, we will get 304 manpower per minute,
since 294 + 10 = 304.

- How to add 50 extra munition income?
{type = RT_Munition, value = 50, math_type = MUT_Addition}

- How to remove 100 from manpower income?
{type = RT_Manpower, value = -100, math_type = MUT_Addition}

- How to double manpower income?
{type = RT_Manpower, value = 2, math_type = MUT_Multiplication}
]]

local ResourceSets = {
standard = {
--german:
[0] = {
manpower = 490,
fuel = 20,
munition = 0,
action = 0,
command = 1,
},
--soviet:
[1] = {
manpower = 490,
fuel = 50,
munition = 0,
action = 0,
command = 1,

},
--Obercommando west:
[2] = {
manpower = 240,
fuel = 40,
munition = 0,
action = 0,
command = 1,
},
--us forces:
[3] = {
manpower = 400,
fuel = 15,
munition = 0,
action = 0,
command = 1,
},
income_modifier = {
{type = RT_Manpower, value = 1, math_type = MUT_Multiplication}, -- manpower. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Munition, value = 1, math_type = MUT_Multiplication}, -- munition. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Fuel, value = 1, math_type = MUT_Multiplication}, -- fuel. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Action, value = 1, math_type = MUT_Multiplication}, -- action/xp. math_type = MUT_Multiplication OR MUT_Addition
},
},
highResources = {
--german:
[0] = {
manpower = 1390,
fuel = 50,
munition = 50,
action = 0,
command = 2,
},
--soviet:
[1] = {
manpower = 1390,
fuel = 80,
munition = 50,
action = 0,
command = 2,
},
--Obercommando west:
[2] = {
manpower = 1140,
fuel = 70,
munition = 50,
action = 0,
command = 2,
},
--us forces:
[3] = {
manpower = 1300,
fuel = 45,
munition = 50,
action = 0,
command = 2,
},
income_modifier = {
{type = RT_Manpower, value = 1, math_type = MUT_Multiplication}, -- manpower. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Munition, value = 1, math_type = MUT_Multiplication}, -- munition. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Fuel, value = 1, math_type = MUT_Multiplication}, -- fuel. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Action, value = 1, math_type = MUT_Multiplication}, -- action/xp. math_type = MUT_Multiplication OR MUT_Addition
},
},
customSet_01 = {
--german:
[0] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
--soviet:
[1] = {
manpower = 2000,
fuel = 100,
munition = 100,
action = 0,
command = 2,
},
--Obercommando west:
[2] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
--us forces:
[3] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
income_modifier = {
{type = RT_Manpower, value = 1, math_type = MUT_Multiplication}, -- manpower. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Munition, value = 1, math_type = MUT_Multiplication}, -- munition. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Fuel, value = 1, math_type = MUT_Multiplication}, -- fuel. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Action, value = 1, math_type = MUT_Multiplication}, -- action/xp. math_type = MUT_Multiplication OR MUT_Addition
},
},
customSet_02 = {
--german:
[0] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
--soviet:
[1] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
--Obercommando west:
[2] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
--us forces:
[3] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
income_modifier = {
{type = RT_Manpower, value = 1, math_type = MUT_Multiplication}, -- manpower. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Munition, value = 1, math_type = MUT_Multiplication}, -- munition. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Fuel, value = 1, math_type = MUT_Multiplication}, -- fuel. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Action, value = 1, math_type = MUT_Multiplication}, -- action/xp. math_type = MUT_Multiplication OR MUT_Addition
},
},
}
--This will set the resource set to use in-game
local g_ResourceSet = ResourceSets.customSet_01

local Player_ApplyResourceSet = function(player, resourceSet)
Player_SetResource(player, RT_Manpower, resourceSet.manpower)
Player_SetResource(player, RT_Fuel, resourceSet.fuel)
Player_SetResource(player, RT_Munition, resourceSet.munition)
Player_SetResource(player, RT_Action, resourceSet.action)
Player_SetResource(player, RT_Command, resourceSet.command)
end
--Population cap override value
g_popCapOverride = 200

for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
local resource_set = g_ResourceSet[Player_GetRaceIndex(player)]
Player_ApplyResourceSet(player, resource_set)
Player_SetPopCapOverride(player, g_popCapOverride)
for key, resource in ipairs(g_ResourceSet.income_modifier) do
local _value = resource.value
if resource.math_type == MUT_Addition then
_value = _value / (60 * 8)
end
Modify_PlayerResourceRate(player, resource.type, _value, resource.math_type)
end
end
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

Scar_AddInit(CustomStartingResources_Init)



Testing the results



Save the <mapname>.scar and close the file. Goto WorldBuilder and do File -> Export Package, run the game, start a match with your map. You should now be able to see custom starting resources. This example uses a pre-made set called ResourceSets.customSet_01, which sets the following:

Code

customSet_01 = {
--german:
[0] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
--soviet:
[1] = {
manpower = 2000,
fuel = 100,
munition = 100,
action = 0,
command = 2,
},
--Obercommando west:
[2] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
--us forces:
[3] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
income_modifier = {
{type = RT_Manpower, value = 1, math_type = MUT_Multiplication}, -- manpower. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Munition, value = 1, math_type = MUT_Multiplication}, -- munition. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Fuel, value = 1, math_type = MUT_Multiplication}, -- fuel. math_type = MUT_Multiplication OR MUT_Addition
{type = RT_Action, value = 1, math_type = MUT_Multiplication}, -- action/xp. math_type = MUT_Multiplication OR MUT_Addition
},



Configuring the code to match your needs



This example comes with four pre-made resource sets, which are called standard, highResources, customSet_01, and customSet_02. First 2 are just copies of the already existing ones and the two customSets are there for customization.

To change which set to use, simply change g_ResourceSet to match the desired resource set, e.g.
Code

local g_ResourceSet = ResourceSets.customSet_02


You can edit any of the resource pre-sets by editing the values. They should be quite self-explanatory, but here they are:

manpower = Manpower resource value
fuel = Fuel resource value
munition = Munition resource value
action = xp amount. e.g. ~1024 action = ~1 command point
command = number of command points
income_modifier = table of income modifiers. By default all income modifiers are * 1 (no effect)
See the information in the top of the script file for configuring income modifiers.

After doing the necessary changes Hit save, Export package, run your map and voilà!

Conclusions


In this tutorial you learned how to set custom starting resources for your map. I tried to spend some time to explain stuff a bit more briefly instead of making this tutorial as humanly short as possible. Hopefully this will give you a better understanding of what you did instead of just adding the code to a file and getting results without knowing why. If you have any additional questions, feed back, or suggestions for future tutorials, please let me know in this thread!


4 Jan 2014, 22:24 PM
#2
avatar of BlackIce

Posts: 7

Thanks for the info. Very helpful.

I don't suppose it's possible to alter the min and max camera height for an individual map is it?
4 Jan 2014, 22:54 PM
#3
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

Camera settings are defined in a file which is unaccessible at the moment.
19 Feb 2014, 07:32 AM
#4
avatar of a459696649

Posts: 20

How to set the growth rate? 490 +200 such as human resources, how to set behind the "+" sign value?
19 Feb 2014, 08:19 AM
#5
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

Code

Modify_PlayerResourceRate(playerId, resourceType, scalefactor)
e.g.
Modify_PlayerResourceRate(World_GetPlayerAt(1), RT_Manpower, 2) --doubles it
20 Feb 2014, 00:47 AM
#6
avatar of a459696649

Posts: 20

Thank you....I try it.
21 Feb 2014, 15:36 PM
#7
avatar of akosi

Posts: 1734

Permanently Banned
in school we are using Notepad++ for making webpages lel.
21 Feb 2014, 18:53 PM
#8
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

I was surprised for finding Notepad++ from university desktops. I guess it's unbeatable for vast amount of supported code languages and free cost.
I use it for all kind coding environments not having a built-in IDE. (e.g. Visual C# has IDE).
24 Jun 2014, 20:54 PM
#9
avatar of RivetrPlate12

Posts: 4

This works fine but now with western Front armies , There are new "homeland" could you do with the Oberkommando and U.S.?
I can not seem to get it!
24 Jun 2014, 21:47 PM
#10
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

Updated to support Western Front factions.
25 Jun 2014, 00:17 AM
#11
avatar of RivetrPlate12

Posts: 4

As my English is bad enough, I can not write out the lines
I want to know or do you replace it for resources numbers of departures exactly. I succeeded once but it was a fluke now when I launch the game it crashes
A (big) helping hand would be welcome
it does not work
WordBuilder in the west is called Oberkommando west_german and us forces is called aef, you do not replace it rather than those it marked?
Have not you made ​​a mistake on the first line because you deleted "function OnInitID ()"?
25 Jun 2014, 15:09 PM
#12
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

The codes in this tutorial have been updated. Use them instead, or replace your old code with the new samples.
11 Jul 2014, 22:29 PM
#13
avatar of Majorkill93

Posts: 2

This thread has been super helpful and thank you for it greatly! However, I am having issues with setting the resource rates. I have set the starting resources, but I am not too exactly sure where to place the "Modify_PlayerResourceRate(World_GetPlayerAt(1), RT_Manpower, 2)" or if I have to do it for each player (looking at the get player at 1 part). Would love some clarification! Also, do bots use these same settings or is it simply for actual players? Not sure if bot build order is changed with increased resources. Thank you very much!
11 Jul 2014, 23:27 PM
#14
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

It applies to all players, whether or not they are bots or humans. I'll add resource rate settings to this tutorial as well.
12 Jul 2014, 11:24 AM
#15
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

Updated with income modifiers!
12 Jul 2014, 16:54 PM
#16
avatar of Majorkill93

Posts: 2

Thank you very much! Your tutorials are a life saver for beginner map makers such as myself. Keep up the great work! :D
24 Jul 2014, 17:55 PM
#17
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

Updated with a fix to work with the recent changes.

function Player_GetRace no longer returns the race index and thus can't be used for indexing a lua table.

The workaround (see first post for full code):
Code

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


25 Jul 2014, 18:07 PM
#18
avatar of Orbifold

Posts: 13

Permanently Banned
25 Jul 2014, 22:02 PM
#19
avatar of CaribbeanCLANK

Posts: 2

I have tried this several times with no luck. Simply not working for me.
25 Jul 2014, 22:43 PM
#20
avatar of Janne252
Admin Black Badge
Patrion 15

Posts: 3421 | Subs: 11

It would help if you could explain a bit more briefly what you have tried and what kind of problems you have encountered.
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

1067 users are online: 1067 guests
1 post in the last 24h
10 posts in the last week
27 posts in the last month
Registered members: 50004
Welcome our newest member, Abtik Services
Most online: 2043 users on 29 Oct 2023, 01:04 AM