• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

AngelFromAnotherPin

Recruit
31 Badges
Sep 10, 2017
2
0
  • Crusader Kings III
  • Prison Architect
  • Crusader Kings II: Holy Fury
  • Crusader Kings II: Jade Dragon
  • BATTLETECH
  • Stellaris - Path to Destruction bundle
  • Crusader Kings II: Monks and Mystics
  • Tyranny: Archon Edition
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: Cadet
  • Stellaris
  • Crusader Kings II: Conclave
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Way of Life
  • Mount & Blade: Warband
  • King Arthur II
  • Ancient Space
  • Heir to the Throne
  • Europa Universalis IV
  • Divine Wind
  • Europa Universalis III: Chronicles
  • Europa Universalis III
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Charlemagne
  • Crusader Kings II
Hello all. Long-time CK2 player, first-time CK2 modder. I have a pretty concrete idea of what I want to do, but I can't really parse the programming to do it (and I'm actually not certain all the commands for it exist) so I'm looking for some help.

The idea is that particularly competent battle commanders will sometimes produce unexpectedly good results, and that conversely, particularly incompetent battle commanders will sometimes produce real disasters.

So a simple english version would look something like:
IF a character is commanding an army in battle;
AND they are EITHER a skilled tactician OR a brilliant strategist;
AND they have a Military attribute ≥ 12;
AND their Military attribute is greater than the opposing commander's;
THEN there is a chance of (their Military minus the opposing commander's military)% that the enemy army will rapidly collapse.
... and then something similar in the other direction for the incompetents.

Any assistance is appreciated.
 

Korbah

Ratel
137 Badges
Mar 3, 2011
4.758
1.272
  • Europa Universalis IV
  • Crusader Kings II: Holy Knight (pre-order)
  • Cities: Skylines - Snowfall
  • Cities: Skylines - Natural Disasters
  • Cities: Skylines - Campus
  • Age of Wonders: Planetfall
  • Age of Wonders: Planetfall Deluxe edition
  • Stellaris: Federations
  • Imperator: Rome - Magna Graecia
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Battle for Bosporus
  • Stellaris: Necroids
  • Stellaris: Nemesis
  • Victoria 3 Sign Up
  • Hearts of Iron IV: No Step Back
There's a couple of ways to do it. The simplest method would be to write a couple of new tactics.
Rough example
Code:
masterful_general_tactic = {
    days = 18
    sprite = 5
    group = charge

    trigger = {
        phase = melee
        knights = 0.01
       leader = { OR = { trait = brilliant_strategist trait = skilled_tactician } }
    }

    mean_time_to_happen = {
        days = 3
    }

    knights_offensive = 10
    light_cavalry_offensive = 10
    camel_cavalry_offensive = 10
    heavy_infantry_offensive = 10
    pikemen_offensive = 10

    enemy = {
        group = charge
        factor = 3
    }
}

You can find more info about tactics by scouring the 00_combat_tactics.txt file or the ck2 wiki.


The other method is an on_action event that's fired from the on_combat_pulse as a random event.
You'd add your events to the random_events block specifying a number like "200 = event.id", this gives it a weight of 200. The random event block by default has a 2750 = 0, which combined with all the other weights you can read as a % chance of an event occuring.
The total (if my quick calculation is right) of all the weights currently in the vanilla file is 3365, this includes the DLC events.
If you add your own event and gave it a weight of 1683 it would have a roughly 50% chance of appearing each combat pulse, 842 would be a roughly 25% chance of appearing instead of one of the other events per combat pulse. 337 would be roughly 10%. Most other events in the random_event block however range from between 5 to 50, if you want your event to occur about as much as the other events you should select something between that range, such as perhaps 15.
Here's a quick example of something like what you've outlined;
Code:
namespace = afap

#Masterful strategies destroy enemy morale
character_event = {
    id = afap.0 #the eventid, this is what you would add to on_actions.
    desc = afap.0.desc #Add to localisation a key afap.0.desc with whatever you'd like the event to say.
    picture = GFX_evt_battle
    border = GFX_event_normal_frame_war
   
    is_triggered_only = yes #We add this as on_actions trigger the event, without this line it will fire with literally every day.
   
    trigger = { #These are the conditions a character must meet to have the event trigger for them.
        OR = {
            trait = brilliant_strategist
            trait = skilled_tactician
        }
        #Currently the operators <= >= < > don't work but are coming in the next patch.
        martial = 12 #Until then we use this, which works as >=, so equal to or greater than.
        #NOT = { martial = 12 } #would mean less than. Might mean equal to or less than, but I can't actually remember...
    }
   
    weight_multiplier = {
        #Instead of setting your weight higher in on_actions, you can influence here in the event itself by adding
        #modifiers to the weight_multiplier. It's much more dynamic than simply upping the value in on_actions.
        #I've included a few here to demonstrate.
        modifier = {
            factor = 1.5
            OR = {
                trait = shrewd
                trait = quick
            }
        }
        modifier = {
            factor = 2.0
            trait = genius
        }
        modifier = {
            factor = 0.5
            OR = {
                trait = slow
                trait = dull
            }
        }
        modifier = {
            factor = 0.25
            trait = inbred
        }
        modifier = {
            factor = 0.25
            trait = imbecile
        }
    }
   
    option = {
        name = afap.0.o1 #Another localisation string, keep this one short.
        FROM = { morale = -1 } #iirc FROM is the enemy commander. This will basically cause the enemy army to lose 100% of it's morale as soon as this option is taken.
    }
}

Now the best thing to do wouldn't be to just stick that event in and assume it'll work 100% how you want. Rather it's to give you an example from which to learn (plus I wrote it from memory). Your next task should be to experiment with simple battle events until you're satisfied with results. You can learn basically everything you need to know about modding events from the CK2 Wiki. It's a great resource and really will help you to learn.
Some very relevant pages;
http://www.ckiiwiki.com/Modding
http://www.ckiiwiki.com/Scripting
http://www.ckiiwiki.com/Event_modding
http://www.ckiiwiki.com/Scopes
http://www.ckiiwiki.com/Commands
http://www.ckiiwiki.com/Conditions
 

AngelFromAnotherPin

Recruit
31 Badges
Sep 10, 2017
2
0
  • Crusader Kings III
  • Prison Architect
  • Crusader Kings II: Holy Fury
  • Crusader Kings II: Jade Dragon
  • BATTLETECH
  • Stellaris - Path to Destruction bundle
  • Crusader Kings II: Monks and Mystics
  • Tyranny: Archon Edition
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: Cadet
  • Stellaris
  • Crusader Kings II: Conclave
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Way of Life
  • Mount & Blade: Warband
  • King Arthur II
  • Ancient Space
  • Heir to the Throne
  • Europa Universalis IV
  • Divine Wind
  • Europa Universalis III: Chronicles
  • Europa Universalis III
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Charlemagne
  • Crusader Kings II
Thanks a bunch! I actually have been looking at the wiki, but the amount of text to dredge through is kind of overwhelming and not intuitively searchable, so this specific clarity is really helpful. I'll keep plugging away.