• 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.

Foraven

Major
17 Badges
May 14, 2016
544
168
  • Sword of the Stars II
  • Stellaris: Humanoids Species Pack
  • Stellaris: Necroids
  • Stellaris: Federations
  • Stellaris: Lithoids
  • Stellaris: Ancient Relics
  • Stellaris: Megacorp
  • Shadowrun Returns
  • Stellaris: Distant Stars
  • Stellaris: Apocalypse
  • Stellaris: Synthetic Dawn
  • Stellaris - Path to Destruction bundle
  • Stellaris: Leviathans Story Pack
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Stellaris
I have been working on this for some time and i believe i've fixed most of the bugs, but i have a major one left that i don't think i can fix myself. As far as i can tell that bug was in PDX original code so i have no idea what i should do about it.

Here the errors :

Code:
[eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
[18:04:25][eventtarget.cpp:934]: Undefined event target: pirate_target, location:  file: events/pirate_events.txt line: 965
[18:04:25][eventtarget.cpp:934]: Undefined event target: pirate_target, location:  file: events/pirate_events.txt line: 965
[18:04:25][eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
[18:04:25][eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
[18:04:25][eventtarget.cpp:934]: Undefined event target: pirate_target, location:  file: events/pirate_events.txt line: 965
[18:04:25][eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
[18:04:25][eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
[18:04:25][eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
[18:04:25][eventtarget.cpp:934]: Undefined event target: pirate_target, location:  file: events/pirate_events.txt line: 965
[18:04:25][eventtarget.cpp:934]: Undefined event target: capital_system, location:  file: events/pirate_events.txt line: 953
over and over...

And here the part of the code that spawn it this:

Code:
# Building a new fleet (HIDDEN)

country_event = {
    id = pirate.2
    hide_window = yes
   
    trigger = {
        is_country_type = pirate
        OR = {
            num_fleets < 2
            num_ships < 5
        }
        any_owned_ship = {
            is_ship_size = pirate_station
        }
    }
   
    mean_time_to_happen = {
        #days = 180
        days = 30
    }
   
   
    immediate = {

        random_country = {
            limit = {
                has_relation_flag = { flag = pirate_relation who = ROOT }
            }
            save_event_target_as = pirate_target           
            capital_scope = {
                solar_system = { save_event_target_as = capital_system }
            }

            owner_species = { save_event_target_as = owner_species }
        }
        # If we get to spawn a new fleet, we want a better admiral to run it
        create_leader = {
            type = admiral
            species = owner_main_species
            name = random
            skill = 300
        }
       
                # What design we will use for our brand new fleet
                if = {
                    limit = { 
                        ROOT = { has_technology = "tech_mass_drivers_1" }
                    }   
                    create_ship_design = {
                        design = "Reaver"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }   
                    create_ship_design = {
                        design = "Hunter"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = { 
                        ROOT = { has_technology = "tech_missiles_1" }
                    }   
                    create_ship_design = {
                        design = "Vagabond"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }   
                    create_ship_design = {
                        design = "Brigand"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_mass_drivers_1" 
                                has_technology = "tech_shields_1"
                            }
                        }   
                    }   
                    create_ship_design = {
                        design = "Skull"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }   
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_lasers_1" 
                                has_technology = "tech_mass_drivers_1" 
                                has_technology = "tech_spaceport_3"
                            }
                        }   
                    }   
                    create_ship_design = {
                        design = "Marauder"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_missiles_1" 
                                has_technology = "tech_mass_drivers_1" 
                                has_technology = "tech_spaceport_3"
                            }
                        }   
                    }   
                    create_ship_design = {
                        design = "Corsair"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_missiles_1" 
                                has_technology = "tech_mass_drivers_1" 
                                has_technology = "tech_spaceport_5"
                            }
                        }   
                    }   
                    create_ship_design = {
                        design = "Strife"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }               
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_lasers_1" 
                                has_technology = "tech_missiles_1" 
                                has_technology = "tech_spaceport_5"
                            }
                        }   
                    }   
                    create_ship_design = {
                        design = "Raven"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }                                       
       
        # We take any pirate station as our new spawn point
       
        random_owned_ship = {
            limit = { is_ship_size = pirate_station }
            save_event_target_as = pirate_home
            create_fleet = { name = "Pirate Fleet" }
           
            last_created_fleet = {
                set_fleet_stance = aggressive
                set_aggro_range_measure_from = self
                set_aggro_range = 150
                set_owner = ROOT


                # We spawn a few ships
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }   
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                } 
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                } 
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }            
                # For the second set

                # We spawn 2-3 more
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_missiles_1" 
                                has_technology = "tech_mass_drivers_1" 
                                has_technology = "tech_spaceport_3"
                                has_technology = "tech_lasers_1"
                            }
                        }   
                    }   
                    random_list = {
                        40 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            } 
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                        }
                        30 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            } 
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                       
                        }
                        20 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                           
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer" 
                                graphical_culture = "pirate_01"
                            }                               
                        }
                        10 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer" 
                                graphical_culture = "pirate_01"
                            }                                   
                        }
                    }
                    else = {
                        random_list = {
                            40 = {    }
                            30 = {
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                    
                            }
                            30 = {
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                    
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                    
                            }
                        }   
                    }       
                }
                if = {
                    limit = {
                        ROOT = { 
                            AND = { 
                                has_technology = "tech_missiles_1" 
                                has_technology = "tech_mass_drivers_1" 
                                has_technology = "tech_spaceport_5"
                                has_technology = "tech_lasers_1"
                            }
                        }   
                    }
                    random_list = {
                        40 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                                    
                        }
                        30 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                           
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                                           
                        }
                        20 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_cruiser"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                                       
                        }
                        10 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_cruiser"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                               
                        }
                    }   
                }
               
                # We assign leader to fleet
                     
                assign_leader = last_created_leader
                set_location = PREV
           
                queue_actions = {
                    repeat = {
                        find_random_system = {
                            trigger = {
                                id = "pirate.2.trigger.1"
                                NOT = {
                                    has_star_flag = hostile_system
                                    is_same_value = event_target:capital_system
                                }
                                any_planet = {
                                    OR = {
                                        has_mining_station = yes
                                        has_research_station = yes
                                    }
                                    # Attacking a spaceport is suicidal
                                    NOT = { 
                                        has_spaceport = yes
                                    }
                                    exists = controller
                                    controller = { is_same_value = event_target:pirate_target }
                                }
                                distance = {
                                    source = PREV
                                    max_distance = 200
                                    min_distance = 20
                                }
                            }
                            found_system = {
                                move_to = THIS
                            } 
                        }
                        # We find a juicy target to kill
                        find_closest_planet = {
                            trigger = {
                                id = "pirate.2.trigger.2"
                                OR = {
                                    has_research_station = yes
                                    has_mining_station = yes
                                }
                            }
                            found_planet = {
                                orbit_planet = THIS
                                    wait = {
                                    duration = 20
                                }
                            }
                        }
                        # We go home to heal
                        find_random_system = {
                            trigger = {
                                id = "pirate.2.trigger.3"
                                any_planet = {
                                    is_planet = event_target:pirate_home
                                }
                            }   
                            found_system = { move_to = THIS } 
                        }
                        # We go to base for some rest
                        find_closest_planet = {
                            trigger = {
                                id = "pirate.2.trigger.4"
                                is_planet = event_target:pirate_home
                            }
                                found_planet = {
                                orbit_planet = THIS
                                wait = {
                                    duration = 200
                                    random = 150
                                }
                            }
                        }
                    }   
                }           
            }       
        }
    }
} # the end of new fleet

