Changing .xml files with lua during gameplay

TK_civftcs

Chieftain
Joined
Jul 4, 2015
Messages
23
Location
Finland
Hello people, halp halp pls

Edit: Solved. I didnt need to change .xml:s, but the ingame database. Doing that is somewhat limited, but on some cases possible.

I have been unable to find this information so far: is it possible to edit .xml files with lua scripts during a running game?

I wish to create a script that would allow me to create a city state out of an already existing major civ city, and the issue is I can't possibly predefine the correct citystate properties inside an xml before loading the mod. This script has to work for any city and civ in play.

Example of desired functionality: the end of Roman empire has come, Mediolanum decides "fukk-a-this, I'm-a citystate-a now #yolo #solo" and breaks free. They become a new citystate: I have enabled all 40ish citystates possible in the pregame and made them not have a single city until now. I pick from the list of citystates, and modify its xml entry to "The Best CS of Mediolanum" and change the ownership of the city Mediolanum to the citystate. The CS loads its information from the .xml files which have been modified, showing as "Mediolanum."

-TK
 
what you want is changing the DB entries, you can't change XML files from in game (not without DLL modification, and even then, you'll need to force a reload in the DB)

Still, most entries in the DB are cached and can't be changed, but here's what I use in the revolution mod to change city states name mid-game:

Code:
-- update localized text
function SetText ( str, tag )
	-- in case of language change mid-game :
	local query = "UPDATE Language_en_US SET Text = '".. str .."' WHERE Tag = '".. tag .."'"
	for result in DB.Query(query) do
	end

	-- that's the table used ingame :
	local query = "UPDATE LocalizedText SET Text = '".. str .."' WHERE Tag = '".. tag .."'"
	for result in DB.Query(query) do
	end
end

and to force the new text to be reloaded:

Code:
function RefreshText()
	Locale.SetCurrentLanguage( Locale.GetCurrentLanguage().Type )
end


for references:

https://github.com/Gedemon/Civ5-RED...aster/Revolutions/Lua/RevolutionFunctions.lua
https://github.com/Gedemon/Civ5-RED-DLL-BNW-Build/blob/master/Revolutions/Lua/RevolutionUtils.lua
https://github.com/Gedemon/Civ5-RED-DLL-BNW-Build
 
Awesome!

Seems I hadn't yet fully understood the basic workings of the game. Thanks a plenty, the references will be useful. :)

-TK
 
Back
Top Bottom