• Civ7 is already available! Happy playing :).

GabeN/Valve Civilization MOD help

probacon241

Chieftain
Joined
Jun 28, 2014
Messages
8
Location
NoVA
Greetings friends,

A couple days ago, I got the best idea: create a GabeN civilization! Even though I had no prior modding experience, I read Kael's longass pdf cover to cover, got SDK/Modbuddy, and got to work. One thing that has completely stumped me is the city names; I know they go:

TXT_KEY_CITY_NAME_YADDAYADDAYADDA

and then you go and define them in a separate xml file, but for whatever reason those text strings simply aren't being defined properly, and I have no idea why. At the bottom are the relevant bits of code, from Valve.xml and CityDefines.xml, and a screencap of me spamming cities using IGE. Note - I found that Savannah works fine, but only because it is defined as an American city.

I've checked and rechecked but I can't find what I'm doing wrong. Can one of you fine people help me?

wr5foY3.png




kEkEhWi.png




o8VwGCh.png
 
Oh yes, I forgot to mention in the OP, all the .xmls are set to update the database OnModActivate. I compiled what I have in the rar; only xml so far, but I plan on making some custom dds icons later, and making a custom trait with Lua.

M7sasU3.png
 

Attachments

Problem solved. (I had a screenshot, but it vanished)

Replace your content on CityDefines.xml with this:
Spoiler :
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 6/28/2014 9:40:51 AM -->
<GameData>
	<Language_en_US>
		<Row Tag="TXT_KEY_CITY_NAME_BELLEVUE">
			<Text>Bellevue</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_MANNHATTAN">
			<Text>Mannhattan</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_RAYFORD">
			<Text>Rayford</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_XEN">
			<Text>Xen</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_DUCATEL">
			<Text>Ducatel</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_MIRAGE">
			<Text>Mirage</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_KONG_KING">
			<Text>Kong King</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_RAVENHOLM">
			<Text>Ravenholm</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_17">
			<Text>17</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_APERTURE">
			<Text>Aperture</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_ST_MARC">
			<Text>St. Marc</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_NEWBURG">
			<Text>Newburg</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_BLACK_MESA">
			<Text>Black Mesa</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_RIVERSIDE">
			<Text>Riverside</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_FAIRFIELD">
			<Text>Fairfield</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_EN_MARAIS">
			<Text>En Marais</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_TEUFORT">
			<Text>Teufort</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_VERTIGO">
			<Text>Vertigo</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_ROTTENBURG">
			<Text>Rottenburg</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_NOVA_PROSPEKT">
			<Text>Nova Prospekt</Text>
		</Row>
		<Row Tag="TXT_KEY_CITY_NAME_MANNWORKS">
			<Text>Mannworks</Text>
		</Row>
	</Language_en_US>
</GameData>

Since you had two Cities that already had entries (New Orleans and another) I believe those caused the whole file not to load properly. Another thing I found was that you had a space (" ") after "Row Tag="; I don't know if it is 'codely' relevant, but if it isn't, is just plain ugly. :lol:

Cheers.
 
Now the problem is in the Lua. For GabeN, what Unique Trait could possibly be suitable, other than the Steam Sale? For civ purposes, that means that during Golden Ages, the cost of hurrying units/buildings is reduced by 90%.

I looked at the Lua API and other civilization mods that have Lua traits (thanks JFD) and I typed this up.

Spoiler :
-- SteamSale
-- Author: probacon241
-- DateCreated: 6/29/2014 10:44:25 AM
--------------------------------------------------------------
GameEvents.PlayerDoTurn.Add(function(iPlayer)
local pPlayer = Players[iPlayer];
if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_VALVE"] and pPlayer:isGoldenAge() == true) then --if Valve is in a Golden Age
for iCity in pPlayer:Cities() do -- In every city...
int cCost == Player:GetHurryGoldCost(1); --Get the normal cost for hurrying production
iCity:hurryCost(1, true) == cCost * .1; --Set the hurry cost to 1/10 of what is normal
end
end
end)


Granted, I didn't exactly expect it to work (I'm almost certain the int cCost is wrong), but its a starting point. Where do I go from here?
 
== is used in a conditional statement (if then) and is used in lua for 'is equal to'
= is used to set a value, as in
Code:
local iDayInAYear = 365
not sure about the rest of your code, may have a chance to look closer after lunch
 
In addition to the above, could it be the lower-case 'h' in "iCity:hurryCost"?
I'll test it out.

EDIT:

