[R&F] How to Find "Visiting Tourists"?

ReggieB

Chieftain
Joined
Mar 28, 2018
Messages
36
Hi all, I have a quick question for a mod I'm working on. The goal of the mod is to add a civ's visiting tourists to their overall score. The problem is, I'm not sure what "visiting tourists" are called in the game code. I'm working in the "scoring.xml" file, and for example, here is the code that adds your civics to your total score:
Code:
<Row LineItemType="LINE_ITEM_CIVICS" Name="LOC_LINE_ITEM_CIVICS_NAME" Category="CATEGORY_CIVICS" Multiplier="2" ScaleByCost="true" Civics="true" TieBreakerPriority="100"/>
Specifically, the line Civics="true" is what finds the civ's total civics and adds that to the equation.

My question is, what is the equivalent for "visiting tourists"? I've tried a few variations like "tourists" and "tourism", but I can't seem to find what the game actually calls visiting tourists in the code. Can anyone tell me the specific wording I'm looking for? Thanks!
 
These are features already coded in the game, you cant add anything here. Civics is the field in the database that has some internal code associated with it. You can only „score” what is coded by devs and enabled by those fields.
And afaik, you can’t change score via Lua because then you could do it via a script.
 
These are features already coded in the game, you cant add anything here. Civics is the field in the database that has some internal code associated with it. You can only „score” what is coded by devs and enabled by those fields.
And afaik, you can’t change score via Lua because then you could do it via a script.

Are you saying there's no way to change the scoring system other than changing the multipliers? That can't be right, because there is already an Alternate Score Victory mod created by Sedjik that adjusts scores based on city districts. After a bit of digging, it looks like the code for that goes something like this:

Code:
-- Set score per district = pop. required per district
UPDATE ScoringLineItems
SET Multiplier = (SELECT Value FROM GlobalParameters WHERE Name = 'DISTRICT_POPULATION_REQUIRED_PER')
WHERE LineItemType = 'LINE_ITEM_DISTRICTS';

So if I just knew how to base something similar on visiting tourists, it should be doable. I just need to know how to ask for that number from the game.
 
That is exaclty what I am saying.
The example you quoted doesn’t introduce any new scoring type, it just sets a different number for a „score per district”. Look into the entire line and you will see that it has one of columns set as active, probably named „districts” or a like.
 
That is exaclty what I am saying.
The example you quoted doesn’t introduce any new scoring type, it just sets a different number for a „score per district”. Look into the entire line and you will see that it has one of columns set as active, probably named „districts” or a like.

That's not the only example though, here is another where the religion score is updated to be a function of the number of followers:

Code:
-- Update player's fake religion score to the number of followers of the
-- player's founded religion.
function ScoreReligionFollowers(player:table)
    local pStats:table = player:GetStats();
    if (pStats ~= nil) then
        local pReligion:table = player:GetReligion();
        if (pReligion ~= nil) then
            local iFollowers = pStats:GetNumFollowers();
            -- print("Player has religion with "..iFollowers.." followers");
            player:SetScoringScenario1(iFollowers);
        end
    end
end

Code:
INSERT INTO Types (Type, Kind) VALUES
('ASV_LINE_ITEM_RELIGION', 'KIND_SCORING_LINE_ITEM');

INSERT INTO ScoringLineItems (LineItemType, Name, Category, Multiplier, ScoringScenario1, ScoringScenario2, ScoringScenario3, TieBreakerPriority) VALUES
('ASV_LINE_ITEM_RELIGION', 'LOC_LINE_ITEM_RELIGION_NAME', 'CATEGORY_SCENARIO1', 1, 1, 0, 0, 50);

It may not technically be a "new scoring type", but that seems like splitting hairs. It definitely does change the scoring system to be a function of something other than the original scoring metrics. And if that can be done, then I can't see any reason why you couldn't use visiting tourists. For all I know it might be as simple as changing "local pReligion:table = player:GetReligion();" to "local pTourists" or something, but that is what I need help with.

Set aside the question of how to integrate the number of tourists into the score; how would you normally find the number of visiting tourists for any mod in general?
 
After a bit more digging, I came across this function, which seems to get the number of visiting tourists.
Code:
Player:GetCulture():GetTouristsTo()
Unfortunately I still can't get it working. Perhaps the GetTouristsTo() function has to be run for each other player in the game? Or maybe it is a table, and I need another function to get a specific number out of that table? I'm pretty new to the modding scene, so I'd appreciate any advice you can offer.
 
It's only valid in UI context.

You need to define the player object 1st before you can use the :GetCulture() method or any of its "child" functions.

Just stating Player:GetCulture() will return a nil value error if you have not first defined what "Player" is such as
Code:
local Player = Players[PlayerID]
local NumberTouristsToUs = Player:GetCulture():GetTouristsTo()
From reading the only UI file where Player:GetCulture():GetTouristsTo() is used, "NumberTouristsToUs" would recieve an integer value.
 
Last edited:
It's only valid in UI context.

You need to define the player object 1st before you can use the :GetCulture() method or any of its "child" functions.

Just stating Player:GetCulture() will return a nil value error if you have not first defined what "Player" is such as
Code:
local Player = Players[PlayerID]
local NumberTouristsToUs = Player:GetCulture():GetTouristsTo()
From reading the only UI file where Player:GetCulture():GetTouristsTo() is used, "NumberTouristsToUs" would recieve an integer value.

Unfortunately that doesn't seem to work either. As a comparison, I tried:

Code:
local Player = Players[PlayerID]
local pCulture = player:GetCulture():GetCultureYield();
player:SetScoringScenario1(pCulture);

And that does correctly add each player's culture yield to their overall score. However, when I try it with GetTouristsTo() instead of GetCultureYield(), the game doesn't seem to return a value and the score isn't updated. Is there any reason why GetTouristsTo() would behave differently than GetCultureYield()?
 
Are you running the lua code from an AddGameplayScripts action ?

Certain lua functions are only available in either an AddGameplayScripts action or in a UI Context, but not both. There are actually far more funcitons that are available in UI Context, but almost all of them are "Get" or "Is" type functions rather than "Set" or "Change" functions.
 
Are you running the lua code from an AddGameplayScripts action ?

Certain lua functions are only available in either an AddGameplayScripts action or in a UI Context, but not both. There are actually far more funcitons that are available in UI Context, but almost all of them are "Get" or "Is" type functions rather than "Set" or "Change" functions.

I believe it is a gameplay script and not a UI function. So it sounds like the GetTouristsTo() function might only work for changing part of the UI, but not for changing game play elements? That's unfortunate, but do you think a workaround might be available? For example, maybe a gameplay script can't get tourism, but maybe a UI script can get tourism and then update the score accordingly? Or is it unlikely that a UI script would be able to change the players' score? Or maybe there is some different function for a gameplay script to find tourism?
 
Top Bottom