Есть такой код. Кто "дока" в кодинге, можете подсказать, как его изменить, чтобы он работал следующим образом:
Событие - захват\основание города.
Действия - проверка принадлежности игрока-захватчика\основателя к нации
- проверка наличия\отсуствия в городе здания из списка N
- Здание присутствует - ничего не делаем
-Здание отсутствует - добавление его.
С основанием я проблему решила, через - FreeStartEra, где нужное здание указываю как "бесплатное" с эры "Древнейшая эра".
Как это должно работать: Арабы захватывают город шведов. В этом городе автоматически должно появиться здание N.
Сперва я попыталась сделать так, чтобы дворец арабов давал FreeBuilding в каждом городе бесплатно (аналогично ЧД Останкино), но в этом случае, при захвате города это здание N исчезает, даже если у него стоит 100% вероятность захвата.
Кто может помочь?
Скрытый текст-----------------------------------
-- FreeBuildings.lua
-- Author: Armin Pudic
-- Created: 02/07/2015
-----------------------------------
---------------------------
-- Game Events --
---------------------------
function OnCityCaptured(playerID, bCapital, iX, iY, newPlayerID)
local newPlayer = Players[newPlayerID];
if (newPlayer == nil) then return; end
local oldPlayer = Players[playerID];
if (oldPlayer == nil) then return; end
local plot = Map.GetPlot(iX, iY);
if (plot == nil) then return; end
local city = plot:GetPlotCity();
if (city == nil) then return; end
-- Add free buildings
for tBuilding1 in GameInfo.Buildings() do
AddBuilding(city, tBuilding1);
end
end
function OnCityFounded(iPlayer, iCityX, iCityY)
local pPlayer = Players[iPlayer];
if (pPlayer == nil) then return; end
local pPlot = Map.GetPlot(iCityX, iCityY);
if (pPlot == nil) then return; end
local pCity = pPlot:GetPlotCity();
if (pCity == nil) then return; end
-- Add free buildings
for tBuilding in GameInfo.Buildings() do
AddBuilding(pCity, tBuilding);
end
end
GameEvents.PlayerCityFounded.Add( OnCityFounded );
GameEvents.CityCaptureComplete.Add( OnCityCaptured );
----------------------
-- Adding Buildings --
----------------------
-- Adds the building to the city if all prerequisites have been met
function AddBuilding(pCity, tBuilding)
if (pCity == nil) then return; end
if (tBuilding == nil) then return; end
local iOwner = pCity:GetOwner();
local pOwner = Players[iOwner];
if (pOwner ~= nil) then
if (pOwner:CanConstruct(tBuilding.ID)) then -- Checks if all prerequisites have been met i.e. Tech, resources, etc
if (not pCity:IsHasBuilding(tBuilding.ID)) then -- Makes sure that the city doesn't already have the building
if (GameInfo.BuildingClasses[tBuilding.BuildingClass].MaxGlobalInstances ~= 1) then -- Makes sure that the building to be added isn't a wonder
if(GameInfo.BuildingClasses[tBuilding.BuildingClass].MaxPlayerInstances ~= 1) then -- Makes sure that the building to be added isn't a national wonder/building
pCity:SetNumRealBuilding(tBuilding.ID, 1); -- Adds the building
end
end
end
end
end
end