Login

russian armor

How-to: Custom Starting Resources

27 Dec 2013, 23:02 PM
#1
avatar of Janne252
Admin Red  Badge

Posts: 1330

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

Important Note



One thing you should notice and understand before going any further:
Every time you save your map in WorldBuilder, yourMapname_ID.scar will be re-generated by the WorldBuilder. This means you have to add the code every time after saving the map if you wish to export the package. If you haven't saved your map yet, do it now!

Map Files



Have you ever looked into your map folder? Perhaps you have and you know there are bunch of files laying around related to your map. For example the yourMapname.sgb file, which is the main file containing all the data of your map. There are also other files, such as yourMapname.tga, yourMapname.info, yourMapname.options, and yourMapname_ID.scar.
The one we are interested in this tutorial is yourMapname_ID.scar.

yourMapname_ID.scar file



Well, what is this file in particular and why are we so interested about it?
yourMapname_ID.scar contains the list of Scar markers, entity groups aka. egroups, and squad groups aka. sgroups from your map. This file is sort of a directory of items listed above. This file also gives us the ability to include custom SCAR script to the map. In this tutorial we will use it for a very basic implementation.

Adding code to override default starting resources



Open yourMapname_ID.scar in notepad / notepad++. It should look something like this:
Code

function OnInitID()

-- [[ Markers ]]

-- [[ Squad Groups ]]

-- [[ Entity Groups ]]

end


Normally, when no Scar markers are placed nor squad/entity groups assigned (sgroups and egroups) yourMapname_ID.scar will look exactly like this. Let's get into adding the custom population cap code!

Add the following code below the line function OnInitID():
Code

local ResourceSets = {
standard = {
--soviet:
[0] = {
manpower = 490,
fuel = 50,
munition = 0,
action = 0,
command = 0,
},
--german:
[1] = {
manpower = 490,
fuel = 20,
munition = 0,
action = 0,
command = 0,
},
},
highResources = {
--soviet:
[0] = {
manpower = 1390,
fuel = 80,
munition = 50,
action = 0,
command = 1,
},
--german:
[1] = {
manpower = 1390,
fuel = 50,
munition = 50,
action = 0,
command = 1,
},
},
customSet_01 = {
--soviet:
[0] = {
manpower = 2000,
fuel = 100,
munition = 100,
action = 0,
command = 2,
},
--german:
[1] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
},
customSet_02 = {
--soviet:
[0] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
--german:
[1] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
},
}
--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

for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
Player_ApplyResourceSet(player, g_ResourceSet[Player_GetRace(player)])
end


The result should look something like this:
Code

function OnInitID()
local ResourceSets = {
standard = {
--soviet:
[0] = {
manpower = 490,
fuel = 50,
munition = 0,
action = 0,
command = 0,
},
--german:
[1] = {
manpower = 490,
fuel = 20,
munition = 0,
action = 0,
command = 0,
},
},
highResources = {
--soviet:
[0] = {
manpower = 1390,
fuel = 80,
munition = 50,
action = 0,
command = 1,
},
--german:
[1] = {
manpower = 1390,
fuel = 50,
munition = 50,
action = 0,
command = 1,
},
},
customSet_01 = {
--soviet:
[0] = {
manpower = 2000,
fuel = 100,
munition = 100,
action = 0,
command = 2,
},
--german:
[1] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
},
customSet_02 = {
--soviet:
[0] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
--german:
[1] = {
manpower = 0,
fuel = 0,
munition = 0,
action = 0,
command = 0,
},
},
}
--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

for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
Player_ApplyResourceSet(player, g_ResourceSet[Player_GetRace(player)])
end
-- [[ Markers ]]

-- [[ Squad Groups ]]

-- [[ Entity Groups ]]

end


Testing the results



Save the yourMapname_ID.scar and close the file. Goto WorldBuilder and DO NOT SAVE the map! You should have done that earlier. Just 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 = {
--soviet:
[0] = {
manpower = 2000,
fuel = 100,
munition = 100,
action = 0,
command = 2,
},
--german:
[1] = {
manpower = 2000,
fuel = 80,
munition = 100,
action = 0,
command = 2,
},
},


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

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: 1

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 Red  Badge

Posts: 1330

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 Red  Badge

Posts: 1330

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: 1252

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

Posts: 1330

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).
1 user is browsing this thread: 1 guest

Operations

SHOUT IT OUT!

No Profanity Number of Shouts
Refresh Shout Box
Napalm: Pro-tip for the Germans if you build two tigers and both hit mines at the same time feel free to quit. Feed the bears.
Today, 04:57 AM
Napalm: THE ANGRY BEARS declare another successful hunt.
Today, 04:56 AM
buckers: :( gym doesn't open for another hour and a half, what do
Today, 04:22 AM
@Brian: Bed calls for me, but added you on steam. We'll go again another night :)
Today, 04:21 AM
AmiPolizeiFunk: join coh2.org chat in game and we'll synch it up :P
Today, 04:19 AM
AmiPolizeiFunk: again?
Today, 04:19 AM
AmiPolizeiFunk: and we got stomped :P
Today, 04:19 AM
@Brian: I was searching when talking to you Ami and got a random 4v4 game. I guess Relic thought we were too op together. Added another Soviet notch to the belt. Krauts ran in fear.
Today, 04:11 AM
sluzbenik: Well you don't need more help then, I'm Ostheer!
Today, 03:38 AM
AmiPolizeiFunk: lol 77% soviet in 4v4 pool w00t
Today, 03:37 AM

Ladders Top 10

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

Replay highlight

VS
  • Soviets flag PwnageMachine
  • Ostheer flag Jesulin
uploaded by PwnageMachine

Board Info

66 users are online: 9 members and 57 guests
GuruSkippy, Rogers, RiflesReady, WiFiDi, kawagisi, utmost, madbull, StephennJF, slother
254 posts in the last 24h
2199 posts in the last week
11846 posts in the last month
Registered members: 6074
Welcome our newest member, thecarver131
Most online: 422 users on 27 Oct 2013, 01:02 AM