Fandom

Supreme Commander Wiki

Script: Spawn resource matrices at spawn points

734pages on
this wiki
Add New Page
Talk0 Share

Purpose: For the resource-happy, map creator or modifier, who likes to have large fields of mass and hydrocarbon, but doesn't like the manual labour of placing all the markers. And for demonstration purposes as well.


Script Edit

   -- Resoure Matrix script (c) Micdah
   local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
   
   -- ResourceType
   -- defines which resource types are available, and the settings for each
   local ResourceType = {
   	Mass = {
   		UID = 0,
   		typeName = "Mass",
   		sizeX = 2,
   		sizeZ = 2,
   		size = 1.00,
   		albedo = "/env/common/splats/mass_marker.dds",
   		prop = "/env/common/props/massDeposit01_prop.bp",
   		lod = 100,
   	},
   	Hydrocarbon = {
   		UID = 2,
   		typeName = "Hydrocarbon",
   		sizeX = 6,
   		sizeZ = 6,
   		size = 3.00,
   		albedo = "/env/common/splats/hydrocarbon_marker.dds",
   		prop = "/env/common/props/hydrocarbonDeposit01_prop.bp",
   		lod = 200,
   	},
   }
   
   -- Create a single resource marker at given coordinates
   -- @param (ResourceType)mType,	Which resource to use
   -- @param (float)x,			X-coordinate for marker
   -- @param (float)y,			Y-coordinate for marker
   -- @param (float)z,			Z-coordinate for marker
   -- @return null				No return
   local function CreateResource(mType,x,y,z)
   	-- Create Resource
   	CreateResourceDeposit(mType.typeName, x, y, z, mType.size);
   	
   	-- Create resource graphic on map
   	CreatePropHPR(mType.prop, x, y, z, Random(0,360), 0, 0);
   	
   	-- Create resource icon on map
   	CreateSplat(VECTOR3(x, y, z), 0, mType.albedo, mType.sizeX, mType.sizeZ, mType.lod, 0, -1, 0);
   end
   
   -- Create a resource matrix
   -- @param (float)startX, 		X coordinate for top-left corner of matrix
   -- @param (float)y, 			Y coordinate for the matrix (all markers are placed in the same z-level)
   -- @param (float)startZ, 		Z coordinate for top-left corner of matrix
   -- @param (float)spaceX, 		Spacing between markers along the x-axis, for perfect alignment use ResourceType.Type.sizeX
   -- @param (float)spaceZ,		Spacing between markers along the z-axis, for perfect alignment use ResourceType.Type.sizeZ
   -- @param (int)rows,			Number of rows in matrix
   -- @param (int)columns,			Number of columns in matrix
   -- @param (ResourceType)mType,	Which resource to use in matrix
   -- @return null				No return
   local function CreateResourceMatrix(mType, startX, y, startZ, spaceX, spaceZ, rows, columns)
   	local tmpX = 0.00;
   	local tmpZ = 0.00;
   	local row, column;
   	
   	for row=0, (rows-1), 1 do
   		for column=0, (columns-1), 1 do
   			tmpX = startX + (column * spaceX);
   			tmpZ = startZ + (row * spaceZ);
   			
   			--- Create resource
   			CreateResource(mType, tmpX, y, tmpZ);
   		end
   	end
   end
   
   -- Get army position
   -- @param (string)mName,	Name of army, ex. ARMY_1
   -- @return {x,y,z},			Returns object with x,y,z coordinates		
   local function GetArmyPosition(mName)
   	return {
   		x = Scenario.MasterChain['_MASTERCHAIN_'].Markers[mName]['position'][1],
   		y = Scenario.MasterChain['_MASTERCHAIN_'].Markers[mName]['position'][2],
   		z = Scenario.MasterChain['_MASTERCHAIN_'].Markers[mName]['position'][3],
   	}
   end
   
   function OnPopulate()
   	ScenarioUtils.InitializeArmies()
   end
   
   function OnStart(self)
   	-- Create mass resource matrixes for each player
   	-- CreateResourceMatrix(ResourceType.Mass, 55.50, 64.00, 55.50, 2.00, 2.00, 4, 5);
   	local rows = 4;
   	local columns = 5;
   	local army, p;
   	local p = {
   		army1 = GetArmyPosition('ARMY_1'),
   		army2 = GetArmyPosition('ARMY_2'),
   		army3 = GetArmyPosition('ARMY_3'),
   		army4 = GetArmyPosition('ARMY_4'),
   	}
   	
   	CreateResourceMatrix(ResourceType.Mass, p.army1.x, p.army1.y, p.army1.z, 2.00, 2.00, rows, columns);
   	CreateResourceMatrix(ResourceType.Mass, p.army2.x, p.army2.y, p.army2.z, 2.00, 2.00, rows, columns);
   	CreateResourceMatrix(ResourceType.Mass, p.army3.x, p.army3.y, p.army3.z, 2.00, 2.00, rows, columns);
   	CreateResourceMatrix(ResourceType.Mass, p.army4.x, p.army4.y, p.army4.z, 2.00, 2.00, rows, columns);
   end

