Swapping UnitArtDefines

I think I may have done something wrong. I have:
Code:
function [COLOR="Red"]Religion[/COLOR]SpecificUnits(playerID, cityID, unitType)
    local majorityReligion = Cities[cityID]:GetReligiousMajority()


-- Turn off the specifics for all but the correct religion
    if (unitType == GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"]) then
        if not (majorityReligion == GameInfoTypes["RELIGION_CHANTRY"]) then
            return false
        end
    elseif (unitType == GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"]) then
        if not (majorityReligion == GameInfoTypes["RELIGION_PARAGONS"]) then
            return false
        end
    end
    return true
end
GameEvents.CityCanTrain.Add([COLOR="red"]Religious[/COLOR]SpecificUnits)

and I'm wanting to make it so that only those that follow the Chantry can build the Seekers of Truth, and only those that follow the Paragons can build the Legion of the Dead. I just tested it out, and while neither units is build-able in a city with no religion, both can be built in a city that follows the Chantry.

(I can link the full mod if need be)

If that is a direct copy of your code, you have mismatched function names. Check your Database.log to be sure part or all of your xml is not being discarded by the game (because what you are describing sounds like a "nil == "nil" / "nil ~= "nil" issue). Otherwise it would be necessary to look at the actual mod -- with the current partial reestablishment of the forum it might be better to provide a link to an off-forum location where the mod can be downloaded rather than trying to attach direct to a post. I've seem to recall conflicting reports on that thread Thunderfall linked to re forum current status and attachments.

also, I would do this to see that you have valid data within the lua function:
Code:
print("GameInfoTypes["RELIGION_CHANTRY"] is " .. GameInfoTypes["RELIGION_CHANTRY"])
print("GameInfoTypes["RELIGION_PARAGONS"] is " .. GameInfoTypes["RELIGION_PARAGONS"])
print("GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"] is " .. GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"])
print("GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"] is " .. GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"])

function ReligionSpecificUnits(playerID, cityID, unitType)
    local majorityReligion = Cities[cityID]:GetReligiousMajority()
	print("A city majorityReligion is " .. majorityReligion)


-- Turn off the specifics for all but the correct religion
    if (unitType == GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"]) then
        if not (majorityReligion == GameInfoTypes["RELIGION_CHANTRY"]) then
            return false
        end
    elseif (unitType == GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"]) then
        if not (majorityReligion == GameInfoTypes["RELIGION_PARAGONS"]) then
            return false
        end
    end
    return true
end
GameEvents.CityCanTrain.Add(ReligionSpecificUnits)
This will throw a bunch of statements of "A city majorityReligion is 1234" into the Live Tunder and lua.log, but otherwise you have no way to be sure what you are getting in that function.

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

[edit = for concept issues]
There is, however, a larger issue with this sort of implimentation in that a city's religious majority is not static, it is volatile. Units or Buildings that can no longer be constructed or trained within a city go instantly *poof* from the build qeues when the volatile condition alters. It is necessary to decide what should happen when a city is building, for example, a UNIT_LEGION_OF_THE_DEAD and an adversary converts the city to their religion, and then it is necessary to add a function to the city-converted event
Code:
GameEvents.CityConvertsReligion(PlayerID owner, ReligionType religion, int x, int y)
in order to determine if the qeue had any UNIT_LEGION_OF_THE_DEAD within it, and what to do in such a case.
 
If that is a direct copy of your code, you have mismatched function names. Check your Database.log to be sure part or all of your xml is not being discarded by the game (because what you are describing sounds like a "nil == "nil" / "nil ~= "nil" issue). Otherwise it would be necessary to look at the actual mod -- with the current partial reestablishment of the forum it might be better to provide a link to an off-forum location where the mod can be downloaded rather than trying to attach direct to a post. I've seem to recall conflicting reports on that thread Thunderfall linked to re forum current status and attachments.

also, I would do this to see that you have valid data within the lua function:
Code:
print("GameInfoTypes["RELIGION_CHANTRY"] is " .. GameInfoTypes["RELIGION_CHANTRY"])
print("GameInfoTypes["RELIGION_PARAGONS"] is " .. GameInfoTypes["RELIGION_PARAGONS"])
print("GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"] is " .. GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"])
print("GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"] is " .. GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"])

