i have a script of spawning princes with Rum faction , these princes hold ancillary of house of Ottoman just like tsardoms . but after choosing a few names one name among them will be selected randomly. i tried in Campaign script and ofc using TW script editor , but always error shows up in the corner of the game which means something wrong . ( i'm noob in scripting btw)
here's the script . :
log ------- Ottoman Princes Spawn -------------------------------------------------

if I_EventCounter Ottoman_Princes_Spawn > 0
inc_event_counter Ottoman_Princes_Spawn -1 ; cool off period (10 turns per army)
end_if

if I_EventCounter temp_purse_rum > 0
inc_event_counter temp_purse_rum -1
end_if

if I_EventCounter temp_purse_rum < 2
and I_EventCounter temp_purse_rum > 0
increment_kings_purse rum -5000
end_if


;======================================================================================================
;------- Ottoman Princes Spawn -----------------------------------------------------------------------
;======================================================================================================

monitor_event PreFactionTurnStart FactionType rum
and I_TurnNumber = 2
and I_EventCounter faction_size_smallormedium == 1 ; Rum has fewer than 11 settlements
and I_EventCounter Ottoman_Princes_Spawn < 1 ; at least 15 years after the previous help
and I_NumberOfSettlements rum > 0 ; just in case of a bug (perhaps not needed)
and RandomPercent < 50

log -------------------- Script : Ottoman Princes Spawn (1) INFORMATION ---------------------

if I_SettlementOwner Angora = rum
and I_EventCounter Byzantines_Invade_Rum_Eskisehir = 0 ; redundant but just in case
and I_CharacterTypeNearTile byzantium, named_character, 10, 312, 132 ; danger 10 tiles from Angora
historic_event OTTOMAN_PRINCES_SPAWN ; info for the player
set_event_counter ottoman_princes_spawn_started 1
end_if

if I_SettlementOwner Nicaea = rum
and I_EventCounter Byzantines_Invade_Rum_Eskisehir = 0
and I_CharacterTypeNearTile byzantium, named_character, 10, 310, 118 ; danger 10 tiles from Eskisehir
historic_event OTTOMAN_PRINCES_SPAWN
set_event_counter ottoman_princes_spawn_started 1
end_if

if I_SettlementOwner Adrianople = rum
and I_EventCounter Byzantines_Invade_Rum_Eskisehir = 0
and I_CharacterTypeNearTile byzantium, named_character, 10, 310, 118
historic_event OTTOMAN_PRINCES_SPAWN
set_event_counter ottoman_princes_spawn_started 1
end_if


log -------------------- Script : Ottoman Princes Spawn (2) FUNDING FOR THE ARMIES -----------

if I_EventCounter temp_purse_rum < 1 ; in case it was increased somewhere else in the script
and I_EventCounter ottoman_princes_spawn_started == 1
add_money rum 25000 ; in case the faction is in debts and would disband the armies outright
increment_kings_purse rum 25000 ; to ensure the AI doesn't disband the armies for some time
inc_event_counter temp_purse_rum 21 ; this counter goes down in another script and after 20 turns this additional income is removed
end_if

log -------------------- Script : Ottoman Princes Spawn (3) SPAWN OF ARMIES ------------------

if RandomPercent > 80
generate_random_counter spawnsixgenerals 1 6
and I_EventCounter ottoman_princes_spawn_started == 1

if I_EventCounter spawnsixgenerals = 1
and not I_CharacterExists Murad1
log ------ spawn Murad
spawn_army
faction rum
character Murad, named character, age 14, x 314, y 135, label Murad1, family
traits LoyaltyStarter 3 , MilitaryInclination 1 , Military_Edu 3 , DynastyOttoman0 1 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Rum_Turkish 1 , BiologicalSon 1 , Handsome 6 , Intelligent 8
unit ME Bodyguard exp 3 armour 1 weapon_lvl 0
unit Ghulams exp 7 armour 1 weapon_lvl 0
unit Ghulams exp 4 armour 1 weapon_lvl 0
unit Ghulams exp 1 armour 1 weapon_lvl 0
unit Ghulams exp 0 armour 0 weapon_lvl 0
end
console_command give_ancillary Murad1 DynastyOttoman

inc_event_counter Ottoman_Princes_Spawn 10 ; it goes down in another script
end_if
if I_EventCounter spawnsixgenerals = 1
and not I_CharacterExists Suleyman1
log ------ spawn Suleyman
spawn_army
faction rum
character Suleyman, named character, age 14, x 314, y 135, label Suleyman1, family
traits LoyaltyStarter 3 , MilitaryInclination 1 , Military_Edu 3 , DynastyOttoman0 1 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Rum_Turkish 1 , BiologicalSon 1 , Handsome 6 , Intelligent 8
unit ME Bodyguard exp 3 armour 1 weapon_lvl 0
unit Ghulams exp 7 armour 1 weapon_lvl 0
unit Ghulams exp 4 armour 1 weapon_lvl 0
unit Ghulams exp 1 armour 1 weapon_lvl 0
unit Ghulams exp 0 armour 0 weapon_lvl 0
end
console_command give_ancillary Suleyman1 DynastyOttoman

inc_event_counter Ottoman_Princes_Spawn 10 ; it goes down in another script
end_if
if I_EventCounter spawnsixgenerals = 1
and not I_CharacterExists Bayezid1
log ------ spawn Bayezid
spawn_army
faction rum
character Bayezid, named character, age 14, x 314, y 135, label Bayezid1, family
traits LoyaltyStarter 3 , MilitaryInclination 1 , Military_Edu 3 , DynastyOttoman0 1 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Rum_Turkish 1 , BiologicalSon 1 , Handsome 6 , Intelligent 8
unit ME Bodyguard exp 3 armour 1 weapon_lvl 0
unit Ghulams exp 7 armour 1 weapon_lvl 0
unit Ghulams exp 4 armour 1 weapon_lvl 0
unit Ghulams exp 1 armour 1 weapon_lvl 0
unit Ghulams exp 0 armour 0 weapon_lvl 0
end
console_command give_ancillary Bayezid1 DynastyOttoman

inc_event_counter Ottoman_Princes_Spawn 10 ; it goes down in another script
end_if
if I_EventCounter spawnsixgenerals = 1
and not I_CharacterExists Mehmed1
log ------ spawn Mehmed
spawn_army
faction rum
character Mehmed, named character, age 14, x 314, y 135, label Mehmed1, family
traits LoyaltyStarter 3 , MilitaryInclination 1 , Military_Edu 3 , DynastyOttoman0 1 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Rum_Turkish 1 , BiologicalSon 1 , Handsome 6 , Intelligent 8
unit ME Bodyguard exp 3 armour 1 weapon_lvl 0
unit Ghulams exp 7 armour 1 weapon_lvl 0
unit Ghulams exp 4 armour 1 weapon_lvl 0
unit Ghulams exp 1 armour 1 weapon_lvl 0
unit Ghulams exp 0 armour 0 weapon_lvl 0
end
console_command give_ancillary Mehmed1 DynastyOttoman

inc_event_counter Ottoman_Princes_Spawn 10 ; it goes down in another script
end_if
if I_EventCounter spawnsixgenerals = 1
and not I_CharacterExists Ala_addin1
log ------ spawn Ala_addin
spawn_army
faction rum
character Ala_addin, named character, age 14, x 314, y 135, label Ala_addin1, family
traits LoyaltyStarter 3 , MilitaryInclination 1 , Military_Edu 3 , DynastyOttoman0 1 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Rum_Turkish 1 , BiologicalSon 1 , Handsome 6 , Intelligent 8
unit ME Bodyguard exp 3 armour 1 weapon_lvl 0
unit Ghulams exp 7 armour 1 weapon_lvl 0
unit Ghulams exp 4 armour 1 weapon_lvl 0
unit Ghulams exp 1 armour 1 weapon_lvl 0
unit Ghulams exp 0 armour 0 weapon_lvl 0
end
console_command give_ancillary Ala_addin1 DynastyOttoman

inc_event_counter Ottoman_Princes_Spawn 10 ; it goes down in another script
end_if
if I_EventCounter spawnsixgenerals = 1
and not I_CharacterExists Mes_ud1
log ------ spawn Mes_ud
spawn_army
faction rum
character Mes_ud, named character, age 14, x 314, y 135, label Mes_ud1, family
traits LoyaltyStarter 3 , MilitaryInclination 1 , Military_Edu 3 , DynastyOttoman0 1 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Rum_Turkish 1 , BiologicalSon 1 , Handsome 6 , Intelligent 8
unit ME Bodyguard exp 3 armour 1 weapon_lvl 0
unit Ghulams exp 7 armour 1 weapon_lvl 0
unit Ghulams exp 4 armour 1 weapon_lvl 0
unit Ghulams exp 1 armour 1 weapon_lvl 0
unit Ghulams exp 0 armour 0 weapon_lvl 0
end
console_command give_ancillary Mes_ud1 DynastyOttoman

inc_event_counter Ottoman_Princes_Spawn 10 ; it goes down in another script
end_if
log -------------------- Script : Ottoman Princes Spawn (4) END ------------------

end_monitor