How to use Edit

  • Create the map, and at least place markers for each army
  • Save the map, and exit whichever map editor you use
  • If not already created, create mapname_script.lua, and open it in your favorite script editor (Notepad++)
  • Insert the script
    • If you have more or less armies than the four, in this example, remember to update the code in OnStat(self)
   function OnStart(self)
   	-- Create mass resource matrixes for each player
   	-- CreateResourceMatrix(ResourceType.Mass, 55.50, 64.00, 55.50, 2.00, 2.00, 4, 5);
   	local rows = 4;
   	local columns = 5;
   	local army, p;
   	local p = {
   		army1 = GetArmyPosition('ARMY_1'),
   		army2 = GetArmyPosition('ARMY_2'),
   		army3 = GetArmyPosition('ARMY_3'),
   		army4 = GetArmyPosition('ARMY_4'),
   	}
   	
   	CreateResourceMatrix(ResourceType.Mass, p.army1.x, p.army1.y, p.army1.z, 2.00, 2.00, rows, columns);
   	CreateResourceMatrix(ResourceType.Mass, p.army2.x, p.army2.y, p.army2.z, 2.00, 2.00, rows, columns);
   	CreateResourceMatrix(ResourceType.Mass, p.army3.x, p.army3.y, p.army3.z, 2.00, 2.00, rows, columns);
   	CreateResourceMatrix(ResourceType.Mass, p.army4.x, p.army4.y, p.army4.z, 2.00, 2.00, rows, columns);
   end
  • Save the file, and you are ready to play.

Documentation Edit

Documentation for costum functions and variables in this script

Object: ResourceType Edit

Object containing settings for each resource type available. This is used when calling CreateResource and CreateResourceMatrix, for defining which resource type to create.

Function: CreateResource() Edit

Parameter Type Description
mType ResourceType Which resoure to insert
x float X-Coordinate for marker
y float Y-Coordinate for marker
z float Z-Coordinate for marker

Inserts a single resource marker of the given type, on the coordinates given.

Example:

   -- Insert Hydrocarbon marker at {x,y,z} = {55.50, 64.00, 55.50}
   CreateResource(ResourceType.Hydrocarbon, 55.50, 64.00, 55.50)

This function has no return value.

Function: CreateResourceMatrix() Edit

Parameter Type Description
startX float X-Coordinate for the top-left corner of the matrix
y float Y-Coordinate for the matrix, all markers y-level
startZ float Z-Coordinate for the top-left corner of the matrix
spaceX float Spacing between markers along the x-axis, for perfect alignment use ResourceType.Type.sizeX
spaceZ float Spacing between markers along the z-axis, for perfect alignment use ResourceType.Type.sizeZ
rows int Number of rows in the matrix
columns int Number of columns in the matrix
mType ResourceType Which resource to use in the matrix

Inserts a matrix of the given type of resource, in the size given, on the coordinates given.

Example:

   -- Insert a 2x4 matrix of Mass on {x,y,z} = {55.50, 64.00, 55.50}.
   CreateResourceMatrix(
       ResourceType.Mass,
       55.50,
       64.00,
       55.50,
       ResourceType.Mass.sizeX,
       ResourceType.Mass.sizeZ,
       2,4,
   );

This function has no return value

Function: GetArmyPosition() Edit

Parameter Type Description
mName string Name of the marker that identifies the army

Retrieves the position information of the given army, from the Scenario variable. Is used for positioning the mass marker matricies at the spawn points for each army in the script example. This function isn't bound to only retrieve army coordinates, any object with a position, defined in the _MASTERCHAIN_ can be retrieved using this function/code.

Returns and object {x,y,z}, containing the coordinates.

Example:

   -- Retrieves coordinates for the marker 'ARMY_1', and prints them to whomever is listening.
   local pos = GetArmyPosition('ARMY_1');
   print(pos.x, pos.y, pos.z)

 !Hack! Invisible to AI Edit

After testing this script in both Skirmish and Multiplayer, using different levels of AI (standard SupCom), I have discovered that the AI doesn't recognize mass markers inserted using this script. Possibly because they aren't registrered in the mapname_save.lua file, but are only created due to the mapname_script.lua.

I tested this script, together with normally inserted mass markers (thrue map editor / mapname_save.lua), and the AI only recognized and build upon the marks from the map editor/lua file, and not the ones inserted with the script.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.