function ReligionSpecificUnits(playerID, cityID, unitType)
    local majorityReligion = Cities[cityID]:GetReligiousMajority()
	print("A city majorityReligion is " .. majorityReligion)


-- Turn off the specifics for all but the correct religion
    if (unitType == GameInfoTypes["UNIT_SEEKERS_OF_TRUTH"]) then
        if not (majorityReligion == GameInfoTypes["RELIGION_CHANTRY"]) then
            return false
        end
    elseif (unitType == GameInfoTypes["UNIT_LEGION_OF_THE_DEAD"]) then
        if not (majorityReligion == GameInfoTypes["RELIGION_PARAGONS"]) then
            return false
        end
    end
    return true
end
GameEvents.CityCanTrain.Add(ReligionSpecificUnits)
This will throw a bunch of statements of "A city majorityReligion is 1234" into the Live Tunder and lua.log, but otherwise you have no way to be sure what you are getting in that function.

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

[edit = for concept issues]
There is, however, a larger issue with this sort of implimentation in that a city's religious majority is not static, it is volatile. Units or Buildings that can no longer be constructed or trained within a city go instantly *poof* from the build qeues when the volatile condition alters. It is necessary to decide what should happen when a city is building, for example, a UNIT_LEGION_OF_THE_DEAD and an adversary converts the city to their religion, and then it is necessary to add a function to the city-converted event
Code:
GameEvents.CityConvertsReligion(PlayerID owner, ReligionType religion, int x, int y)
in order to determine if the qeue had any UNIT_LEGION_OF_THE_DEAD within it, and what to do in such a case.

Alright, I fixed the function names, but it's still doing the same thing. I'm not sure What exactly you're meaning by the other bits, but here's the link to the mod.

http://www.mediafire.com/download/y...t)_-_Religions_of_Thedas_(Enhanced)_(v_1).rar

On a second note, both units (Seekers and Dead Legion) are supposed to require having researched the Steel tech on top of their corresponding religions, yet they can be purchased without researching steel. About the only thing really working for them is the fact that I've set them so that you can only purchase them with faith.
 
