Help - Improvement generates dummy building

Luxius

Chieftain
Joined
Apr 5, 2015
Messages
12
First, I've been trying to use .lua for some time but I'm not sure if I'm just terrible at making it work or if I need to activate it somewhere (like associations for .xml). Do it need to be imported into VFS or do I need to add it in content as InGameUIAddin (and if I need to, is it supposed to not appear in the options?)?

Now the real question,

I tried to make a small change in some of Damasc's (and JFD) code to make a custom improvement (in the Civilization territory) creates a dummy building in a city (effect stacks):

Code:
local civilisationID = GameInfoTypes["CIVILIZATION_OLD_ONES"]
------------------------------------------------------------------------------------------------------------------------
-- Sholds
------------------------------------------------------------------------------------------------------------------------
function Sholds(playerID)
	local player = Players[playerID]
	if player:IsAlive() and player:GetCivilizationType() == civilizationID then
		for pCity in pPlayer:Cities() do
			local iNumPlots = pCity:GetNumCityPlots()
			for i = 0, iNumPlots - 1 do
				local pPlot = pCity:GetCityIndexPlot(i)
				if pPlot and pPlot:GetOwner() == iPlayer then
					if pPlot:GetImprovementType() == GameInfoTypes.IMPROVEMENT_STRONGHOLD then
						city:SetNumRealBuilding(GameInfoTypes["BUILDING_ELDERSCI"], 1)
					end
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(Sholds)

It doesn't work and I'm not sure why...




PS.: If you have difficulty understanding something I said because of the grammar, pls tell me so I can try to explain it better. English is not my native language >.>
 

Attachments

You have mismatch between pCity in line # 8 and city in line #14. pCity and city need to be named the same, and as a general rule should use the form specified on the line
Code:
for [COLOR="Blue"]pCity[/COLOR] in pPlayer:Cities() do

Further than this I cannot diagnose without the actual mod to look at. See whoward's tutorial on what to zip and attach to a thread reply so we can look at the code: whoward69's zip your mods and attach tutorial

Yes, this lua script also needs to be specified as an InGameUIAddin: whoward69's what ModBuddy setting for what file types tutorial see post #3
 
You have mismatch between pCity in line # 8 and city in line #14. pCity and city need to be named the same, and as a general rule should use the form specified on the line
Code:
for [COLOR="Blue"]pCity[/COLOR] in pPlayer:Cities() do

Further than this I cannot diagnose without the actual mod to look at. See whoward's tutorial on what to zip and attach to a thread reply so we can look at the code: whoward69's zip your mods and attach tutorial

Yes, this lua script also needs to be specified as an InGameUIAddin: whoward69's what ModBuddy setting for what file types tutorial see post #3

