C++/Lua Request Thread

Code:
-- Kirkwall_IsCivilisationActive
------------------------------------------------------------------------------------------------------------------------
local civilisationID = GameInfoTypes["CIVILIZATION_KIRKWALL"]

function Kirkwall_IsCivilisationActive(civilisationID)
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local slotStatus = PreGame.GetSlotStatus(iSlot)
		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
			if PreGame.GetCivilization(iSlot) == civilisationID then
				return true
			end
		end
	end

	return false
end

local isKirkwallCivActive = Kirkwall_IsCivilisationActive(civilisationID)

if isKirkwallCivActive == true then
	print("No $#it, there I was!")
end

local buildingKirkwalldummyID = GameInfoTypes["BUILDING_KIRKWALL_DUMMY"]
local mathFloor = math.floor
----------------------------------------------------------------------------------------------------------------------------
-- Kirkwall_CityStateConquests
----------------------------------------------------------------------------------------------------------------------------
function Kirkwall_CityStateConquests(oldOwnerID, isCapital, cityX, cityY, newOwnerID, pop, isConquest)
	local player = Players[newOwnerID]
	local capturedPlayer = Players[oldOwnerID]
	if player:GetCivilizationType() == civilisationID then
		local city = Map.GetPlot(cityX, cityY):GetPlotCity()
		if city:IsOriginalCapital() and capturedPlayer:IsMinorCiv() then
			if not city:IsHasBuilding(buildingKirkwalldummyID) then
				city:SetNumRealBuilding(buildingKirkwalldummyID, 1)
			end
			
			city:ChangeResistanceTurns(-mathFloor(city:GetResistanceTurns()))
		end 
	end
end

if isKirkwallCivActive then
	GameEvents.CityCaptureComplete.Add(Kirkwall_CityStateConquests)
end
--==========================================================================================================================
--==========================================================================================================================

The above code prevents city-states captured by my custom civ from entering resistance. What do I add to prevent captured cities from major civs from going into resistance?
 
Code:
-- Kirkwall_IsCivilisationActive
------------------------------------------------------------------------------------------------------------------------
local civilisationID = GameInfoTypes["CIVILIZATION_KIRKWALL"]

function Kirkwall_IsCivilisationActive(civilisationID)
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local slotStatus = PreGame.GetSlotStatus(iSlot)
		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
			if PreGame.GetCivilization(iSlot) == civilisationID then
				return true
			end
		end
	end

	return false
end

local isKirkwallCivActive = Kirkwall_IsCivilisationActive(civilisationID)

if isKirkwallCivActive == true then
	print("No $#it, there I was!")
end

local buildingKirkwalldummyID = GameInfoTypes["BUILDING_KIRKWALL_DUMMY"]
local mathFloor = math.floor
----------------------------------------------------------------------------------------------------------------------------
-- Kirkwall_CityStateConquests
----------------------------------------------------------------------------------------------------------------------------
function Kirkwall_CityStateConquests(oldOwnerID, isCapital, cityX, cityY, newOwnerID, pop, isConquest)
	local player = Players[newOwnerID]
	local capturedPlayer = Players[oldOwnerID]
	if player:GetCivilizationType() == civilisationID then
		local city = Map.GetPlot(cityX, cityY):GetPlotCity()
		if city:IsOriginalCapital() [S][B]and capturedPlayer:IsMinorCiv()[/B][/S] then
			if not city:IsHasBuilding(buildingKirkwalldummyID) then
				city:SetNumRealBuilding(buildingKirkwalldummyID, 1)
			end
			
			city:ChangeResistanceTurns(-mathFloor(city:GetResistanceTurns()))
		end 
	end
end

if isKirkwallCivActive then
	GameEvents.CityCaptureComplete.Add(Kirkwall_CityStateConquests)
end
--==========================================================================================================================
--==========================================================================================================================

The above code prevents city-states captured by my custom civ from entering resistance. What do I add to prevent captured cities from major civs from going into resistance?

The part you need to remove is

Code:
[B][S]and capturedPlayer:IsMinorCiv()[/S][/B]

The code snippet has been bolded & crossed out in the big quoted post as well.
 
The part you need to remove is

Code:
[B][S]and capturedPlayer:IsMinorCiv()[/S][/B]

The code snippet has been bolded & crossed out in the big quoted post as well.

Alright, I tried it, it's only working for capital cities. I tried getting rid of the "if city:IsOriginalCapital()" bit, but that caused every city to go into resistance.
 
