Little help to finally complete my mod civilization

You have a structure like:
Code:
if A then
	SomethingA
elseif B then
	SomethingB
else
	SomethingC
[color="red"]elseif D then
	SomethingD
end[/color]
Lua will evaluate for A, and if A is not true, it will then evaluate for B, and if B is not true, it will execute the "else" clause. The portion in red will never be executed and is I think breaking the if xxx then yyyyy elseif rrrrr then ssssss else zzzzz end structure of a conditional "code-block ".

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

Code:
[1292078.468] Syntax Error: C:\Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\Kingdom of Two Sicilies (v 2)\Mod\TwoSicilies_Decisions.lua:67: ')' expected (to close '(' at line 53) near 'save'
Look more closely at your code and I think you will find you have an extra 'end' in the code at line 65. It does not match-up to the "for" on line 61 nor to the "if" on line 62. Code-breakages like this cause the lua 'parser' to see line number 66 as the terminator for the "function" on line 54, which makes it impossible really for the system to give a 'correct' error report. I have had similar types of errors reported when I forgot the second '=' in '==' but never got an error directly related to the actual problem.

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

Don't be suprised if Events.EndCombatSim.Add(YouWillFollowMeToHell) does not work correctly. My understanding is Events.EndCombatSim will only run if the human player can observe the action of the 'Sim'.

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

Not Sure what other people are currently using to ferret-out code errors.

I look 1st at the code in ModBuddy for errors in syntax like missing </Row> closers in XML. Modbuddy is nearly useless for finding SQL or LUA errors, however. In the images you attached to your post, whatever program you are using to view the code is showing a little "code-block" symbol just to the right of the line-numbers. That vertical line + symbol system is showing you everything that would be successfully assigned to a function within lua. ModBuddy does the same, so in Modbuddy I quickly check for that in my lua files.

I always check the lua.log and the Database.log 1st for any errors in my code. Remember that lua errors show only in the lua.log.

LiveTuner (a part of the SDK that comes with ModBuddy) will also show you the contents of the lua.log in real-time as you run the game and test a mod.

Alternatively you can ALT-TAB from the game to desktop view, open your browser, and use you browser to look at the contents of the lua.log, but this is a poor second to LiveTuner, since it is a lot of fiddling around to get to something LiveTuner will do by default. Also, when using the 'open the lua log in Notepad' method, you only get the contents of the lua.log at the instant you open the log to look at it, and you really need to close the file again before trying to proceed with anything else in-game.
 
Congrats jarcast I've have been following the progress you have been making with LeeS and I'm glad you got it sorted finally. You've been very unfortunate to have LeeS he's one of the best for advice/guidance here a civfanatics imo nice job :goodjob:
 
Congrats jarcast I've have been following the progress you have been making with LeeS and I'm glad you got it sorted finally. You've been very unfortunate to have LeeS he's one of the best for advice/guidance here a civfanatics imo nice job :goodjob:
Houston! I think we have a problem here! The L.E.M. air purifier takes a square cartridge, but the ones from the C.M. are round! HALP! :D
 
Opps, lol, face plant :hammer2:, hmm lets see if we can make that fit Apollo

Congrats jarcast I've have been following the progress you have been making with LeeS and I'm glad you got it sorted finally. You've been very fortunate to have LeeS he's one of the best for advice/guidance here at civfanatics imo :thumbsup:
 
Congrats jarcast I've have been following the progress you have been making with LeeS and I'm glad you got it sorted finally. You've been very un:nono:fortunate to have LeeS he's one of the best for advice/guidance here a civfanatics imo nice job :goodjob:

Thank you onmy6 :D
the best in here i don't know, but the kindest indeed :D

But it is not ended yet. :)
In fact quod erat demonstrandum no lua code is working :wallbash:

But first...

You have a structure like:
Code:
if A then
	SomethingA
elseif B then
	SomethingB
else
	SomethingC
[color="red"]elseif D then
	SomethingD
end[/color]
Lua will evaluate for A, and if A is not true, it will then evaluate for B, and if B is not true, it will execute the "else" clause. The portion in red will never be executed and is I think breaking the if xxx then yyyyy elseif rrrrr then ssssss else zzzzz end structure of a conditional "code-block ".
i dragged it before else, so it should work now
Spoiler :
Code:
			elseif building.SpecialistType == "SPECIALIST_ARTIST" then
				controlTable.BuildingFilledSpecialistSlot1:SetTexture(artistTexture);
				controlTable.BuildingFilledSpecialistSlot2:SetTexture(artistTexture);
				controlTable.BuildingFilledSpecialistSlot3:SetTexture(artistTexture);
			elseif building.SpecialistType == "SPECIALIST_ENGINEER" then
				controlTable.BuildingFilledSpecialistSlot1:SetTexture(engineerTexture);
				controlTable.BuildingFilledSpecialistSlot2:SetTexture(engineerTexture);
				controlTable.BuildingFilledSpecialistSlot3:SetTexture(engineerTexture);
			-- Sneaks Specialist
			elseif building.SpecialistType == "SPECIALIST_PIZZAIOLO" then
				controlTable.BuildingFilledSpecialistSlot1:SetTexture(pizzaioloTexture);
				controlTable.BuildingFilledSpecialistSlot2:SetTexture(pizzaioloTexture);
				controlTable.BuildingFilledSpecialistSlot3:SetTexture(pizzaioloTexture);
			else
				controlTable.BuildingFilledSpecialistSlot1:SetTexture(workerTexture);
				controlTable.BuildingFilledSpecialistSlot2:SetTexture(workerTexture);
				controlTable.BuildingFilledSpecialistSlot3:SetTexture(workerTexture);
			end
		end