Can't find any mistake there and i don't get any error from my code, even with the heavy changes i made.
 
Well, there's nothing wrong with the code. Which means it's executing properly... and failing to find the target. Remove

limit = {
has_relation_flag = { flag = pirate_relation who = ROOT }
}

And then re-run the event and see if the errors spawn. If not, then we know it's something to do with the targeting, which cuts down the field a LOT.
 
If you could pastebin your entire pirate_events.txt that would help.

Just guessing from the error you've shown, something to do with maybe this part getting skipped or cut out:

Code:
        set_country_flag = birth_of_piracy
        capital_scope = { save_event_target_as = capital }
        capital_scope = {
            solar_system = { save_event_target_as = capital_system }
        }

Since it is saying that capital_system has not been defined.
 
Well, there's nothing wrong with the code. Which means it's executing properly... and failing to find the target. Remove

limit = {
has_relation_flag = { flag = pirate_relation who = ROOT }
}

And then re-run the event and see if the errors spawn. If not, then we know it's something to do with the targeting, which cuts down the field a LOT.

Thanks for checking it. I think i have a hint of what is wrong with it. I have enable AI empires to get the event but i think i haven't completely filtered out Fallen Empires and such so when a Pirate station spawn in one of those it screw things up. At least it's my current guess.
 
If you could pastebin your entire pirate_events.txt that would help.

Just guessing from the error you've shown, something to do with maybe this part getting skipped or cut out:

Code:
        set_country_flag = birth_of_piracy
        capital_scope = { save_event_target_as = capital }
        capital_scope = {
            solar_system = { save_event_target_as = capital_system }
        }

Since it is saying that capital_system has not been defined.

I'm a bit reluctant to post the whole thing right now as i have put a lot of work in it, but i may do so if i can't get it to work.

By the way, is there a way in Stellaris to make the event report when it is fired?
 
No, it's not spawning in a fallen empire - then it would still pick up the target. How are you assigning the relation flag in the first place? You firing the previous pirate events?
 
I'm a bit reluctant to post the whole thing right now as i have put a lot of work in it, but i may do so if i can't get it to work.

By the way, is there a way in Stellaris to make the event report when it is fired?

Don't hide the window and give it an 'OK' option. If it's firing for another country, then make a simple un-hidden event for any_country = { ai = no } and the call it from the event you're testing.
 
  • 1
Reactions:
I have been testing it and i can attest it works. The Birth of Space Piracy happen, ships designs are created and pirate fleet is properly spawned (with random ship designs). Problem happen when a new fleet get created from the existing station.