Did you change this section:
Code:
		if city:IsOriginalCapital() and capturedPlayer:IsMinorCiv() then
			if not city:IsHasBuilding(buildingKirkwalldummyID) then
				city:SetNumRealBuilding(buildingKirkwalldummyID, 1)
			end
			
			city:ChangeResistanceTurns(-mathFloor(city:GetResistanceTurns()))
		end
to this
Code:
		if not city:IsHasBuilding(buildingKirkwalldummyID) then
			city:SetNumRealBuilding(buildingKirkwalldummyID, 1)
		end
		city:ChangeResistanceTurns(-mathFloor(city:GetResistanceTurns()))
Or did you make a different change that perhaps isn't quite giving you the logic-flow you would want?

Though I'm not sure why the math.floor
X * -1 ought to do it.
 
Did you change this section:
Code:
		if city:IsOriginalCapital() and capturedPlayer:IsMinorCiv() then
			if not city:IsHasBuilding(buildingKirkwalldummyID) then
				city:SetNumRealBuilding(buildingKirkwalldummyID, 1)
			end
			
			city:ChangeResistanceTurns(-mathFloor(city:GetResistanceTurns()))
		end
to this
Code:
		if not city:IsHasBuilding(buildingKirkwalldummyID) then
			city:SetNumRealBuilding(buildingKirkwalldummyID, 1)
		end
		city:ChangeResistanceTurns(-mathFloor(city:GetResistanceTurns()))
Or did you make a different change that perhaps isn't quite giving you the logic-flow you would want?

Though I'm not sure why the math.floor
X * -1 ought to do it.

I changed it to exactly as you have in your example.
 
How would I make it so I get +1 production and culture from forest tiles? Do I really have to use dummy buildings?
 
I changed it to exactly as you have in your example.
not sure where your trouble is then, because that is as identical a set of commands as can be that I used on something else a while back with no problems.
 
not sure where your trouble is then, because that is as identical a set of commands as can be that I used on something else a while back with no problems.

Ok, I must have messed something up then. I'll try tinkering with it and see where that gets me. Thanks for the help.
 
How would I make it so I get +1 production and culture from forest tiles? Do I really have to use dummy buildings?

No need for dummy buildings for that. Assuming it's for the UA of a custom civ, just put the following in your Traits XML file.

Code:
	<Trait_UnimprovedFeatureYieldChanges>
		<Row>
			<TraitType>TRAIT_[COLOR="Blue"]YOURTRAITNAME[/COLOR]</TraitType>
			<FeatureType>FEATURE_FOREST</FeatureType>
			<YieldType>YIELD_PRODUCTION</YieldType>
			<Yield>1</Yield>
		</Row>
		<Row>
			<TraitType>TRAIT_[COLOR="Blue"]YOURTRAITNAME[/COLOR]</TraitType>
			<FeatureType>FEATURE_FOREST</FeatureType>
			<YieldType>YIELD_CULTURE</YieldType>
			<Yield>1</Yield>
		</Row>
	</Trait_UnimprovedFeatureYieldChanges>

(obviously, replace the YOURTRAITNAME with whatever you've defined your civ's trait to be.)
 
I suppose he's talking about all tiles at all costs, not unimproved ones.
 
How would I make it so I get +1 production and culture from forest tiles? Do I really have to use dummy buildings?

Substitute 'YIELD_CULTURE' for whatever yield you want, and '1' for whatever value you want. Do note that Forest tiles already provide +1 Production in the base game, so you would not need to touch that.
Code:
INSERT INTO Feature_YieldChanges VALUES ('FEATURE_FOREST', 'YIELD_CULTURE', 1);
 
I think he wants an additional +1 Production like the Longhouse.
 
For some reason my civ isn't showing up in the selection screen. Is there something special I need to do? I already set my files to update the database.
 
For some reason my civ isn't showing up in the selection screen. Is there something special I need to do? I already set my files to update the database.
You'd probably be better off posting a help request thread in the main C&C forum. But I would direct you here to see if any of the sorts of mistakes mentioned could be your problem.

PS -- your description of your problem is generally indicative of one of two or three common problems:
a) modbuddy settings are [not]* quite correct
b) syntax errors in the xml file(s) cause the file where the civilization is defined to be rejected by the game
c) leader is not properly "hooked-up" to the civ

[edit]* aded the word "not" because it was what I intended to type.
 
I'm looking to make a UA for a civ where they receive 4 culture per turn for every captured city. I'm guessing this can be done by spawning in a dummy building that yields culture in each conquered city.