Code:
[1292078.468] Syntax Error: C:\Users\Lee\Documents\My Games\Sid Meier's Civilization 5\MODS\Kingdom of Two Sicilies (v 2)\Mod\TwoSicilies_Decisions.lua:67: ')' expected (to close '(' at line 53) near 'save'
Look more closely at your code and I think you will find you have an extra 'end' in the code at line 65. It does not match-up to the "for" on line 61 nor to the "if" on line 62. Code-breakages like this cause the lua 'parser' to see line number 66 as the terminator for the "function" on line 54, which makes it impossible really for the system to give a 'correct' error report. I have had similar types of errors reported when I forgot the second '=' in '==' but never got an error directly related to the actual problem.

fixed

Don't be suprised if Events.EndCombatSim.Add(YouWillFollowMeToHell) does not work correctly. My understanding is Events.EndCombatSim will only run if the human player can observe the action of the 'Sim'.

I would like to understand how events work but i didn't find any reference/tutorial here in and out the forum :\
And I don't think that the good ol' GameEvents.PlayerDoTurn.Add() works for this at all.

In substitution if I'll not be able to write this I was thinking about a promotion that gives incremental strenght the less are the unit's HP up to +50% combact strenght when 1 HP

Spoiler :
Code:
function FightingTillDeath(PlayerID)
	local iPromotion = GameInfoTypes.PROMOTION_TILLDEATH
	local Player = Players[PlayerID]
	local unitHP = pUnit:GetCurrHitPoints()
	local unitMaxHP = pUnit:GetMaxHitPoints()
	local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat
	for pUnit in player:Units() do
		if pUnit:IsHasPromotion(iPromotion) then
			pUnit:SetBaseCombatStrength(iStrength * ( 1 + 0.5 * ((unitMaxHP - unitHP + 1) / unitMaxHP)))
		end
	end
end

GameEvents.PlayerDoTurn.Add(FightingTillDeath)

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

Back to other problems.

1st step: Is it correct?
Spoiler :


2nd step: are the codes correct?

1) Trait

a) +5 (too much) +3 Happiness to coastal cities

I deleted the code and use sql instead putting the dummy building in Trait, FreeBuilding and specifying Water = 1 in Building

Another barely related adjustement: +100% (too much) +35% Tourism from great works in the city from Pizzeria building.

It works :thumbsup:

b) Coastal cities receive 10% of Capital culture output if connected

Code:
function CultureCoast(playerID)
	local pPlayer = Players[playerID]
	local capital = pPlayer:GetCapitalCity()
	local CapitalCulture = capital:GetJONSCulturePerTurn()
	local CultureBonus = math.floor(0.1 * CapitalCulture)
	if (pPlayer:GetCivilizationType() == civilisationID) then
		for city in pPlayer:Cities() do
			if city:IsCoastal() then
				if not city:IsCapital() then
					if (pPlayer:IsCapitalConnectedToCity(city) and not city:IsHasBuilding(GameInfoTypes["BUILDING_CULTCOAST"]) then
						city:SetNumRealBuilding(GameInfoTypes["BUILDING_CULTCOAST"], CultureBonus)
						print("This city now gets +" .. CultureBonus .. " Culture from being connected to the Capital.")
					end
				end
			end
		end
	end
end

c) Give a free policy that turns 100% happiness into science.
(shamelessly copied from JFS's Papal States)

Code:
function HappyScience(playerID)
	for playerID = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
		local pPlayer = Players[playerID]
		if pPlayer:GetCivilizationType() == civilisationID then
			if (not pPlayer:HasPolicy(GameInfoTypes["POLICY_2S_HAPPY_SCIENCE"])) then
				pPlayer:SetNumFreePolicies(1)
				pPlayer:SetNumFreePolicies(0)
				pPlayer:SetHasPolicy(GameInfoTypes["POLICY_2S_HAPPY_SCIENCE"], true)
			end
		end
	end 
end

obsviously
Code:
if isTwoSiciliesCivActive then
	GameEvents.PlayerDoTurn.Add(CultureCoast)
	Events.LoadScreenClose.Add(HappyScience)
end

2) Unique unit

a) +2 Production to the city when garrisoned

Code:
function CivilianWithin(playerID)
	local bBRIGANTE = GameInfoTypes["BUILDING_BRIG_PROD"]
	local pPlayer = Players[playerID]
	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == civilisationID) then
			for city in pPlayer:Cities() do
				local garrison = city:GetGarrisonedUnit()
				if (garrison and garrison:IsHasPromotion(GameInfoTypes["PROMOTION_CIVILIAN_WITHIN"])) then
					city:SetNumRealBuilding(bBRIGANTE, 1)
				else[S][COLOR="Red"]if city:IsHasBuilding(bBRIGANTE) then[/COLOR][/S]
					city:SetNumRealBuilding(bBRIGANTE, 0)
				end
			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(CivilianWithin)

b) +25% combact strenght in plot originally owned by the player (those currently owned and those conquered by others)

Code:
function HomelandClaimant(playerID)
	local player = Players[playerID]
	for pUnit in player:Units() do
		if pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_HOMELAND_CLAIMANT"]) then
			local unitplot = pUnit:GetPlot()
			local cityplot = unitplot:GetPlotCity()
			local orownerplot = cityplot:GetOriginalOwner()
			local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat
				if orownerplot == player then 
					pUnit:SetBaseCombatStrength(math.floor(iStrenght * 1.25))
				else[S][COLOR="Red"]if orownerplot ~= player then[/COLOR][/S] 
					pUnit:SetBaseCombatStrength(iStrenght)
				end
			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(HomelandClaimant)

Adding other irons to the fire

there's a little dark circle round the UU and in certain views also the civ icon

Spoiler :


why this? do i have to remake them?

___________

Last updated version.

EDIT: where are the attachments? xD:
i deleted them from the past post and reattached here, they occupy space but i cannot see neither remve to reupload ._.


