• 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.
Random, pulls from any valid portrait, traits, and government (anything not specifically disabled for random use).

Starting systems are scripted in common\Stellaris\common\solar_system_initializers\empire_initializers.txt
 
I'm not entirely sure what you want, but this is a great question that hasn't been handled very well in other threads. I'm sure someone will come looking for some information via the search bar. Anyways, here is some code from the Star-Spawn of Cthulhu mod for generating a custom space-faring empire and custom species when the game starts. I hope this helps someone.

Just change all the Cthulhu parts to meet your needs. =)

/common/on_actions/11_chr_on_actions.txt

===================================
Set-up a game start action so we can choose if we want our empire in this galaxy or not.
on_game_start = {
events = {
story.2900 #Creates window to check if we want to spawn our empire
}
}


/events/12_chr_story_events.txt
=========================
Makes the window appear for the game start choice (Spawn Cthulhu vs Burn the Necronomicon)
namespace = story

#Necronomicon (Full version in the actual mod, this is cut down to one choice)
country_event = {
id = story.2900
title = story.2900.title
picture = GFX_evt_necronomicon
show_sound = event_alien_nature

#trigger = { always = yes }
#hide_window = no
#is_triggered_only = yes

desc = {
trigger = {
NOT = { has_government = chr_govt_old_one }
NOT = { has_government = chr_govt_outer_god }
}
text = story.2900.desc.1
}
desc = {
trigger = {
has_government = chr_govt_old_one
has_government = chr_govt_outer_god
}
text = story.2900.desc.2
}

trigger = {
is_ai = no
NOT = { has_country_flag = Story2900 }
}

immediate = {
hidden_effect = { country_event = { id = story.2899 } }
}

#Summon Cthulhu
option = {
name = story.2900.option.1
custom_tooltip = story.2900.option.1.tooltip

#Add horrors
trigger = {
NOT = { has_country_flag = CosmicSpawnComplete }
}
set_country_flag = CosmicSpawnComplete
hidden_effect = { country_event = { id = buildempire.1 } }

hidden_effect = { country_event = { id = buildempire.99 } } #Fix Leaders
}

#Burn the book
option = {
name = story.2900.option.2
custom_tooltip = story.2900.option.4.tooltip

trigger = {
NOT = { has_country_flag = CosmicSpawnComplete }
}
set_country_flag = CosmicSpawnComplete
}
}


/events/11_chr_build_empires.txt
==========================
This is where I like to keep clean code for spawning the empires and replacing generated leaders.
namespace = buildempire

#Build Star-Spawn of Cthulhu Empire
country_event = {
id = buildempire.1
hide_window = yes
is_triggered_only = yes

immediate = {
trigger = {
has_country_flag = Story2900
has_country_flag = CosmicSpawnComplete
}
### Spawn Star-Spawn of Cthulhu
if = {
limit = {
NOT = {
any_country = {
species_portrait = cthulhu #We only want 1 Cthulhu
}
}
}
random_system = {
limit = {
#NOT = { has_owner = yes }
NOT = {
any_neighbor_system = {
exists = space_owner
}
exists = space_owner
}
}
spawn_system = { initializer = "chr_cthulhu_system_npc" } #Most important code
}
}
}
}


#Add Leaders
country_event = {
id = buildempire.99
hide_window = yes
is_triggered_only = yes

immediate = {
#Add Cthulhu
every_country = {
limit = {
has_country_flag = add_cthulhu
}
country_event = { id = buildempire.2901 }
}
}
}