Your basic problem is in the definition of the units.
Spoiler :
Code:
	<Units>
		<Row>
			<Class>UNITCLASS_SEEKER_OF_TRUTH</Class>
			<Type>UNIT_SEEKER_OF_TRUTH</Type>
			<PrereqTech>TECH_STEEL</PrereqTech>
			[COLOR="Red"]<Cost>-1</Cost>
			<FaithCost>200</FaithCost>[/COLOR]
			<Combat>25</Combat>
			<Moves>2</Moves>
			<CombatClass>UNITCOMBAT_MELEE</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_SEEKER_OF_TRUTH</Description>
			<Civilopedia>TXT_KEY_CIV5_ANTIQUITY_SEEKER_OF_TRUTH_TEXT</Civilopedia>
			<Strategy>TXT_KEY_UNIT_SEEKER_OF_TRUTH_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_SEEKER_OF_TRUTH</Help>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<AdvancedStartCost>10</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_SEEKER_OF_TRUTH</UnitArtInfo>
			<UnitFlagAtlas>CIV_ALPHA_ATLAS_RELIGIOUS_UNITS</UnitFlagAtlas>
			<UnitFlagIconOffset>0</UnitFlagIconOffset>
			<IconAtlas>THEDAS_RELIGIONS_COLOR_ATLAS_LEGENDS</IconAtlas>
			<PortraitIndex>0</PortraitIndex>
		</Row>
		<Row>
			<Class>UNITCLASS_LEGION_OF_THE_DEAD</Class>
			<Type>UNIT_LEGION_OF_THE_DEAD</Type>
			<PrereqTech>TECH_STEEL</PrereqTech>
			[COLOR="red"]<Cost>-1</Cost>
			<FaithCost>200</FaithCost>[/COLOR]
			<Combat>25</Combat>
			<Moves>2</Moves>
			<CombatClass>UNITCOMBAT_MELEE</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_LEGION_OF_THE_DEAD</Description>
			<Civilopedia>TXT_KEY_CIV5_ANTIQUITY_LEGION_OF_THE_DEAD_TEXT</Civilopedia>
			<Strategy>TXT_KEY_UNIT_LEGION_OF_THE_DEAD_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_LEGION_OF_THE_DEAD</Help>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<AdvancedStartCost>10</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_LEGION_OF_THE_DEAD</UnitArtInfo>
			<UnitFlagAtlas>CIV_ALPHA_ATLAS_RELIGIOUS_UNITS</UnitFlagAtlas>
			<UnitFlagIconOffset>1</UnitFlagIconOffset>
			<IconAtlas>THEDAS_RELIGIONS_COLOR_ATLAS_LEGENDS</IconAtlas>
			<PortraitIndex>1</PortraitIndex>
		</Row>
	</Units>
  1. Setting a unit's <Cost> to -1:
    • makes the unit unbuildable in any city
    • makes the unit unbuyable with gold in any city.
    • eliminates the need or usefulness of any lua code within GameEvents.CityCanTrain.Add(XYZ) because the CityCanTrain event is an "AND" event. This means that all lua's CityCanTrain event will do is add extra restrictions on building/buying the unit. But the setting of <Cost>-1</Cost> has already "falsed out" the unit for all conditions
  2. Setting a unit's <FaithCost> to any positive number without also adding <RequiresFaithPurchaseEnabled>true</RequiresFaithPurchaseEnabled>:
    • Makes the unit instantly purchasable with Faith from the beginning of the game, regardless of any other settings for availability restrictions on the unit.
    • So far as purchasing with Faith is concerned, essentially overrides the setting of <Cost>, and ignores whether or not <Cost> has been set to -1
    • This may seem like the route to get a unit that is Faith-buyable without also having to select "Holy Warriors" or "Religious Fervor", but the reality is it is not workable, always causes the "instant buyability", and cannot really be "cured" through any combination of lua + xml + sql code "work-arounds". Many have tried this (including myself) and it is simply a nightmare scenario to try to get it to work without having these extra unintended consequences. Been there, done that -- got the Tshirt.

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

So far as my point regarding the volatility of a city's religious majority goes:
  • Assume I have set up a restriction where only cities with Catholicism as their majority can build a "Holy Defender" unit.
  • Assume I have a city with Catholicism as the religious majority, and that I am almost finished building a "Holy Defender" unit in that city.
  • I press "NEXT TURN", and before I can finish the "Holy Defender" unit, an adversary AI sends a prophet over to my city and converts it.
  • What happens to all that production I put into that "Holy Defender" unit ?
    Spoiler Answer :
    It goes *poof*
 