So here the code if anyone wants to run it (just put # in front of the cruisers as they are not a vanilla pirate design) . I purposedly reduced the time and conditions to get the event, normal conditions could take forever to happen.

Code:
############################
#
# Pirate Events
#
# Re-Written by Philippe Raymond (aka Foraven)
#
# FRB Mod
#
############################

namespace = pirate

# Birth of Space Piracy
country_event = {
    id = pirate.1
    title = "pirate.1.name"
    picture = GFX_evt_exploding_ship
    show_sound = event_space_battle
  
    desc = { # Spiritual
        text = pirate.1.desc_01
        trigger = {
            OR = {
                has_government = theocratic_republic
                has_government = transcendent_republic
                has_government = theocratic_oligarchy
                has_government = transcendent_oligarchy
                has_government = divine_mandate
                has_government = transcendent_empire
            }
        }
    }

    desc = { # Militarist
        text = pirate.1.desc_02
        trigger = {
            OR = {
                has_government = military_dictatorship
                has_government = martial_empire
                has_government = military_junta
                has_government = ordered_stratocracy
                has_government = military_republic
                has_government = martial_demarchy
            }
        }
    }

    desc = { # Materialist
        text = pirate.1.desc_03
        trigger = {
            OR = {
                has_government = despotic_hegemony
                has_government = ai_overlordship
                has_government = science_directorate
                has_government = illuminated_technocracy
                has_government = direct_democracy
                has_government = subconscious_consensus
            }
        }
    }

    desc = { # Pacifist
        text = pirate.1.desc_04
        trigger = {
            OR = {
                has_government = moral_democracy
                has_government = irenic_democracy
                has_government = peaceful_bureaucracy
                has_government = irenic_protectorate
                has_government = enlightened_monarchy
                has_government = irenic_monarchy
            }
        }
    }

    desc = { # Generic Autocracy
        text = pirate.1.desc_05
        trigger = {
            OR = {
                has_government = despotic_empire
                has_government = star_empire
            }
        }
    }

    desc = { # Generic Oligarchy
        text = pirate.1.desc_06
        trigger = {
            OR = {
                has_government = plutocratic_oligarchy
                has_government = mega_corporation
            }
        }
    }

    desc = { # Generic Democracy
        text = pirate.1.desc_07
        trigger = {
            OR = {
                has_government = indirect_democracy
                has_government = democratic_utopia
            }
        }
    }

    trigger = {
        is_country_type = default
        NOT = {
            has_country_flag = birth_of_piracy
            is_country_type = fallen_empire
            is_country_type = swarm
            is_country_type = sentinels
            is_country_type = extradimensional
            is_country_type = extradimensional_2
            is_country_type = extradimensional_3                      
        }      
        exists = capital_scope
        capital_scope = {
            solar_system = {
                ROOT = {
                    any_controlled_planet = {
                        OR = {
                            has_mining_station = yes
                            has_research_station = yes
                        }
                        solar_system = {
                            NOT = { is_same_value = PREVPREVPREV }
                        }
                    }
                }
            }
        }
    }

    is_triggered_only = yes 

    #mean_time_to_happen = {
    #    months = 12 #Triggered by pirate.4 now
    #}

    immediate = {
        save_event_target_as = pirate_target  
        set_country_flag = birth_of_piracy
        capital_scope = { save_event_target_as = capital }
        capital_scope = {
            solar_system = { save_event_target_as = capital_system }
        }
        owner_species = { save_event_target_as = owner_species }
    
        # Define what FTL we have
        if = {
            limit = {
                AND = {
                    has_technology = "tech_warp_drive_1"
                    NOT = {
                        has_technology = "tech_hyper_drive_1"
                        has_technology = "tech_wormhole_generation_1"
                    }
                }
            }
            set_country_flag = warp_pirates  
        }      
        if = {  
            limit = {
                AND = {
                    has_technology = "tech_hyper_drive_1"              
                    NOT = {
                        has_technology = "tech_warp_drive_1"
                        has_technology = "tech_wormhole_generation_1"
                    }  
                }
            }
            set_country_flag = hyper_pirates
        }  
        if = {  
            limit = {
                AND = {
                    has_technology = "tech_wormhole_generation_1"              
                    NOT = {
                        has_technology = "tech_warp_drive_1"
                        has_technology = "tech_hyper_drive_1"
                    }
                }
            }
            set_country_flag = wormhole_pirates                  
            else = {set_country_flag = jump_pirates}  
        }

        # We set our home now

            random_system = {
                limit = {
                    distance = {
                        source = event_target:capital
                        max_distance = 120
                        min_distance = 20
                    }
                    # look for a system with planets
                    any_planet = { is_colonizable = no }
                    NOT = {
                        ROOT = {
                            any_owned_planet = {
                                is_homeworld = no
                            }
                        }  
                        has_star_flag = hostile_system
                    }  
                    OR = {
                        has_owner = no
                        is_owned_by = ROOT
                    }
                }  
          
                random_system_planet = {
                   # But we don't care what planet pirates settle around so long as it' not a potential colony
                    limit = {
                        is_colonizable = no
                    }
                    save_event_target_as = pirate_home
                    create_country = {
                        name = "Pirates"
                        type = pirate
                        species = event_target:owner_species
                        name_list = "PRT1"
                        flag = {
                            icon = {
                                category = "pirate"
                                file = "flag_pirate_7.dds"
                            }
                            background = {
                                category = "backgrounds"
                                file = "00_solid.dds"
                            }
                            colors ={
                                "red"
                                "red"
                                "null"
                                "null"
                            }
                        }
                    }
                    if = {
                        limit = {
                            ROOT = {
                                has_country_flag = wormhole_pirates
                            }
                        }  
                                      
                        solar_system = {
                            create_wormhole_station = {
                                owner = last_created_country
                                angle = random
                            }
                        }                  
                    }
                    # We just created a country, now we name it
                    last_created_country = {
                        set_name = random
                        save_event_target_as = pirate_band
                        set_relation_flag = {
                            who = ROOT
                            flag = pirate_relation
                        }
                        establish_communications_no_message = ROOT                          
                                      
                        # Now creating home base inside said country
                        # Creating station designs according to starting tech  
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_mass_drivers_1" }
                                }              
                                create_ship_design = {
                                    design = "Pirate Nest"
                                }
                                add_ship_design = last_created_design
                            }  
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_lasers_1" }
                                }
                                create_ship_design = {
                                    design = "Pirate Lair"
                                }
                                add_ship_design = last_created_design
                            }  
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_lasers_1" }
                                }
                                create_ship_design = {
                                    design = "Pirate Den"
                                }
                                add_ship_design = last_created_design
                            }
                            # What design we will use for first fleet
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_mass_drivers_1" }
                                }  
                                create_ship_design = {
                                    design = "Reaver"
                                    ftl = ROOT
                                }
                                add_ship_design = last_created_design
                            }
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_lasers_1" }
                                }  
                                create_ship_design = {
                                    design = "Hunter"
                                    ftl = ROOT
                                }
                                add_ship_design = last_created_design
                            }
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_missiles_1" }
                                }  
                                create_ship_design = {
                                    design = "Vagabond"
                                    ftl = ROOT
                                }
                                add_ship_design = last_created_design
                            }
                            if = {
                                limit = {
                                    ROOT = { has_technology = "tech_lasers_1" }
                                }  
                                create_ship_design = {
                                    design = "Brigand"
                                    ftl = ROOT
                                }
                                add_ship_design = last_created_design
                            }
                            if = {
                                limit = {
                                    ROOT = {
                                        AND = {
                                            has_technology = "tech_mass_drivers_1"
                                            has_technology = "tech_shields_1"
                                        }
                                    }  
                                }  
                                create_ship_design = {
                                    design = "Skull"
                                    ftl = ROOT
                                }
                                add_ship_design = last_created_design
                            }                                          
                          
              
                        create_fleet = { name = "Pirate Station" }
                        # We pick a station design at random
                        last_created_fleet = {
                      
      
                            set_owner = PREV
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_station"
                                graphical_culture = "pirate_01"
                            }
                            set_location = PREVPREV
                        }
                        # Now creating an admiral for our first fleet
                        create_leader = {
                            type = admiral
                            species = owner_main_species
                            name = random
                            skill = 100
                        }              

                        # Now that scummy fleet
              
                        create_fleet = { name = "Pirate Fleet" }
                        last_created_fleet = {
                            set_fleet_stance = aggressive
                            set_aggro_range_measure_from = self
                            set_aggro_range = 150
                            set_owner = PREV
                      

                            # We spawn a few ships
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette" 
                                graphical_culture = "pirate_01"
                            }  
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                          
                            # And an extra one for luck
                            random_list = {
                                50 = {
                                    create_ship = {
                                        name = random
                                        random_existing_design = "pirate_corvette"
                                        graphical_culture = "pirate_01"
                                    }                              
                                }
                                50 = {   }
                            }
                          
                            # We assign leader to fleet
                      
                            assign_leader = last_created_leader
                            set_location = PREVPREV  
                      
                            # Now sending that fleet on rampage
                  
                            queue_actions = {
                                repeat = {
                                    find_random_system = {
                                        trigger = {
                                            id = "pirate.1.trigger.1"
                                            NOT = {
                                                has_star_flag = hostile_system
                                                is_same_value = event_target:capital_system
                                            }
                                            any_planet = {
                                                OR = {
                                                    has_mining_station = yes
                                                    has_research_station = yes
                                                }
                                                # Attacking system with wormhole station or a starport is suicidal
                                                NOT = {
                                                    has_spaceport =yes      
                                                }
                                                exists = controller
                                                controller = { is_same_value = event_target:pirate_target }
                                            }
                                            distance = {
                                                source = PREV
                                                max_distance = 200
                                                min_distance = 20
                                            }
                                        }
                                        found_system = {
                                            move_to = THIS
                                        }
                                    }
                                    # We find a juicy target to kill
                                    find_closest_planet = {
                                        trigger = {
                                            id = "pirate.1.trigger.2"
                                            OR = {
                                                has_research_station = yes
                                                has_mining_station = yes
                                            }
                                        }
                                        found_planet = {
                                            orbit_planet = THIS
                                            wait = {
                                                duration = 20
                                            }
                                        }
                                    }
                                    # We go back to home system
                                    find_random_system = {
                                        trigger = {
                                            id = "pirate.1.trigger.3"
                                            any_planet = {
                                                is_planet = event_target:pirate_home
                                            }
                                        }  
                                        found_system = { move_to = THIS }
                                    }
                                    # We go to base for some rest
                                    find_closest_planet = {
                                        trigger = {
                                            id = "pirate.1.trigger.4"
                                            is_planet = event_target:pirate_home
                                        }
                                        found_planet = {
                                            orbit_planet = THIS
                                            wait = {
                                                duration = 200
                                                random = 150
                                            }
                                        }
                                    }  
                                }  
                            }
                        }  
                    }
                }  
            }                         
    }
      

    option = {
        name = pirate.2.a
        trigger = {
            OR = {
                has_government = theocratic_republic
                has_government = transcendent_republic
                has_government = theocratic_oligarchy
                has_government = transcendent_oligarchy
                has_government = divine_mandate
                has_government = transcendent_empire
            }
        }
    }
    option = {
        name = pirate.2.b
        trigger = {
            OR = {
                has_government = military_dictatorship
                has_government = martial_empire
                has_government = military_junta
                has_government = ordered_stratocracy
                has_government = military_republic
                has_government = martial_demarchy
            }
        }
    }
    option = {
        name = pirate.2.c
        trigger = {
            OR = {
                has_government = despotic_hegemony
                has_government = ai_overlordship
                has_government = science_directorate
                has_government = illuminated_technocracy
                has_government = direct_democracy
                has_government = subconscious_consensus
            }
        }
    }
    option = {
        name = pirate.2.d
        trigger = {
            OR = {
                has_government = moral_democracy
                has_government = irenic_democracy
                has_government = peaceful_bureaucracy
                has_government = irenic_protectorate
                has_government = enlightened_monarchy
                has_government = irenic_monarchy
            }
        }
    }
    option = {
        name = pirate.2.e
        trigger = {
            OR = {
                has_government = despotic_empire
                has_government = star_empire
            }
        }
    }
    option = {
        name = pirate.2.f
        trigger = {
            OR = {
                has_government = plutocratic_oligarchy
                has_government = mega_corporation
            }
        }
    }
    option = {
        name = pirate.2.g
        trigger = {
            OR = {
                has_government = indirect_democracy
                has_government = democratic_utopia
            }
        }
    }
}