#Add Cthulhu
country_event = {
id = buildempire.2901

hide_window = yes
is_triggered_only = yes

immediate = {
#Kill all exisiting leaders
every_owned_leader = {
#kill_leader = { type = scientist show_notification = no }
#kill_leader = { type = governor show_notification = no }
kill_leader = { type = ruler show_notification = no }
}
#Add new Cthulhu
create_species = {
name = "Great Old One"
plural = "Great Old Ones"
adjective = "Great Old Onelike"
class = "PLA_CHR"
portrait = "cthulhu_oldone"
#homeworld = THIS
traits = {
trait = "chr_trait_strange_aeons"
trait = "chr_trait_cosmic_horrors"
}
}
create_leader = {
type = ruler #scientist governor
species = last_created
name = "Cthulhu"
skill = 0
set_age = 90000
traits = {
trait = trait_ruler_world_shaper
trait = trait_ruler_warlike
}
}
assign_leader = last_created_leader
remove_country_flag = add_cthulhu
}
}

/solar_system/initializers/11_chr_system.txt
==================================
This is the code where the acutal 'empire' is hidden. It won't spawn unless you force it to.
#################
# NPC Initializers
#################

## Black Hole System
chr_cthulhu_system_npc = {
name = "Twenty Third Nebula"
class = "sc_black_hole"
asteroids_distance = 50
flags = { cthulhu_system cosmichorror_system}

max_instances = 1
usage_odds = 0 #No chance of spawning naturally. The opposite is like 20000? I think

planet = {
name = "The Wanderer"
count = 1
class = pc_black_hole
orbit_distance = 10
orbit_angle = 1
size = { min = 20 max = 20 }
has_ring = no
}

change_orbit = 10

#Binary Black Hole
planet = {
name = "Infernal Twin"
count = 1
class = pc_black_hole
orbit_distance = -10
orbit_angle = 180
size = { min = 20 max = 20 }
has_ring = no
}

planet = {
name = "Vhoorl"
class = pc_continental
orbit_distance = 60
orbit_angle = 340
size = 20
has_ring = no
entity = "continental_planet_01_entity"
tile_blockers = none
modifiers = none

init_effect = {
prevent_anomaly = yes
}
init_effect = {
create_species = {
name = "Cthulhi"
plural = "Cthulhi"
adjective = "Cthuvian"
class = "PLA_CHR"
portrait = "cthulhu"
homeworld = THIS
traits = {
trait = "chr_trait_cosmic_horrors"
trait = "chr_trait_strange_aeons"
}
}
create_country = {
name = "Star-Spawn of Cthulhu"
government = chr_govt_old_one
species = last_created
ethos = {
ethic = "ethic_fanatic_spiritualist"
ethic = "ethic_xenophobe"
}
name_list = "PLA_CHR"
ship_prefix = ""
#ftl = warp
#weapon = "tech_lasers_1"
flag = {
icon={
category = "cosmichorrors"
file = "flag_chr_1.dds"
}
background={
category = "backgrounds"
file = "new_dawn.dds"
}
colors={
"black"
"red"
"null"
"null"
}
}
}
last_created_country = {
set_graphical_culture = cosmichorrors_01
set_country_flag = cthulhu_1
set_country_flag = cosmichorrors_flag_1
set_country_flag = add_cthulhu
}
create_colony = {
owner = last_created_country
species = last_created
ethos = {
ethic = "ethic_fanatic_spiritualist"
ethic = "ethic_xenophobe"
}
}

#Defensive armies
create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

create_army = {
name = random
owner = last_created
species = last_created
type = "defense_army"
}

#Science Ship
create_fleet = {
name = random
}
last_created_fleet = {
set_owner = last_created_country
create_ship = {
name = random
design = "Prototype"
}
}

#Construction Ship
create_fleet = {
name = random
}
last_created_fleet = {
set_owner = last_created_country
create_ship = {
name = random
design = "Constructor"
}
}

#Defensive Fleet
create_fleet = {
name = "Legless Horrors"
}
last_created_fleet = {
set_owner = last_created_country
create_ship = {
name = random
design = "Dagger"
}
create_ship = {
name = random
design = "Dagger"
}
create_ship = {
name = random
design = "Dagger"
}
create_ship = {
name = random
design = "Dagger"
}
create_ship = {
name = random
design = "Dagger"
}
create_ship = {
name = random
design = "Dagger"
}
set_location = PREV
}

#Spaceport
create_spaceport = {
owner = last_created_country
initial_module = "fallen_empire_weapon"
}
spaceport = {
set_spaceport_level = 1
}

random_tile = {
limit = {
has_blocker = no
has_grown_pop = no
has_growing_pop = no
}
create_pop = {
species = last_created
ethos = owner
}
}
random_tile = {
limit = {
has_blocker = no
has_grown_pop = no
has_growing_pop = no
}
create_pop = {
species = last_created
ethos = owner
}
}
random_tile = {
limit = {
has_blocker = no
has_grown_pop = no
has_growing_pop = no
}
create_pop = {
species = last_created
ethos = owner
}
}
random_tile = {
limit = {
has_blocker = no
has_grown_pop = no
has_growing_pop = no
}
create_pop = {
species = last_created
ethos = owner
}
}
random_tile = {
limit = {
has_blocker = no
has_grown_pop = no
has_growing_pop = no
}
create_pop = {
species = last_created
ethos = owner
}
}
}

init_effect = {
random_tile = {
limit = { has_blocker = no has_building = no num_adjacent_tiles > 3 }
set_building = "building_capital_1"
add_resource = {
resource = food
amount = 2
replace = yes
}
add_resource = {
resource = minerals
amount = 2
}
random_neighboring_tile = {
limit = { has_blocker = no has_building = no }
set_building = "building_hydroponics_farm_1"
add_resource = {
resource = food
amount = 2
replace = yes
}
}
random_neighboring_tile = {
limit = { has_blocker = no has_building = no }
set_building = "building_power_plant_1"
add_resource = {
resource = energy
amount = 2
replace = yes
}
}
random_neighboring_tile = {
limit = { has_blocker = no has_building = no }
set_building = "building_mining_network_1"
add_resource = {
resource = minerals
amount = 2
replace = yes
}
}
}
}
moon = {
name = "Vulis"
class = "pc_frozen"
size = 5
orbit_distance = 18
orbit_angle = 100
has_ring = no
}
}

planet = {
count = { min = 3 max = 3 }
orbit_distance = 25
class = random_non_colonizable
orbit_angle = { min = 90 max = 270 }
}


#neighbor_system = {
# distance = { min = 10 max = @distance }
# initializer = "neighbor_t1"
#}
#neighbor_system = {
# distance = { min = 10 max = @distance }
# initializer = "neighbor_t1_first_colony"
#}
}

