# |---------------------|---------------------------|-----------------|--------|--------|--------|------|-----|-----|------|
# | id                  | name                      | origin          | class  | chance | weight | cost | hp  | enc | chop |
# |---------------------|---------------------------|-----------------|--------|--------|--------|------|-----|-----|------|
# | mer_lute_fat        | Fat Lute                  |                 |        |        |  10.00 |  200 | 500 | 100 |    5 |
# | mer_lute            | Lute                      |                 |        |        |   3.00 |  300 | 500 | 100 |    5 |
# |---------------------|---------------------------|-----------------|--------|--------|--------|------|-----|-----|------|
# | avp_lute_fat_shabby | Shabby Fat Lute           | Morrowind       | fat    |  5.55% |  10.00 |  140 | 170 |  30 |    5 |
# | avp_lute_fat        | Fat Lute                  | Morrowind       | fat    | 11.11% |  10.00 |  200 | 190 |  30 |    5 |
# | avp_lute_shabby     | Shabby Lute               | Morrowind       | low    | 27.77% |   3.00 |  210 | 110 |  45 |    3 |
# | avp_lute            | Lute                      | Morrowind       | medium | 30.55% |   3.00 |  300 | 120 |  45 |    3 |
# | avp_lute_rosewood   | Rosewood Lute             | Skyrim          | medium |  4.17% |   3.60 |  400 | 135 |  50 |    3 |
# | avp_lute_minstrel   | Minstrel's Uka-Lute       | High Rock       | medium |  4.17% |   1.90 |  450 |  90 |  40 |    2 |
# | avp_lute_torban     | Morthal Torban            | Skyrim          | high   |  1.67% |   4.10 |  650 | 150 |  55 |    3 |
# | avp_lute_oud        | Stros M'Kai Oud           | Hammerfell      | high   |  1.67% |   2.90 |  700 | 110 |  55 |    3 |
# | avp_lute_kwitra     | Lilmoth Kwitra            | Black Marsh     | high   |  1.67% |   3.50 |  750 | 140 |  75 |    3 |
# | avp_lute_swarabat   | Rawl'kha Swarabat         | Elsweyr         | high   |  1.67% |   3.30 |  800 | 130 |  65 |    3 |
# | avp_lute_mandolin   | Skingrad Mandolin         | Cyrodiil        | high   |  1.67% |   4.20 |  850 | 145 |  60 |    3 |
# | avp_lute_exquisite  | Exquisite Lute            | Morrowind       | high   |  3.33% |   2.60 |  900 | 115 |  65 |    3 |
# | avp_lute_gallichon  | Northpoint Gallichon      | High Rock       | high   |  1.67% |   3.20 |  950 | 130 |  70 |    3 |
# | avp_lute_pandura    | Lillandril Pandura        | Summerset Isles | high   |  1.67% |   2.50 | 1050 | 105 |  70 |    3 |
# | avp_lute_antique    | Antique Lute              | Morrowind       | top    |  1.25% |   3.80 | 1850 | 160 |  95 |    3 |
# | avp_lute_hissmir    | Hissmir Cypress-Wood Lute | Black Marsh     | top    |  0.41% |   4.60 | 5700 | 220 | 135 |    4 |
# |---------------------|---------------------------|-----------------|--------|--------|--------|------|-----|-----|------|

# first modify script with added inns:
#   Reminder:
#     1. copy plugins and requirements
#     2. edit
#     3. copy back
#     4. get cell_donor.esp
#     5. run
tes3cmd=./tes3cmd
for plugin in "Bardic Inspiration V2 - Lute and Inn Expansion.esp" "Bardic Inspiration V2 - Lute and Inn Expansion - Luck and Gifts.esp"; do
# delete records
$tes3cmd delete "${plugin}" --hide-backups --type CONT --type CELL --type WEAP --type LEVI --type MISC

# add script to vanilla MISC lute and lute_phat
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type MISC --exact-id "misc_de_lute_01"
$tes3cmd modify "${plugin}" --hide-backups --type MISC --exact-id "misc_de_lute_01" --run "\
                  \$R->append(MISC::SCRI->new({'script', 'avp_scpt_get_lute'}))"

$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type MISC --exact-id "misc_de_lute_01_phat"
$tes3cmd modify "${plugin}" --hide-backups --type MISC --exact-id "misc_de_lute_01_phat" --run "\
                  \$R->append(MISC::SCRI->new({'script', 'avp_scpt_get_lute_fat'}))"

# create avp_lute_fat_shabby
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute_fat"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute_fat" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_fat_shabby'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Shabby Fat Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '10.00'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '140'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '170'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '30'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '5')"

