cromcrom
Cernu
Let's hope they will release it ...
Hello. There are two functions listed: Player:GetTechs():SetTech() and Player:GetCulture():SetCivic() which I cannot find being used in any file in entire Civ6 directory. Where did you find those?
Using this
or thisCode:function l(object) for k, v in pairs(getmetatable(object).__index) do print(k); end; end
on whatever I found in the Lua files of the game.Code:function p(table) for k, v in pairs(table) do print(k); end; end
need to do units and cities, events, ...
see also: http://forums.civfanatics.com/threads/lua-environment-and-sandboxing.487598/
you need to select an unit (or player, city...) first, for example using:
u = Players[0]:GetUnits():GetFirstReadyUnit()
c = Players[0]:GetCities():GetCapitalCity()
and print (u) or print(c) to check it's not nil then the function.
note that what we can access depend of the context (UI in game or a script defined in the modinfo), see http://forums.civfanatics.com/threads/current-status-of-lua-modding.603706/
local player = Players[0]
local unit = nil
local playerUnits = player:GetUnits()
for i, u in playerUnits:Members() do
if u then
unit = u
end
end
local pConfig = PlayerConfigurations[0]
local city = nil -- will be listed under player (Capital City)
local seenO = {}
local seenT = {}
listDump = {GameConfiguration = GameConfiguration, NotificationManager = NotificationManager, PlayerConfigurations = pConfig, PlayerManager = PlayerManager, Players = player, Cities = Cities, CityManager = CityManager, Units = Units, UnitManager = UnitManager, Calendar = Calendar, AutoplayManager = AutoplayManager, Achievements = Achievements, GameEffects = GameEffects, CombatManager = CombatManager, Game = Game, DealManager = DealManager, GetUnitStats = GetUnitStats, DiplomacyManager = DiplomacyManager, Map = Map, Unit = unit }
listExceptionStr = {
"IsNone",
"ToPlot",
"ToArea",
"GetDiplomaticState",
"HasProductionProgress",
"ToolTip",
"HasBeenPlaced",
"GetAvailableProductionType",
"GetTurnsLeft",
"GetName",
"GetScienceYieldToolTip",
"GetPlayerName",
"GetLeaderName",
"Name",
"Description",
"Text",
"Password",
"GetNextEscapingSpyID",
"Advice",
"IsResourceExtractableAt",
"Tooltip",
"GetNextPursuedSpyID",
"GetTurnFromIndex",
"GetTurn",
"GetNthOffMapSpy",
"GetPlayerFromIndex",
"FromIndex",
"GetDiplomaticActionCost",
"Turn",
"Level",
"GetDiplomatic"
}
function canTest(functionName)
local bCanTest = false
local get = string.find(functionName, "Get")
--local is = string.find(functionName, "Is")
--local has = string.find(functionName, "Has")
if get == 1 or is == 1 or has == 1 then
bCanTest = true
end
for k, str in pairs(listExceptionStr) do
if string.find(functionName, str) then
return false
end
end
return bCanTest
end
function dumpO(object,i)
seenO[object]=true
local s={}
local n=0
for k, v in pairs(getmetatable(object).__index) do
print(i,k)
if type(v)=="table" and not seenT[v] then
dumpT(v,i.."\t")
end
if type(v)=="function" then
object.f = object[k]
local value = nil
if canTest(tostring(k)) then
value = object:f()
--print(i.."\t - ".."return value :", value)
end
if getmetatable(v) and getmetatable(v).__index and not seenO[v] then
dumpO(v,i.."\t")
end
if value and getmetatable(value) and getmetatable(value).__index and not seenO[value] then
dumpO(value,i.."\t")
end
if value and type(value)=="table" and not seenT[value] then
dumpT(value,i.."\t")
end
end
end;
end
function dumpT(table,i)
seenT[table]=true
local s={}
local n=0
for k in pairs(table) do
n=n+1 s[n]=k
end
for k,v in ipairs(s) do
print(i,v)
v=table[v]
if type(v)=="table" and not seenT[v] then
dumpT(v,i.."\t")
end
end
end
function dumpAll()
print("-----------------------------------------------------------------------------------------------------")
print("-----------------------------------------------------------------------------------------------------")
print("------------------------------------- STARTING DUMP -------------------------------------------------")
print("-----------------------------------------------------------------------------------------------------")
print("-----------------------------------------------------------------------------------------------------")
for k,v in pairs(listDump) do
local i = ""
if type(v)=="function" then
local value = v()
print("return value :" .. value)
if getmetatable(v) and getmetatable(v).__index then
dumpO(v,i.."\t")
end
if getmetatable(value) and getmetatable(value).__index then
dumpO(value,i.."\t")
end
if type(value)=="table" then
dumpT(value,i.."\t")
end
end
if getmetatable(v) and getmetatable(v).__index then
print("----- object:", k)
dumpO(v,i)
print("----- End attributes.")
end
if type(v)=="table" then
print("------ table:", k)
dumpT(v,i)
print("----- End attributes.")
end
end
end
dumpAll()
-- Check for being too close to another of this goody type.
local uniqueRange = improvement.GoodyRange;
local plotX = plot:GetX();
local plotY = plot:GetY();
for dx = -uniqueRange, uniqueRange - 1, 1 do
for dy = -uniqueRange, uniqueRange - 1, 1 do
local otherPlot = Map.GetPlotXYWithRangeCheck(plotX, plotY, dx, dy, uniqueRange);
if(otherPlot and otherPlot:GetImprovementType() == improvementID) then
return false;
end
end
end
if(otherPlot and otherPlot:GetImprovementType() == improvementID) then
return false;
end
See Post #91
local tCityPlots = GetCityPlots(pCity)
for Item,pPlot in pairs(tCityPlots) do
if not pPlot:IsWater() then
print("Thar be Land here!")
end
end
for row in GameInfo.GlobalParameters() do
if row.Name == "CITY_MAX_BUY_PLOT_RANGE" then
iCityWorkRange = row.Value
end
end
I don't understand why Firaxis made some functions available only in a specific context, quite confusing.
Map.GetPlotXYWithRangeCheck
local iCityRadius = 3
--this is the radius from the player's city-plot to look for resources and the like
function GetCityPlots(pCity)
local tTempTable = {}
if pCity ~= nil then
local iCityOwner = pCity:GetOwner()
local iCityX, iCityY = pCity:GetX(), pCity:GetY()
for dx = (iCityRadius * -1), iCityRadius do
for dy = (iCityRadius * -1), iCityRadius do
local pPlotNearCity = Map.GetPlotXYWithRangeCheck(iCityX, iCityY, dx, dy, iCityRadius);
if pPlotNearCity and (pPlotNearCity:GetOwner() == iCityOwner) and (pCity == Cities.GetPlotPurchaseCity(pPlotNearCity:GetIndex())) then
table.insert(tTempTable, pPlotNearCity)
end
end
end
end
return tTempTable
end
It's not available to scripts, I had to get it from a gameplay context in my mod, but it uses Map.GetCityPlots():GetPurchasedPlots(pCity)Yeah, Map.GetCityPlots isn't valid in gameplay context.
function expected instead of nil
if Map.GetCityPlots():GetPurchasedPlots(pCity) ~= nil then
for i, pCity in pCities:Members() do
if Map.GetCityPlots():GetPurchasedPlots(pCity) ~= nil then
local tPlots = Map.GetCityPlots():GetPurchasedPlots(pCity)
for k,v in pairs(tPlots) do
print("tPlots (k) is " .. tostring(k) .. " : (v) is " .. tostring(v))
end
else
print("Map.GetCityPlots():GetPurchasedPlots(pCity) is considered nil")
end
SetCityLockerStatuses(pCity)
end
<InGameActions>
<AddGameplayScripts id="LUA_Gameplay2">
<File>LUA/EraLockerBuildings.lua</File>
</AddGameplayScripts>
</InGameActions>
Policies usually use modifiers to enforce their effects, so you might try to use GameEffects to determine which modifiers are attached to a player. It's tedious, I know, but it might work.I just realized you can't determine which Policies a player is running from the Gameplay Lua
CreateIncompleteBuilding() works for me just fine in a Gameplay Context but I am pretty sure it is nil in a UI context. If you are running from Gameplay Context perhaps you do not have the format correct ?Is there a way of forcing code to run in a specific context?
For instance, I have code running in a UI screen which I want to Create\Destroy a dummy building at certain points in the game.
I understand that the City:GetBuildQueue():CreateIncompleteBuilding() function will not run in the UI context so I have this in a Gameplay script.
I set the city for the building by using ExposedMembers, but don't try to create the building until the start of the player's turn (in the OnLocalPlayerTurnBegin event).
It however always fails on the call to CreateIncompleteBuilding(). I have checked that none of the objects it relies on are nil, but the message
'function expected instead of nil' always gets logged.
I think it's because it's not running in the correct context.
function PlaceBuildingInCityCenter(pCity, iBuilding)
local iCityPlotIndex = Map.GetPlot(pCity:GetX(), pCity:GetY()):GetIndex()
if not pCity:GetBuildings():HasBuilding(iBuilding) then
pCity:GetBuildQueue():CreateIncompleteBuilding(iBuilding, iCityPlotIndex, 100);
else
if pCity:GetBuildings():IsPillaged(iBuilding) then
pCity:GetBuildings():RemoveBuilding(iBuilding);
pCity:GetBuildQueue():CreateIncompleteBuilding(iBuilding, iCityPlotIndex, 100);
end
end
end
function RemoveBuildingFromCityCenter(pCity, iBuilding)
if pCity:GetBuildings():HasBuilding(iBuilding) then
pCity:GetBuildings():RemoveBuilding(iBuilding);
end
end