/localisation/chr_I_english.yml
========================
This contains English words to use for our event window that appeared earlier.
#NECRONOMICON
#Beginning settings for the mod
story.2900.title:0 "Necronomicon Discovered"
story.2900.desc.1:0 "Through dreams most dark, your species has uncovered the location of a forbidden tome your people have loathsomely titled \"Necronomicon\". Within, it depicts rites of summoning the Old Ones."
story.2900.desc.2:0 "Following [Root.GetRulerTitle] [Root.GetRulerName]'s inexorable rise to power, the loathsomely titled \"Necronomicon\" has been claimed. As it falls into the outstretched vile clutches of [Root.GetRulerName], it is within their power to call other Old Ones to this plane of existence."
story.2900.option.1:0 "Host a grand summoning ritual"
story.2900.option.1.tooltip:0 "Brings forth Cthulhu."
story.2900.option.2:0 "Destroy it"
story.2900.option.2.tooltip:0 "Nothing happens... for now?"
 
What i want is to see how assigning portraits is handled+, and if i can limit duplicates or at least duplicates of player's species portrait.
Star-Spawn of C'thulu mod creates it's empire via event and just assigns C'thulu portrait to it's species so it is not very helpful.
 
As far as limiting duplicates goes, the game only has a 'randomized' flag that you can set to yes (default --spawn this species randomly) or no (only if spawned by an event or letting players use it) in the species classes file.

In species_classes, under your species just add this line of code under a custom species.
randomized = no
And that will prevent the AI from utilizing the portraits randomly.