# Building a new fleet (HIDDEN)

country_event = {
    id = pirate.2
    hide_window = yes
  
    trigger = {
        is_country_type = pirate
        OR = {
            num_fleets < 2
            num_ships < 5
        }
        any_owned_ship = {
            is_ship_size = pirate_station
        }
    }
  
    mean_time_to_happen = {
        #days = 180
        days = 30
    }
  
  
    immediate = {

        random_country = {
            limit = {
                has_relation_flag = { flag = pirate_relation who = ROOT }
            }
            save_event_target_as = pirate_target          
            capital_scope = {
                solar_system = { save_event_target_as = capital_system }
            }

            owner_species = { save_event_target_as = owner_species }
        }
        # If we get to spawn a new fleet, we want a better admiral to run it
        create_leader = {
            type = admiral
            species = owner_main_species
            name = random
            skill = 300
        }
      
                # What design we will use for our brand new fleet
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_mass_drivers_1" }
                    }  
                    create_ship_design = {
                        design = "Reaver"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }  
                    create_ship_design = {
                        design = "Hunter"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_missiles_1" }
                    }  
                    create_ship_design = {
                        design = "Vagabond"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }  
                    create_ship_design = {
                        design = "Brigand"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_shields_1"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Skull"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }  
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_lasers_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_3"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Marauder"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_3"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Corsair"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_5"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Strife"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }              
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_lasers_1"
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_spaceport_5"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Raven"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }                                      
      
        # We take any pirate station as our new spawn point
      
        random_owned_ship = {
            limit = { is_ship_size = pirate_station }
            save_event_target_as = pirate_home
            create_fleet = { name = "Pirate Fleet" }
          
            last_created_fleet = {
                set_fleet_stance = aggressive
                set_aggro_range_measure_from = self
                set_aggro_range = 150
                set_owner = ROOT


                # We spawn a few ships
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }  
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }           
                # For the second set

                # We spawn 2-3 more
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_3"
                                has_technology = "tech_lasers_1"
                            }
                        }  
                    }  
                    random_list = {
                        40 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                        }
                        30 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                      
                        }
                        20 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                          
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                              
                        }
                        10 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                                  
                        }
                    }
                    else = {
                        random_list = {
                            40 = {    }
                            30 = {
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                   
                            }
                            30 = {
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                   
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                   
                            }
                        }  
                    }      
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_5"
                                has_technology = "tech_lasers_1"
                            }
                        }  
                    }
                    random_list = {
                        40 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                                   
                        }
                        30 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                          
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                                          
                        }
                        20 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_cruiser"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                                      
                        }
                        10 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_cruiser"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                              
                        }
                    }  
                }
              
                # We assign leader to fleet
                    
                assign_leader = last_created_leader
                set_location = PREV
          
                queue_actions = {
                    repeat = {
                        find_random_system = {
                            trigger = {
                                id = "pirate.2.trigger.1"
                                NOT = {
                                    has_star_flag = hostile_system
                                    is_same_value = event_target:capital_system
                                }
                                any_planet = {
                                    OR = {
                                        has_mining_station = yes
                                        has_research_station = yes
                                    }
                                    # Attacking a spaceport is suicidal
                                    NOT = {
                                        has_spaceport = yes
                                    }
                                    exists = controller
                                    controller = { is_same_value = event_target:pirate_target }
                                }
                                distance = {
                                    source = PREV
                                    max_distance = 200
                                    min_distance = 20
                                }
                            }
                            found_system = {
                                move_to = THIS
                            }
                        }
                        # We find a juicy target to kill
                        find_closest_planet = {
                            trigger = {
                                id = "pirate.2.trigger.2"
                                OR = {
                                    has_research_station = yes
                                    has_mining_station = yes
                                }
                            }
                            found_planet = {
                                orbit_planet = THIS
                                    wait = {
                                    duration = 20
                                }
                            }
                        }
                        # We go home to heal
                        find_random_system = {
                            trigger = {
                                id = "pirate.2.trigger.3"
                                any_planet = {
                                    is_planet = event_target:pirate_home
                                }
                            }  
                            found_system = { move_to = THIS }
                        }
                        # We go to base for some rest
                        find_closest_planet = {
                            trigger = {
                                id = "pirate.2.trigger.4"
                                is_planet = event_target:pirate_home
                            }
                                found_planet = {
                                orbit_planet = THIS
                                wait = {
                                    duration = 200
                                    random = 150
                                }
                            }
                        }
                    }  
                }          
            }      
        }
    }
} # the end of new fleet

