Quick Modding Questions Thread

To a Player or a City, yes.

But the modifier cannot be un-attached by lua.

Code:
function AddModifierToPlayer(iPlayer, sModifierID, bDebugPrint)
	local function Dprint(sMessage)
		if bDebugPrint then print(sMessage) end
	end
	Dprint("function AddModifierToPlayer was executed with argument values of iPlayer = " .. tostring(iPlayer) .. ", sModifierID = " .. tostring(sModifierID) .. ", bDebugPrint = " .. tostring(bDebugPrint))
	local pPlayer = Players[iPlayer]
	if (pPlayer ~= nil) then
		Dprint("AddModifierToPlayer(" .. tostring(iPlayer) .. ", " .. tostring(sModifierID) .. ", " .. tostring(bDebugPrint) .. "): Proceeding with evaluating whether the player already has the modifier.")
		local PlayerProperty = pPlayer:GetProperty(sModifierID)
		Dprint("pPlayer:GetProperty(" .. sModifierID .. ") == " .. tostring(PlayerProperty))
		if (PlayerProperty == nil) then
			Dprint("Modifier " .. sModifierID .. " was seen as NOT being already attached to the player")
			pPlayer:AttachModifierByID(sModifierID)		
			pPlayer:SetProperty(sModifierID, 1)
			Dprint("Modifier " .. sModifierID .. " attached to the player")
		else
			Dprint("Modifier " .. sModifierID .. " was seen as being already attached to the player")
		end
	else
		Dprint("AddModifierToPlayer(" .. tostring(iPlayer) .. ", " .. tostring(sModifierID) .. ", " .. tostring(bDebugPrint) .. ") failed because the iPlayer value is not usable")
	end
end


     --     how to use the toolkit function
	AddModifierToPlayer(0, "FARMS_INCREASED_PRODUCTION_TRAIT_X", false)
Usable Toolkit function with an example of how to enact the function. In this case lua player # 0 (ie, the human player) would get the modifier called "FARMS_INCREASED_PRODUCTION_TRAIT_X" added to it. The modifier must first be defined in the normal way via either XML or SQL into the game's database. The text-string for the ModifierID must exactly match between that which is used in the Database and that which is used in the lua script.

The toolkit function also records whether or not the modifier has already been applied to that player by the toolkit function, and will not attempt a second application of the same modifier no matter how many times the same data is fed into the function by an lua script, or by saving and reloading a game.

The final argument for the toolkit function is a Boolean to turn ON/OFF printing into the lua log for debugging and confirmation purposes.

------------------------------------------------------------------------------

For units there is no direct way to attach a modifier to a unit, but we can (though I have not tested all of this as yet) attach and un-attach Unit Abilities which is a bit more complicated lua-codewise. Since UnitAbilities all have modifiers associated with them, altering the unit's "Unit Ability Count" for a given UnitAbility from "0" to "1", or vice versa would have the same net effect as adding and then later removing a modifier.
 
Hello,i have a Question about this Code:
<GameInfo>
<ModifierArguments>
<Row>
<ModifierId>TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS</ModifierId>
<Name>Amount</Name>
<Value>20,20,20,20,20,20</Value>
</Row>
</ModifierArguments>
</GameInfo>

Could I build this in Modbuddy and it would work?(as in ,the maya would have a 20 instead of a 10 percent boost to nearby cities?)
 
No, because the game already has a <Row> where <ModifierId> is TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS and <Name> is "Amount"

What would be needed is an <Update> to the existing Row
Code:
<GameInfo>
    <ModifierArguments>
         <Update>
              <Where ModifierId="TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS" Name="Amount" />
              <Set Value="20,20,20,20,20,20" />
         </Update>
    </ModifierArguments>
</GameInfo>
The update will only work however if your code loads after the expansions and the new DLC load. Otherwise there will be nothing to "Update" at the time your code executes.
 
No, because the game already has a <Row> where <ModifierId> is TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS and <Name> is "Amount"

What would be needed is an <Update> to the existing Row
Code:
<GameInfo>
    <ModifierArguments>
         <Update>
              <Where ModifierId="TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS" Name="Amount" />
              <Set Value="20,20,20,20,20,20" />
         </Update>
    </ModifierArguments>
</GameInfo>
The update will only work however if your code loads after the expansions and the new DLC load. Otherwise there will be nothing to "Update" at the time your code executes.
How do i make sure that it will load after the dlc?
 
Need to add a LoadOrder to the UpdateDatabase action in your modinfo. At least 200 or higher to be safe.
Code:
<Properties>
   <LoadOrder>200</LoadOrder>