# create avp_lute_fat
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute_fat"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute_fat" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_fat'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Fat Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '10.00'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '200'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '190'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '30'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '5')"

# create avp_lute_shabby
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_shabby'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Shabby Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.00'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '210'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '110'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '45'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.00'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '300'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '120'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '45'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_rosewood
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_rosewood'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Rosewood Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.60'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '400'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '135'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '50'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_minstrel
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_minstrel'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Minstrel\'s Uka-Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '1.90'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '450'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '90'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '40'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '2')"

# create avp_lute_torban
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_torban'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Morthal Torban'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '4.10'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '650'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '150'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '55'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_oud
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_oud'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Stros M\'Kai Oud'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '2.90'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '700'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '110'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '55'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_kwitra
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_kwitra'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Lilmoth Kwitra'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.50'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '750'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '140'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '75'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_swarabat
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_swarabat'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Rawl\'kha Swarabat'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.30'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '800'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '130'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '65'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_mandolin
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_mandolin'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Skingrad Mandolin'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '4.20'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '850'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '145'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '60'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_exquisite
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_exquisite'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Exquisite Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '2.60'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '900'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '115'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '65'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_gallichon
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_gallichon'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Northpoint Gallichon'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.20'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '950'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '130'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '70'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_pandura
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_pandura'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Lillandril Pandura'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '2.50'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '1050'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '105'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '70'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_antique
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_antique'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Antique Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '3.80'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '1850'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '160'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '95'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '3')"

# create avp_lute_hissmir
$tes3cmd dump   "BardicInspirationOMW.esp" --raw "${plugin}" --type WEAP --exact-id "mer_lute"
$tes3cmd modify "${plugin}" --hide-backups --type WEAP --exact-id "mer_lute" --run "\
                  \$R->set({t=>'NAME', f=>'ID'}, 'avp_lute_hissmir'), \
                  \$R->set({t=>'FNAM', f=>'Name'}, 'Hissmir Cypress-Wood Lute'), \
                  \$R->set({t=>'WPDT', f=>'Weight'}, '4.60'), \
                  \$R->set({t=>'WPDT', f=>'Value'}, '5700'), \
                  \$R->set({t=>'WPDT', f=>'Health'}, '220'), \
                  \$R->set({t=>'WPDT', f=>'Enchantment'}, '135'), \
                  \$R->set({t=>'WPDT', f=>'Chop_Max'}, '4')"