#Starting the pirate chain
ship_event = {
    id = pirate.3
    hide_window = yes
    is_triggered_only = yes

    trigger = {
        owner = { is_country_type = default }
        from = {
            solar_system = {
                NOT = {
                    any_planet = {
                        is_homeworld = yes
                    }
                }
            }
        }
        NOT = {
            owner = {
                has_country_flag = outer_system_mining_stations_constructed
                has_country_flag = birth_of_piracy
                is_country_type = fallen_empire
                is_country_type = swarm
                is_country_type = sentinels
                is_country_type = extradimensional
                is_country_type = extradimensional_2
                is_country_type = extradimensional_3              
            }
        }
    }

    immediate = {
        owner = {
            if = {
                limit = {
                    NOT = {
                        check_variable = {
                            which = outer_system_mining_stations
                            value > 0
                        }
                    }
                }
                set_variable = {
                    which = "outer_system_mining_stations"
                    value = 1
                }
                else = {
                    change_variable = {
                        which = "outer_system_mining_stations"
                        value = 1
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = outer_system_mining_stations
                        value > 4
                    }
                }
                set_country_flag = outer_system_mining_stations_constructed
            }
        }
    }
}

event = {
    id = pirate.4
    hide_window = yes
    is_triggered_only = yes
  
    immediate = {
        every_country = {
            limit = {
                #is_ai = no   #we want ais to suffer too :D
                NOT = {
                    has_country_flag = birth_of_piracy
                    is_country_type = fallen_empire
                    is_country_type = swarm
                    is_country_type = sentinels
                    is_country_type = extradimensional
                    is_country_type = extradimensional_2
                    is_country_type = extradimensional_3                      
                }
            }
            country_event = { id = pirate.5 }
        }
    }
}          
          
