Lua for Unique Diplomacy Entries - whether to split some functions

Typhlomence

Magical Tomomo
Joined
Mar 19, 2014
Messages
394
Location
Brisbane, Australia
This thread is now obsolete - new thread can be found here.

For my Koopa Troop civilization I included some lua that gave him unique diplomacy responses depending on who the player was playing as, using the lua from Ryoga's Unique Cultural Influence as a reference. I've been working on cleaning it up and expanding it into a lua file with various functions that others can drop into their own mods and use.

Here's the file at the moment.

There are eight functions in total. For manipulating the Diplomacy Responses Table, there's:
  • ChangeDiplomacyResponse()
  • AddDiplomacyResponse()
  • RemoveDiplomacyResponse()
The other five actually modify Game Text entries in the current locale.
  • ChangeDiplomacyGameText()
  • AddDiplomacyGameText() (Technically, this copies an existing entry.)
  • RemoveDiplomacyGameText()
  • ChangeDiplomacyGameTextToString()
  • AddDiplomacyGameTextFromString()
Now, while I wouldn't mind feedback on the functions in general, my query here is about the functions that manipulate the Game Text. Since Game Text covers much more than just Diplomacy, I was wondering whether it would be useful for modders if I split them off into their own lua file (while changing the function names, of course) that could be used when they need to modify Game Text entries.

However, I'm not sure of the approach others use when they need to change a Game Text line, since you could change a reference to an entry easily using SQL (if it's before the game starts), and Civ Names By Policies doesn't query the database to change the civilization names during the game (and that dynamically generates strings). UCI is the only one I've looked at so far that does query the database to change Game Text.

So... would having a seperate GameTextUtils.lua be useful to anyone? Or should I just polish off and release UniqueDiplomacyUtils.lua?

(I'll make a proper thread for UniqueDiplomacyUtils.lua if/when I release that one, with instructions on how to use it.)
 
I'm going to give this a test with my next civ-release: Akhenaten. Not the best example, but I'm sure he can benefit from disparaging Ramesses for not being Aten :p Pending it's success (I'm a bit worried about performance), I may add some unique intro/defeats for my other civs, which change according to the civ you're playing as/against. I'll credit you when I'm done.

If there's anything you need to update in the files, please let me know as soon as you can, so I can include them before releasing Akhenaten.

By the looks of it, the functions you included would work for normal game text anyway, wouldn't it? In some cases I want to update a civ or leader name (e.g. Sardinia-Piedmont becomes Italy with a certain decision) - I can't use the PreGame method to do this because in my Prestige mod I use PreGame extensively to manipulate titles. A seperate GameTextUtils.lua could be useful for clarity's sake though.

Oh, lol, love the Louis-centred diplo texts :D
 
Pending it's success (I'm a bit worried about performance), I may add some unique intro/defeats for my other civs, which change according to the civ you're playing as/against.

Performance only has a hit at the time the functions are replaced, which I tied to GameEvents.LoadScreenClose(). Depending on the number of queries you're doing, there is a noticeable pause while it does its work, but once it is done, there are no performance issues whatsoever.

Of course, if you're like me and have an entirely new dialog bank for a character when she is Hostile towards the player, and it updates the database every time her disposition changes between Hostile and anything else, the performance can get a little noticeable...


By the looks of it, the functions you included would work for normal game text anyway, wouldn't it? In some cases I want to update a civ or leader name (e.g. Sardinia-Piedmont becomes Italy with a certain decision) - I can't use the PreGame method to do this because in my Prestige mod I use PreGame extensively to manipulate titles. A seperate GameTextUtils.lua could be useful for clarity's sake though.

Yeah, these should have no issue updating any item of text in the localization database.
 
Assuming they're not cached, anyway.

I did some testing of this a while back for other pieces of text in the UI, but any updates, although reflected in the database, wouldn't show up in the interface. Not everything was like this, but I suppose I was trying to look for cases where it wouldn't work.
 
By the stars, there's some activity in this thread! :p
I'm going to give this a test with my next civ-release: Akhenaten. Not the best example, but I'm sure he can benefit from disparaging Ramesses for not being Aten :p Pending it's success (I'm a bit worried about performance), I may add some unique intro/defeats for my other civs, which change according to the civ you're playing as/against. I'll credit you when I'm done.

If there's anything you need to update in the files, please let me know as soon as you can, so I can include them before releasing Akhenaten.
I think the main thing is removing some of the checks I included due to me being a bit overcautious. When I asked Vicevirtuoso about my code when planning to do a tutorial on it, he said that constantly accessing the database to check whether what you're doing is actually valid will cost a lot if you want to replace many lines at a time. Hence why when he included ChangeDiplomacyResponse() with Blanc, he removed those checks. Like he said above, as well, he not only changes them at the game start, but also during the game depending on Blanc's mood, which is another good reason for removing those checks for performance's sake.