</Properties>
It does not do anything :(
I have rewritten it in SQL in Modbuddy,DatabaseUpdate has a LoadOrder of >500.
Code:
UPDATE ModifierArguments SET Value=20 WHERE ModifierId='TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS';
 
Could the Problem be modbuddy itself?Maybe it hasnt updated or something?
 
I use LoadOrder 1 and it works fine, not sure why anything higher should be necessary
Sure, you can use a LoadOrder of anything >0 and probably still be fine. But, as I said, it's better/safer to have a higher LoadOrder just to ensure that your mod will load after all the FXS files. I mean having a high LoadOrder in the hundreds, thousands, or millions like YnAMP isn't going to hurt anything so why take the risk of having your mod overwritten, causing UC errors, or other issues. :rolleyes:
 
It does not do anything :(
I have rewritten it in SQL in Modbuddy,DatabaseUpdate has a LoadOrder of >500.
Code:
UPDATE ModifierArguments SET Value=20 WHERE ModifierId='TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS';
This is not going to work because there is more than one row in table ModifierArguments where ModifierId='TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS' and because you need to set multiple numerical values as one continuous text-string:
Code:
'20,20,20,20,20,20'
instead of
Code:
20
.

Code:
<GameInfo>
    <ModifierArguments>
         <Update>
              <Where ModifierId="TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS" Name="Amount" />
              <Set Value="20,20,20,20,20,20" />
         </Update>
    </ModifierArguments>
</GameInfo>
  1. There are two components to the "Where" clause. Moving the code into SQL does not eliminate the need for the two components to the "Where" clause.
  2. The "Value" argument is one long text-string, just as is the original code in the game-file
  3. The original relevant chunk of code from the game file
    Code:
    		<Row>
    			<ModifierId>TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS</ModifierId>
    			<Name>YieldType</Name>
    			<Value>YIELD_PRODUCTION, YIELD_FOOD, YIELD_SCIENCE, YIELD_CULTURE, YIELD_GOLD, YIELD_FAITH</Value>
    		</Row>
    		<Row>
    			<ModifierId>TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS</ModifierId>
    			<Name>Amount</Name>
    			<Value>10, 10, 10, 10, 10, 10</Value>
    		</Row>
  4. Two rows exist wherein ModifierId is "TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS" so the "Where" clause of any Update statement must contain condition matches to ensure only one row is affected.
  5. The "Value" setting in both rows have multiple data and so any update to either of these two rows needs to also contain multiple data.
In SQL the required update would be
Code:
UPDATE ModifierArguments SET Value = '20,20,20,20,20,20' WHERE ModifierId = 'TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS' AND Name = 'Amount' ;
In XML the "AND" is implied when more than one column-condition is specified in a "Where" clause, so you never have to type "AND" in an XML "Where" clause.
 
Last edited:
Firaxis has used LoadOrder values of '100' in some of the Scenarios so to be safe to ensure that mod code loads after anything by Firaxis we generally recommend a LoadOrder value of 200 or higher. This ensures the code loads after the Firaxis stuff but also gives some wiggle room for the future when/if Firaxis adds stuff with LoadOrder of around 100 for non-Scenario code. 500 is even better in terms of when code loads relative to Firaxis code as this will tend to make sure that your mod does not need an update just because of a LoadOrder issue later on.

The two expansions are currently using LoadOrder values of -100 (to load theoretically before anything else to create the new tables added by the expansions) and the default value of '0' for everything else.

When no LoadOrder value is assigned the game uses the default value of '0' and then the other rules of "order-of-loading" apply, which are not very reliable to ensure that one's code always loads in a certain order relative to the expansions' code.
 
In SQL the required update would be
Code:
UPDATE ModifierArguments SET Value = '20,20,20,20,20,20' WHERE ModifierId = 'TRAIT_LEADER_NEARBY_CITIES_GAIN_YIELDS' AND Name = 'Amount' ;
In XML the "AND" is implied when more than one column-condition is specified in a "Where" clause, so you never have to type "AND" in an XML "Where" clause.

Still does nothing... im mega confused now
 
Then you need to start a specific help request thread and post the mod in your OP

  1. Zip the version of the mod the game is actually trying to use, which will be found as a sub-folder in ~\Documents\My Games\Sid Meier's Civilization VI\Mods. Zip the whole sub-folder for your mod.
  2. Attach the zip to your OP using the button called Upload A File.
Without the actual mod to look at it will be impossible to determine what you are doing wrong. And detailed analyses of errors you might be making isn't really appropro a quick modding questions thread
 
Then you need to start a specific help request thread and post the mod in your OP

  1. Zip the version of the mod the game is actually trying to use, which will be found as a sub-folder in ~\Documents\My Games\Sid Meier's Civilization VI\Mods. Zip the whole sub-folder for your mod.
  2. Attach the zip to your OP using the button called Upload A File.
Without the actual mod to look at it will be impossible to determine what you are doing wrong. And detailed analyses of errors you might be making isn't really appropro a quick modding questions thread
I will do that.Thanks for your help (and patience lol)
 
I have religion ID. How do I get ID of player who founded it?
How do I get religion object when I have religion ID?
 
Last edited:
Code:
local religions = Game.GetReligion():GetReligions()
local iReligionId = ?? -- this is where you would shove the Religion ID # you already have
local iFoundingPlayer = -1
for _, religion in ipairs(religions) do
	if (religion.Religion == iReligionId) then
		if (religion.Founder ~= nil) and (religion.Founder ~= -1) then
			iFoundingPlayer = religion.Founder
			break;
		end
	end
end
if (iFoundingPlayer ~= -1) then
	-- do more stuff here
end
So far as I am aware these methods ought to be usable in both User Interface and GameplayScript but you would have to verify.

If the methods are not valid within a Gameplay Script then a loop through all players would be needed looking for a match between the Religion ID you already have and
Code:
Players[PlayerId]:GetReligion():GetReligionTypeCreated()
 
Can someone help me with this pseudo-code requirement?

I am trying to write a requirement for my requirement set that checks if your leader is Kupe, or that the civ is Maori. Im not sure if they are linked. This is my first dabble into civ 6 modding.

I need help figuring out the actual RequirementType, Name, and Value. What I have in here is made up based upon examples, but I have no idea how to figure out what keyword needs to actually go there.


Code:
INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES
('PB_MY_REQUIREMENT_SET', 'PB_REQUIRES_NOT_OCEAN_START');

INSERT INTO Requirements (RequirementId, RequirementType, Inverse) VALUES
('PB_REQUIRES_NOT_OCEAN_START', 'REQUIREMENT_CIVILIZATION_TYPE_MATCHES', 1);

INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES
('PB_REQUIRES_NOT_OCEAN_START', 'CivilizationType', 'CIVILIZATION_KUPE_MAORI');
 
Can someone help me with this pseudo-code requirement?

I am trying to write a requirement for my requirement set that checks if your leader is Kupe, or that the civ is Maori. Im not sure if they are linked. This is my first dabble into civ 6 modding.

I need help figuring out the actual RequirementType, Name, and Value. What I have in here is made up based upon examples, but I have no idea how to figure out what keyword needs to actually go there.


Code:
INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES
('PB_MY_REQUIREMENT_SET', 'PB_REQUIRES_NOT_OCEAN_START');

INSERT INTO Requirements (RequirementId, RequirementType, Inverse) VALUES
('PB_REQUIRES_NOT_OCEAN_START', 'REQUIREMENT_CIVILIZATION_TYPE_MATCHES', 1);

INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES
('PB_REQUIRES_NOT_OCEAN_START', 'CivilizationType', 'CIVILIZATION_KUPE_MAORI');
There's no such thing as "CIVILIZATION_KUPE_MAORI". So there can never be a successful match to it. Since you are using an "Inverse" on the Requirement, the condition will always be met by all players since none of them are "CIVILIZATION_KUPE_MAORI"

The correct designation is "CIVILIZATION_MAORI".

Further, there is no REQUIREMENT_CIVILIZATION_TYPE_MATCHES. Don't remember if there used to be, but if so it's gone now.

There is REQUIREMENT_PLAYER_LEADER_TYPE_MATCHES
Code:
	<Requirements>
		<Row>
			<RequirementId>REQUIREMENT_NUBIA_SCENARIO_PLAYER_IS_EGYPT</RequirementId>
			<RequirementType>REQUIREMENT_PLAYER_LEADER_TYPE_MATCHES</RequirementType>
		</Row>
	</Requirements>
	<RequirementArguments>
		<Row>
			<RequirementId>REQUIREMENT_NUBIA_SCENARIO_PLAYER_IS_EGYPT</RequirementId>
			<Name>LeaderType</Name>
			<Value>LEADER_CLEOPATRA</Value>
		</Row>
	</RequirementArguments>
and REQUIREMENT_PLAYER_TYPE_MATCHES:
Code:
	<Requirements>
		<Row RequirementId="PLAYER_IS_MAYA" RequirementType="REQUIREMENT_PLAYER_TYPE_MATCHES"/>
	</Requirements>
	<RequirementArguments>
		<Row RequirementId="PLAYER_IS_MAYA" Name="CivilizationType" Value="CIVILIZATION_MAYA"/>
	</RequirementArguments>
There is also REQUIREMENT_PLAYER_HAS_CIVILIZATION_OR_LEADER_TRAIT
Code:
	<Requirements>
		<Row>
			<RequirementId>REQUIRES_PLAYER_HAS_NOBEL_PRIZE_TRAIT</RequirementId>
			<RequirementType>REQUIREMENT_PLAYER_HAS_CIVILIZATION_OR_LEADER_TRAIT</RequirementType>
		</Row>
	</Requirements>
	<RequirementArguments>
		<Row>
			<RequirementId>REQUIRES_PLAYER_HAS_NOBEL_PRIZE_TRAIT</RequirementId>
			<Name>TraitType</Name>
			<Value>TRAIT_CIVILIZATION_NOBEL_PRIZE</Value>
		</Row>
	</RequirementArguments>
 
Top Bottom