-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbta-test.sh
961 lines (890 loc) · 27.1 KB
/
bta-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
#Bash-Theft-Auto music and sfx © 2024 by stuffbymax - Martin Petik is licensed under CC BY 4.0
#https://creativecommons.org/licenses/by/4.0/
#!/bin/bash
#ver 1.9.9-b
# --- 0. Global Variables ---
player_name=""
location=""
cash=0
health=0
declare -a guns
declare -a items
declare -A drugs
declare -A skills
body_armor_equipped=false
SAVE_DIR="saves"
# --- Sound Effects Setup ---
sfx_dir="sfx" # Directory for sound effects
#mpg123
# Function to play sound effects (using mpg123)
play_sfx_mpg() {
local sound_file="$sfx_dir/$1.mp3"
if [[ -f "$sound_file" ]]; then
mpg123 -q "$sound_file" &
return 0 # Indicate success
else
echo "Sound file '$sound_file' not found!"
return 1 # Indicate failure
fi
}
# --- 1. Plugin Loading ---
plugin_dir="plugins"
if [[ -d "$plugin_dir" ]]; then
while IFS= read -r -d $'\0' plugin; do
[[ -f "$plugin" ]] && source "$plugin"
done < <(find "$plugin_dir" -maxdepth 1 -name "*.sh" -print0)
else
echo "Warning: Plugin directory '$plugin_dir' not found."
fi
# --- 3. Functions ---
# Clear the screen and display game information
clear_screen() {
clear
printf "\e[1;34m-----------------------------------------\e[0m\n"
printf "\e[1;43m| Bash theaft auto |\e[0m\n"
printf "\e[1;34m-----------------------------------------\e[0m\n"
printf "Player: %s Location: %s\n" "$player_name" "$location"
printf "Cash: %d dollars Health: %d%%\n" "$cash" "$health"
printf "\e[1;34m-----------------------------------------\e[0m\n"
printf "\e[1;44m| made by stuffbymax |\e[0m\n"
printf "\e[1;34m-----------------------------------------\e[0m\n"
}
# Function to check if the player is alive
check_health() {
if (( health <= 0 )); then
echo "You have no health left! Transporting to hospital..."
read -r -p "Press Enter to continue..."
hospitalize_player
fi
}
# Function for traveling to a new location
travel_to() {
local travel_cost="$1"
local new_location="$2"
if (( cash >= travel_cost )); then
echo "Traveling to $new_location..."
play_sfx_mpg "air"
# --- Air Travel Animation (Plugin Call) ---
air_travel_animation # Call the function in animation.sh
# --- End Air Travel Animation ---
cash=$((cash - travel_cost))
# Remove the press enter prompt here, it is unnessecary with the animation
location="$new_location"
clear_screen
echo "You have arrived at $new_location."
else
echo "Not enough cash to travel to $new_location."
read -r -p "Press Enter to continue..."
clear_screen
fi
}
# Function for buying guns
buy_guns() {
local gun_choice
clear_screen
echo "Gun Store - Choose a gun to buy:"
echo "1. Pistol (100$)"
echo "2. Shotgun (250$)"
echo "3. SMG (500$)"
echo "4. Rifle (750$)"
echo "5. Sniper (1000$)"
echo "6. Back to main menu"
read -r -p "Enter your choice (number): " gun_choice
[[ ! "$gun_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number from the menu."
read -r -p "Press Enter to continue..."
return
}
case "$gun_choice" in
1) buy_item "Pistol" 100;;
2) buy_item "Shotgun" 250;;
3) buy_item "SMG" 500;;
4) buy_item "Rifle" 750;;
5) buy_item "Sniper" 1000;;
6) clear_screen;;
*) echo "Invalid choice.";;
esac
}
# Helper function for buying items
buy_item() {
local item_name="$1"
local item_cost="$2"
buy_animation
if (( cash >= item_cost )); then
cash=$((cash - item_cost))
guns+=("$item_name")
echo "You bought a $item_name."
play_sfx_mpg "cash_register" # Play a sound when buying a gun
read -r -p "Press Enter to continue..."
else
echo "Not enough cash to buy a $item_name."
read -r -p "Press Enter to continue..."
fi
}
# Function to show inventory
show_inventory() {
clear_screen
echo "Your Inventory:"
printf "Cash: %d dollars\n" "$cash"
printf "Health: %d%%\n" "$health"
printf "Guns: %s\n" "${guns[*]}"
printf "Items: %s\n" "${items[*]}"
echo "Drugs: "
local IFS=$'\n'
for drug in "${!drugs[@]}"; do
printf " - %s: %s\n" "$drug" "${drugs[$drug]}"
done
IFS=$' \t\n' # Restore IFS
echo "Skills:"
local IFS=$'\n'
for skill in "${!skills[@]}"; do
printf " - %s: %s\n" "$skill" "${skills[$skill]}"
done
IFS=$' \t\n' # Restore IFS
read -r -p "Press Enter to return to main menu."
}
# Function for working (simplified logic)
work_job() {
local job_type="$1"
local earnings
local min_earnings max_earnings
local driving_skill=$((skills["driving"] * 5)) #Example of using skills
case "$location" in
"Los Santos") min_earnings=20; max_earnings=$((60 + driving_skill));;
"San Fierro") min_earnings=25; max_earnings=$((70 + driving_skill));;
"Las Venturas") min_earnings=30; max_earnings=$((90 + driving_skill));;
"Vice City") min_earnings=15; max_earnings=$((50 + driving_skill));;
"Liberty City") min_earnings=35; max_earnings=$((100 + driving_skill));;
*) min_earnings=10; max_earnings=$((40 + driving_skill));; # Default values
esac
case "$job_type" in
"taxi")
earnings=$((RANDOM % (max_earnings - min_earnings + 1) + min_earnings))
play_sfx_mpg "taxi"
working_animation
;;
"delivery")
earnings=$((RANDOM % (max_earnings - min_earnings + 1) + min_earnings + 10))
working_animation
;;
"mechanic")
earnings=$((RANDOM % (max_earnings - min_earnings + 1) + min_earnings + 20))
working_animation
;;
"security")
earnings=$((RANDOM % (max_earnings - min_earnings + 1) + min_earnings + 30))
working_animation
;;
"performer")
earnings=$((RANDOM % (max_earnings - min_earnings + 1) + min_earnings - 20))
working_animation
;;
"race") # Different logic for race
work_race
return
;;
*) echo "Invalid Job"; return;;
esac
echo "You are working as a $job_type driver in $location..."
read -r -p "Press Enter to continue..."
cash=$((cash + earnings))
play_sfx_mpg "cash_register" # Play a working sound
clear_screen
printf "You earned %d dollars. You now have %d dollars.\n" "$earnings" "$cash"
read -r -p "Press Enter to continue..."
}
# Function for street racing (separate function)
work_race() {
working_animation
echo "You are participating in a street race in $location..."
read -r -p "Press Enter to continue..."
local winnings
local damage
local driving_skill=$((skills["driving"] * 5))
local win_chance=$((50 + driving_skill)) # Influence win chance
if (( RANDOM % 100 < win_chance )); then
winnings=$((RANDOM % 201 + 100))
cash=$((cash + winnings))
damage=$((RANDOM % 21 + 10))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
health=$((health - damage))
check_health
clear_screen
printf "You won the street race and got %d dollars, but lost %d%% health. You now have %d dollars and %d%% health.\n" "$winnings" "$damage" "$cash" "$health"
play_sfx_mpg "win" # Play a winning sound
read -r -p "Press Enter to continue..."
else
damage=$((RANDOM % 41 + 20))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
health=$((health - damage))
check_health
clear_screen
printf "You lost the street race and took %d%% damage. You now have %d%% health.\n" "$damage" "$health"
play_sfx_mpg "lose" # Play a losing sound
read -r -p "Press Enter to continue..."
fi
}
# Function to use guns for jobs
use_guns() {
if [[ " ${guns[*]} " == *" $1 "* ]]; then
echo "You used your $1 for this job."
play_sfx_mpg "gun_shot" # Play a gunshot sound when using a gun
read -r -p "Press Enter to continue..."
else
echo "You don't have a $1. Job failed."
read -r -p "Press Enter to continue..."
fi
}
# Function for visiting the hospital
visit_hospital() {
local hospital_choice
clear_screen
echo "Hospital Services:"
echo "1. Basic Treatment (50$) - Full heal"
echo "2. Advanced Treatment (100$) - Full heal + 10% health boost"
echo "3. Buy Health Pack (30$) - Heal 25% health"
echo "4. Buy Body Armor (75$) - Reduce damage by 50% in next encounter"
echo "5. Back to main menu"
read -r -p "Enter your choice (number): " hospital_choice
[[ ! "$hospital_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number from the menu."
read -r -p "Press Enter to continue..."
return
}
case "$hospital_choice" in
1) buy_hospital_item 50 "basic_treatment";;
2) buy_hospital_item 100 "advanced_treatment";;
3) buy_hospital_item 30 "health_pack";;
4) buy_hospital_item 75 "body_armor";;
5) clear_screen;;
*) echo "Invalid choice.";;
esac
}
# Helper function for buying hospital items
buy_hospital_item() {
local item_cost="$1"
local item_type="$2"
if (( cash >= item_cost )); then
cash=$((cash - item_cost))
case "$item_type" in
"basic_treatment")
health=100
echo "You received basic treatment and are fully healed."
play_sfx_mpg "heal" # Play a healing sound
read -r -p "Press Enter to continue..."
;;
"advanced_treatment")
health=$((health + 10))
(( health > 100 )) && health=100
echo "You received advanced treatment and are fully healed with a health boost."
play_sfx_mpg "heal" # Play a healing sound
read -r -p "Press Enter to continue..."
;;
"health_pack")
items+=("Health Pack")
echo "You bought a Health Pack."
play_sfx_mpg "item_buy" # Play an item buying sound
read -r -p "Press Enter to continue..."
;;
"body_armor")
body_armor_equipped=true
echo "You bought Body Armor."
play_sfx_mpg "item_buy" # Play an item buying sound
read -r -p "Press Enter to continue..."
;;
esac
else
echo "Not enough cash for $item_type."
read -r -p "Press Enter to continue..."
fi
}
# Function for robbing a store
rob_store() {
robbing_animation
echo "Attempting to rob a store in $location..."
read -r -p "Press Enter to continue..."
local loot
local damage
local fine
local stealth_skill=$((skills["stealth"] * 5))
if (( RANDOM % 100 < stealth_skill )); then
loot=$((RANDOM % 201 + 100))
cash=$((cash + loot))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
damage=$((RANDOM % 31 + 10))
health=$((health - damage))
check_health
clear_screen
printf "You successfully robbed the store and got %d dollars, but lost %d%% health. You now have %d dollars and %d%% health.\n" "$loot" "$damage" "$cash" "$health"
play_sfx_mpg "cash_register" # Play a robbing sound
read -r -p "Press Enter to continue..."
else
fine=$((RANDOM % 51 + 25))
cash=$((cash - fine))
clear_screen
printf "You got caught and fined %d dollars. You now have %d dollars.\n" "$fine" "$cash"
play_sfx_mpg "lose" # Play a losing sound
read -r -p "Press Enter to continue..."
fi
}
# Function for participating in a heist
heist() {
heist_animation
echo "Planning a heist in $location..."
read -r -p "Press Enter to continue..."
local loot
local damage
local fine
local stealth_skill=$((skills["stealth"] * 5))
if (( RANDOM % 100 < stealth_skill )); then
loot=$((RANDOM % 501 + 200))
cash=$((cash + loot))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
damage=$((RANDOM % 51 + 20))
health=$((health - damage))
check_health
clear_screen
printf "The heist was successful! You got %d dollars, but lost %d%% health. You now have %d dollars and %d%% health.\n" "$loot" "$damage" "$cash" "$health"
play_sfx_mpg "cash_register" # Play a heist sound
read -r -p "Press Enter to continue..."
else
fine=$((RANDOM % 101 + 50))
cash=$((cash - fine))
clear_screen
printf "The heist failed and you got caught, losing %d dollars. You now have %d dollars.\n" "$fine" "$cash"
play_sfx_mpg "lose" # Play a losing sound
read -r -p "Press Enter to continue..."
fi
}
# Function for gang wars
gang_war() {
gang_war_animation
echo "Starting a gang war in $location..."
read -r -p "Press Enter to continue..."
local loot
local damage
local fine
local strength_skill=$((skills["strength"] * 5))
if (( RANDOM % 100 < strength_skill )); then
loot=$((RANDOM % 301 + 100))
cash=$((cash + loot))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
damage=$((RANDOM % 51 + 30))
health=$((health - damage))
check_health
clear_screen
printf "You won the gang war and got %d dollars, but lost %d%% health. You now have %d dollars and %d%% health.\n" "$loot" "$damage" "$cash" "$health"
play_sfx_mpg "win" # Play a gang war sound
read -r -p "Press Enter to continue..."
else
fine=$((RANDOM % 151 + 50))
cash=$((cash - fine))
damage=$((RANDOM % 41 + 20))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
health=$((health - damage))
check_health
clear_screen
printf "You lost the gang war, got fined %d dollars, and lost %d%% health. You now have %d dollars and %d%% health.\n" "$fine" "$damage" "$cash" "$health"
play_sfx_mpg "lose" # Play a losing sound
read -r -p "Press Enter to continue..."
fi
}
# Function for carjacking
carjack() {
carjacking_animation
echo "Attempting to carjack a vehicle in $location..."
read -r -p "Press Enter to continue..."
local loot
local damage
local fine
local driving_skill=$((skills["driving"] * 5))
local stealth_skill=$((skills["stealth"] * 5))
local success_chance=$((driving_skill + stealth_skill))
if (( RANDOM % 100 < success_chance )); then
loot=$((RANDOM % 201 + 50))
cash=$((cash + loot))
if $body_armor_equipped; then
damage=$((damage / 2))
echo "Your body armor reduced the damage!"
body_armor_equipped=false
fi
damage=$((RANDOM % 21 + 10))
health=$((health - damage))
check_health
clear_screen
printf "You successfully carjacked a vehicle and got %d dollars, but lost %d%% health. You now have %d dollars and %d%% health.\n" "$loot" "$damage" "$cash" "$health"
play_sfx_mpg "car_start" # Play a car jacking sound
read -r -p "Press Enter to continue..."
else
fine=$((RANDOM % 76 + 25))
cash=$((cash - fine))
clear_screen
printf "You got caught and fined %d dollars. You now have %d dollars.\n" "$fine" "$cash"
play_sfx_mpg "lose" # Play a losing sound
read -r -p "Press Enter to continue..."
fi
}
# Function to handle hospital visit after death
hospitalize_player() {
clear_screen
echo "You have been hospitalized and are being treated..."
read -r -p "Press Enter to continue..."
health=100
clear_screen
echo "You are fully healed but lost $200 for the treatment."
cash=$((cash - 200))
(( cash < 0 )) && cash=0
read -r -p "Press Enter to continue..."
clear_screen
}
# Function to hire a hooker
hire_hooker() {
echo "You are looking for a hooker in $location..."
read -r -p "Press Enter to continue..."
local hooker_cost
local health_gain
local charisma_skill=$((skills["charisma"] * 2))# Influence price
hooker_cost=$((RANDOM % (101 - charisma_skill) + (50 - charisma_skill) ))
if (( hooker_cost < 10 )); then
hooker_cost = 10
fi
health_gain=$((RANDOM % 21 + 10))
if (( cash >= hooker_cost )); then
cash=$((cash - hooker_cost))
health=$((health + health_gain))
(( health > 100 )) && health=100
clear_screen
printf "You hired a hooker for %d dollars and gained %d%% health. You now have %d dollars and %d%% health.\n" "$hooker_cost" "$health_gain" "$cash" "$health"
play_sfx_mpg "hooker" # Play a hooker sound
read -r -p "Press Enter to continue..."
else
clear_screen
echo "Not enough cash to hire a hooker."
read -r -p "Press Enter to continue..."
fi
clear_screen
}
# Function to buy drugs
buy_drugs() {
local drug_choice drug_amount cost
clear_screen
echo "Drug Dealer - Choose a drug to buy:"
echo "1. Weed (10$/unit)"
echo "2. Cocaine (50$/unit)"
echo "3. Heroin (100$/unit)"
echo "4. Meth (75$/unit)"
echo "5. Back to main menu"
read -r -p "Enter your choice (number): " drug_choice
[[ ! "$drug_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number from the menu."
read -r -p "Press Enter to continue..."
return
}
read -r -p "Enter the amount you want to buy: " drug_amount
[[ ! "$drug_amount" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
read -r -p "Press Enter to continue..."
return
}
case "$drug_choice" in
1) buy_drug "Weed" 10 "$drug_amount";;
2) buy_drug "Cocaine" 50 "$drug_amount";;
3) buy_drug "Heroin" 100 "$drug_amount";;
4) buy_drug "Meth" 75 "$drug_amount";;
5) clear_screen;;
*) echo "Invalid choice.";;
esac
clear_screen
}
# Helper function for buying drugs
# Centralized Drug Transaction Function
drug_transaction() {
local action="$1" # "buy" or "sell"
local drug_name="$2"
local drug_price="$3"
local drug_amount="$4"
local cost income selling_price
local drug_dealer_skill=$((skills["drug_dealer"]))
if [[ "$action" == "buy" ]]; then
cost=$((drug_price * drug_amount))
if (( cash >= cost )); then
drug_transaction_animation
cash=$((cash - cost))
drugs["$drug_name"]=$((drugs["$drug_name"] + drug_amount))
printf "You bought %s units of %s.\n" "$drug_amount" "$drug_name"
play_sfx_mpg "cash_register"
return 0
else
echo "Not enough cash to buy $drug_name."
return 1
fi
elif [[ "$action" == "sell" ]]; then
if [[ -v "drugs[$drug_name]" ]] && (( drugs["$drug_name"] >= drug_amount )); then
drug_transaction_animation
# Adjust selling price based on skill
local price_modifier=$((drug_dealer_skill * 2)) # Example: 2% increase per skill point
local adjusted_price=$((drug_price + (drug_price * price_modifier / 100)))
income=$((adjusted_price * drug_amount))
cash=$((cash + income))
drugs["$drug_name"]=$((drugs["$drug_name"] - drug_amount))
printf "You sold %s units of %s for %d dollars (adjusted for your drug dealing skill).\n" "$drug_amount" "$drug_name" "$income"
play_sfx_mpg "cash_register"
# Increase drug dealer skill
skills["drug_dealer"]=$((drug_dealer_skill + 1)) # Simple increase
echo "Your drug dealing skill has increased!"
return 0
else
echo "Not enough $drug_name to sell."
return 1
fi
else
echo "Invalid action: $action"
return 1
fi
}
buy_drugs() {
local drug_choice drug_amount
clear_screen
echo "Drug Dealer - Choose a drug to buy:"
echo "1. Weed (10$/unit)"
echo "2. Cocaine (50$/unit)"
echo "3. Heroin (100$/unit)"
echo "4. Meth (75$/unit)"
echo "5. Back to main menu"
read -r -p "Enter your choice (number): " drug_choice
[[ ! "$drug_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number from the menu."
read -r -p "Press Enter to continue..."
return
}
read -r -p "Enter the amount you want to buy: " drug_amount
[[ ! "$drug_amount" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
read -r -p "Press Enter to continue..."
return
}
case "$drug_choice" in
1) drug_transaction "buy" "Weed" 10 "$drug_amount";;
2) drug_transaction "buy" "Cocaine" 50 "$drug_amount";;
3) drug_transaction "buy" "Heroin" 100 "$drug_amount";;
4) drug_transaction "buy" "Meth" 75 "$drug_amount";;
5) clear_screen; return;;
*) echo "Invalid choice."; return;;
esac
read -r -p "Press Enter to continue..."
}
sell_drugs() {
local drug_choice drug_amount
clear_screen
echo "Drug Dealer - Choose a drug to sell:"
echo "1. Weed"
echo "2. Cocaine"
echo "3. Heroin"
echo "4. Meth"
echo "5. Back to main menu"
read -r -p "Enter your choice (number): " drug_choice
[[ ! "$drug_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number from the menu."
read -r -p "Press Enter to continue..."
return
}
read -r -p "Enter the amount you want to sell: " drug_amount
[[ ! "$drug_amount" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
read -r -p "Press Enter to continue..."
return
}
case "$drug_choice" in
1) drug_transaction "sell" "Weed" 15 "$drug_amount";;
2) drug_transaction "sell" "Cocaine" 75 "$drug_amount";;
3) drug_transaction "sell" "Heroin" 150 "$drug_amount";;
4) drug_transaction "sell" "Meth" 100 "$drug_amount";;
5) clear_screen; return;;
*) echo "Invalid choice."; return;;
esac
read -r -p "Press Enter to continue..."
}
# Function to play music
play_music() {
local music_files=(
"music/platforma.mp3"
"music/the_loading_screen.mp3"
"music/doom.mp3"
"music/Jal.mp3"
)
while true; do
clear_screen
echo "Choose a song to play:"
for i in "${!music_files[@]}"; do
printf "%d. %s\n" $((i + 1)) "$(basename "${music_files[$i]}")"
done
echo "press q to Stop Music"
printf "%d. Back to Main menu\n" $(( ${#music_files[@]} + 1 ))
read -r music_choice
if ! [[ "$music_choice" =~ ^[0-9]+$ ]]; then
echo "Invalid input. Please enter a number."
sleep 2
continue # Go back to music player menu
fi
if (( music_choice <= ${#music_files[@]} )); then
local selected_track="${music_files[$((music_choice - 1))]}"
if [[ -f "$selected_track" ]]; then
echo "Playing: $(basename "$selected_track")"
mpg123 -q "$selected_track"
else
echo "Error: Music file '$selected_track' not found."
sleep 2
fi
elif (( music_choice == ${#music_files[@]} + 1 )); then
pkill mpg123
clear_screen
break # Exit the music player menu
else
echo "Invalid choice."
sleep 2
fi
done
}
# Save the game state to a file
save_game() {
echo "$player_name" > "$SAVE_DIR/player_name.sav"
echo "$location" > "$SAVE_DIR/location.sav"
echo "$cash" > "$SAVE_DIR/cash.sav"
echo "$health" > "$SAVE_DIR/health.sav"
printf '%s\n' "${guns[@]}" > "$SAVE_DIR/guns.sav"
printf '%s\n' "${items[@]}" > "$SAVE_DIR/items.sav"
> "$SAVE_DIR/drugs.sav"
for key in "${!drugs[@]}"; do
printf "%s %s\n" "$key" "${drugs[$key]}" >> "$SAVE_DIR/drugs.sav"
done
echo "$body_armor_equipped" > "$SAVE_DIR/body_armor_equipped.sav"
# Save skills
> "$SAVE_DIR/skills.sav" # Clear the file first
for key in "${!skills[@]}"; do
printf "%s %s\n" "$key" "${skills[$key]}" >> "$SAVE_DIR/skills.sav"
done
echo "Game saved successfully."
read -r -p "Press Enter to continue..."
}
# Load the game state from a file
load_game() {
local IFS=$'\n'
if [[ -f "$SAVE_DIR/player_name.sav" && -f "$SAVE_DIR/location.sav" && -f "$SAVE_DIR/cash.sav" && -f "$SAVE_DIR/health.sav" && -f "$SAVE_DIR/guns.sav" && -f "$SAVE_DIR/items.sav" && -f "$SAVE_DIR/body_armor_equipped.sav" && -f "$SAVE_DIR/skills.sav" ]]; then
read -r player_name < "$SAVE_DIR/player_name.sav"
read -r location < "$SAVE_DIR/location.sav"
read -r cash < "$SAVE_DIR/cash.sav"
read -r health < "$SAVE_DIR/health.sav"
read -r -a guns < "$SAVE_DIR/guns.sav"
read -r -a items < "$SAVE_DIR/items.sav"
read -r body_armor_equipped < "$SAVE_DIR/body_armor_equipped.sav"
declare -A drugs
while IFS=$'\n' read -r line; do
if [[ -n "$line" ]]; then
IFS=$' ' read -r key value <<< "$line"
drugs["$key"]="$value"
fi
done < "$SAVE_DIR/drugs.sav"
# Load skills
declare -A skills
while IFS=$'\n' read -r line; do
if [[ -n "$line" ]]; then
IFS=$' ' read -r key value <<< "$line"
skills["$key"]="$value"
fi
done < "$SAVE_DIR/skills.sav"
echo "Game loaded successfully."
read -r -p "Press Enter to continue..."
IFS=$' \t\n' # Restore IFS
return 0 # Indicate successful load
else
echo "No saved game found."
read -r -p "Press Enter to continue..."
IFS=$' \t\n' # Restore IFS
return 1 # Indicate load failure
fi
}
# --- 4. Game Initialization and Loop ---
# Function to initialize game variables
Game_variables() {
clear_screen
read -r -p "Enter your player name: " player_name
play_sfx_mpg "new_game" # Play a New Game sound
location="Los Santos"
cash=500
health=100
guns=()
items=()
declare -A drugs
drugs=( ["Weed"]=0 ["Cocaine"]=0 ["Heroin"]=0 ["Meth"]=0 )
# Initialize skills
declare -A skills
skills=( ["driving"]=1 ["strength"]=1 ["charisma"]=1 ["stealth"]=1 ["drug_dealer"]=1 )
clear_screen
}
# Function to remove save files
remove_save_files() {
rm -f "$SAVE_DIR/player_name.sav"
rm -f "$SAVE_DIR/location.sav"
rm -f "$SAVE_DIR/cash.sav"
rm -f "$SAVE_DIR/health.sav"
rm -f "$SAVE_DIR/guns.sav"
rm -f "$SAVE_DIR/items.sav"
rm -f "$SAVE_DIR/drugs.sav"
rm -f "$SAVE_DIR/body_armor_equipped.sav"
rm -f "$SAVE_DIR/skills.sav" # Remove skills save file
if [[ ! -d "$SAVE_DIR" ]]; then
echo "No saved game found."
else
echo "Old save deleted!"
fi
}
# Initial game menu
while true; do
clear_screen
echo "Welcome to Bash Theft Auto"
echo "Choose an option:"
echo "1. New Game"
echo "2. Load Game"
echo "3. Exit Game"
read -r -p "Enter your choice: " initial_choice
[[ ! "$initial_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
sleep 2
continue
}
case "$initial_choice" in
1) remove_save_files; Game_variables; break;;
2) if [[ -d "$SAVE_DIR" ]] && load_game; then break; else continue; fi;;
3) exit;;
*) echo "Invalid choice.";;
esac
done
while true; do
clear_screen
echo "Choose an action:"
echo "1. Travel to another city"
echo "2. Buy guns"
echo "3. Show inventory"
echo "4. Work (earn money)"
echo "5. Work (criminal activity)"
echo "6. Buy drugs"
echo "7. Sell drugs"
echo "8. Hire hooker"
echo "9. Visit hospital"
echo "10. Exit Game"
echo "11. Save Game"
echo "12. Load Game"
echo "13. Play music"
read -r -p "Enter your choice: " choice
[[ ! "$choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
sleep 2
continue
}
case "$choice" in
1) clear
echo "Choose a city to travel to:"
echo "1. Los Santos (50$)"
echo "2. San Fierro (75$)"
echo "3. Las Venturas (100$)"
echo "4. Vice City (150$)"
echo "5. Liberty City (200$)"
echo "6. Back to main menu"
read -r -p "Enter your choice: " city_choice
[[ ! "$city_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
sleep 2
continue
}
case "$city_choice" in
1) travel_to 50 "Los Santos";;
2) travel_to 75 "San Fierro";;
3) travel_to 100 "Las Venturas";;
4) travel_to 150 "Vice City";;
5) travel_to 200 "Liberty City";;
6) clear_screen;;
*) echo "Invalid choice.";;
esac;;
2) buy_guns;;
3) show_inventory;;
4) clear
echo "Choose a job:"
echo "1. Taxi Driver"
echo "2. Delivery Driver"
echo "3. Mechanic"
echo "4. Security Guard"
echo "5. Street Performer"
echo "6. Street Racing"
echo "7. Back to main menu"
read -r -p "Enter your choice: " job_choice
[[ ! "$job_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
sleep 2
continue
}
case "$job_choice" in
1) work_job "taxi";;
2) work_job "delivery";;
3) work_job "mechanic";;
4) work_job "security";;
5) work_job "performer";;
6) work_job "race";;
7) clear_screen;;
*) echo "Invalid choice.";;
esac;;
5) clear
echo "Choose a criminal activity:"
echo "1. Heist"
echo "2. Gang war"
echo "3. Carjack"
echo "4. Carjack"
echo "5. Back to main menu"
read -r -p "Enter your choice: " criminal_choice
[[ ! "$criminal_choice" =~ ^[0-9]+$ ]] && {
echo "Invalid input. Please enter a number."
sleep 2
continue
}
case "$criminal_choice" in
1) heist;;
2) gang_war;;
3) carjack;;
4) rob_store;;
5) clear_screen;;
*) echo "Invalid choice.";;
esac;;
6) buy_drugs;;
7) sell_drugs;;
8) hire_hooker;;
9) visit_hospital;;
10) exit;;
11) save_game;;
12) load_game;;
13) play_music;;
*) echo "Invalid choice.";;
esac
done