Your basic problem is in the definition of the units.
Spoiler :
Code:
	<Units>
		<Row>
			<Class>UNITCLASS_SEEKER_OF_TRUTH</Class>
			<Type>UNIT_SEEKER_OF_TRUTH</Type>
			<PrereqTech>TECH_STEEL</PrereqTech>
			[COLOR="Red"]<Cost>-1</Cost>
			<FaithCost>200</FaithCost>[/COLOR]
			<Combat>25</Combat>
			<Moves>2</Moves>
			<CombatClass>UNITCOMBAT_MELEE</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_SEEKER_OF_TRUTH</Description>
			<Civilopedia>TXT_KEY_CIV5_ANTIQUITY_SEEKER_OF_TRUTH_TEXT</Civilopedia>
			<Strategy>TXT_KEY_UNIT_SEEKER_OF_TRUTH_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_SEEKER_OF_TRUTH</Help>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<AdvancedStartCost>10</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_SEEKER_OF_TRUTH</UnitArtInfo>
			<UnitFlagAtlas>CIV_ALPHA_ATLAS_RELIGIOUS_UNITS</UnitFlagAtlas>
			<UnitFlagIconOffset>0</UnitFlagIconOffset>
			<IconAtlas>THEDAS_RELIGIONS_COLOR_ATLAS_LEGENDS</IconAtlas>
			<PortraitIndex>0</PortraitIndex>
		</Row>
		<Row>
			<Class>UNITCLASS_LEGION_OF_THE_DEAD</Class>
			<Type>UNIT_LEGION_OF_THE_DEAD</Type>
			<PrereqTech>TECH_STEEL</PrereqTech>
			[COLOR="red"]<Cost>-1</Cost>
			<FaithCost>200</FaithCost>[/COLOR]
			<Combat>25</Combat>
			<Moves>2</Moves>
			<CombatClass>UNITCOMBAT_MELEE</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_LEGION_OF_THE_DEAD</Description>
			<Civilopedia>TXT_KEY_CIV5_ANTIQUITY_LEGION_OF_THE_DEAD_TEXT</Civilopedia>
			<Strategy>TXT_KEY_UNIT_LEGION_OF_THE_DEAD_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_LEGION_OF_THE_DEAD</Help>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<AdvancedStartCost>10</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_LEGION_OF_THE_DEAD</UnitArtInfo>
			<UnitFlagAtlas>CIV_ALPHA_ATLAS_RELIGIOUS_UNITS</UnitFlagAtlas>
			<UnitFlagIconOffset>1</UnitFlagIconOffset>
			<IconAtlas>THEDAS_RELIGIONS_COLOR_ATLAS_LEGENDS</IconAtlas>
			<PortraitIndex>1</PortraitIndex>
		</Row>
	</Units>
  1. Setting a unit's <Cost> to -1:
    • makes the unit unbuildable in any city
    • makes the unit unbuyable with gold in any city.
    • eliminates the need or usefulness of any lua code within GameEvents.CityCanTrain.Add(XYZ) because the CityCanTrain event is an "AND" event. This means that all lua's CityCanTrain event will do is add extra restrictions on building/buying the unit. But the setting of <Cost>-1</Cost> has already "falsed out" the unit for all conditions
  2. Setting a unit's <FaithCost> to any positive number without also adding <RequiresFaithPurchaseEnabled>true</RequiresFaithPurchaseEnabled>:
    • Makes the unit instantly purchasable with Faith from the beginning of the game, regardless of any other settings for availability restrictions on the unit.
    • So far as purchasing with Faith is concerned, essentially overrides the setting of <Cost>, and ignores whether or not <Cost> has been set to -1
    • This may seem like the route to get a unit that is Faith-buyable without also having to select "Holy Warriors" or "Religious Fervor", but the reality is it is not workable, always causes the "instant buyability", and cannot really be "cured" through any combination of lua + xml + sql code "work-arounds". Many have tried this (including myself) and it is simply a nightmare scenario to try to get it to work without having these extra unintended consequences. Been there, done that -- got the Tshirt.

Alright, I made those two changes, but it's still letting me buy the Legion of the Dead in a city following the Chantry. But this time, both units are buildable, and can be purchased by gold. In fact, I can't purchase them with faith now.

the updated link is here, if need be:
http://www.mediafire.com/download/c...t)_-_Religions_of_Thedas_(Enhanced)_(v_1).rar

So far as my point regarding the volatility of a city's religious majority goes:
  • Assume I have set up a restriction where only cities with Catholicism as their majority can build a "Holy Defender" unit.
  • Assume I have a city with Catholicism as the religious majority, and that I am almost finished building a "Holy Defender" unit in that city.
  • I press "NEXT TURN", and before I can finish the "Holy Defender" unit, an adversary AI sends a prophet over to my city and converts it.
  • What happens to all that production I put into that "Holy Defender" unit ?
    Spoiler Answer :
    It goes *poof*

Well, the unit is supposed to only be buyable using faith (like cathedrals, or a Great Prophet), so you can't sink any production into it. That should circumvent the need for any lines of code that handle that.
 
You mis-interpretted my item # 2

It was a warning that you will not find the attempt very workable. I experimented heavily with trying to do something very similar re allowing a unit only to be faith-buyable, and only under certain conditions. I was never able to get past the issues inherent in having the FaithCost set while not also having the RequiresFaithPurchaseEnabled also set to true. The game's systems really only want you to allow faith purchasing of units or buildings based on adoption of beliefs that have been specifically set-up to allow such.
 
Back
Top Bottom