#yearly pulse event to start the "birth of piracy" somewhere
country_event = {
    id = pirate.5
    hide_window = yes
    is_triggered_only = yes
    trigger = {
        is_country_type = default
        OR = {
            has_country_flag = outer_system_mining_stations_constructed
            any_owned_planet = {
                is_homeworld = no
            }
        }
        NOT = {
            has_country_flag = birth_of_piracy
            is_country_type = fallen_empire
            is_country_type = swarm
            is_country_type = sentinels
            is_country_type = extradimensional
            is_country_type = extradimensional_2
            is_country_type = extradimensional_3                      
        }      
    }
  
    immediate = {  
        #random_list = {
        #    30 = { country_event = { id = pirate.1 days = 50 random = 45 } }
        #    30 = { country_event = { id = pirate.1 days = 500 random = 450 } }
        #    40 = {  }
        #}
        country_event = { id = pirate.1 } #country_event = { id = pirate.1 days = 50 random = 45 }
    }
}          

# Look for an existing Pirate Country that lost it's pirate station so it can spawn another one elsewhere.
country_event = {
    id = pirate.6
    hide_window = yes
  
    trigger = {
        is_country_type = pirate
        any_owned_ship = {
            NOT {
                is_ship_size = pirate_station
            }      
        }
    }
  
    mean_time_to_happen = {
        #Months = 12
        Months = 2
    }
  
    immediate = {
  
        random_country = {
            limit = {
                has_relation_flag = { flag = pirate_relation who = ROOT }
            }
            save_event_target_as = pirate_target          
            capital_scope = { save_event_target_as = capital }
            capital_scope = {
                solar_system = { save_event_target_as = capital_system }
            }

            owner_species = { save_event_target_as = owner_species }
        }
        # If we get to spawn a new fleet, we want a better admiral to run it
        create_leader = {
            type = admiral
            species = owner_main_species
            name = random
            skill = 300
        }
      
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_mass_drivers_1" }
                    }              
                    create_ship_design = {
                        design = "Pirate Nest"
                    }
                    add_ship_design = last_created_design
                }  
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }
                    create_ship_design = {
                        design = "Pirate Lair"
                    }
                    add_ship_design = last_created_design
                }  
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }
                    create_ship_design = {
                        design = "Pirate Den"
                    }
                    add_ship_design = last_created_design
                }                          


                # What design we will use for our brand new fleet
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_mass_drivers_1" }
                    }  
                    create_ship_design = {
                        design = "Reaver"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }  
                    create_ship_design = {
                        design = "Hunter"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_missiles_1" }
                    }  
                    create_ship_design = {
                        design = "Vagabond"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = { has_technology = "tech_lasers_1" }
                    }  
                    create_ship_design = {
                        design = "Brigand"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_shields_1"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Skull"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }  
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_lasers_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_3"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Marauder"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_3"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Corsair"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_5"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Strife"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }              
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_lasers_1"
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_spaceport_5"
                            }
                        }  
                    }  
                    create_ship_design = {
                        design = "Raven"
                        ftl = ROOT
                    }
                    add_ship_design = last_created_design
                }  
              
        # We take any pirate station as our new spawn point
      
        random_system = {
            limit = {
                distance = {
                    source = event_target:capital
                    max_distance = 120
                    min_distance = 20
                }
                # look for a system with planets
                any_planet = { is_colonizable = no }
                NOT = {
                    ROOT = {
                        any_owned_planet = {
                            is_homeworld = no
                        }
                    }  
                    has_star_flag = hostile_system
                }  
                OR = {
                    has_owner = no
                    is_owned_by = ROOT
                }
            }  
          
            random_system_planet = {
               # But we don't care what planet pirates settle around so long as it' not a potential colony
                limit = {
                    is_colonizable = no
                }
                save_event_target_as = pirate_home
            }
            create_fleet = { name = "Pirate Station" }
            # We pick a station design at random
            last_created_fleet = {
                set_owner = PREV
                create_ship = {
                    name = random
                    random_existing_design = "pirate_station"
                    graphical_culture = "pirate_01"
                }
                set_location = PREVPREV
            }                      

            last_created_fleet = {
                set_fleet_stance = aggressive
                set_aggro_range_measure_from = self
                set_aggro_range = 150
                set_owner = ROOT


                # We spawn a few ships
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }  
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }
                create_ship = {
                    name = random
                    random_existing_design = "pirate_corvette"
                    graphical_culture = "pirate_01"
                }           
                # For the second set

                # We spawn 2-3 more
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_3"
                                has_technology = "tech_lasers_1"
                            }
                        }  
                    }  
                    random_list = {
                        40 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                        }
                        30 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                      
                        }
                        20 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                          
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                              
                        }
                        10 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                                  
                        }
                    }
                    else = {
                        random_list = {
                            40 = {    }
                            30 = {
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                   
                            }
                            30 = {
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                   
                                create_ship = {
                                    name = random
                                    random_existing_design = "pirate_corvette"
                                    graphical_culture = "pirate_01"
                                }                   
                            }
                        }  
                    }      
                }
                if = {
                    limit = {
                        ROOT = {
                            AND = {
                                has_technology = "tech_missiles_1"
                                has_technology = "tech_mass_drivers_1"
                                has_technology = "tech_spaceport_5"
                                has_technology = "tech_lasers_1"
                            }
                        }  
                    }
                    random_list = {
                        40 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                                   
                        }
                        30 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                          
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                                          
                        }
                        20 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_cruiser"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_corvette"
                                graphical_culture = "pirate_01"
                            }                                      
                        }
                        10 = {
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_cruiser"
                                graphical_culture = "pirate_01"
                            }
                            create_ship = {
                                name = random
                                random_existing_design = "pirate_destroyer"
                                graphical_culture = "pirate_01"
                            }                              
                        }
                    }  
                }
              
                # We assign leader to fleet
                    
                assign_leader = last_created_leader
                set_location = PREV  
          
                queue_actions = {
                    repeat = {
                        find_random_system = {
                            trigger = {
                                id = "pirate.6.trigger.1"
                                NOT = {
                                    has_star_flag = hostile_system
                                    is_same_value = event_target:capital_system
                                }
                                any_planet = {
                                    OR = {
                                        has_mining_station = yes
                                        has_research_station = yes
                                    }
                                    # Attacking a spaceport is suicidal
                                    NOT = {
                                        has_spaceport = yes
                                    }
                                    exists = controller
                                    controller = { is_same_value = event_target:pirate_target }
                                }
                                distance = {
                                    source = PREV
                                    max_distance = 200
                                    min_distance = 20
                                }
                            }
                            found_system = {
                                move_to = THIS
                            }
                        }
                        # We find a juicy target to kill
                        find_closest_planet = {
                            trigger = {
                                id = "pirate.6.trigger.2"
                                OR = {
                                    has_research_station = yes
                                    has_mining_station = yes
                                }
                            }
                            found_planet = {
                                orbit_planet = THIS
                                    wait = {
                                    duration = 20
                                }
                            }
                        }
                        # We go home to heal
                        find_random_system = {
                            trigger = {
                                id = "pirate.6.trigger.3"
                                any_planet = {
                                    is_planet = event_target:pirate_home
                                }
                            }  
                            found_system = { move_to = THIS }
                        }
                        # We go to base for some rest
                        find_closest_planet = {
                            trigger = {
                                id = "pirate.6.trigger.4"
                                is_planet = event_target:pirate_home
                            }
                            found_planet = {
                                orbit_planet = THIS
                                wait = {
                                    duration = 200
                                    random = 150
                                }
                            }
                        }
                    }  
                }          
            }      
        }
    }
} # the end of new pirate station and fleet  
  

