Improvement doubles luxury resource

For your second function, I'm pretty sure its dependent function DMS_MetalExport() is not returning any results for your function to use because you've specified this:
Code:
GameInfoTypes["Resource_Iron"]
Pretty sure it needs to be capitalized, otherwise it won't find the resource you're looking for:
Code:
GameInfoTypes["RESOURCE_IRON"]
Yup.
Has to be as used by Firaxis. Capitalization is important.

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

Danmacsch,

I was trying earlier today to find the documentation on the UnitPreKill in the wiki and on the two threads I know of where API methods and Hooks are listed, but didn't see it. This is aggravating for me because I know I've seen it discussed before.

I was trying to double-check whether it is an "Event" as opposed to a "GameEvent". The two are not the same, and if you try to "hook-up" your function under the wrong type, nothing will happen.
 
I was trying to double-check whether it is an "Event" as opposed to a "GameEvent". The two are not the same, and if you try to "hook-up" your function under the wrong type, nothing will happen.

It's a GameEvent.
I'm using it for the Shana Civ's Lua.
 
I've tried looking through your code from the Shana civ.

It just occurred to me, that in this code
Spoiler :
Code:
function DMS_KillsOnIpogeoGivesFaith(playerID, unitID, unitTypeID, unitX, unitY)
	local player = Players[playerID]
	if player:IsEverAlive() and player:GetCivilizationType() == civilisationID then
		local pPlot = Map.GetPlot(unitX, unitY)
		for iPlot in PlotAreaSweepIterator(pPlot, 1, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
			if iPlot:GetImprovementType() == improvementIpogeoID then
				local speedMod = ((GameInfo.GameSpeeds[Game.GetGameSpeedType()].FaithPercent)/100)
				local unit = player:GetUnitByID(unitID)
				local unitLevel = unit:GetLevel()
				local currentFaith = player:GetFaith()
				local faithBonus = (8 + unitLevel) * speedMod
				
				-- player:ChangeFaith(faithBonus)
				player:ChangeFaith(100) -- using a fixed integer instead of "faithBonus" until I'm sure it's working
				print("unit is killed near Ipogeo")
			end
		end
	end
end
if isNuragicCivActive then
	GameEvents.UnitPrekill.Add(DMS_KillsOnIpogeoGivesFaith)
end
I'm actually checking if the unit killed is owned by the player. It was supposed to be that when a unit, which is not owned by the player, is killed near the specified improvement, then if the killee of the unit is the player, then the player should be receive a faith bonus.

I've changed the code to the following, but now I'm getting a "attempt to index local 'pPlayer' (a nil value)" error. I've marked the line referenced in the error with orange.
Spoiler :
Code:
function DMS_KillsOnIpogeoGivesFaith(playerID, unitID, unitTypeID, unitX, unitY[COLOR="Red"], bDelay, killerID[/COLOR])
	[COLOR="red"]local pPlayer = Players[killerID][/COLOR]
	[COLOR="DarkOrange"]if pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == civilisationID then[/COLOR]
		local pPlot = Map.GetPlot(unitX, unitY)
		for iPlot in PlotAreaSweepIterator(pPlot, 1, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
			if iPlot:GetImprovementType() == improvementIpogeoID then
				local speedMod = ((GameInfo.GameSpeeds[Game.GetGameSpeedType()].FaithPercent)/100)
				[COLOR="Red"]local iPlayer = Players[playerID]
				local unit = iPlayer:GetUnitByID(unitID)[/COLOR]
				local unitLevel = unit:GetLevel()
				local currentFaith = pPlayer:GetFaith()
				local faithBonus = (8 + unitLevel) * speedMod
				
				-- pPlayer:ChangeFaith(faithBonus)
				pPlayer:ChangeFaith(100) -- using a fixed integer instead of "faithBonus" until I'm sure it's working
				print("unit is killed near Ipogeo")
			end
		end
	end
end
if isNuragicCivActive then
	GameEvents.UnitPrekill.Add(DMS_KillsOnIpogeoGivesFaith)
end
Still not sure what to do with the bDelay statement.
 
Well, I would need to know when it gave you that pPlayer is nil error. Did you kill an enemy unit, or did an enemy unit kill yours?

As I've stated several times already, this event fires twice in rapid succession every time a unit is about to be removed from the map (not just being killed.)

The first time it fires, bDelay is true. The second time it fires, bDelay is false. However, I've also noticed that the other arguments, notably killerID seems to change between the two instances. This is why the function I wrote for Shana is structured the way it is -- the first time I fired, it seems to have the right killerID, but the second time it fired, killerID was 0 for some reason.

Also, each instance fires during a different 'phase' of combat -- the first time is when only the target unit is on the hex, and the second time is when the aggressor unit moves onto the target unit's hex. My code needed to account for this, since Shana needs to move the enemy unit away in order to spawn a new unit in place of the unit that was killed.

Here's something you can try to use, in case it may help you figure out what exactly Prekill is doing:
Code:
function prekillListener(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
	print("prekillListener: Dumping data..")
	print("iOwner: " .. iOwner)
	print("iUnit: " .. iUnit)
	print("iUnitType: " .. iUnitType .. " (" .. GameInfo.Units[iUnitType].Type .. ")")
	print("iX: " .. iX)
	print("iY: " .. iY)
	print("bDelay: " .. tostring(bDelay))
	-- bDelay returns true before unit is killed (before UnitKilledInCombat) and only has one unit on the plot
	-- bDelay returns false after the unit is killed (after UnitKilledInCombat) and an enemy melee unit may be on the same plot at this point
	print("iKiller: " .. iKiller)
	print("numUnits: " .. Map.GetPlot(iX, iY):GetNumUnits())
end
GameEvents.UnitPrekill.Add(prekillListener)

This is the test function I wrote up to spit out all the information the event returns, when I was trying to figure it out myself. Simply add this function temporarily into your script, or load it into Firetuner. Then, spawn a couple units and just have them kill each other (easiest way is to set up X-Com vs. Archer/Scout battles or something, for one-hit kills) and view the Lua log (again, easiest with Firetuner's live Lua log display) and see what changes.

You can see I've also added a comment in there to remind myself when bDelay fires in relation to the number of units on the tile.
 
Hi again,

Just want to thank you guys, DarkScythe and LeeS, for all your help and patience. All the functions I was experiencing problems with are now working. :D
 
Hi again,

Just want to thank you guys, DarkScythe and LeeS, for all your help and patience. All the functions I was experiencing problems with are now working. :D
well, whoward was very patient with me once upon a time, so I figure the best method to thank him for that is to pay it forward.

Plus, that DarkScythe feller was pretty patient with and helpful to me on a number of occasions.
 
Hello once again..

I'm trying to use the CityConstructed GameEvent with the following function

Code:
function(ownerId, cityId, buildingType)
	local pPlayer = Players[ownerId]
	if (pPlayer:GetCivilizationType() ~= GameInfoTypes["CIVILIZATION_DMS_NURAGIC"]) then return end
		local pCity = pPlayer:GetCityByID(cityId)
		[COLOR="Red"]local pBuilding = GameInfo.BuildingClasses[buildingType.BuildingClass][/COLOR]
		if pBuilding.MaxGlobalInstances == 1 then
			pCity:ChangeWeLoveTheKingDayCounter(20)
		end
	end
end

but I'm getting attempt to index local 'buildingType' (a number value) in the marked red.
Clearly I did something wrong in my code - not sure how to fix it?
 
Code:
local pBuilding = GameInfo.Buildings[buildingType]
local pBuildingClass = GameInfo.BuildingClasses[pBuilding.BuildingClass]
 
What whoward provided is correct (of course.)

However, to explain:
The 'buildingType' that CityConstructed returns is an integer -- it is the building's ID.
What you attempted to do was to find "buildingType.BuildingClass" -- this "dot syntax" is a shortcut for accessing named indices in a Lua table, but if you'll recall, I just stated that the 'buildingType' is a number and not a table. This is why you got the error you had.

What you have to do then is as whoward has described, you need to look through the Buildings table with the ID you have and get the game object for the building -- that is pBuilding. This is a table for that building; the buildingType ID specifies the row in the database that this table sits in. Once you have this table, you can then proceed to do the 'dot syntax' to find data in another column because you now have a table, instead of just an integer.
 
Hi Danmacsch,

Just for curiosity, do you managed to make 'ResourceExtractionMod' work?
When I tried, it did nothing.
 
If you haven't already, you can also add Improvements_FreshWaterYields.. At least I can't get it to work
 
If you haven't already, you can also add Improvements_FreshWaterYields.. At least I can't get it to work

I know, but the Mighty Whoward (look here) made it work (with all the yields :D), as part of the Community DLL.

I suggest you to consider it as base of your mods, it expands the modding possibilities to an entire new level.

Ulixes
 
I'm aware, but thanks. I did consider it, but since there's so many people (especially those on Steam whose only interaction with the Civ5 modding community is through the Workshop) that doesn't use the Community DLL.

But you are completely correct - it does expand ones possibilities to a completely new level.
 
Back
Top Bottom