Thank you! I edited the main post with the mod (still doesn't work >.>)
 
You still had multiple mis-matches of variable names. See the color-coding for what needs to match to each other. Also, double-check that I did not miss any more of these errors in your code (this is your code as included in the attached version of the mod, each color-group has one mis-match in naming):
Code:
local [color="red"]civilisationID[/color] = GameInfoTypes["CIVILIZATION_OLD_ONES"]
------------------------------------------------------------------------------------------------------------------------
-- StrongSci
------------------------------------------------------------------------------------------------------------------------
function Sholds([color="green"]playerID[/color])
	local [color="blue"]player[/color] = Players[[color="green"]playerID[/color]]
	if [color="blue"]player[/color]:IsAlive() and [color="blue"]player[/color]:GetCivilizationType() == [color="red"]civilizationID[/color] then
		for pCity in [color="blue"]pPlayer[/color]:Cities() do
			local iNumPlots = pCity:GetNumCityPlots()
			for i = 0, iNumPlots - 1 do
				local pPlot = pCity:GetCityIndexPlot(i)
				if pPlot and pPlot:GetOwner() == [color="green"]iPlayer[/color] then
					if pPlot:GetImprovementType() == GameInfoTypes.IMPROVEMENT_STRONGHOLD then
						pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_ELDERSCI"], 1)
					end
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(Sholds)
 
You've localised civilisationID, but checks GetCivilizationType with CivilizationID, which will never return true..

EDIT: Just noticed that LeeS already noted that - I didn't read through his entire post. Sorry.
 
I fixed it and now it works, but, how can I make the building go only to the capital and relocate when it falls to the enemy?



I tried to add a code from Vicevirtuoso (City of Heroes Civilizations mod) too and now I broke the mod. It happens when I try to add the new camp (<VictoryPointsPerStrengthPoint>) in trait.xml

I got this error
Code:
[16108.953] Runtime Error: Assets\UI\FrontEnd\GameSetup\GameSetupScreen.lua:492: attempt to index local 'trait' (a nil value)

:confused:
 

Attachments

  • You can't just make up a name of a column and stick it into the xml.
  • In order to add a new column-name to an existing game-table:
    1. You need a line in SQL that alters the original definition of the game-table by adding the new column.
      Code:
      ALTER TABLE Traits ADD COLUMN 'VictoryPointsPerStrengthPoint' INTEGER DEFAULT 0;
      This would need to be higher-up in the list of UpdateDatabase commands in Modbuddy than your file that defines the new Trait.
    2. Then you need lua to make the game do anything with the values you specify for the new column you have added.
  • You should also have seen an error in the Database.log telling you there is no such column as "VictoryPointsPerStrengthPoint" in table "Traits".
  • There is a lot more going on within the City of Heroes mod from which you borrowed that than what you realised. The line of SQL code I quoted is directly copied from the file "COHTraitTableUpdate.sql" within that mod.
 
  • You can't just make up a name of a column and stick it into the xml.
  • In order to add a new column-name to an existing game-table:
    1. You need a line in SQL that alters the original definition of the game-table by adding the new column.
      Code:
      ALTER TABLE Traits ADD COLUMN 'VictoryPointsPerStrengthPoint' INTEGER DEFAULT 0;
      This would need to be higher-up in the list of UpdateDatabase commands in Modbuddy than your file that defines the new Trait.
    2. Then you need lua to make the game do anything with the values you specify for the new column you have added.
  • You should also have seen an error in the Database.log telling you there is no such column as "VictoryPointsPerStrengthPoint" in table "Traits".
  • There is a lot more going on within the City of Heroes mod from which you borrowed that than what you realised. The line of SQL code I quoted is directly copied from the file "COHTraitTableUpdate.sql" within that mod.

  • I see. I tried to find the things related to this script and didn't notice the "Shared" folder... tought the .lua would made it possible to put it here.

  • I checked the Database, xml and lua logs but only the lua one was showing an erro for some reason...

  • By "a lot more going on within the City of Heroes mod", do you mean about this script or just in general? Because I did q quick check-up before trying to get what I needed and the other scripts didn't seem related :confused:
 
I meant about the SQL file/xml-Traits/lua combination ViceV is using.

And I only made that comment because I quite commonly see people borrowing one element from another mod without the borrower realizing that the mod contains three or more components each of which is required to make the borrowed element work.
 
The "Victory Points = Combat Strenght" is not working for some reason. The mod is loading normally now (no crashes, weird traits or anything like that) but I still get nothing ._.
 

Attachments

If lua-file "A.lua" appears anywhere in an include statement within another lua-file, then "A.lua" must be set as VFS=true and should not have an "EntryPoint". whoward69's what ModBuddy setting for what file types tutorial

From file "VtSMain.lua"
Code:
include('VictoryToStr.lua');
modinfo file:
Code:
    <File md5="33F24EA58287CB3FF68132DE187CA972" import="0">LUA/VtSMain.lua</File>
    <File md5="E619A7F0B888E14103C8A144767D8E95" import="0">LUA/Stronghold.lua</File>
    <File md5="5737B255830CE7799E43F18B2B0CC332" import="[COLOR="Red"][B]0[/B][/COLOR]">LUA/VictoryToStr.lua</File>
and
Code:
  <EntryPoints>
    <EntryPoint type="InGameUIAddin" file="LUA/Stronghold.lua">
      <Name>Elder Trait</Name>
      <Description>Elder Trait</Description>
    </EntryPoint>
    [COLOR="Red"][B]<EntryPoint type="InGameUIAddin" file="LUA/VictoryToStr.lua">
      <Name>VP to Str</Name>
      <Description>VP = Combat Str</Description>
    </EntryPoint>[/B][/COLOR]
    <EntryPoint type="InGameUIAddin" file="LUA/VtSMain.lua">
      <Name>VP = CStr Main</Name>
      <Description>Vp = Cbt Str Main</Description>
    </EntryPoint>
  </EntryPoints>
 
A new erro has appeared :D (better than nothing)

Code:
[54782.265] Runtime Error: C:\Users\Usuario\Documents\My Games\Sid Meier's Civilization 5\MODS\Elderan Civilization (v 10)\LUA\VictoryToStr.lua:9: attempt to index global 'tTraits' (a nil value)
 

Attachments

That message is telling me that "tTraits" has not previously been given a value. The "t" part at the beginning is usually meant to signify it is an lua-table. Either the table is empty (nothing has been inserted into the table) or the code that would construct the lua-table is not recieving anything so the lua-table remains defined as an empty table.

I would think you would want to ask ViceV whether he is willing to help you out on understanding what it is you are doing incorrectly in making his VictoryPointsPerStrengthPoint system work. Probably better to ask on his civs thread if he is able to help you out. If I were doing so, I would also add a cross-link to this thread.

It isn't clear to me what it is you are doing wrong in using the system from ViceV's CoH mod.
 
Back
Top Bottom