Advice for modding construction speed

jackgames

Warlord
Joined
Aug 10, 2013
Messages
115
Hello,
I'm thinking about the following: I'd like to increase workers construction speed on each era change. I thought of creating a new technology and use the WorkerSpeedModifier.

But 1st question: how to give this free tech each time a new era is reached ?

And how to make this technology not to appear in the technology tree ?

Finally, is this the right way to achieve my goal ?
 
But 1st question: how to give this free tech each time a new era is reached ?

You'll need to use Lua.

The GameEvents.TeamSetEra(teamId, eEra) event can be used to detect an era change.

(Don't forget that techs are owned by teams, not players)
 
Hmm... Thanks for quick reply. I've just thought in the meanwhile about using the Technology_ORPrereqTechs table to achieve this: what if I create my tech and then set in this table all techs that appear in first column in the tech tree, for each era ? Would this work ?
 
How stupid! This would give my free tech for each first column tech discovered in a given era!!!
Thank you whoward! But I don't know where my Lua code should be placed and, furthermore, I don't know how to listen to an event in Lua ?
 
This is some example code from a mod I am making that adds a dummy tech to major players on advancing to new eras.
  1. This defines the dummy techs in XML
    Spoiler XML Code :
    Code:
    <GameData>
    	<Technologies>
    		<Row>
    			<Type>TECH_LRSDUMMY_CLASSICAL</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_CLASSICAL_TITLE</Description>
    			<Era>ERA_CLASSICAL</Era>
    			<GridX>3</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>15</PortraitIndex>
    			<IconAtlas>TECH_ATLAS_1</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_CLASSICAL_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_CLASSICAL_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_CLASSICAL_QUOTE</Quote>
    		</Row>
    		<Row>
    			<Type>TECH_LRSDUMMY_MEDIEVAL</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_TITLE</Description>
    			<Era>ERA_MEDIEVAL</Era>
    			<GridX>5</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>21</PortraitIndex>
    			<IconAtlas>TECH_ATLAS_1</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_QUOTE</Quote>
    		</Row>
    		<Row>
    			<Type>TECH_LRSDUMMY_RENAISSANCE</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_TITLE</Description>
    			<Era>ERA_RENAISSANCE</Era>
    			<GridX>7</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>31</PortraitIndex>
    			<IconAtlas>TECH_ATLAS_1</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_QUOTE</Quote>
    		</Row>
    		<Row>
    			<Type>TECH_LRSDUMMY_INDUSTRIAL</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_TITLE</Description>
    			<Era>ERA_INDUSTRIAL</Era>
    			<GridX>9</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>5</PortraitIndex>
    			<IconAtlas>EXPANSION_TECH_ATLAS_1</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_QUOTE</Quote>
    		</Row>
    		<Row>
    			<Type>TECH_LRSDUMMY_MODERN</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_MODERN_TITLE</Description>
    			<Era>ERA_MODERN</Era>
    			<GridX>11</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>49</PortraitIndex>
    			<IconAtlas>TECH_ATLAS_1</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_MODERN_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_MODERN_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_MODERN_QUOTE</Quote>
    		</Row>
    		<Row>
    			<Type>TECH_LRSDUMMY_POSTMODERN</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_POSTMODERN_TITLE</Description>
    			<Era>ERA_POSTMODERN</Era>
    			<GridX>13</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>52</PortraitIndex>
    			<IconAtlas>TECH_ATLAS_1</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_POSTMODERN_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_POSTMODERN_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_POSTMODERN_QUOTE</Quote>
    		</Row>
    		<Row>
    			<Type>TECH_LRSDUMMY_FUTURE</Type>
    			<Cost>13500</Cost>
    			<Description>TXT_KEY_TECH_LRSDUMMY_FUTURE_TITLE</Description>
    			<Era>ERA_FUTURE</Era>
    			<GridX>15</GridX>
    			<GridY>12</GridY>
    			<PortraitIndex>0</PortraitIndex>
    			<IconAtlas>EXPANSION2_TECH_ATLAS</IconAtlas>
    			<Disable>true</Disable>
    			<Civilopedia>TXT_KEY_TECH_LRSDUMMY_FUTURE_DESC</Civilopedia>
    			<Help>TXT_KEY_TECH_LRSDUMMY_FUTURE_HELP</Help>
    			<Quote>TXT_KEY_TECH_LRSDUMMY_FUTURE_QUOTE</Quote>
    		</Row>
    	</Technologies>
    	<Language_en_US>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_CLASSICAL_TITLE">
    			<Text>Classical Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_CLASSICAL_DESC">
    			<Text>Signifies you have entered the Classical Era and unlocks:[COLOR_POSITIVE_TEXT]Cold Cellars, Odeons, Apothacaries, and Cablemakers[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_CLASSICAL_HELP">
    			<Text>Signifies you have entered the Classical Era and unlocks:[COLOR_POSITIVE_TEXT]Cold Cellars, Odeons, Apothacaries, and Cablemakers[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_CLASSICAL_QUOTE">
    			<Text>Toga! Toga! Toga![NEWLINE]-- John Belushi</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_TITLE">
    			<Text>Medieval Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_DESC">
    			<Text>Signifies you have entered the Medieval Era and unlocks:[COLOR_POSITIVE_TEXT]Tactical Schools, Seminaries, Farmer's Markets, Fairgrounds, Reliquaries, City Kilns, and Sailmakers[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_HELP">
    			<Text>Signifies you have entered the Medieval Era and unlocks:[COLOR_POSITIVE_TEXT]Tactical Schools, Seminaries, Farmer's Markets, Fairgrounds, Reliquaries, City Kilns, and Sailmakers[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MEDIEVAL_QUOTE">
    			<Text>[COLOR_POSITIVE_TEXT]Messenger[ENDCOLOR]: Sire! The peasants are revolting![NEWLINE][COLOR_POSITIVE_TEXT]King[ENDCOLOR]: Yes they are.</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_TITLE">
    			<Text>Renaissance Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_DESC">
    			<Text>Signifies you have entered the Renaissance Era and unlocks:[COLOR_POSITIVE_TEXT]Mandirs, Slaughtering Yards, Haberdasheries, Salons, Brickworks, and Shipyards[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_HELP">
    			<Text>Signifies you have entered the Renaissance Era and unlocks:[COLOR_POSITIVE_TEXT]Mandirs, Slaughtering Yards, Haberdasheries, Salons, Brickworks, and Shipyards[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_RENAISSANCE_QUOTE">
    			<Text>Let us all now be Renaissance Men.</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_TITLE">
    			<Text>Industrial Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_DESC">
    			<Text>Signifies you have entered the Industrial Era and unlocks:[COLOR_POSITIVE_TEXT]War Colleges, Synagogues, Packing Plants, Millineries, City Academies, Cement Factories, and Boilermakers[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_HELP">
    			<Text>Signifies you have entered the Industrial Era and unlocks:[COLOR_POSITIVE_TEXT]War Colleges, Synagogues, Packing Plants, Millineries, City Academies, Cement Factories, and Boilermakers[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_INDUSTRIAL_QUOTE">
    			<Text>Who needs Robber Barons? Much more fun and far easier to be an 'Industrialist'!</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MODERN_TITLE">
    			<Text>Modern Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MODERN_DESC">
    			<Text>Signifies you have entered the Modern Era and unlocks:[COLOR_POSITIVE_TEXT]Armored Warfare Schools, Churches, Refrigeration Facilities, Assembly Plants, HorseTracks, Tech Institutes, and DryDocks[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MODERN_HELP">
    			<Text>Signifies you have entered the Modern Era and unlocks:[COLOR_POSITIVE_TEXT]Armored Warfare Schools, Churches, Refrigeration Facilities, Assembly Plants, HorseTracks, Tech Institutes, and DryDocks[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_MODERN_QUOTE">
    			<Text>I am the very model of a Modern Major General. Really!</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_POSTMODERN_TITLE">
    			<Text>Atomic Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_POSTMODERN_DESC">
    			<Text>Signifies you have entered the Atomic Era and unlocks:[COLOR_POSITIVE_TEXT]Stupas, Hydroponics Plants, Automated Factories, TV Stations, and Research Facilities[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_POSTMODERN_HELP">
    			<Text>Signifies you have entered the Atomic Era and unlocks:[COLOR_POSITIVE_TEXT]Stupas, Hydroponics Plants, Automated Factories, TV Stations, and Research Facilities[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_POSTMODERN_QUOTE">
    			<Text>Ghandi! Are you happy to see me again, or is that just a boatload of Nuclear Missiles you have hidden there under your Sarong?</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_FUTURE_TITLE">
    			<Text>Information Era Dummy</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_FUTURE_DESC">
    			<Text>Signifies you have entered the Information Era and unlocks:[COLOR_POSITIVE_TEXT]Food Replicators, Intelligent Manufactories, VR Projectors, and Virtual Universities[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_FUTURE_HELP">
    			<Text>Signifies you have entered the Information Era and unlocks:[COLOR_POSITIVE_TEXT]Food Replicators, Intelligent Manufactories, VR Projectors, and Virtual Universities[ENDCOLOR]</Text>
    		</Row>
    		<Row Tag="TXT_KEY_TECH_LRSDUMMY_FUTURE_QUOTE">
    			<Text>Who knows what the future holds?</Text>
    		</Row>
    	</Language_en_US>
    </GameData>
  2. This is the lua I am using
    Spoiler LUA Code :

    1. I create an lua table to hold all my correspndances between era numbers and the dummy tech to be given
    2. When a player advances to a next era, I sort out which of the correspondances apply, and give that tech to that team
    3. For games where players play in teams it may or may not work correctly because of the line
      Code:
      if pTeam:IsBarbarian() or pTeam:IsMinorCiv() then return end
    4. These lines are in the code only to print some confirmation when the event runs, and for whom it is running, and can be eliminated:
      Code:
      	print("The Function AddTechsUponEraAdvance is running")
      	print("teamId = " .. teamId)
      	print("eEra = " .. eEra)
    5. The code could be simpified/optimized a bit, but I haven't got around to it yet.
    Code:
    DummyTechsList = {}
    DummyTechsList.gDummyTechClassical = GameInfoTypes.TECH_LRSDUMMY_CLASSICAL
    DummyTechsList.gDummyTechMedieval = GameInfoTypes.TECH_LRSDUMMY_MEDIEVAL
    DummyTechsList.gDummyTechRenaissance = GameInfoTypes.TECH_LRSDUMMY_RENAISSANCE
    DummyTechsList.gDummyTechIndustrial = GameInfoTypes.TECH_LRSDUMMY_INDUSTRIAL
    DummyTechsList.gDummyTechModern = GameInfoTypes.TECH_LRSDUMMY_MODERN
    DummyTechsList.gDummyTechPostModern = GameInfoTypes.TECH_LRSDUMMY_POSTMODERN
    DummyTechsList.gDummyTechFuture = GameInfoTypes.TECH_LRSDUMMY_FUTURE
    
    function AddTechsUponEraAdvance(teamId, eEra)
    	print("The Function AddTechsUponEraAdvance is running")
    	print("teamId = " .. teamId)
    	print("eEra = " .. eEra)
    	local pTeam = Teams[teamId]
    	if pTeam:IsBarbarian() or pTeam:IsMinorCiv() then return end
    	if not pTeam:IsAlive() then return end
    	local iTechToSet = "NONE"
    	if eEra == 1 then
    		iTechToSet = DummyTechsList.gDummyTechClassical
    	elseif eEra == 2 then
    		iTechToSet = DummyTechsList.gDummyTechMedieval
    	elseif eEra == 3 then
    		iTechToSet = DummyTechsList.gDummyTechRenaissance
    	elseif eEra == 4 then
    		iTechToSet = DummyTechsList.gDummyTechIndustrial
    	elseif eEra == 5 then
    		iTechToSet = DummyTechsList.gDummyTechModern
    	elseif eEra == 6 then
    		iTechToSet = DummyTechsList.gDummyTechPostModern
    	elseif eEra == 7 then
    		iTechToSet = DummyTechsList.gDummyTechFuture
    	end
    	if iTechToSet ~= "NONE" then
    		pTeam:SetHasTech(iTechToSet, true)
    	end
    end
    GameEvents.TeamSetEra.Add(AddTechsUponEraAdvance)
    You would need to set the lua file you place this code into as an InGameUIAddin in Modbuddy. See Post #3 of whoward69's what ModBuddy setting for what file types tutorial and you would want to do step #6 in those instructions before step #3.
  3. Feel free to use all or any part of it, but change all of the _LRSDUMMY_ to something else so there can be no clash possibility between the mods once I have mine completed.
    • Hint: close ModBuddy, navigate in your browser to the mod-project's location, then open and edit your files using a text editor and use a global "Find/Replace". Much easier than trying to edit stuff from inside ModBuddy.
 
OK. I've well understood your code that creates your AddTechsUponEraAdvance event. But what I'd like to see is the code that fires your event elsewhere in another lua file. Where do you place that code ? How to detect that a Civ has reached a new Era ? In other words, how and where do you tell the game "fire my event each time a Civ enters a new era" ?
 
You place the lua code in post #5 into an Something.lua file that you create within ModBuddy, and set the file's activation as directed in the tutorial to which I linked.

GameEvents.TeamSetEra() is pre-provided by Firaxis.

GameEvents.TeamSetEra() detects the advancement into another era. This event is used instead of one called, for example, GameEvents.PlayerSetEra(), because Firaxis does not actually track techs by player, they track them by Teams (ie, see post #2 of this thread). When multiple players are assigned to the same team, all those players advance in techs together, essentially. But other than when players are playing together in teams, Player #1 will belong to Team #1, Player #2 will belong to Team #2, etc. Unfortunately we have no control over what Firaxis decided to impliment via individual players, and what they decided to impliment via Teams.
 
OK! I didn't read well the last line: so you just have to add your new function to the TeamSetEra event. Simple indeed.
Thanks for help.
 
Top Bottom