Danmacsch
Geheimekabinetsminister
Thanks _bane and LeeS, just the info I needed. I'll try it out.
The answer is pretty much 'No' because lua events related to combat are either intended for graphical display, for combat-related UI panels, or only give info on what unit was killed as a result of combat. Graphical Display and Combat-Related UI 'events' don't fire except in certain pre-defined condiitons, and so are essentially useless. Some only are fired if the human player can see the action, some don't fire when the game is in strategic view, and some don't fire (as I recall) when Quick Combat is turned on.Is it possible using only lua to add a new conditional combat modifier that follows conditions not existing on existing promotions? (eg +10% combat strength if enemy unit has less health than you). I know I can on DLL, but the lua events I see seem to be after the damage is done.
Im thinking that MAYBE I could edit the lua that displays the combat preview to enhance the combat strength of the attacking unit if the conditions match, but in that case, if the Ai were to attack me, as the preview is not shown, the modifier would not work on defense, and also probably would bring desynch problems if multi as the UI only shows on the attacking player.
I wouldn't do it not so much from a point of view of memory allocation issues as the fact that cities get conquered. If a city is not a player's original capital, it can be both captured and razed, which means that your pointer would then be nil. Nothing wrong really with caching data for the run of a game-session -- the problem is in doing so for data like pointer objects that can be nil or irrelevant by the time you get back to 'reading' this data again. I would probably cache the city's XY position as opposed to the city pointer, as an example, because the plot's XY isn't going to be affected by city ownership or city-razing.Also is it safe to keep an engine object pointer in LUA, or should I only keep ids and search for the objects at every sequential block execution? eg: local city = player:GetCapitalCity();, if I save city to a global to be used later (eg next turn, or in 20 turns), would it be safe to keep it for the duration of the session? or does the game do memory reallocation at "random" points as you play?
-- NOTE: Storing the PlayerID/CityID for the city, it is not safe to store the pointer to a city
-- over multiple frames, the city could get removed by the game core thread
Hi, Is there in LUA-only, a way for a player to get open borders with another, skipping the trade logic? eg player:SetOpenBorders( otherplayer, finalturn );
Not directly. What you need to do is setup up a trade between the two players in Lua (see the trade deal UI code for how that's done) and then execute the deal via UI.DoFinalizePlayerDeal(...);
Added directly to the treasury, or as a hidden building with YieldChange of +2 Gold ?Alright this is bugging me because I feel like I'm missing something completely obvious to get this working.
Essentially want a code that Generates +2 gold per Science Building (Library, Observatory, University, Research Lab, Public School) when the city has the civ's unique building built.
Added directly to the treasury, or as a hidden building with YieldChange of +2 Gold ?
The hidden building allows the gold to be multiplied by Markets and the like, whereas the direct addition of gold to the treasury does not.
<GameData>
<Buildings>
<Row>
<Type>BUILDING_YOUR_DUMMY</Type>
<BuildingClass>BUILDINGCLASS_YOUR_DUMMY</BuildingClass>
<Cost>-1</Cost>
<FaithCost>-1</FaithCost>
<PrereqTech>NULL</PrereqTech>
<GreatWorkCount>-1</GreatWorkCount>
<ArtDefineTag>NONE</ArtDefineTag>
<MinAreaSize>-1</MinAreaSize>
<NeverCapture>true</NeverCapture>
<HurryCostModifier>-1</HurryCostModifier>
<IconAtlas>BW_ATLAS_1</IconAtlas>
<PortraitIndex>19</PortraitIndex>
<Description>TXT_KEY_BUILDING_YOUR_DUMMY</Description>
<NukeImmune>true</NukeImmune>
</Row>
</Buildings>
<BuildingClasses>
<Row>
<Type>BUILDINGCLASS_YOUR_DUMMY</Type>
<DefaultBuilding>BUILDING_YOUR_DUMMY</DefaultBuilding>
<Description>TXT_KEY_BUILDING_YOUR_DUMMY</Description>
<NoLimit>true</NoLimit>
</Row>
</BuildingClasses>
<Building_YieldChanges>
<Row>
<BuildingType>BUILDING_YOUR_DUMMY</BuildingType>
<YieldType>YIELD_GOLD</YieldType>
<Yield>2</Yield>
</Row>
</Building_YieldChanges>
<Language_en_US>
<Row Tag="TXT_KEY_BUILDING_YOUR_DUMMY">
<Text>Give Your Dummy A Name</Text>
</Row>
</Language_en_US>
</GameData>
local bAddGlobalAndAreaYieldModifiers = false
local bAddGlobalAndAreaYieldModifiers = true
local bAddFeatureYieldChanges = false
local bAddFeatureYieldChanges = true
local iDummyBuilding = GameInfoTypes.BUILDING_YOUR_DUMMY
local iCivUniqueBuilding = GameInfoTypes.BUILDING_YOUR_UNIQUE_BUILDING
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_YOUR_CIVILIZATION_NAME
local bAddGlobalAndAreaYieldModifiers = false
local bAddFeatureYieldChanges = false
-------------------------------------------------------------------------------------------------------
--DON'T CHANGE BELOW THIS LINE
-------------------------------------------------------------------------------------------------------
local tScienceBuildings = {}
for row in GameInfo.Building_YieldChangesPerPop("YieldType='YIELD_SCIENCE'") do
if not tScienceBuildings[row.BuildingType] then
tScienceBuildings[row.BuildingType] = GameInfoTypes[row.BuildingType]
end
end
for row in GameInfo.Building_YieldModifiers("YieldType='YIELD_SCIENCE'") do
if not tScienceBuildings[row.BuildingType] then
tScienceBuildings[row.BuildingType] = GameInfoTypes[row.BuildingType]
end
end
if bAddGlobalAndAreaYieldModifiers then
for row in GameInfo.Building_AreaYieldModifiers("YieldType='YIELD_SCIENCE'") do
if not tScienceBuildings[row.BuildingType] then
tScienceBuildings[row.BuildingType] = GameInfoTypes[row.BuildingType]
end
end
for row in GameInfo.Building_GlobalYieldModifiers("YieldType='YIELD_SCIENCE'") do
if not tScienceBuildings[row.BuildingType] then
tScienceBuildings[row.BuildingType] = GameInfoTypes[row.BuildingType]
end
end
end
if bAddFeatureYieldChanges then
for row in GameInfo.Building_FeatureYieldChanges("YieldType='YIELD_SCIENCE'") do
if not tScienceBuildings[row.BuildingType] then
tScienceBuildings[row.BuildingType] = GameInfoTypes[row.BuildingType]
end
end
end
function GetNumberBuildingsInCity(pCity, tTable)
local iNumBuildingsPresent = 0
for Item,BuildingID in pairs(tTable) do
if pCity:IsHasBuilding(BuildingID) then
iNumBuildingsPresent = iNumBuildingsPresent + 1
end
end
return iNumBuildingsPresent
end
function UniqueBuilding_ScienceBuildingExtraYields(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == iRequiredCivilization then
if pPlayer:CountNumBuildings(iCivUniqueBuilding) > 0 then
for pCity in pPlayer:Cities() do
if pCity:IsHasBuilding(iCivUniqueBuilding) then
pCity:SetNumRealBuilding(iDummyBuilding, GetNumberBuildingsInCity(pCity, tScienceBuildings))
else
pCity:SetNumRealBuilding(iDummyBuilding, 0)
end
end
end
end
end
function BuildingPurchasedOrConstructed(iPlayer, cityId, buildingType, bGold, bFaithOrCulture)
if buildingType == iCivUniqueBuilding then
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == iRequiredCivilization then
local pCity = pPlayer:GetCityByID(cityId);
pCity:SetNumRealBuilding(iDummyBuilding, GetNumberBuildingsInCity(pCity, tScienceBuildings))
end
end
end
------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------
function IsCivInPlay(iCivType)
for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local iSlotStatus = PreGame.GetSlotStatus(iSlot)
if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
if (PreGame.GetCivilization(iSlot) == iCivType) then
return true
end
end
end
return false
end
------------------------------------------------------------
---- Game Event Hooks
------------------------------------------------------------
if IsCivInPlay(iRequiredCivilization) then
GameEvents.CityConstructed.Add(BuildingPurchasedOrConstructed)
GameEvents.PlayerDoTurn.Add(UniqueBuilding_ScienceBuildingExtraYields)
end
I don't see how this could be happening unless the Palace is being changed by a mod to make it give science via either of <Building_YieldChangesPerPop> or <Building_YieldModifiers>.Thanks this is doing what I wanted. One very minor thing I noticed is that if you lose your Capital and the city that gains the palace and has the unique building will grant the +2 Gold since the Palace generates science. Very minor thing and it doesn't really matter.
I don't see how this could be happening unless the Palace is being changed by a mod to make it give science via either of <Building_YieldChangesPerPop> or <Building_YieldModifiers>.
Are you sure it isn't a city with the National College? National College qualifies as a "Science" building under the definition of the way it is being used in the lua-code.
The Palace generates science via <Building_YieldChanges>, which the lua-script is specifically not looking at.
Players[63]:AddTemporaryDominanceZone (iX, iY)