EDIT 2 - Chasing them down to the abyss: ok, tutto apposto (it's all right), gone to my account, deleted and reposted.
 

Attachments

  • Kingdom of Two Sicilies (v 2).part1.rar
    10 MB · Views: 32
  • Kingdom of Two Sicilies (v 2).part2.rar
    9.6 MB · Views: 33
I'll try to look at your latest a little later today assuming no one else does beforehand. This morning the forum is really laggy and slow for me.
[edit]
  1. Code:
    function FightingTillDeath(PlayerID)
    	local iPromotion = GameInfoTypes.PROMOTION_TILLDEATH
    	local Player = Players[PlayerID]
    	[color="red"]local unitHP = pUnit:GetCurrHitPoints()
    	local unitMaxHP = pUnit:GetMaxHitPoints()
    	local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat[/color]
    	for pUnit in player:Units() do
    		if pUnit:IsHasPromotion(iPromotion) then
    			pUnit:SetBaseCombatStrength(iStrength * ( 1 + 0.5 * ((unitMaxHP - unitHP + 1) / unitMaxHP)))
    		end
    	end
    end
    
    GameEvents.PlayerDoTurn.Add(FightingTillDeath)
    • "pUnit" hasn't been defined yet so you would get a nil value. If you did not get a nil value, however, grabbing the info where you have would have applied the same set of data for each and every unit that had the required promotion.
    • You need to round-off the result of the calculation for pUnit:SetBaseCombatStrength(iStrength * ( 1 + 0.5 * ((unitMaxHP - unitHP + 1) / unitMaxHP))) since it wants an integer value. Whether you "floor" or "ceiling" is really up to you.
    • Concept-Wise I can't see anything really wrong here other than I think for a nearly-killed unit it won't make a whole lot of difference.
    Change to:
    Code:
    function FightingTillDeath(PlayerID)
    	local iPromotion = GameInfoTypes.PROMOTION_TILLDEATH
    	local Player = Players[PlayerID]
    	for pUnit in player:Units() do
    		if pUnit:IsHasPromotion(iPromotion) then
    			local unitHP = pUnit:GetCurrHitPoints()
    			local unitMaxHP = pUnit:GetMaxHitPoints()
    			local iStrength = math.floor(GameInfo.Units[pUnit:GetUnitType()].Combat * ( 1 + 0.5 * ((unitMaxHP - unitHP + 1) / unitMaxHP)))
    			pUnit:SetBaseCombatStrength(iStrength)
    		end
    	end
    end
    
    GameEvents.PlayerDoTurn.Add(FightingTillDeath)
  2. Here are some of the relevant bits from one of JFD's mods, from his modinfo file, and with non-relevant bits snipped out:
    Code:
      <References>
        <Mod id="7fdd72a5-d4ae-441c-bc4e-2e3d2a26cff4" minversion="0" maxversion="999" title="Ethnic Units" />
        <Mod id="6bc3cb6e-a697-491e-9347-5e3e02640f00" minversion="0" maxversion="999" title="Historical Religions Edit (BNW or GK)" />
        <Mod id="8c101299-95c5-4b28-b7ed-4e0f774857ef" minversion="0" maxversion="999" title="Historical Religions (BNW or GK)" />
        <Mod id="88cf706d-7bf9-431a-b8e1-aa8a8514c462" minversion="0" maxversion="999" title="Community Patch" />
        <Mod id="d1b6328c-ff44-4b0d-aad7-c657f83610cd" minversion="0" maxversion="999" title="DLL - Various Mod Components" />
        <Mod id="1f941088-b185-4159-865c-472df81247b2" minversion="0" maxversion="999" title="Events and Decisions" />
        <Mod id="36e88483-48fe-4545-b85f-bafc50dde315" minversion="0" maxversion="999" title="Yet (not) Another Earth Maps Pack&quot;" />
      </References>
      <Files>
        <File md5="B978FA9120D52C68BCE6E32FA25CF7E7" import="0">Core/Gedemon's YnAEMP Support/CivilizationStartPos.sql</File>
        [color="blue"]<File md5="0A5068BFF4358E657A9F27C8ACEC5601" import="0">Core/Sukritact's Decisions Support/Decisions.sql</File>
        <File md5="CC549B6215DDBC049398D91DFC4BA94F" import="0">Core/Sukritact's Decisions Support/GameText.xml</File>[/color]
        <File md5="00D8391C2809351F62A5AEC803E15E99" import="0">Lua/JFD_NorwayFunctions.lua</File>
        [color="blue"]<File md5="550837BD23EEF21006C7CAE57DF40BA7" import="1">Lua/Sukritact's Decisions Support/JFD_NorwayDecisions.lua</File>[/color]
      </Files>
      <Actions>
        <OnModActivated>
          <UpdateDatabase>Core/Gedemon's YnAEMP Support/CivilizationStartPos.sql</UpdateDatabase>
          [color="blue"]<UpdateDatabase>Core/Sukritact's Decisions Support/Decisions.sql</UpdateDatabase>
          <UpdateDatabase>Core/Sukritact's Decisions Support/GameText.xml</UpdateDatabase>[/color]
        </OnModActivated>
      </Actions>
      <EntryPoints>
        <EntryPoint type="InGameUIAddin" file="Lua/JFD_NorwayFunctions.lua">
          <Name>JFD_CoreFunctions</Name>
          <Description>
          </Description>
        </EntryPoint>
      </EntryPoints>
    • JFD's two SQL files I highlighted are creating two promotions and a policy or two to be used when Events & Decisions is active
    • The lua file (which does not use an "EntryPoint"), is ImportIntoVFS=true.
  3. I think I finally realised what it is you are attempting to do with the file CityView_2S.lua.
    • You are attempting a custom city-view manager to apply only to your civ, I think.
    • What you have in the file CityView_2S.lua is everything from CityView.lua plus your changes.
    • I do not believe you will ever get this to work using a different file-name and adding the lua file as an "EntryPoint". You will forever get what you are getting, I think, which appears to be a clash between the game's standard CityView.lua and your CityView_2S.lua because both are trying to take control of the game's city interface whenever a city view is opened.
    • Generally what is required when you have to make a custom version of one of the game's UI-interface lua files is that you have to use the same exact filename as used by Firaxis, and you use your custom version of the standard file to replace the original Firaxis-made one.
    • Your file would not therefore have an "EntryPoint", and would be ImportIntoVFS=true.
    • Note I have not had a chance to dig into what you are attempting within your file CityView_2S.lua looking to see if I can spot any problems with code. I am only speaking to the modinfo method that needs to be employed.
 
c. Concept-Wise I can't see anything really wrong here other than I think for a nearly-killed unit it won't make a whole lot of difference.

yes, but for example he has +25% combact strenght when half HP, so i don't think it's totally useless :p (it's a classical age unit with 17 cs, so at half hp is +4 = 21, more than a longswordsman)

Code:
    <File md5="00D8391C2809351F62A5AEC803E15E99" import="0">Lua/JFD_NorwayFunctions.lua</File>
    [color="blue"]<File md5="550837BD23EEF21006C7CAE57DF40BA7" import="1">Lua/Sukritact's Decisions Support/JFD_NorwayDecisions.lua</File>[/color]
  • JFD's two SQL files I highlighted are creating two promotions and a policy or two to be used when Events & Decisions is active
  • The lua file (which does not use an "EntryPoint"), is ImportIntoVFS=true.

Relevant part of the mod info file
Code:
[...]
 <File md5="BA0872599F402CFB5EBB2A4C8AA07643" import="1">Core/CityView_2S.lua</File>
    <File md5="803A7C273E6E891F76E3ED9AB0292526" import="0">Core/Civ_ArtDefine.xml</File>
    <File md5="1535D1C06AD0A4B478780BF45FF612F1" import="0">Core/Sql/Civilization.sql</File>
    <File md5="5FCA13D8BB2EF403F5FC4B60FA6E299C" import="0">Core/Sql/Trait_Uniques.sql</File>
    <File md5="E3D1E602B6493E95727618CC1BE464F3" import="0">Core/Sql/Unit_ArtDefines.sql</File>
    <File md5="079DCC4D6918D6F0DC672B939ED13606" import="0">Core/Sql/GameDefines_Diplomacy.sql</File>
    <File md5="C9111508FAE6C1F7E442929AFD344794" import="0">Core/Text/TwoSicilies_GameText.xml</File>
    <File md5="D2F83A7BA5585B77C414342360ACE6C8" import="0">Core/Text/TwoSicilies_GameText_Diplomacy.xml</File>
[COLOR="Blue"]    <File md5="596ED179EDA3723E60AC16A40DDF28F2" import="1">Core/TwoSicilies_Functions.lua</File>
    <File md5="B9F49DEBE7D6EF1DCDA43EE21B594E69" import="1">Mod/TwoSicilies_Decisions.lua</File>
    <File md5="9476EDBFAF76F5D891A7F2FC51BB78A8" import="1">Mod/TwoSicilies_Events.lua</File>[/COLOR]
    <File md5="F88043CA1BC812673ED70DB7C5DAC441" import="0">Mod/TwoSicilies_GameDefines_ModSupport.sql</File>
    <File md5="FD4EDED99CC91B595F1DC11BA2FCC039" import="0">Mod/TwoSicilies_GameText_ModSupport.xml</File>
  </Files>
  <Actions>
    <OnModActivated>
      <UpdateDatabase>Core/Sql/Civilization.sql</UpdateDatabase>
      <UpdateDatabase>Core/Sql/Trait_Uniques.sql</UpdateDatabase>
      <UpdateDatabase>Core/Sql/Unit_ArtDefines.sql</UpdateDatabase>
      <UpdateDatabase>Core/Sql/GameDefines_Diplomacy.sql</UpdateDatabase>
      <UpdateDatabase>Mod/TwoSicilies_GameDefines_ModSupport.sql</UpdateDatabase>
      <UpdateDatabase>Core/Text/TwoSicilies_GameText.xml</UpdateDatabase>
      <UpdateDatabase>Core/Text/TwoSicilies_GameText_Diplomacy.xml</UpdateDatabase>
      <UpdateDatabase>Mod/TwoSicilies_GameText_ModSupport.xml</UpdateDatabase>
      <UpdateDatabase>Core/Civ_ArtDefine.xml</UpdateDatabase>
    </OnModActivated>
  </Actions>
  <EntryPoints>
    <EntryPoint type="InGameUIAddin" file="Core/CityView_2S.lua">
      <Name>CityView_2S</Name>
      <Description>CityView_2S</Description>
    </EntryPoint>
    <EntryPoint type="InGameUIAddin" file="Mod/TwoSicilies_Events.lua">
      <Name>Sukritact's Events</Name>
      <Description>Sukritact's Events</Description>
    </EntryPoint>
    <EntryPoint type="InGameUIAddin" file="Mod/TwoSicilies_Decisions.lua">
      <Name>Sukritact's Decisions</Name>
      <Description>Sukritact's Decisions</Description>
    </EntryPoint>
    <EntryPoint type="InGameUIAddin" file="Core/TwoSicilies_Functions.lua">
      <Name>Core Functions</Name>
      <Description>Core Functions</Description>
    </EntryPoint>
  </EntryPoints>

So because I put them in the entry point I shall write import="0" in their relative entries?
Even so the two Decisions appeared in the city view (although I dunno if they actually work since in such game i was not in the industrial age yet and i don't want to trigger it manually by IGE).
The Events, instead, happened never once, but i think it's because i didn't really understand the stuff regarding the weight number: is it that like the higher the more likely to happen?

Spoiler :
Reference from Sukritact
The Weight is REQUIRED. Excluding the weight will ensure that the Event is never triggered by the Random Events system, in which case, there&#8217;s no point adding it to the tEvents table. Understanding what Weight actually does requires a basic understanding of the system:

&#8220;Each player has a &#8220;Random Event Level&#8221;, on every turn, a random number between 0 and 19 is added to this tally unless the tally already exceeds the average number of turns between events * 10, which is 250 (25 turns between events) by default (this number changes according to game speed). If the number already exceeds 250, for events where the CanFunc == nil OR returns true, the event is entered into a pool the same number of times as specified by the weight. A single event is drawn from that pool and that decision is triggered. In other words, the whole thing is basically a Lucky Draw.&#8221;

Example from my codes

Code:
--------------------------------------------------------------------------------------------------------------------------
--  Immigration
--------------------------------------------------------------------------------------------------------------------------
local Event_Immigration = {}
	Event_Immigration.Name = "TXT_KEY_EVENT_TWOSICILIES_IMMIGRATION"
	Event_Immigration.Desc = "TXT_KEY_EVENT_TWOSICILIES_IMMIGRATION_DESC"
	[B][COLOR="Blue"]Event_Immigration.Weight = 10[/COLOR][/B]
	Event_Immigration.CanFunc = (
		function(player)	
			if load(player, "Event_Immigration") == true	then return false end
			if player:GetCivilizationType() ~= civilisationID			then return false end
			if player:GetExcessHappiness() > 20 								then return false end
			local cities = {}
			cityID = nil

			local count = 1
			for city in player:Cities() do
				cities[count] = city:GetID()
				count = count + 1
			end

			cityID = cities[GetRandom(1, #cities)]
			if cityID == nil then return false end
			
			Event_Immigration.Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_TWOSICILIES_IMMIGRATION_DESC", player:GetCityByID(cityID):GetName())
			return true
		end
		)
	Event_Immigration.Outcomes = {}
[other stuff below]
Code:
--------------------------------------------------------------------------------------------------------------------------
-- Vesuvius Eruption
--------------------------------------------------------------------------------------------------------------------------
local eraIndustrialID					= GameInfoTypes["ERA_INDUSTRIAL"]

local Event_VesuviusEruption = {}
	Event_VesuviusEruption.Name = "TXT_KEY_EVENT_TWOSICILIES_VESUVIUS_ERUPTION"
	Event_VesuviusEruption.Desc = "TXT_KEY_EVENT_TWOSICILIES_VESUVIUS_ERUPTION_DESC"
	[B][COLOR="Blue"]Event_VesuviusEruption.Weight = 10[/COLOR][/B]
	Event_VesuviusEruption.CanFunc = (
		function(player)			
			Event_VesuviusEruption.Desc = "TXT_KEY_EVENT_TWOSICILIES_VESUVIUS_ERUPTION_DESC"
			if player:GetCivilizationType() ~= civilisationID	then return false end
		
			local cities = {}
			cityID = nil

			local count = 1
			for city in player:Cities() do
				cities[count] = city:GetID()
				count = count + 1
			end

			cityID = cities[GetRandom(1, #cities)]
			if cityID == nil then return false end
			
			Event_VesuviusEruption.Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_TWOSICILIES_VESUVIUS_ERUPTION_DESC", player:GetCityByID(cityID):GetName())
			return true
		end
		)
	Event_VesuviusEruption.Outcomes = {}
[other stuff below]

3. I think I finally realised what it is you are attempting to do with the file CityView_2S.lua.
  • You are attempting a custom city-view manager to apply only to your civ, I think.
  • What you have in the file CityView_2S.lua is everything from CityView.lua plus your changes.
  • I do not believe you will ever get this to work using a different file-name and adding the lua file as an "EntryPoint". You will forever get what you are getting, I think, which appears to be a clash between the game's standard CityView.lua and your CityView_2S.lua because both are trying to take control of the game's city interface whenever a city view is opened.
  • Generally what is required when you have to make a custom version of one of the game's UI-interface lua files is that you have to use the same exact filename as used by Firaxis, and you use your custom version of the standard file to replace the original Firaxis-made one.
  • Your file would not therefore have an "EntryPoint", and would be ImportIntoVFS=true.
  • Note I have not had a chance to dig into what you are attempting within your file CityView_2S.lua looking to see if I can spot any problems with code. I am only speaking to the modinfo method that needs to be employed.

mmm ok so if it's in entry point it has to be import="0" and if not then import="1"
what is the difference?

And I used this reference to make specialists.

So at the end of the day, it should be this:

Code:
[...]
[COLOR="Blue"] <File md5="BA0872599F402CFB5EBB2A4C8AA07643" import="[COLOR="Red"]0[/COLOR]">Core/CityView[COLOR="Red"][S]_2S[/S][/COLOR].lua</File>[/COLOR]
    <File md5="803A7C273E6E891F76E3ED9AB0292526" import="0">Core/Civ_ArtDefine.xml</File>
    <File md5="1535D1C06AD0A4B478780BF45FF612F1" import="0">Core/Sql/Civilization.sql</File>
    <File md5="5FCA13D8BB2EF403F5FC4B60FA6E299C" import="0">Core/Sql/Trait_Uniques.sql</File>
    <File md5="E3D1E602B6493E95727618CC1BE464F3" import="0">Core/Sql/Unit_ArtDefines.sql</File>
    <File md5="079DCC4D6918D6F0DC672B939ED13606" import="0">Core/Sql/GameDefines_Diplomacy.sql</File>
    <File md5="C9111508FAE6C1F7E442929AFD344794" import="0">Core/Text/TwoSicilies_GameText.xml</File>
    <File md5="D2F83A7BA5585B77C414342360ACE6C8" import="0">Core/Text/TwoSicilies_GameText_Diplomacy.xml</File>
[COLOR="Blue"]    <File md5="596ED179EDA3723E60AC16A40DDF28F2" import="[COLOR="Red"]0[/COLOR]">Core/TwoSicilies_Functions.lua</File>
    <File md5="B9F49DEBE7D6EF1DCDA43EE21B594E69" import="1">Mod/TwoSicilies_Decisions.lua</File>
    <File md5="9476EDBFAF76F5D891A7F2FC51BB78A8" import="1">Mod/TwoSicilies_Events.lua</File>[/COLOR]
    <File md5="F88043CA1BC812673ED70DB7C5DAC441" import="0">Mod/TwoSicilies_GameDefines_ModSupport.sql</File>
    <File md5="FD4EDED99CC91B595F1DC11BA2FCC039" import="0">Mod/TwoSicilies_GameText_ModSupport.xml</File>
  </Files>
  <Actions>
    <OnModActivated>
      <UpdateDatabase>Core/Sql/Civilization.sql</UpdateDatabase>
      <UpdateDatabase>Core/Sql/Trait_Uniques.sql</UpdateDatabase>
      <UpdateDatabase>Core/Sql/Unit_ArtDefines.sql</UpdateDatabase>
      <UpdateDatabase>Core/Sql/GameDefines_Diplomacy.sql</UpdateDatabase>
      <UpdateDatabase>Mod/TwoSicilies_GameDefines_ModSupport.sql</UpdateDatabase>
      <UpdateDatabase>Core/Text/TwoSicilies_GameText.xml</UpdateDatabase>
      <UpdateDatabase>Core/Text/TwoSicilies_GameText_Diplomacy.xml</UpdateDatabase>
      <UpdateDatabase>Mod/TwoSicilies_GameText_ModSupport.xml</UpdateDatabase>
      <UpdateDatabase>Core/Civ_ArtDefine.xml</UpdateDatabase>
    </OnModActivated>
  </Actions>
  <EntryPoints>
[COLOR="Blue"]    <EntryPoint type="InGameUIAddin" file="Core/CityView[COLOR="Red"][S]_2S[/S][/COLOR].lua">
      <Name>CityView_2S</Name>
      <Description>CityView_2S</Description>
    </EntryPoint>[/COLOR]
[COLOR="Red"][S]    <EntryPoint type="InGameUIAddin" file="Mod/TwoSicilies_Events.lua">
      <Name>Sukritact's Events</Name>
      <Description>Sukritact's Events</Description>
    </EntryPoint>
    <EntryPoint type="InGameUIAddin" file="Mod/TwoSicilies_Decisions.lua">
      <Name>Sukritact's Decisions</Name>
      <Description>Sukritact's Decisions</Description>
    </EntryPoint>[/S][/COLOR]
[COLOR="Blue"]    <EntryPoint type="InGameUIAddin" file="Core/TwoSicilies_Functions.lua">
      <Name>Core Functions</Name>
      <Description>Core Functions</Description>
    </EntryPoint>[/COLOR]
  </EntryPoints>

... right?

EDIT: yay, the updated city view now is working! ...hem... more or less...

Spoiler :
 
  1. [Nevermind this #1, I think you have it correct now]

    Look again at what JFD did for the decisions/events (even though he did not add anything in the mod for the events side).
    • He had "import=1", and did not have an "EntrryPoint".
    • He also had a reference to the Events&Decisions mod, so that Events&Decisions will load 1st when the two mods are enabled at the same time.
  2. whoward69's zip your mods and attach tutorial
    • If you examine the OP on whoward's thread you will see that no single file (lua or otherwise) has more than one "activation" method.
    • import=1 is a file activation method
    • <UpdateDatabase> is a file activation method
    • EntryPoint is a file activation method
    • Reread my previous post (especially 3e). Your version of CityView.lua needs to be
      • import=1
      • it should not have an entry point
  3. I would interpret Sukritact's instructions as the higher the "weight" number the more likely the event will occur. But remember as he also said you are looking at Random Numbers and luck.
  4. From [TUTORIAL] Creating New Specialists by Sneaks

    Step 4: Getting the Suckers into the Lua

    .Lua is pretty rough for most people so I included my CityView.lua file to work with.

    First step, add the CityView.lua to your Mod, and go into properties, and set that suckers Import into VFS to True.
    and later on:
    Remember, you do NOT want to add CityView.lua to the Actions or Content menu, but DO want to add your Icon Atlas update to the Actions menu as an OnModActivated.
    • "Actions" = <Actions> in the modinfo file
    • "Content" = <EntryPoints> in the modinfo file
    Also, now that I think of it I am not sure I saw an IconTextureAtlases or set of dds files for your new specialist, but this may be because I simply missed it when looking over your mod to see where everything was within the folders of your mod.
  5. Clash Issues:
    • If you are using EUI I think it has it's own version of CityView.lua, and your version might be clashing.
    • If you last used the settings shown in post #27 you are still creating a clash between the game's standard CityView.lua and your version you are telling to game to execute via the "EntryPoint" setting.
 
It's really cool that all these people are helping you, but I have to ask- this civ seems like it'd be really over powered... Excess happiness is science? That's huge at the beginning of the game. If you don't need open borders to enter enemy territory, are you still expelled on DoW or can you just move your navy into position before DoW?
 
I totally deleted the CityView file, it is not worth the effort.
The only difference now is that the specialist slot will appear empty (black) even if it is actually used (it can be seen because if you count the number of citizens then switch to "manual specialist" then another one appears, meaning that the pizzeria slot was used but the citizen was not "lighted").

So now the greatest problem left is that my core function lua doesn't work :\ even with entrypoint and import="0".

EDIT:
It's really cool that all these people are helping you, but I have to ask- this civ seems like it'd be really over powered... Excess happiness is science? That's huge at the beginning of the game. If you don't need open borders to enter enemy territory, are you still expelled on DoW or can you just move your navy into position before DoW?

In fact I'm doing some games as test and I've already nerfed two characteristics:
1) +5 -> +3 global happiness per coastal city;
2) +100% -> +35% tourism from great works in cities with pizzeria building.

Much probably i'll pass from 100% to 50% happiness to science or even lower if i manage to get the code working first and to evaluate how much op it is.

As alternative i thought to put a simple +20% culture and science in coastal cities if lua keeps not working.
 
So now the greatest problem left is that my core function lua doesn't work :\ even with entrypoint and import="0".
These settings in the modinfo are going to ensure that the file is activated properly, but if the code within the file still contains errors, then the lua will seem like it is not being used by the game. It actually is being used, but it is either crashing when the game loads the mod, or it is crashing in real-time when the functions within the file try to run.
 
It's really cool that all these people are helping you, but I have to ask- this civ seems like it'd be really over powered... Excess happiness is science? That's huge at the beginning of the game. If you don't need open borders to enter enemy territory, are you still expelled on DoW or can you just move your navy into position before DoW?

Yeah, the civ kinda suffers from feature creep. It has way too many things, too strong things, going on. But I guess that's not what is being discussed here right now.
 
I found that I missed a ")" here

Code:
function CultureCoast(playerID)
	local pPlayer = Players[playerID]
	if (pPlayer:GetCivilizationType() == civilisationID) then
		for city in pPlayer:Cities() do
			if city:IsCoastal() then
				if not city:IsCapital() then
					local capital = pPlayer:GetCapitalCity()
					local CapitalCulture = capital:GetJONSCulturePerTurn()
					local CultureBonus = math.floor(0.1 * CapitalCulture)
					if (pPlayer:IsCapitalConnectedToCity(city) and not city:IsHasBuilding(GameInfoTypes["BUILDING_CULTCOAST"])[B][COLOR="Red"])[/COLOR][/B] then
						city:SetNumRealBuilding(GameInfoTypes["BUILDING_CULTCOAST"], CultureBonus)
					end
				end
			end
		end
	end
end

can the lack of this single bracket mess up everything follows?

Another question: do you know where can I find the portrait indexes of the promotions?

Yeah, the civ kinda suffers from feature creep. It has way too many things, too strong things, going on. But I guess that's not what is being discussed here right now.

When I imagined the UA I had really no idea of the magnitude of the effects in game.
So when I get everything working, I'll see what to nerf and what to remove.
If I see that "rival territory" promotion is op, I'll remove it giving instead +1 Sight and +1 movement to ships.
If I see that happiness to science is unbalanced, i.e to much in the early game and useless from middle-late game, I'll remove it and give another science buff (+20% science to coastal cities maybe).

Originally instead of happiness to science my idea was to give a science buff equal to 5% production cost of the possessed naval units.
So for example you have 3 Trireme? Then 45 :c5production: (standard speed) --> 2 :c5science: ---> 3*2 = +6 :c5science: Science globally from ships.

Imho I prefer this but I have absolutely no idea how to write it by lua correctly.
If someone knows and wants to help, is welcome. :)
 
What bothers me the most actually is the +5 Happiness in Coastal Cities, which by itself is incredibly powerful, in conjunction with the Science boost through Happiness. The Pizzeria having a zillion effects doesn't help much either.
 
I found that I missed a ")" here



LeeS Highlighted:can the lack of this single bracket mess up everything follows?
Another question: do you know where can I find the portrait indexes of the promotions?



When I imagined the UA I had really no idea of the magnitude of the effects in game.
So when I get everything working, I'll see what to nerf and what to remove.
If I see that "rival territory" promotion is op, I'll remove it giving instead +1 Sight and +1 movement to ships.
If I see that happiness to science is unbalanced, i.e to much in the early game and useless from middle-late game, I'll remove it and give another science buff (+20% science to coastal cities maybe).

Originally instead of happiness to science my idea was to give a science buff equal to 5% production cost of the possessed naval units.
So for example you have 3 Trireme? Then 45 :c5production: (standard speed) --> 2 :c5science: ---> 3*2 = +6 :c5science: Science globally from ships.

Imho I prefer this but I have absolutely no idea how to write it by lua correctly.
If someone knows and wants to help, is welcome. :)

To answer the question highlighted in blue. Missing ")", "=", etc., where required will make the entire file fail in one way or another.
  • If it is a missing character that creates a code-syntax-error, the entire file will be rejected by the game's lua 'parser'.
  • If it merely creates unintended results from a math formula, for example, you can get wildly different results in-game than anticipated.
  • If you forget to pre-define a variable before you try to use it within a function, you will not get a syntax "fatal error" -- the code will load into the game's lua system, but when the event tries to run, the undefined variable will be seen by the game as having a value of "nil", and you will normally get a run-time error relating to a nil value trying to "index" something. This behavior of setting the undefined variable to a value of "nil" is a feature of lua, not something that Firaxis invented. You get the same sort of behavior if you make a little test program and use this to test it. Just bear in mind that the lua demo page does not understand CIV5-specific stuff like "city" or "player", or game events.
 
To answer the question highlighted in blue. Missing ")", "=", etc., where required will make the entire file fail in one way or another.
  • If it is a missing character that creates a code-syntax-error, the entire file will be rejected by the game's lua 'parser'.
  • If it merely creates unintended results from a math formula, for example, you can get wildly different results in-game than anticipated.
  • If you forget to pre-define a variable before you try to use it within a function, you will not get a syntax "fatal error" -- the code will load into the game's lua system, but when the event tries to run, the undefined variable will be seen by the game as having a value of "nil", and you will normally get a run-time error relating to a nil value trying to "index" something. This behavior of setting the undefined variable to a value of "nil" is a feature of lua, not something that Firaxis invented. You get the same sort of behavior if you make a little test program and use this to test it. Just bear in mind that the lua demo page does not understand CIV5-specific stuff like "city" or "player", or game events.

Oh! Thank you very much!
Thanks to this checker I found that in the last code (function HomelandClaimant) I put an end more than necessary, whereas the others have already been ok.

Now that the syntax are correct everything should works, but actually...

  1. :c5happy: the function that enables the science-boosting policy works. And now I understand the complains: I knew that HappinessToScience meant that added the extrahappiness as science (e.g. 100% * +5 Happiness = +5 Science) but instead it adds x% science from global generated science when excess happiness > 0.
    Yes, now that I see I agree that 100% is too fu**ing OP. :eek:
    Well, I think +1 Happiness from coastal cities and 20% Happiness to Science are enough.
  2. :c5unhappy: the function that adds to coastal cities +1 culture dummy buildings according to 10% culture of the capital doesn't work;
  3. :c5happy: the function that adds a dummy building giving +2 production to city when the uu is garrisoned works but i have to wait the next turn until it activates/disactivates;
  4. :c5unhappy: the function that gives +25% combact strenght in originally owned lands (i.e. only cities founded by player regardless of the last owner) doesn't work.

bonus: the custom decision appears...
Spoiler :


...but the moment they are enactable everything disappear...
Spoiler :
 
For the deal with the decisions you might want to see if Sukritact can give you some guidance on using his (her?) system. Obviously you have something not correct in your decisions code, but I am not sure where to look within that part of your code for a mistake that would be causing that result.

#3 is normal behavior when using PlayerDoTurn as your GameEvent. PlayerDoTurn runs only when you press NEXT TURN.
#2 I would need to see the current version of the code to try to figure out what is wrong. To make less "stuff" to look at you could copy the current version of the lua, and the current version of the SQL/XML file where the dummy building is defined into a folder and only zip those two, and attach. The actual files rather than snippets from the files is better.
 
EDIT:
I've decided to do the following changes:

UA: Land of the Sun
  • +3 +2 happiness from coastal cities;
  • 30% science when excess happiness;
  • +10% +15% of Capital culture output to connected coastal cities;
  • +50% production towards ships;
  • Navy promotion: +1 movement, +1 sight, can enter rival territory;
  • Ships give science equal to the 5% of their production cost.

UB: Pizzeria
  • +2 Happiness (as zoo);
  • +2 food;
  • +35% tourism from great works in the city;
  • 1 specialist slot.

UU: Brigante
  • -5 -3 combact strenght than Cavalry;
  • +2 production to the city where garrisoned;
  • can repair pillaged improvements;
  • +25% combact strenght when in plots originally owned by thw player.

I'm working to the code that gives Science = 5% ship production cost.
Albeit lua demo says it's all ok I'm sure there are errors, can you please check it?
How can I make this bonus show in the toolbar view e.g. "+x :c5science: is added from owned naval units" ?

EDIT2! (inspired by Pouakai's Tibet civ)
Code:
function GetScienceFromShips(pPlayer)
	local SciencePT = math.floor(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_GALLEY"].ID) * GameInfo.UnitClasses["UNITCLASS_GALLEY"].Cost * 0.05);
	SciencePT = SciencePT + math.floor(0.05 * (
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_TRIREME"].ID) * GameInfo.UnitClasses["UNITCLASS_TRIREME"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_GALLEASS"].ID) * GameInfo.UnitClasses["UNITCLASS_GALLEASS"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_CARAVEL"].ID) * GameInfo.UnitClasses["UNITCLASS_CARAVEL"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_FRIGATE"].ID) * GameInfo.UnitClasses["UNITCLASS_FRIGATE"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_PRIVATEER"].ID) * GameInfo.UnitClasses["UNITCLASS_PRIVATEER"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_IRONCLAD"].ID) * GameInfo.UnitClasses["UNITCLASS_IRONCLAD"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_DESTROYER"].ID) * GameInfo.UnitClasses["UNITCLASS_DESTROYER"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_BATTLESHIP"].ID) * GameInfo.UnitClasses["UNITCLASS_BATTLESHIP"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_SUBMARINE"].ID) * GameInfo.UnitClasses["UNITCLASS_SUBMARINE"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_CARRIER"].ID) * GameInfo.UnitClasses["UNITCLASS_CARRIER"].Cost) +
	(player:GetUnitClassCount(GameInfo.UnitClasses["UNITCLASS_NUCLEAR_SUBMARINE"].ID) * GameInfo.UnitClasses["UNITCLASS_NUCLEAR_SUBMARINE"].Cost)
	))
	return SciencePT