# Respawn Wormhole Station for the Wormholes Pirates  
country_event = {
    id = pirate.7
    hide_window = yes
  
    trigger = {
        is_country_type = pirate
        has_country_flag = wormhole_pirates
        any_owned_ship = {
            is_ship_size = pirate_station
        }
        NOT = {
            any_owned_ship = {
                is_ship_size = wormhole_station
            }
        }
    }
  
    mean_time_to_happen = {
        Months = 4
    }  

    immediate = {
  
        random_system = {  
            limit = {
                is_pirate_system = yes
            }
            solar_system = {
                create_wormhole_station = {
                    owner = last_created_country
                    angle = random
                }
            }                              
        }
    }  
}

I hope this can be fixed, i have put many hours in this.
 
Rather than define ship designs inside the event, it might be cleaner to design the ships and just select them here.

Line 614 in your script reads:
has_relation_flag = { flag = pirate_relation who = ROOT }

Whereas line 694 in pirate_events.txt reads:
reverse_has_relation_flag = { flag = pirate_relation who = ROOT }

Your line 621 adds in this additional line not in the original:
owner_species = { save_event_target_as = owner_species }

is there a way to comment out blocks of script, like /# /# or something?
 
Rather than define ship designs inside the event, it might be cleaner to design the ships and just select them here.

