[R&F] Is there a way to make a LUA function trigger on Modifiers/RequirementSet?

TheLunarArmy

Chieftain
Joined
Jul 9, 2014
Messages
59
Location
South-Africa
Hi all,

I'm busy making a civ with a UA that levels up a non-constructable building based on the number of flavoured quests the player achieves. I've written the lua code for the level of the building and it works as intended, and it basically needs to call a LevelUp() function whenever the player achieves a quest. Now I need to go about writing the triggers which will call LevelUp(), and traditionally I would need to write testing conditions in a function and subscribe it to a corresponding Game Events. Problem is I might want to change some quests if I deem them too easy or hard after some testing, so I was wondering if there was a away to make use of RequirementSets that causes certain logic checks to occur for Modifiers, to fire this lua function. For example I might want to call LevelUp() when the player researches the Apprenticeship Tech; which can be achieved using:

Code:
INSERT INTO Requirements
       (RequirementId,                                   RequirementType)
VALUES   ('REQUIRES_PLAYER_HAS_APPRENTICESHIP_TECH',       'REQUIREMENT_PLAYER_HAS_TECHNOLOGY');

INSERT INTO RequirementArguments
       (RequirementId,                                   Name,               Value)
VALUES   ('REQUIRES_PLAYER_HAS_APPRENTICESHIP_TECH',       'TechnologyType',   'TECH_APPRENTICESHIP' );

INSERT INTO RequirementSets
       (RequirementSetId,                                   RequirementSetType)
VALUES   ('PLAYER_HAS_APPRENTICESHIP_TECH_REQUIREMENTS',       'REQUIREMENTSET_TEST_ALL' );

INSERT INTO RequirementSetRequirements
       (RequirementSetId, RequirementId)
VALUES   ('PLAYER_HAS_APPRENTICESHIP_TECH_REQUIREMENTS',       'REQUIRES_PLAYER_HAS_APPRENTICESHIP_TECH' );

Is this possible? I'm still very green when it comes to Civ 6 events.
 
You have Lua Events for that, there is an event called when a tech or civic is researched.
It is unrelated to modifiers.

Yes I understand, the tech was just an example. I was curious if it was possible to use Modifiers as event triggers. So for example at the start of each turn check to see if some set is true and then fire a function. I am trying to avoid subscribing to 10 different Lua events for 10 different quests.
 
In Firetuner you can open Requirements.ltp and find some useful code snippets in there.
Holy cow that is useful, thanks for the resource.
(Pro Tip: for fellow newbies, once opened, rigth click on a field and click "edit", glorious code!)
 
Yes I understand, the tech was just an example. I was curious if it was possible to use Modifiers as event triggers. So for example at the start of each turn check to see if some set is true and then fire a function. I am trying to avoid subscribing to 10 different Lua events for 10 different quests.
I am not aware of any such functions / events. All Lua functions related to modifiers and requirements are typical read-only stuff afaik.
 
I am not aware of any such functions / events. All Lua functions related to modifiers and requirements are typical read-only stuff afaik.

Darn, oh well I'll try and figure out a better way. Thanks for the input.
 
I think the Lua functions for the requirements return whether a certain requirement has been met or not. So they just return informations, but this can still be useful, if you put this informations in a if-check in your code.
Of course triggering Lua functions should be done using Events. You might already know of Gedemon's spreadsheet that show you lots of events:
https://docs.google.com/spreadsheet...mun4qAHj6SsOVfa1vGTbk5mVvs/edit#gid=742065491.
E.g. you can use Events.ResearchCompleted to trigger a function, when a player has researched something.
 
Even if there aren't events specifically tied to a RequirementSet if you can access the same read-only values available in FireTuner you could trigger them off other events like end of turn, etc. Most of the RequirementSets are only updated at the end of every turn or so anyway in real logistical terms.
 
Top Bottom