end

function ShipScience(playerID)
	print("science from ships check");
	local pPlayer = Players[playerID]
	local Sciboost = GetScienceFromShips(pPlayer)
	print("science: " .. Sciboost);	
	if pPlayer:GetCivilizationType() == civilisationID then
		local Research = pPlayer:GetCurrentResearch()
		local fTeamID = pPlayer:GetTeam();
		local fTeam = Teams[fTeamID];
		local fTeamTechs = fTeam:GetTeamTechs();
		fTeamTechs:ChangeResearchProgress(Research, Sciboost, playerID)
	end
end

GameEvents.PlayerDoTurn.Add(ShipScience)
Here the files
 

Attachments

  • sql+lua.rar
    3.6 KB · Views: 28
Your code for function CultureCoast(playerID) is running just fine as-is for me.

Bear in mind that at 15% of the Capital's culture, the Capital would have to generate 7 Culture before any buildings are added. "math.floor" also comes into effect in requiring a 7:1 ratio, as 6 * .15 = 0.90 and will be rounded down to '0'.

The outlaying city must have a road/railroad/harbor connection to the capital, and the player must have the tech appropriate for the connection-type. So for testing code, if you added roads between a Capital and Outlaying Coastal city, but did not add Tech_Wheel to the player, there would be no effect.

Haven't looked too closely at the other stuff in your previous, but you have mismatch between pPlayer and player in that function that is calculating an amount of science to add based on the number of naval units.

"Directly Editing" the top panel displays requires editing the TopPanel.lua in one form or another. JFD has a Dynamic Top Panel utility he has offered on the forum (it would be in the utilities sub-forum, I would guess) but I haven't looked into it yet to see how it works.
 
Top Bottom