building yield based on bonus hapiness

garatoi

Chieftain
Joined
Aug 18, 2021
Messages
2
Hi, i'm new to modding with sql, and I was wondering if it is possible to SET a yield with a variable that changes during the game ?
So let's say i want to change the Aztec's tlachtli to only a culture yield, based on bonus hapiness.
The only way i found related to a city bonus hapiness is with "LOC_HOF_GRAPH_CITY_POPULATION" (I'm not even sure this is really the city population of the building) and Entertainment.

My first thought was :

DELETE FROM Building_YieldChanges WHERE BuildingType='BUILDING_TLACHTLI' AND YieldType='YIELD_FAITH';
UPDATE Building_YieldChanges SET YieldChange=Entertainment-LOC_HOF_GRAPH_CITY_POPULATION//2 WHERE BuildingType='BUILDING_TLACHTLI';

I guess it doesn't work this way, and It should be more complicated. How would you do it ?
 
It cannot be done with any alteration to table Building_YieldChanges.

A modifier attached to BUILDING_TLACHTLI would be required, assuming there is even a type of modifier available to achieve this effect. I have not looked to see whether there is or is not.

Anything that begins with the text string "LOC_" is a text localization key, used to tell the game which tag to look up for the needed ingame text the user will see, based on the language they are running. So there is a "LOC_HOF_GRAPH_CITY_POPULATION" used when the player is running in the English language, and another for when the player is running the game using the French language, etc. You cannot access the contents of these text keys from the gameplay database.

You cannot jam a column-name from one game table into another game-table where it does not belong. Each game table has its own specific set of columns that are allowed for use within that table.

You can make your SQL code perform calculations when it adds or alters data within a game table, but once that calculation is executed as part of loading up the code from the base game, expansions, dlc, and mods, the content of the database is locked. It is never dynamic based on anything that happens during actual gameplay. So after all mods etc load info into the SQL database, if a field in the database has a value of "27" it will always have a value of "27" for the remainder of that game session. You can alter this value to "29" by saving the game, exiting the game, editing the SQL code to make it assign "29" instead of "27", and then reloading the saved game -- but the value in that particular field is never going to be altered by anything that happens once the game is in session.

Everything that gets shoved into the game's SQL database is just text. In and of itself it does nothing -- the effect all this info stored within the database has is executed by the game's source-level code, which reads the contents of the SQL database and creates in-game effects based on the contents found -- but the game's source code never alters what is in the gameplay database during actual gameplay.
 
Ok Thx for your answer,

I understood my sql code won't perform any calculation once the game has started. with what you said i was thinking of doing something like the japanese electronic factory, with a lot of requirements for each value of happiness :

INSERT OR IGNORE INTO Modifiers (ModifierId , ModifierType, SubjectRequirementSetId) VALUES
('TLACHTLI_CULTURE_MODIFIER' , 'MODIFIER_BUILDING_YIELD_CHANGE' , 'TLACHTLI_HAPPINESS_REQUIREMENTS');
INSERT OR IGNORE INTO ModifierArguments (ModifierId, Name, Value) VALUES
('TLACHTLI_CULTURE_MODIFIER', 'BuildingType', 'BUILDING_TLACHTLI'),
('TLACHTLI_CULTURE_MODIFIER', 'YieldType', 'YIELD_CULTURE'),
('TLACHTLI_CULTURE_MODIFIER', 'Amount', '1')

The big problem here is there isn't any RequiremenType that matches with what i want to do. I read in your guide that we cannot create RequirementTypes.


So I guess the only way would be a .lua script ?
I found this line in CitySupport.lua :

data.AmenitiesNetAmount = pCityGrowth:GetAmenities() - pCityGrowth:GetAmenitiesNeeded();

would it be possible to update the Tlachtli so that it matches the "data.AmenitiesNetAmount" in a lua script ? And how can i know in which file the function GetCityData( pCity:table ) is used to see how it is working ?
 
Last edited:
If I understand what you are asking, no.

An lua script cannot affect anything in the SQL database so it cannot alter or update a building to add more entertainment value to it. If it could do so, it would have the effect on every copy of the building in the game everywhere and for all players who had Building_X

An lua gameplay script can directly add a modifier that is already defined within the SQL database to a city or player, but it cannot then remove that same modifier.

Since the User Interface and Gameplay portions of the lua system are separated implementations, what one finds in a UI file's code will often not work in a gameplay script and vice versa. As a general rule, a User Interface script cannot directly make changes to the gameplay side of the game. User Interface scripts "see" the clicks the human player makes for builder build actions, city production choices, etc., and then that User Interface script sends a request to the game's operating engine to enact the effect of that choice. The game's operating engine (often referred to here on CFC as the "gamecore") is what actually makes the changes and effects that look like are being done by a User Interface script when playing the game. This is what is happening when you see commands like
Code:
UI.RequestAction(ActionTypes.ACTION_SOMETHING)
in a User Interface lua script.

Pretty much any lua file that is part of the base game or the expansions is a User Interface file, with the exception of the lua files found within the various folders for the scenarios that come with the game.
 
Top Bottom