And to be fair, if you're playing around with Lua for unique diplomacy, you probably know enough about what you're doing to not need those checks in the first place. I'll keep around the "full" version because it might be useful for debugging purposes, however.
By the looks of it, the functions you included would work for normal game text anyway, wouldn't it? In some cases I want to update a civ or leader name (e.g. Sardinia-Piedmont becomes Italy with a certain decision) - I can't use the PreGame method to do this because in my Prestige mod I use PreGame extensively to manipulate titles. A seperate GameTextUtils.lua could be useful for clarity's sake though.
Yes, it can techinically be used with any entry in the language tables, and that's why I was asking if I should seperate them out. I think I might do that anyway, since it's probably better when dealing with diplomacy responses to only change around the entries in the Response table rather than playing around replacing the TXT_KEYs (another thing that came up when talking with Vicevirtuoso).

Since I still feel I'm not an expert modder, though, I didn't know whether others would find such functions useful, hence why I started this thread.
Oh, lol, love the Louis-centred diplo texts :D
I couldn't resist - I have no idea whether the real life Louis XIIV was that vain, but I would be pretty sure that Bowser would have something to say about his constant prattling about how beautiful he was. :p

Assuming they're not cached, anyway.

I did some testing of this a while back for other pieces of text in the UI, but any updates, although reflected in the database, wouldn't show up in the interface. Not everything was like this, but I suppose I was trying to look for cases where it wouldn't work.
While this is important, fortunately it doesn't affect diplomacy lines as far as I know, even if they've changed in game (e.g. Blanc's different emotions and Bowser talking about which female leader to kidnap). To be fair, I have not seen these myself, but Vicevirtuoso said it worked fine and someone left a comment on Bowser's workshop page about those special lines, so it must have worked. ;)

I guess it's also worth mentioning that since this alters the database directly, the line changes will stay even if you load a different game. You could account for this and reset the lines on each game load (before changing them again), but that depends on whether you think it's worth it, since very few people would load a totally different game with the same set of mods in the same CiV session.

Also, I do want to write up a tutorial for this stuff soon - not that I expect that you'll need it, JFD, but because less experienced modders might want to try it (and I've had a PM request for how to use this).
 
What interests me about this is that it may be possible to have the AI act in certain ways in response to custom civ special abilities.

Like, for the Cree, you can errrm.... requisition horses for your own use. If you do, the AI will denounce you, because I programmed them that way. But, with this, you may be able to have them actually call you up and rage at you for stealing their horses and THEN denounce you.
 
You certainly could do that, as you can set the lines to change whenever you want, not just at game start. Well, you can't make a completely new message, but you could replace the normal denouncing message with something like that.

Just make sure that if you're doing something like that, that you change it back afterwards (so they don't keep talking about denouncing you because you nicked their horses forever). Also, it might be tricky to account for civilizations that might have their own denouncing messages. Not impossible by any means, but a bit involved.
 
As per Vicevirtuoso's recommendations that I don't need to check the database as much, I've updated the Lua file with a version that cuts back on those checks - get it from the same place. I'll still keep a link to the original version here, just in case you want it for debugging purposes or something.

I did run a quick test with Bowser and fixed the errors when they came up, and I still get the greeting text changes with Eggman and Louis XIV, so I think it's still working correctly. :mischief:
 
Wanted to chime in to say that I successfully made this work for changing the name of a civilization. There are two civilizations on the workshop named Planeptune; if the first one is present in the game, mine gets named to "Planeptune mk2" and its capital is named "New Planeptune"; otherwise, mine just remains Planeptune.

I think JFD could make serious use of that, what with his 50 Russias...
 
If any of you has my updated Bowser, you might have noticed that it has "UniqueDiplomacyUtilsV2.lua". I'm getting second opinions on the basic tutorial I wrote, but otherwise, expect a proper release thread for that soon. Very soon.
 
Aaaaaaand... it's posted. While you're still welcome to make any comments here, I'll only be updating the latter thread from now on.

Changes in V2:
  • ChangeDiplomacyResponse() no longer requires a targetResponseType - passing nil for that parameter will replace all entries that match targetResponse regardless of their response type.
  • Locale parameter is now optional for ChangeDiplomacyGameTextToString() and AddDiplomacyGameTextFromString() - they will default to the current locale if it is not supplied.
 
Back
Top Bottom