I don't know, but the line 6 seems a bit weird. Also, there should be no 'int' before 'cCost'.
I believe you need to use City.ChangeProduction() and the HurryCost to set the integer you'll put there.
 
Now the problem is in the Lua. For GabeN, what Unique Trait could possibly be suitable, other than the Steam Sale? For civ purposes, that means that during Golden Ages, the cost of hurrying units/buildings is reduced by 90%.

I looked at the Lua API and other civilization mods that have Lua traits (thanks JFD) and I typed this up.

Spoiler :
-- SteamSale
-- Author: probacon241
-- DateCreated: 6/29/2014 10:44:25 AM
--------------------------------------------------------------
GameEvents.PlayerDoTurn.Add(function(iPlayer)
local pPlayer = Players[iPlayer];
if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_VALVE"] and pPlayer:isGoldenAge() == true) then --if Valve is in a Golden Age
for iCity in pPlayer:Cities() do -- In every city...
int cCost == Player:GetHurryGoldCost(1); --Get the normal cost for hurrying production
iCity:hurryCost(1, true) == cCost * .1; --Set the hurry cost to 1/10 of what is normal
end
end
end)


Granted, I didn't exactly expect it to work (I'm almost certain the int cCost is wrong), but its a starting point. Where do I go from here?

Actually, this is not as easy as it might at first seem. There are two commands to get current gold hurry cost. One for direct hurry cost and one for the player's current hurry cost modifier.
You can store these values in locals like this
Code:
local iHurryGoldCost = pPlayer:GetHurryGoldCost(1)

local iHurryGoldModifier = pPlayer:GetHurryModifier(1)
but you can't directly make changes to them with these comands. I did not find anything in the Player or City lua references for directly changing these values, however. I would have to look back through the City lua reference to see if there's anything there I might have missed for directly changing a hurry cost or a hurry modifer, but I don't think there is.
 
In the API, I didn't see any function that went something like 'SetHurryCostModifiers', which is what I'm looking for in my case. I cleaned up the code somewhat based on the suggestions given, but I think the problem rests in the last line, since I'm not seeing a way to set the modifier for hurry costs to something else.

Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer)
	local pPlayer = Players[iPlayer];
	if (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_VALVE"] and pPlayer:isGoldenAge() == true) then --if Valve is in a Golden Age
		for iCity in pPlayer:Cities() do -- In every city...
			local Cost = Player:GetHurryGoldModifier(1); --Get the normal cost for hurrying production
			iCity:HurryCost(1, true) = Cost * .1; --Set the hurry cost to 1/10 of what is normal 	
		end
	end 
end)

What does this mean for me now? Is there a way to program this trait?
 
Try this as your lua. It's an adaptation of JFD's original Nicholas II of Russia lua
Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer)
local pPlayer = Players[iPlayer];
	if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_VALVE"] then
		for iCity in pPlayer:Cities() do
			if iCity:IsCapital() then
				if pPlayer:isGoldenAge() then
					if not iCity:IsHasBuilding(GameInfoTypes.BUILDING_VALVE_GOLDEN_AGE) then
						iCity:SetNumRealBuilding(GameInfoTypes.BUILDING_VALVE_GOLDEN_AGE, 1);
					end
				else
					if iCity:IsHasBuilding(GameInfoTypes.BUILDING_VALVE_GOLDEN_AGE) then
						iCity:SetNumRealBuilding(GameInfoTypes.BUILDING_VALVE_GOLDEN_AGE, 0);
					end
				end
			end
		end
	end