# create levi top
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'avp_levi_lute_top'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '0'), \
                  \$R->append(LEVI::INDX->new({'item_count', '4'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_antique'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_antique'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_antique'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_hissmir'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create levi high
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'avp_levi_lute_high'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '0'), \
                  \$R->append(LEVI::INDX->new({'item_count', '10'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_torban'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_oud'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_kwitra'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_swarabat'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_mandolin'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_exquisite'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_exquisite'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_gallichon'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_pandura'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_top'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create levi medium
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'avp_levi_lute_medium'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '0'), \
                  \$R->append(LEVI::INDX->new({'item_count', '4'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_rosewood'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_minstrel'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create levi low
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'avp_levi_lute_low'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '0'), \
                  \$R->append(LEVI::INDX->new({'item_count', '3'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_shabby'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_shabby'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create levi fat
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'avp_levi_lute_fat'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '0'), \
                  \$R->append(LEVI::INDX->new({'item_count', '3'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_fat'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_fat'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_fat_shabby'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create levi random
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'avp_levi_lute_random'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '0'), \
                  \$R->append(LEVI::INDX->new({'item_count', '6'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_fat'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_shabby'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_low'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_medium'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_high'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create levi wares random
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->set({t=>'Name', f=>'ID'}, 'aa_avp_levi_lute_random'), \
                  \$R->set({t=>'NNAM', f=>'Chance_None'}, '83'), \
                  \$R->append(LEVI::INDX->new({'item_count', '6'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_fat'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute_shabby'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_low'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_lute'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_medium'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'avp_levi_lute_high'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# add to wares aa_trader_misc
$tes3cmd dump "Wares-base.esm" --raw "${plugin}" --type LEVI --exact-id "aa_trader_misc"
$tes3cmd modify "${plugin}" --hide-backups --type LEVI --exact-id "aa_trader_misc" --run "\
                  \$R->append(LEVI::INDX->new({'item_count', '2'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'aa_avp_levi_lute_random'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'})), \
                  \$R->append(LEVI::INAM->new({'item_id', 'aa_avp_levi_lute_random'})), \
                  \$R->append(LEVI::INTV->new({'level', '1'}))"

# create lute cont
$tes3cmd dump "Cooking and Eating - Publicans Expansion.esp" --raw "${plugin}" --type CONT --exact-id "aspc_tr_m3_doryn naves"
$tes3cmd modify "${plugin}" --hide-backups --type CONT --exact-id "aspc_tr_m3_doryn naves" --run "\
          \$R->set({t=>'NAME', f=>'ID'}, 'avp_cont_lute_random'), \
          \$R->append(CONT::NPCO->new({'count', '1', 'object', 'avp_levi_lute_random'}))"

# create cont instance vivec
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Vivec, Hlaalu Pawnbroker'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '0.75'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '1', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'alveno andules'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '-96.000', 'y', '-224.000', 'z', '-237.804', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

# create cont instance dagon fel
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Dagon Fel, End of the World Renter Rooms'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '0.75'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '2', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'hjotra the peacock'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '697.332', 'y', '1.705', 'z', '-123.169', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

# create cont instance mournhold
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Mournhold, Pawnbroker'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '0.50'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '3', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'Ten-Tongues_Weerhat'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '-29.188', 'y', '302.848', 'z', '-364.737', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

# create cont instance helnim
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Helnim, Aarlen Lleranoth: Pawnbroker'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '0.75'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '4', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'TR_m2_Aarlen Lleranoth'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '4307.116', 'y', '3869.434', 'z', '15717.900', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

# create cont instance sailen
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Sailen, Golveso Darys: Pawnbroker'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '0.50'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '5', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'TR_m3_Golveso_Darys'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '3996.723', 'y', '3911.844', 'z', '14976.451', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

# create cont instance karthwasten
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Karthwasten, Tivela Tyravel: Pawnbroker'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '1.00'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '6', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'Sky_iRe_KW_Tivela'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '472.234', 'y', '-50.674', 'z', '12.108', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

# create cont instance stirk
$tes3cmd dump   "cell_donor.esp" --raw "${plugin}" --type CELL --exact-id "interior for generator"
$tes3cmd modify "${plugin}" --hide-backups --type CELL --exact-id "interior for generator" --run "\
                  \$R->set({t=>'NAME', f=>'Name'}, 'Stirk, Harbor Gate Pawnbrokers'), \
                  \$R->set({t=>'DATA', f=>'Fog_Density'}, '0.75'), \
                  \$R->set({t=>'DATA', f=>'Flags'}, '5'), \
                  \$R->append(CELL::NAM0->new({'reference_count', '1'})), \
                  \$R->append(CELL::FRMR->new({'objidx', '7', 'mastidx', '0'})), \
                  \$R->append(CELL::NAME->new({'name', 'avp_cont_lute_random'})), \
                  \$R->append(CELL::ANAM->new({'owner_actor', 'PC_i1-Str_Joclyn'})), \
                  \$R->append(CELL::INTV->new({'health_left', '0'})), \
                  \$R->append(CELL::NAM9->new({'owned', '1'})), \
                  \$R->append(CELL::DATA->new({'x', '1283.748', 'y', '-1107.435', 'z', '16.079', 'x_angle', '0', 'y_angle', '0', 'z_angle', '0'}))"

$tes3cmd modify "${plugin}" --hide-backups --type TES3 --run "\
                      \$R->append(TES3::MAST->new({'master', 'BardicInspirationOMW.esp'})), \
                      \$R->append(TES3::DATA->new({'length', '21757'}))"

$tes3cmd header "${plugin}" --synchronize --hide-backups
done

set -e 
false

Begin avp_scpt_get_lute_fat
  Short OnPCAdd
  Short Button
  Short MessageOn
  If ( MenuMode )
    Return
  EndIf
  If ( OnPCAdd )
    Set OnPCAdd To 0
    Set MessageOn To 1
  EndIf
  If ( MessageOn == 1 )
    MessageBox, "Examine the Fat Lute?", "Yes", "No"
    Set MessageOn To 2
  EndIf
  If ( MessageOn == 2 )
    Set Button To GetButtonPressed
    If ( Button == -1 )
      Return
    EndIf
    If ( Button == 0 )
      Player->StartScript "avp_scpt_swap_lute_fat"
      Set MessageOn To 0
      Return
    EndIf
    If ( Button == 1 )
      Set MessageOn To 0
      Return
    EndIf
  EndIf
End avp_scpt_get_lute_fat

Begin avp_scpt_get_lute
  Short OnPCAdd
  Short Button
  Short MessageOn
  If ( MenuMode )
    Return
  EndIf
  If ( OnPCAdd )
    Set OnPCAdd To 0
    Set MessageOn To 1
  EndIf
  If ( MessageOn == 1 )
    MessageBox, "Examine the Lute?", "Yes", "No"
    Set MessageOn To 2
  EndIf
  If ( MessageOn == 2 )
    Set Button To GetButtonPressed
    If ( Button == -1 )
      Return
    EndIf
    If ( Button == 0 )
      Player->StartScript "avp_scpt_swap_lute"
      Set MessageOn To 0
      Return
    EndIf
    If ( Button == 1 )
      Set MessageOn To 0
      Return
    EndIf
  EndIf
End avp_scpt_get_lute

Begin avp_scpt_swap_lute_fat
  Short PrevCountLuteFatShabby
  Short PrevCountLuteFat
  Short CurCountLuteFatShabby
  Short CurCountLuteFat
  Short Rand
  If ( MenuMode )
    Return
  EndIf
  If ( Player->GetItemCount "misc_de_lute_01_phat" >= 1 )
    Set PrevCountLuteFat To ( Player->GetItemCount "avp_lute_fat" )
    Set PrevCountLuteFatShabby To ( Player->GetItemCount "avp_lute_fat_shabby" )
    Player->RemoveItem "misc_de_lute_01_phat" 1
    Set Rand To ( Random 10000 )
    If ( Rand <= 6667 )
      Player->AddItem "avp_lute_fat" 1
    Else
      Player->AddItem "avp_lute_fat_shabby" 1
    EndIf
    Set CurCountLuteFat To ( Player->GetItemCount "avp_lute_fat" )
    Set CurCountLuteFatShabby To ( Player->GetItemCount "avp_lute_fat_shabby" )
    If ( CurCountLuteFat > PrevCountLuteFat )
      MessageBox "This is the ordinary Fat Lute, heavy and reliable."
      StopScript "avp_scpt_swap_lute_fat"
    EndIf
    If ( CurCountLuteFatShabby > PrevCountLuteFatShabby )
      MessageBox "This Fat Lute is in poor condition."
      StopScript "avp_scpt_swap_lute_fat"
    EndIf
  EndIf
End avp_scpt_swap_lute_fat

Begin avp_scpt_swap_lute
  Short PrevCountLuteRosewood
  Short PrevCountLuteMinstrel
  Short PrevCountLuteShabby
  Short PrevCountLute
  Short CurCountLuteRosewood
  Short CurCountLuteMinstrel
  Short CurCountLuteShabby
  Short CurCountLute
  Short Rand
  If ( MenuMode )
    Return
  EndIf
  If ( Player->GetItemCount "misc_de_lute_01" >= 1 )
    Set PrevCountLuteMinstrel To ( Player->GetItemCount "avp_lute_minstrel" )
    Set PrevCountLuteRosewood To ( Player->GetItemCount "avp_lute_rosewood" )
    Set PrevCountLute To ( Player->GetItemCount "avp_lute" )
    Set PrevCountLuteShabby To ( Player->GetItemCount "avp_lute_shabby" )
    Player->RemoveItem "misc_de_lute_01" 1
    Set Rand To ( Random 10000 )
    If ( Rand <= 417 )
      Player->AddItem "avp_lute_minstrel" 1
    ElseIf ( Rand <= 834 )
      Player->AddItem "avp_lute_rosewood" 1
    ElseIf ( Rand <= 6667 )
      Player->AddItem "avp_lute" 1
    Else
      Player->AddItem "avp_lute_shabby" 1
    EndIf
    Set CurCountLuteMinstrel To ( Player->GetItemCount "avp_lute_minstrel" )
    Set CurCountLuteRosewood To ( Player->GetItemCount "avp_lute_rosewood" )
    Set CurCountLute To ( Player->GetItemCount "avp_lute" )
    Set CurCountLuteShabby To ( Player->GetItemCount "avp_lute_shabby" )
    If ( CurCountLuteMinstrel > PrevCountLuteMinstrel )
      MessageBox "This is the Minstrel's Uka-Lute. A miniature, playable stringed lute of lacquered wood, favored by wandering minstrels for its portability."
      StopScript "avp_scpt_swap_lute"
    EndIf
    If ( CurCountLuteRosewood > PrevCountLuteRosewood )
      MessageBox "Though quite old, this Rosewood Lute is still in excellent condition. There are no noticeable scratches in the lacquered wood."
      StopScript "avp_scpt_swap_lute"
    EndIf
    If ( CurCountLute > PrevCountLute )
      MessageBox "This is the ordinary Lute."
      StopScript "avp_scpt_swap_lute"
    EndIf
    If ( CurCountLuteShabby > PrevCountLuteShabby )
      MessageBox "This Lute is in poor condition."
      StopScript "avp_scpt_swap_lute"
    EndIf
  EndIf
End avp_scpt_swap_lute
