I've always been annoyed by the localisation system of CK2: When you want an event to display some text you have to create a localisation key, go to another file and create the corresponding localisation there. While it's a bit tedious to switch files for every event, it's much more annoying when you want to remember what the localisation of a specific event is, since you'll have to go back to the localisation file again. Wouldn't it be much easier, if the localisation were located in the same file?
Some time ago (when I made my murder plot mod), I decided to make a quick and dirty python script to fix that issue. Then I wanted macros and added them as well, making the whole thing less quick and more dirty. Nonetheless, it might be helpful to others as well and there do not seem to be other tools for it.
So what does it do?
Instead of writing:
and a loc file entry
you can now write
in a .ck2script file. Don't you think that this is much nicer? The same thing works for all other localisation keys, like decisions, tooltips, event options. When executing the python script, all .ck2script files will be "converted" into .txt and .csv files.
There is also a somewhat terrible, regex subsitution based macro support:
The script replaces the macro call with the macro definition, so the indentation might look terrible... You can use other macros in macros as well (non circular, of course).
Then went a little crazy and added an even worse script that allows you to use a special macro: @Python. It takes a parameter string (for example "a,b,c"), a code string (for example "print(str(int(a)+int(b)*int(c)))") and an argument string (for example "42,6,7"). Since the implementation is regex based, it's... a bit picky about strings as arguments and such things, so better use single words only.
This macro needs to end with ')endpython' (since it is awfully implemented): @python(...)endpython
What is it good for?
Of course, you could just write that code somewhere else and copy the result in your event file but then making changes is a more difficult. However, the macro approach also has it's obvious weaknesses: It's hard to read and hard to debug. But hey, it might be useful one day.
Usage: Write .ck2script and .ck2macro files, run the python script in the mod folder (I added a .bat file since that allows you to just click on it). Done. Make changes to the script files, run again.
Some time ago (when I made my murder plot mod), I decided to make a quick and dirty python script to fix that issue. Then I wanted macros and added them as well, making the whole thing less quick and more dirty. Nonetheless, it might be helpful to others as well and there do not seem to be other tools for it.
So what does it do?
Instead of writing:
Code:
character_event = {
id = N.1
desc = EVTDESC.N.1
...
}
Code:
EVTDESC.N.1;This is an event description...;;;;;;;;;;;;;x
Code:
character_event = {
id = N.1
desc = <<EVTDESC.N.1;"This is an event description...">>
...
option = {
name = <<EVTOPT_a_N.1;"Interesting...">>
...
}
...
}
There is also a somewhat terrible, regex subsitution based macro support:
Code:
#local macros are defined in the same file, global macros in extra file at root level.
#the first macro might be useful for balancing: Instead of changing the magic number 12 everywhere, you only have to adjust it here.
@beginmacro medium_cost():
12
@endmacro
#The difference between this macro and scripted effects is that you can specify the chance. Scripted effects don't take parameters...
@beginmacro remove_trait_chance(macroP_trait, macroP_chance):
if = {limit = {has_trait = macroP_trait}
random = {
chance = macroP_chance
remove_trait = macroP_trait
}
}
@endmacro
#somewhere later
effect = {
@remove_trait(kind, 42)
wealth = -@medium_cost()
}
Then went a little crazy and added an even worse script that allows you to use a special macro: @Python. It takes a parameter string (for example "a,b,c"), a code string (for example "print(str(int(a)+int(b)*int(c)))") and an argument string (for example "42,6,7"). Since the implementation is regex based, it's... a bit picky about strings as arguments and such things, so better use single words only.
This macro needs to end with ')endpython' (since it is awfully implemented): @python(...)endpython
What is it good for?
Code:
@python("skill, max_level","
import math
s = ''
for i in range(0,int(max_level)):
factor = math.sqrt(i)/2
s+= 'modifier = {\n factor = '+str(factor)+'\n '+skill+' = '+str(i)+' \nNOT = {'+skill+' = ' + str(i+1)+'}\n}\n'
print(s)
",intrigue,25)endpython
Usage: Write .ck2script and .ck2macro files, run the python script in the mod folder (I added a .bat file since that allows you to just click on it). Done. Make changes to the script files, run again.