Fandom

Supreme Commander Wiki

Script: Spawn resources according to players in game

734pages on
this wiki
Add New Page
Talk0 Share

Purpose: Resources tagged with the "SpawnWithArmy" code will only spawn when the specific player is in the game. Can be used with all other types of markers too, i guess.

Script:

   -- imports
   local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
   local ScenarioFramework = import('/lua/ScenarioFramework.lua')
   
   -- this function creates all mex and hydrocarbon markers
   -- resource scale script (c) Jotto, reworked by tecxx
   function ScenarioUtils.CreateResources()
   	-- fetch markers and iterate them
   	local markers = ScenarioUtils.GetMarkers();
   	for i, tblData in pairs(markers) do
   		-- spawn resources?
   		local doit = false;
   		if (tblData.resource and not tblData.SpawnWithArmy) then
   			-- standard resources, spawn it
   			doit = true;
   		elseif (tblData.resource and tblData.SpawnWithArmy) then
   			-- resources bound to player, check if army is presend
   			for j, army in ListArmies() do
   				if (tblData.SpawnWithArmy == army) then
   					doit = true;  -- we made sure the army is present, allow spawn
   					break;
   				end
   			end
   		end
   		
   		if (doit) then
   			-- check type of resource and set parameters
   			local bp, albedo, sx, sz, lod;
   			if tblData.type == "Mass" then
   				albedo = "/env/common/splats/mass_marker.dds";
   				bp = "/env/common/props/massDeposit01_prop.bp";
   				sx = 2;
   				sz = 2;
   				lod = 100;
   			else
   				albedo = "/env/common/splats/hydrocarbon_marker.dds";
   				bp = "/env/common/props/hydrocarbonDeposit01_prop.bp";
   				sx = 6;
   				sz = 6;
   				lod = 200;
   			end
   			-- create the resource
   			CreateResourceDeposit(tblData.type,	tblData.position[1], tblData.position[2], tblData.position[3], tblData.size);
   			-- create the resource graphic on the map
   			CreatePropHPR(bp, tblData.position[1], tblData.position[2], tblData.position[3], Random(0,360), 0, 0);
   			-- create the resource icon on the map
   			CreateSplat(
   				tblData.position,           # Position
   				0,                          # Heading (rotation)
   				albedo,                     # Texture name for albedo
   				sx, sz,                     # SizeX/Z
   				lod,                        # LOD
   				0,                          # Duration (0 == does not expire)
   				-1,                         # army (-1 == not owned by any single army)
   				0							# ???
   			);
   		end
   	end
   end
   
   function OnPopulate()
   	ScenarioUtils.InitializeArmies()
   	ScenarioFramework.SetPlayableArea('AREA_1', false)
   end
   
   function OnStart(self)
   
   end

HOW TO USE

  • create your map and place mex/hydrogen markers. for easier use i recommend to RENAME YOUR MARKERS (e.g. Mass1_1, Mass1_2, etc..)
  • save it, exit map editor
  • open mapname_save.lua in editor
  • search for your Mass1_1 entries and add the line
               ['SpawnWithArmy'] = STRING( 'ARMY_1' ),

so it looks like this:

          ['Mass1_1'] = {
               ['size'] = FLOAT( 1.000000 ),
               ['resource'] = BOOLEAN( true ),
               ['amount'] = FLOAT( 100.000000 ),
               ['color'] = STRING( 'ff808080' ),
               ['editorIcon'] = STRING( '/textures/editor/marker_mass.bmp' ),
               ['type'] = STRING( 'Mass' ),
               ['prop'] = STRING( '/env/common/props/markers/M_Mass_prop.bp' ),
               ['orientation'] = VECTOR3( 0, -0, 0 ),
               ['position'] = VECTOR3( 199.5, 25.5156, 189.5 ),
               ['SpawnWithArmy'] = STRING( 'ARMY_1' ),
           },
  • save the file, done!

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.