Results 1 to 4 of 4

Thread: AI Helper Scripts

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default AI Helper Scripts

    This thread is for scripts which aid the AI. You can suggest scripts of this nature or amendments to existing scripts here.

    Currently planned sub-scripts:

    - Garrison (0% Done)
    - Lucky Factions (100% Done)
    - Income Boost (0% Done)
    - Debt Remover (0% Done)

    Garrison

    The purpose of all garrison scripts is to cope with the AI consistently leaving its cities undefended by spawning local garrison to take up the defense of its cities when they come under siege. One of the key problems with most garrison scripts is they don't seem to distinguish if it's the AI or Player laying siege. This could be problematic as having units spawn when AI siege AI could mess up their AI Decision Trees determining that they could win the battle by effecting it through a medium they can't understand(scripts). So that should be the first thing to solve when this script is made.

    Lucky Factions

    The goal of the lucky factions is to randomly give an edge to a few select factions every game(namely incrementing the kings purse substantially). This should create interesting scenarios where different factions take the fore in different games and dominate.

    Considerations

    - Should be based on difficulty level (Done)
    - Based on player faction (Done)
    - Enable multiple lucky factions (Done)
    - Cope with hotseat games (Done)
    - Insure 3 separate factions get lucky (Done)

    13 factions are eligible to become 'lucky'(exc. Local, Ghurid). Of these 13 factions:

    - 5 should have a Low chance (3% Chance)
    - 5 should have a Medium chance (8% Chance)
    - 3 should have a High chance (15% Chance)

    This is based on factions that can present the player with a challenge. 2 of the 3 should be close countries, 1 should be a distant country which can build up to challenge the player.

    Current List of High/Medium/Low per Faction:
    Spoiler Alert, click show to read: 

    Champa

    High
    Dai Viet
    Song
    Pagan

    Medium
    Khmer
    Mongols
    Tibet
    Dali
    Jin

    Low
    Khitans
    Minamoto
    Taira
    Xi Xia
    Goryeo
    Dai Viet

    High
    Champa
    Jin
    Minamoto

    Medium
    Khmer
    Pagan
    Mongols
    Song
    Dali

    Low
    Taira
    Xi Xia
    Goryeo
    Khitans
    Tibet
    Dali

    High
    Tibet
    Champa
    Xi Xia

    Medium
    Taira
    Song
    Khitans
    Goryeo
    Mongols

    Low
    Khmer
    Dai Viet
    Jin
    Pagan
    Minamoto
    Goryeo

    High
    Taira
    Minamoto
    Mongols

    Medium
    Jin
    Khitans
    Xi Xia
    Dai Viet
    Pagan

    Low
    Champa
    Khmer
    Tibet
    Song
    Dali
    Jin

    High
    Song
    Mongols
    Xi Xia

    Medium
    Dali
    Khmer
    Tibet
    Goryeo
    Minamoto

    Low
    Dai Viet
    Champa
    Pagan
    Taira
    Khitans
    Khitans

    High
    Goryeo
    Tibet
    Champa

    Medium
    Jin
    Dali
    Pagan
    Mongols
    Xi Xia

    Low
    Song
    Dai Viet
    Minamoto
    Taira
    Khmer
    Khmer

    High
    Dai Viet
    Pagan
    Dali

    Medium
    Champa
    Song
    Tibet
    Taira
    Mongols

    Low
    Goryeo
    Minamoto
    Xi Xia
    Khitans
    Jin
    Minamoto

    High
    Taira
    Khitans
    Khmer

    Medium
    Jin
    Song
    Goryeo
    Dali
    Champa

    Low
    Pagan
    Dai Viet
    Tibet
    Mongols
    Xi Xia
    Mongols

    High
    Jin
    Song
    Khitans

    Medium
    Khmer
    Dai Viet
    Pagan
    Tibet
    Goryeo

    Low
    Xi Xia
    Taira
    Minamoto
    Champa
    Dali
    Pagan

    High
    Dali
    Xi Xia
    Khmer

    Medium
    Song
    Tibet
    Goryeo
    Minamoto
    Pagan

    Low
    Dai Viet
    Champa
    Jin
    Mongols
    Khitans
    Taira

    High
    Minamoto
    Goryeo
    Dai Viet

    Medium
    Jin
    Khitans
    Xi Xia
    Song
    Champa

    Low
    Pagan
    Khmer
    Tibet
    Dali
    Mongols
    Tibet

    High
    Taira
    Khitans
    Dali

    Medium
    Song
    Mongols
    Khmer
    Xi Xia
    Pagan

    Low
    Goryeo
    Champa
    Dai Viet
    Minamoto
    Jin
    Xi Xia

    High
    Goryeo
    Tibet
    Pagan

    Medium
    Jin
    Khitans
    Mongols
    Khmer
    Song

    Low
    Champa
    Dai Viet
    Minamoto
    Taira
    Dali
    Song

    High
    Jin
    Mongols
    Khmer

    Medium
    Tibet
    Dai Viet
    Dali
    Goryeo
    Xi Xia

    Low
    Champa
    Pagan
    Minamoto
    Taira
    Khitans


    Left to do:

    - Potentially come up with other benefits to give AI Lucky Factions

    Code Snippet:

    Code:
    ;**********Script 1H-1. Lucky Factions**********
    ;|Author| Augustus Lucifer
    ;|Purpose| Designates a certain # of lucky factions each game which get bonuses.
    ;|Changelog|
    ; o Script Created 7-05-09
    ; o 7-06-09
    ;		Difficulty Levels, While, Faction Derivatives added
    
    declare_counter champa_got_lucky
    declare_counter song_got_lucky
    declare_counter jin_got_lucky
    declare_counter goryeo_got_lucky
    declare_counter xixia_got_lucky
    declare_counter mongols_got_lucky
    declare_counter khitans_got_lucky
    declare_counter daiviet_got_lucky
    declare_counter dali_got_lucky
    declare_counter khmer_got_lucky
    declare_counter pagan_got_lucky
    declare_counter tibet_got_lucky
    declare_counter minamoto_got_lucky
    declare_counter taira_got_lucky
    declare_counter lucky_factions
    
    set_counter champa_got_lucky 0
    set_counter song_got_lucky 0
    set_counter jin_got_lucky 0
    set_counter goryeo_got_lucky 0
    set_counter xixia_got_lucky 0
    set_counter mongols_got_lucky 0
    set_counter khitans_got_lucky 0
    set_counter daiviet_got_lucky 0
    set_counter dali_got_lucky 0
    set_counter khmer_got_lucky 0
    set_counter pagan_got_lucky 0
    set_counter tibet_got_lucky 0
    set_counter minamoto_got_lucky 0
    set_counter taira_got_lucky 0
    set_counter lucky_factions 0
    
    ;Generate 3 Lucky Factions and increase their kings purses, then terminate
    monitor_event PreFactionTurnStart FactionIsLocal
    ;;Player = Song Dynasty;;
    	if I_LocalFaction song
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Champa
    if I_LocalFaction champa
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Dai Viet
    if I_LocalFaction daiviet
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Dali
    if I_LocalFaction dali
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Goryeo
    if I_LocalFaction goryeo
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Jin
    if I_LocalFaction jin
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Khitans
    if I_LocalFaction khitans
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Khmer
    if I_LocalFaction khmer
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Minamoto
    if I_LocalFaction minamoto
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Mongols
    if I_LocalFaction mongols
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Pagan
    if I_LocalFaction pagan
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Taira
    if I_LocalFaction taira
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Tibet
    if I_LocalFaction tibet
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse xixia 1000
    			inc_counter xixia_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    ;;Player = Xi Xia
    if I_LocalFaction xixia
    	;;Run loop until 3 lucky factions chosen
    	while I_CompareCounter lucky_factions < 3
    		generate_random_counter lucky_faction 1 100
    		if I_EventCounter lucky_faction < 16 ; 15% Chance
    			increment_kings_purse goryeo 1000
    			inc_counter goryeo_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 31
    		 and I_EventCounter lucky_faction > 15 ; 15% Chance
    			increment_kings_purse tibet 1000
    			inc_counter tibet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 46
    		 and I_EventCounter lucky_faction > 30 ; 15% Chance
    			increment_kings_purse pagan 1000
    			inc_counter pagan_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 54
    		 and I_EventCounter lucky_faction > 45 ; 8% Chance
    			increment_kings_purse jin 1000
    			inc_counter jin_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 62
    		 and I_EventCounter lucky_faction > 53 ; 8% Chance
    			increment_kings_purse khitans 1000
    			inc_counter khitans_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 70
    		 and I_EventCounter lucky_faction > 61 ; 8% Chance
    			increment_kings_purse mongols 1000
    			inc_counter mongols_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 78
    		 and I_EventCounter lucky_faction > 69 ; 8% Chance
    			increment_kings_purse khmer 1000
    			inc_counter khmer_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 86
    		 and I_EventCounter lucky_faction > 77 ; 8% Chance
    			increment_kings_purse song 1000
    			inc_counter song_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 89
    		 and I_EventCounter lucky_faction > 85 ; 3% Chance
    			increment_kings_purse champa 1000
    			inc_counter champa_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 92
    		 and I_EventCounter lucky_faction > 88 ; 3% Chance
    			increment_kings_purse minamoto 1000
    			inc_counter minamoto_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 95
    		 and I_EventCounter lucky_faction > 91 ; 3% Chance
    			increment_kings_purse taira 1000
    			inc_counter taira_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction < 98
    		 and I_EventCounter lucky_faction > 94 ; 3% Chance
    			increment_kings_purse daiviet 1000
    			inc_counter daiviet_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		if I_EventCounter lucky_faction > 97 ;3% Chance
    			increment_kings_purse dali 1000
    			inc_counter dali_got_lucky 1
    			inc_counter lucky_factions 1
    		end_if
    		
    		;;Prevent same faction from getting lucky twice
    		
    		if I_CompareCounter champa_got_lucky > 1
    			increment_kings_purse champa -1000
    			inc_counter champa_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter daiviet_got_lucky > 1
    			increment_kings_purse daiviet -1000
    			inc_counter daiviet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter dali_got_lucky > 1
    			increment_kings_purse dali -1000
    			inc_counter dali_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter goryeo_got_lucky > 1
    			increment_kings_purse goryeo -1000
    			inc_counter goryeo_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter jin_got_lucky > 1
    			increment_kings_purse jin -1000
    			inc_counter jin_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khitans_got_lucky > 1
    			increment_kings_purse khitans -1000
    			inc_counter khitans_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter khmer_got_lucky > 1
    			increment_kings_purse khmer -1000
    			inc_counter khmer_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter minamoto_got_lucky > 1
    			increment_kings_purse minamoto -1000
    			inc_counter minamoto_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter mongols_got_lucky > 1
    			increment_kings_purse mongols -1000
    			inc_counter mongols_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter pagan_got_lucky > 1
    			increment_kings_purse pagan -1000
    			inc_counter pagan_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter song_got_lucky > 1
    			increment_kings_purse song -1000
    			inc_counter song_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter taira_got_lucky > 1
    			increment_kings_purse taira -1000
    			inc_counter taira_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter tibet_got_lucky > 1
    			increment_kings_purse tibet -1000
    			inc_counter tibet_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    		if I_CompareCounter xixia_got_lucky > 1
    			increment_kings_purse xixia -1000
    			inc_counter xixia_got_lucky -1
    			inc_counter lucky_factions -1
    		end_if
    	end_while
    	end_if
    terminate_monitor
    end_monitor
    
    ;Additional bonuses for lucky faction based on difficulty setting
    monitor_event PreFactionTurnStart FactionIsLocal
    		and not I_HotseatEnabled
    	if I_CompareCounter champa_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse champa 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse champa 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse champa 9000
    		end_if
    	end_if
    	if I_CompareCounter daiviet_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse daiviet 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse daiviet 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse daiviet 9000
    		end_if
    	end_if
    	if I_CompareCounter dali_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse dali 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse dali 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse dali 9000
    		end_if
    	end_if
    	if I_CompareCounter goryeo_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse goryeo 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse goryeo 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse goryeo 9000
    		end_if
    	end_if
    	if I_CompareCounter jin_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse jin 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse jin 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse jin 9000
    		end_if
    	end_if
    	if I_CompareCounter khitans_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse khitans 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse khitans 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse khitans 9000
    		end_if
    	end_if
    	if I_CompareCounter khmer_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse khmer 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse khmer 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse khmer 9000
    		end_if
    	end_if
    	if I_CompareCounter minamoto_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse minamoto 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse minamoto 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse minamoto 9000
    		end_if
    	end_if
    	if I_CompareCounter mongols_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse mongols 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse mongols 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse mongols 9000
    		end_if
    	end_if
    	if I_CompareCounter pagan_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse pagan 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse pagan 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse pagan 9000
    		end_if
    	end_if
    	if I_CompareCounter song_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse song 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse song 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse song 9000
    		end_if
    	end_if
    	if I_CompareCounter taira_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse taira 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse taira 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse taira 9000
    		end_if
    	end_if
    	if I_CompareCounter tibet_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse tibet 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse tibet 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse tibet 9000
    		end_if
    	end_if
    	if I_CompareCounter xixia_got_lucky == 1
    		if I_EventCounter difficulty_medium == 1
    			increment_kings_purse xixia 1500
    		end_if
    		if I_EventCounter difficulty_hard == 1
    			increment_kings_purse xixia 4000
    		end_if
    		if I_EventCounter difficulty_very_hard == 1
    			increment_kings_purse xixia 9000
    		end_if
    	end_if
    terminate_monitor
    end_monitor
    
    ;Make sure that a player faction in hotseat isn't getting bonus
    monitor_event FactionTurnStart FactionIsLocal
    		and I_HotseatEnabled
    	if I_LocalFaction champa
    		if I_CompareCounter champa_got_lucky == 1
    			increment_kings_purse champa -1000
    			set_counter champa_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction daiviet
    		if I_CompareCounter daiviet_got_lucky == 1
    			increment_kings_purse daiviet -1000
    			set_counter daiviet_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction dali
    		if I_CompareCounter dali_got_lucky == 1
    			increment_kings_purse dali -1000
    			set_counter dali_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction goryeo
    		if I_CompareCounter goryeo_got_lucky == 1
    			increment_kings_purse goryeo -1000
    			set_counter goryeo_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction jin
    		if I_CompareCounter jin_got_lucky == 1
    			increment_kings_purse jin -1000
    			set_counter jin_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction khitans
    		if I_CompareCounter khitans_got_lucky == 1
    			increment_kings_purse khitans -1000
    			set_counter khitans_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction khmer
    		if I_CompareCounter khmer_got_lucky == 1
    			increment_kings_purse khmer -1000
    			set_counter khmer_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction minamoto
    		if I_CompareCounter minamoto_got_lucky == 1
    			increment_kings_purse minamoto -1000
    			set_counter minamoto_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction mongols
    		if I_CompareCounter mongols_got_lucky == 1
    			increment_kings_purse mongols -1000
    			set_counter mongols_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction pagan
    		if I_CompareCounter pagan_got_lucky == 1
    			increment_kings_purse pagan -1000
    			set_counter pagan_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction song
    		if I_CompareCounter song_got_lucky == 1
    			increment_kings_purse song -1000
    			set_counter song_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction taira
    		if I_CompareCounter taira_got_lucky == 1
    			increment_kings_purse taira -1000
    			set_counter taira_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction tibet
    		if I_CompareCounter tibet_got_lucky == 1
    			increment_kings_purse tibet -1000
    			set_counter tibet_got_lucky 0
    		end_if
    	end_if
    	if I_LocalFaction xixia
    		if I_CompareCounter xixia_got_lucky == 1
    			increment_kings_purse xixia -1000
    			set_counter xixia_got_lucky 0
    		end_if
    	end_if
    end_monitor
    Income Boost

    King's purse will be increased for all factions that are not the player faction to better suit the AI(independent of the lucky factions modifier). In addition the "AI Building" will provide valuable benefits and only persist in AI-held settlements.

    Debt Remover

    Simple debt removing script to check if the AI has plunged into the negatives and give them some money to help keep them afloat.

    Possible new solution to this common problem, using the Income condition check various levels of losing money and increment the kings purse temporarily accordingly to stabilize, coupled with the funding of finite money to hopefully encourage economic investment. May also want to experiment with killing off all priests/assassins/spies/boats when dip into negatives.
    Last edited by Augustus Lucifer; July 07, 2009 at 06:47 PM.

  2. #2
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: AI Helper Scripts

    Lucky Factions is completed, roughly 2,400 lines of code, most of which only has to run once and is then terminated.

    Can still modify the smaller monitor which runs off the {param}_lucky_faction counters to balance the difficulty setting increases and add in more benefits.

  3. #3
    S-te-Fan's Avatar Primicerius
    Join Date
    Jun 2008
    Location
    Diessen, The Netherlands, Near the belgium border.
    Posts
    3,905

    Default Re: AI Helper Scripts

    Is it possible to get the AI so far that if you have a succesfull faction a faction which doesn't like you will do everything about it to stop you? Or making a faction that has been succesful realy though to conquerer? OR..... making the AI conquerer large territories to be a real oppenent in the late game?

  4. #4
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: AI Helper Scripts

    Quote Originally Posted by stefaneke View Post
    Is it possible to get the AI so far that if you have a succesfull faction a faction which doesn't like you will do everything about it to stop you? Or making a faction that has been succesful realy though to conquerer? OR..... making the AI conquerer large territories to be a real oppenent in the late game?
    Not sure what you mean. It's possible but not in any direct sense. We can only set up the possibility for all those things to happen and a lot of random factors to help the AI along. If we rely to much on definitive things(like player having 30 cities = gift all cities to faction that is doing well) then it not only hampers the play experience, but may not make the game any more of a challenge. We just can't predict how the game will play out, so all we can do is make the AI more aggressive and more logical.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •