Culture per science on building

Starrynite120

Prince
Joined
Jul 15, 2015
Messages
472
I'm trying to make a building give 50% of your culture as science. This is easy to do with energy to science, but i can't figure it out with culture to science. Could anyone tell me how to do this? I know it's possible easily with a policy, but I want to make it with a building.
 
It is possible to fake it via lua. Hook into PlayerDoTurn, if they have the wonder get their culture rate and give them half it in science.
 
Yeah, and you can mimic the code from there too. It checks for a player having a specific dummy perk which is given when a player gets the policy. You can have the wonder give the perk.

Presumably a player wouldn't be able to have multiple instances of this building right? Otherwise you'll need a couple extra lines.
 
Would you mind taking a look at this code? I'm having trouble getting it to work, and I'm not very familiar with lua. I slightly edited your code from your virtues Mod to this:

function MantleAbility(playerID)
local player = Players[playerID];
local perk = GameInfo.PlayerPerks["PLAYERPERK_STARRYNITE_SCIENCE_FROM_CULTURE"].ID;

if(player:HasPerk(perk)) then
local bonus = math.floor(player:GetTotalCulturePerTurn() / 2);

if(bonus > 0) then
player:ChangeScience(bonus);

-- Send a notification to the player
local text = Locale.ConvertTextKey("TXT_KEY_STARRYNITE_SCIENCE_FROM_CULTURE_NOTIFICATION", tostring(bonus));
player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, text);
end
end
end
GameEvents.PlayerDoTurn.Add(MantleAbility);

Then for the xml I have is this (I don't think there's anything wrong here, but just in case)

<Buildings>
<Update>
<Set Help="Gain [ICON_RESEARCH] Science income equal to 50% of global [ICON_CULTURE] Culture income."
FreePlayerPerk="PLAYERPERK_STARRYNITE_SCIENCE_FROM_CULTURE"
EnergyMaintenance="0"/>
<Where BuildingClass="BUILDINGCLASS_MANTLE"/>
</Update>
</Buildings>

<PlayerPerks>
<Row>
<Type>PLAYERPERK_STARRYNITE_SCIENCE_FROM_CULTURE</Type>
<Help>Gain [ICON_RESEARCH] Science income equal to 50% of global [ICON_CULTURE] Culture income.</Help>
</Row>
</PlayerPerks>
 
I think it is:

player:GrantScience(bonus);

instead of:

player:ChangeScience(bonus);
----------------
The Help entries should be TXT_KEY_XXX combined with an additional row in the language table. You don't want to be putting your string directly in the perk or building table.

Code:
<GameData>
	<Language_en_US>
		<Row Tag="TXT_KEY_XXX">
			<Text>Gain [ICON_RESEARCH] Science income equal to 50% of global [ICON_CULTURE] Culture income.</Text>
		</Row>
	</Language_en_US>
</GameData>
 
That worked! Great. The only strange thing is the notification just says "TXT_KEY_STARRYNITE_SCIENCE_FROM_CULTURE_NOTIFICATION" instead of saying how much science I'm actually getting. How do I get the notification to display properly?

edit: Nevermind, I figured it out.
 
Did you add a row to Language_en_US for TXT_KEY_STARRYNITE_SCIENCE_FROM_CULTURE_NOTIFICATION? It should be something like:

+{@1_num}[ICON_RESEARCH] Science from Mantle.
 
Back
Top Bottom