Adding xml tags that work through Lua (eg, policy-dependent units & buildings)

This line:

ALTER TABLE Units ADD COLUMN 'UnitArtInfoEraVariationStartEra_RED' TEXT DEFAULT NULL;

tells SQlite that that column has "text" affinity. Use INTEGER instead.
 
There's already a Unit_BuildingClassRequireds table. Doesn't that work?

But yes, you could using GameEvents.CityCanTrain(ownerID, cityID, unitTypeID).
 
is there a PlayerCanGetPolicy event?
id like to add tech prereqs to policies

I believe this one is already in the policies xml file. I think it works but gives no help text to tell you why you can't adopt.

In any case, there is also a PlayerCanAdoptPolicy if you want to make it conditional on anything else. Here are the the list of added GameEvents (from patch 1.0.1.332) that are not in the wiki:

Code:
(Lua) Added GameEvents.CityCanBuyAnyPlot(ownerID, cityID) (TestAll)
(Lua) Added GameEvents.CityCanBuyPlot(ownerID, cityID, plotX, plotY) (TestAll)
(Lua) Added GameEvents.CityCanCreate(ownerID, cityID, projectTypeID); (TestAll)
(Lua) Added GameEvents.CityCanMaintain(ownerID, cityID, processTypeID); (TestAll)
(Lua) Added GameEvents.CityCanPrepare(ownerID, cityID, specialistTypeID); (TestAll)
(Lua) Added GameEvents.CityCanTrain(ownerID, cityID, unitTypeID); (TestAll)
(Lua) Added GameEvents.PlayerAdoptPolicy(playerID, policyTypeID); (Hook)
(Lua) Added GameEvents.PlayerAdoptPolicyBranch(playerID, policyBranchTypeID); (Hook)
(Lua) Added GameEvents.PlayerCanAdoptPolicy(playerID, policyTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanAdoptPolicyBranch(playerID, policyBranchTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanConstruct(playerID, buildingTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanCreate(playerID, projectTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanEverReseearch(playerID, techtypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanMaintain(playerID, processTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanPrepare(playerID, specialistTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanResearch(playerID, techTypeID); (TestAll)
(Lua) Added GameEvents.PlayerCanTrain(playerID, unitTypeID); (TestAll)
(Lua) Added GameEvents.TeamSetHasTech(teamID, techID); (Hook)

also, are those lua fields added from .sql files or from the lua code somehow?
is it possible to change the game DB from lua?
All changes to DebugDatabase (odd name but that is the one used by the game) should be done as OnModActivated changes, either by SQL directly or XML (which is translated to SQL). Don't even think about changing this DB in game. Values like combat str, etc., need to be changed in game via Lua functions listed at the wiki, and if that doesn't exist then you can't really change it.

There is another DB that you can alter in-game via Lua (or really SQL commands embedded in Lua). This is SavedGameDB. You can add tables, change values, etc., but these only interact with your own Lua. The game engine doesn't need SavedGameDB at all. This is where my TableSaverLoader mod component saves/restores your Lua tables on game exit/reload.
 
nothing, that's the problem.

If you think about the underlying C++ code, it would be surprising if it did. It's going to be a lot slower to reference a DB every time you need a value rather than holding it internally. So slow as to be unplayable, I would imagine.

However, I could imagine it will be possible to build dll functions that update internal values from the DB on some command. That would be a large effort and one can't expect the developers to do it for no reason. But it should be possible when we have the dll.

Questions:
1) Do you have any ready mod with added xml tags through Lua?
2) Does OnModActivated event is activated only in SP or also in MultiPlayer mode?
1. You'll have to wait for my mods release, hopefully in April.
2. I don't know anything about multiplayer (I thought that was not modable, yet...).
 
Okay, I'm making my first mod and all of this coding stuff is foreign to me. This seems like the appropriate area to ask my question and beg for help. I'm making a unique belief to add to a religion in Gods and Kings but there doesn't seem to be an ingame tag that will do what I need to do. Is the guide you've made how I'd go about creating this tag? I'm actually trying to create three unique tags:

1 - A golden age will occur every x number of turns.
2 - EXP earned doubles when at war with a city state that follows your religion
3 - Every time one of your unit dies in enemy territory, it acts a mini-missionary exerting x amount of faith.

Is this technically possible?
 
Just remember that the XML tag doesn't do anything by itself. Something has to read it and do something. For existing tags, that would be the dll. For added tags, it has to be Lua code. All 3 of your items could be programmed in Lua, but these are pretty difficult. You would have to learn Lua to do this.
 
All right, well this was my best shot at #1 but it didn't work:

Code:
GameEvents.GoldenAge.Add
function(iPlayer, beliefType)
	local XiuhAge = GameInfo.Beliefs[beliefType].XiuhAge
	local pPlayer = Players[iPlayer];
		if pPlayer:GetBeliefType(Belief.Founder) == local GameInfo.Beliefs['BELIEF_XIUHMOLPILLI'] then
			if XiuhAge = true and (Game.GetGameTurn() = 55 or 110 or 165 or 220 or 275 or 330 or 385 or 440 or 495') then return true
			break
		break
end)

If I had to guess as to why, I'd say its because GameEvents.GoldenAge was just a wild guess. I for the life of me couldn't find the object that actually started GoldenAges - but what do I know? Maybe you can see some flaw that I can't. I'd appreciate any help you can offer...
 
There is no game event for golden ages, as far as I recall. I suspect it would be a player function -- you should be looking for this stuff in the wiki. What you should do is figure out how to trigger a golden age with a single command in the fire tuner. I haven't done this but I think you will find a way. Worry about XML tags later, after you have your function working and you can trigger it from the tuner. (Folks will help on the main forum with Lua if you post some code and what you are trying to do.)
 
If I had to guess as to why, I'd say its because GameEvents.GoldenAge was just a wild guess.

As is

Code:
if pPlayer:GetBeliefType(Belief.Founder) == local GameInfo.Beliefs['BELIEF_XIUHMOLPILLI'] then
  if XiuhAge = true and 
     (Game.GetGameTurn() = 55 or 110 or 165 or 220 or 275 or 330 or 385 or 440 or 495') then
       return true
    break
  break

Before venturing into the Wiki, you may want to start with the Lua Tutorials
 
Well, here is my latest unsuccessful attempt:
Code:
Player.ChangeGoldenAgeTurns.Add(
function(pPlayer, iChange)
local Player = Players[pPlayer]
if pPlayer:GetBeliefType(Belief.Founder) == local GameInfo.Beliefs['BELIEF_XIUHMOLPILLI'] then
  if XiuhAge = true 
       return "10"
    break
  break
  end)
 
That code looks really random. I hate to sound mean, but there is not a single line it that is proper syntax or makes any sense, except maybe the last line "end)". You can't just make stuff up and expect it to work. Follow link above to a Lua tutorial.

In any case, you don't need an xml tag for this. The logic you need is to check for a belief and then do something. So don't try to follow my example in the OP. You first need to learn how to do something in Lua. Start with something simple like a print statement. (I'm not being sarcastic. If you can't print something and see it in Fire Tuner, there is no way that you can mod Lua.)
 
Pazyryk would it be possible to add a terrain feature (such as forest) as prereq for a building using your method ?

And if yes could you provide the lua code please ? :)
 
Back
Top Bottom