end)
then add a 'something.xml' file to your mod with this code. The lines shown in red would make America's civilization icon show up for the building icon in Valve's capital city when the civ is in a golden age. You would want to alter those to be correct for your civ's icon, or pick some other icon to use. The part shown in blue is similar to what is used by the Big Ben World Wonder to reduce hurry gold costs throughout the empire. I haven't tested this to confirm that when the lua removes the building from the capital after the golden age expires the hurry gold costs are reset back to the normal level.
Code:
<GameData>
	<BuildingClasses>
		<Row>
			<Type>BUILDINGCLASS_VALVE_GOLDEN_AGE</Type>
			<DefaultBuilding>BUILDING_VALVE_GOLDEN_AGE</DefaultBuilding>
			<Description>TXT_KEY_BUILDING_VALVE_GOLDEN_AGE</Description>
		</Row>
	</BuildingClasses>
	<Buildings>
		<Row>
			<Type>BUILDING_VALVE_GOLDEN_AGE</Type>
			<BuildingClass>BUILDINGCLASS_VALVE_GOLDEN_AGE</BuildingClass>
			<Cost>-1</Cost>
			<PrereqTech/>
			<Description>TXT_KEY_BUILDING_VALVE_GOLDEN_AGE</Description>
			<Civilopedia>TXT_KEY_CIVILOPEDIA_BUILDINGS_VALVE_GOLDEN_AGE_TEXT</Civilopedia>
			<Help>TXT_KEY_BUILDING_VALVE_GOLDEN_AGE_HELP</Help>
			<Strategy>TXT_KEY_BUILDING_VALVE_GOLDEN_AGE_STRATEGY</Strategy>
			<ArtDefineTag></ArtDefineTag>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>	
			<NukeImmune>true</NukeImmune>
			[COLOR="Red"]<PortraitIndex>0</PortraitIndex>
			<IconAtlas>CIV_COLOR_ATLAS</IconAtlas>[/COLOR]
		</Row>
	</Buildings>
	[COLOR="Blue"]<Building_HurryModifiers>
		<Row>
			<BuildingType>BUILDING_VALVE_GOLDEN_AGE</BuildingType>
			<HurryType>HURRY_GOLD</HurryType>
			<HurryCostModifier>-90</HurryCostModifier>
		</Row>
	</Building_HurryModifiers>[/COLOR]
	<Language_en_US>
	<Row Tag="TXT_KEY_BUILDING_VALVE_GOLDEN_AGE">
		<Text>Valve Golden Age</Text>
	</Row>
	<Row Tag="TXT_KEY_BUILDING_VALVE_GOLDEN_AGE_HELP">
		<Text>During Golden Ages, Gold Hurrying is reduced.</Text>
	</Row>
	</Language_en_US>
</GameData>

[edit]there were a couple of typo boo-boos in there that I didn't see until after original post. I think I caught them all.
 
I implemented your changes LeeS, and I rebuilt the mod and re-added it to the mods folder. I was surprised to see that it didn't work, (the building did not seem to exist at all in the civilopedia) but then I remembered I forgot to set both files to OnModActivate. So I went back into Modbuddy, and tried to set the files to OnModActivate, but for some reason the Lua file simply does not show up on the drop down menu. The drop-down displayed all the xml files, but not the lua. I checked the other combinations (OnModActivate - UpdateUserData, OnCreateModUserData - UpdateUserData, etc.) but an option to add the lua did not appear. Is the lua file not supposed to be added this way, or is ModBuddy screwing with me?
 
OK, I read his tutorial. The same problem appears; the dropdown menu doesn't have the Lua file as an available selection. I typed it in manually (checking for misspells), but I don't think the game loaded it properly, since the building does not appear when a golden age begins, or on the next turn either.

On the other hand, when I copied the lua text, deleted the file, and then made an identical Lua file, the InGameUIAddin entry deleted itself, which means it should be detecting the file, right?

EDIT: Since I'm already using IGE, I decided to see if I could manually plop it into my capital. Once it was already there, the building did its job; all gold purchases were 90% off. The building stayed, and did not disappear the next turn, so I'm convinced that this is a failing of the game to detect the lua.

EDIT2: I found out that if you select the UIAddin before you select the file, then you are able to select the lua, and then subsequently select the type of Addin that you want. But when I loaded it, the game still did not add the building in on Golden Age, and now I'm very confused, since the logic of the lua code itself should be working.
 
It might be a shot in the dark, but if the lua is still set to OnModActivate, it might not work. Just a guess, I'm not sure.
 
Slight typo. Not sure if I added it into the mix or in came from me copying your original lua to use as a starting point.

need a capital 'I' where shown:
Code:
if pPlayer:[COLOR="Red"][B]I[/B][/COLOR]sGoldenAge() then

also, if you have not done so, look at whoward's tutorial on how to enable logging. when I ran the lua and the building in a new mod I got an error in the lua log that pointed me to the line number where the typo was. I took me a minute to spot the error, but it was obvious to me as soon as I spotted it.

The lua log sometimes gives you error messages that are a bit of a head-scratcher trying to figure out what the error really means, but it always points you to the correct line where there is a problem. Many times (at least for me) the problem is a format error in the command, even though the messages are often text such as 'attempt to index a global field ( a nil value)', which often makes me questions my sanity because...well, we aren't supposed to curse on the forum.
 
That one change did it LeeS! The special building now appears on golden ages, and disappears when the golden ages end. Thanks so much! :goodjob: Any other questions I have in the future will be posted in this thread I guess, but the mod right now is functionally finished, now I just need to do some artwork and do some civilopedia entries.
 
Top Bottom