so, for my dummy building's XML, I have;
Code:
<GameData>
	<BuildingClasses>
		<Row>
			<Type>BUILDINGCLASS_ORLAIS_DUMMY</Type>
			<DefaultBuilding>BUILDING_ORLAIS_DUMMY</DefaultBuilding>
		</Row>
	</BuildingClasses>
	<Buildings>
		<Row>
			<Type>BUILDING_ORLAIS_DUMMY</Type>
			<BuildingClass>BUILDINGCLASS_ORLAIS_DUMMY</BuildingClass>
			<Cost>-1</Cost>
			<FaithCost>-1</FaithCost>
			<PrereqTech>NULL</PrereqTech>
			<GreatWorkCount>-1</GreatWorkCount>
			<NeverCapture>true</NeverCapture>
		</Row>
	</Buildings>
	<Building_YieldChanges>
		<Row>
			<BuildingType>BUILDING_ORLAIS_DUMMY</BuildingType>
			<YieldType>YIELD_CULTURE</YieldType>
			<Yield>4</Yield>
		</Row>
	</Building_YieldChanges>
</GameData>


and for my Lua that's supposed to spawn in the dummy building, I have:
Code:
-- UTILITY FUNCTIONS	
--=======================================================================================================================
-- Orlais_IsCivilisationActive
------------------------------------------------------------------------------------------------------------------------
local civilisationID = GameInfoTypes["CIVILIZATION_ORLAIS"]

function Orlais_IsCivilisationActive(civilisationID)
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local slotStatus = PreGame.GetSlotStatus(iSlot)
		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
			if PreGame.GetCivilization(iSlot) == civilisationID then
				return true
			end
		end
	end

	return false
end

local isOrlaisCivActive = Orlais_IsCivilisationActive(civilisationID)

if isOrlaisCivActive == true then
	print("Empress of Fire")
end

local buildingOrlaisdummyID = GameInfoTypes["BUILDING_ORLAIS_DUMMY"]
local mathFloor = math.floor
----------------------------------------------------------------------------------------------------------------------------
-- Orlais_CityStateConquests
----------------------------------------------------------------------------------------------------------------------------
function Orlais_CityStateConquests(oldOwnerID, isCapital, cityX, cityY, newOwnerID, pop, isConquest)
	local player = Players[newOwnerID]
	local capturedPlayer = Players[oldOwnerID]
	if player:GetCivilizationType() == civilisationID then
		local city = Map.GetPlot(cityX, cityY):GetPlotCity()
			if not city:IsHasBuilding(buildingOrlaisdummyID) then
				city:SetNumRealBuilding(buildingOrlaisdummyID, 1)
			end
end

if isOrlaisCivActive then
	GameEvents.CityCaptureComplete.Add(Orlais_CityStateConquests)
end
--==========================================================================================================================
--==========================================================================================================================

yet, the culture per turn is not being gained. I'm pretty sure that whatever's wrong is in the Lua. How can I fix it?
 
You can actually set that in the Trait:

Code:
<GameData>
  <Traits>
    <Row>
      <Type>TRAIT_ORLAIS</Type>
      <Description>TXT_KEY_TRAIT_ORLAIS</Description>
      <ShortDescription>TXT_KEY_TRAIT_ORLAIS_SHORT</ShortDescription>
      <FreeBuildingOnConquest>BUILDING_ORLAIS_DUMMY</FreeBuildingOnConquest>
  </Traits>
</GameData>
 
refer to the lua.log, it will most likely be telling you there are not enough 'end' commands in function Orlais_CityStateConquests

line
Code:
if player:GetCivilizationType() == civilisationID then
appear to me to have no 'end' asociated with it.

Also as a general rule you should provide a <Description> in your BuildingClasses and <Buildings> definitions.

I generally also add the palace's <IconAtlas> and <PortraitIndex> settings even in dummy buildings because the Civilopedia randomly selects building-icons to use as the Buildings 'cover' image so without these there is the small occasional possibility of the player seeing an ugly-blob on that civilopedia page -- which they will then promptly report to you as being a 'bug' in your mod.
 
@GPuzzle:
You're missing a closing </Row> there, so that would cause the game to run into an error and dump that file.

@DoktorApplejuce
That Lua looks suspiciously like JFD's code.
In either case, right off the bat, before even looking at any logic, you should be able to tell that your second function is a mismatched set of end pairs for each logical block. If you check your Lua logs, you should find some sort of error from Lua complaining about this.

Edit:
Ninaj'd again by LeeS. I'm going to stop trying to provide help now. :P
 
@GPuzzle:
You're missing a closing </Row> there, so that would cause the game to run into an error and dump that file.

I got too used to modding with SQL, damnit.
 
Back
Top Bottom