Still learning what can be done with Stellaris script, i would rather have fleet created in one function rather than have multiple instance. One of the reason i use saved designs instead of creating new one every time like in the original script.

Line 614 in your script reads:
has_relation_flag = { flag = pirate_relation who = ROOT }

Whereas line 694 in pirate_events.txt reads:
reverse_has_relation_flag = { flag = pirate_relation who = ROOT }

Yes, that's a voluntary change. The "owner" of the pirate is the one with the relation, not the reverse from what i understand. But the errors happen if i leave it like the original so the problem isn't there.

Your line 621 adds in this additional line not in the original:
owner_species = { save_event_target_as = owner_species }

Added line, but as far as i know it's not related to the problem.

is there a way to comment out blocks of script, like /# /# or something?

Yes, #, used in many place in the file already.
 
Well, seem the best solution for now is to not use that function at all. I quoted out the pirate_target and capital_system and everything works fine. Of course i have to use something else to prevent the pirates from just storming the homeworld system.
 
Well, seem the best solution for now is to not use that function at all. I quoted out the pirate_target and capital_system and everything works fine. Of course i have to use something else to prevent the pirates from just storming the homeworld system.


is_homeworld in the target selection of what system to invade?

In the target selection part where it checks for a mining station or science station:


NOT = { any_planet = is_homeworld }

perhaps? It is confusing, since any_planet uses "this" system, whether "this" system will scope to the system of the mining or science station, or the current system the pirate fleet is in.

or every_system_planet, I'm not sure the difference between the two.
 
Last edited:
I made some progress with my code. I found the bug : "exists = capital_scope" is needed in the trigger. From what i understand the code look for the Empire capital, once it's found the rest of the script can take effect (because the pirates are not supposed to attack the capital system at all). I found quite a few other bugs, especially for spawning new stations. But i'm getting there, soon that darn event script will work and make nasty recuring pirates a reality.
 
Well, seem i got rid of most of the bugs now, but still have some issue with the "has_technology" check. Works well for the Birth of Piracy part, but the new fleets and new station seem to have all the tech they want thus can create any ships. Not sure how to make it check for the tech it's parent empire has.