state checkformalakiangem

        // Check Malakian Gem [Permenant Boost Item]
        ifvarvarg PARTYSIZE MALAKIANGEMS setvarvar TEMP6 MALAKIANGEMS else setvarvar TEMP6 PARTYSIZE
        mulvar TEMP6 -2 // 2% per item
        addvar TEMP6 100
        mulvarvar TEMP7 TEMP6
        divvar TEMP7 100

ends

state checkfornyxgloves
 setvar DAMAGEMODIFIER 0
 ifvare PLAYEREQUIPSLOTITEM1 11 addvar DAMAGEMODIFIER 1
 ifvare PLAYEREQUIPSLOTITEM2 11 addvar DAMAGEMODIFIER 1
 ifvare PLAYEREQUIPSLOTITEM3 11 addvar DAMAGEMODIFIER 1
 ifvare PLAYEREQUIPSLOTITEM4 11 addvar DAMAGEMODIFIER 1
ends

state playerdamagehuestength2
     setvarvar TEMPVAR5 DAMAGEHUEFACTOR
     divvar TEMPVAR5 5 // 10
     addvarvar DAMAGEHUETIMER TEMPVAR5
     ifvarl DAMAGEHUETIMER 0 setvar DAMAGEHUETIMER 0
     ifvarg DAMAGEHUETIMER 200 setvar DAMAGEHUETIMER 200
//     addlogvar DAMAGEHUEFACTOR
//     addlogvar TEMPVAR5
//     addlogvar DAMAGEHUETIMER
ends

state playerdamagehues-shakescreen
     ifvarg DAMAGEHUEFACTOR 249 wackplayer
     ifvarg DAMAGEHUEFACTOR 499 wackplayer
     ifvarg DAMAGEHUEFACTOR 749 wackplayer
     ifvarg DAMAGEHUEFACTOR 999 wackplayer
     ifvarg DAMAGEHUEFACTOR 1249 wackplayer
     ifvarg DAMAGEHUEFACTOR 1499 wackplayer
     ifvarg DAMAGEHUEFACTOR 1749 wackplayer
     ifvarg DAMAGEHUEFACTOR 1999 wackplayer
ends

state calcdmgfactor
     mulvar DAMAGEHUEFACTOR 1000
     divvarvar DAMAGEHUEFACTOR MAXHITPOINTS
     state playerdamagehuestength2
ends

state playerdamagehues-normaltype
     state calcdmgfactor

     ifvarg DAMAGEHUEFACTOR -1 ifvarl DAMAGEHUEFACTOR 25 palfrom 1 64
     else ifvarg DAMAGEHUEFACTOR 24 ifvarl DAMAGEHUEFACTOR 50 palfrom 2 64
     else ifvarg DAMAGEHUEFACTOR 49 ifvarl DAMAGEHUEFACTOR 75 palfrom 3 64
     else ifvarg DAMAGEHUEFACTOR 74 ifvarl DAMAGEHUEFACTOR 100 palfrom 4 64
     else ifvarg DAMAGEHUEFACTOR 99 ifvarl DAMAGEHUEFACTOR 125 palfrom 5 64
     else ifvarg DAMAGEHUEFACTOR 124 ifvarl DAMAGEHUEFACTOR 150 palfrom 6 64
     else ifvarg DAMAGEHUEFACTOR 149 ifvarl DAMAGEHUEFACTOR 175 palfrom 7 64
     else ifvarg DAMAGEHUEFACTOR 174 ifvarl DAMAGEHUEFACTOR 200 palfrom 8 64
     else ifvarg DAMAGEHUEFACTOR 199 ifvarl DAMAGEHUEFACTOR 225 palfrom 9 64
     else ifvarg DAMAGEHUEFACTOR 224 ifvarl DAMAGEHUEFACTOR 250 palfrom 10 64
     else ifvarg DAMAGEHUEFACTOR 249 ifvarl DAMAGEHUEFACTOR 275 palfrom 11 64
     else ifvarg DAMAGEHUEFACTOR 274 ifvarl DAMAGEHUEFACTOR 300 palfrom 12 64
     else ifvarg DAMAGEHUEFACTOR 299 ifvarl DAMAGEHUEFACTOR 325 palfrom 13 64
     else ifvarg DAMAGEHUEFACTOR 324 ifvarl DAMAGEHUEFACTOR 350 palfrom 14 64
     else ifvarg DAMAGEHUEFACTOR 349 ifvarl DAMAGEHUEFACTOR 375 palfrom 15 64
     else ifvarg DAMAGEHUEFACTOR 374 ifvarl DAMAGEHUEFACTOR 400 palfrom 16 64
     else ifvarg DAMAGEHUEFACTOR 399 ifvarl DAMAGEHUEFACTOR 425 palfrom 17 64
     else ifvarg DAMAGEHUEFACTOR 424 ifvarl DAMAGEHUEFACTOR 450 palfrom 18 64
     else ifvarg DAMAGEHUEFACTOR 449 ifvarl DAMAGEHUEFACTOR 475 palfrom 19 64
     else ifvarg DAMAGEHUEFACTOR 474 ifvarl DAMAGEHUEFACTOR 500 palfrom 20 64
     else ifvarg DAMAGEHUEFACTOR 499 ifvarl DAMAGEHUEFACTOR 525 palfrom 21 64
     else ifvarg DAMAGEHUEFACTOR 524 ifvarl DAMAGEHUEFACTOR 550 palfrom 22 64
     else ifvarg DAMAGEHUEFACTOR 549 ifvarl DAMAGEHUEFACTOR 575 palfrom 23 64
     else ifvarg DAMAGEHUEFACTOR 574 ifvarl DAMAGEHUEFACTOR 600 palfrom 24 64
     else ifvarg DAMAGEHUEFACTOR 599 ifvarl DAMAGEHUEFACTOR 625 palfrom 25 64
     else ifvarg DAMAGEHUEFACTOR 624 ifvarl DAMAGEHUEFACTOR 650 palfrom 26 64
     else ifvarg DAMAGEHUEFACTOR 649 ifvarl DAMAGEHUEFACTOR 675 palfrom 27 64
     else ifvarg DAMAGEHUEFACTOR 674 ifvarl DAMAGEHUEFACTOR 700 palfrom 28 64
     else ifvarg DAMAGEHUEFACTOR 699 ifvarl DAMAGEHUEFACTOR 725 palfrom 29 64
     else ifvarg DAMAGEHUEFACTOR 724 ifvarl DAMAGEHUEFACTOR 750 palfrom 30 64
     else ifvarg DAMAGEHUEFACTOR 749 ifvarl DAMAGEHUEFACTOR 775 palfrom 31 64
     else ifvarg DAMAGEHUEFACTOR 774 ifvarl DAMAGEHUEFACTOR 800 palfrom 32 64
     else ifvarg DAMAGEHUEFACTOR 799 ifvarl DAMAGEHUEFACTOR 825 palfrom 33 64
     else ifvarg DAMAGEHUEFACTOR 824 ifvarl DAMAGEHUEFACTOR 850 palfrom 34 64
     else ifvarg DAMAGEHUEFACTOR 849 ifvarl DAMAGEHUEFACTOR 875 palfrom 35 64
     else ifvarg DAMAGEHUEFACTOR 874 ifvarl DAMAGEHUEFACTOR 900 palfrom 36 64
     else ifvarg DAMAGEHUEFACTOR 899 ifvarl DAMAGEHUEFACTOR 925 palfrom 37 64
     else ifvarg DAMAGEHUEFACTOR 924 ifvarl DAMAGEHUEFACTOR 950 palfrom 38 64
     else ifvarg DAMAGEHUEFACTOR 949 ifvarl DAMAGEHUEFACTOR 975 palfrom 39 64
     else ifvarg DAMAGEHUEFACTOR 974 ifvarl DAMAGEHUEFACTOR 1000 palfrom 40 64
     else ifvarg DAMAGEHUEFACTOR 999 ifvarl DAMAGEHUEFACTOR 1025 palfrom 41 64
     else ifvarg DAMAGEHUEFACTOR 1024 ifvarl DAMAGEHUEFACTOR 1050 palfrom 42 64
     else ifvarg DAMAGEHUEFACTOR 1049 ifvarl DAMAGEHUEFACTOR 1075 palfrom 43 64
     else ifvarg DAMAGEHUEFACTOR 1074 ifvarl DAMAGEHUEFACTOR 1100 palfrom 44 64
     else ifvarg DAMAGEHUEFACTOR 1099 ifvarl DAMAGEHUEFACTOR 1125 palfrom 45 64
     else ifvarg DAMAGEHUEFACTOR 1124 ifvarl DAMAGEHUEFACTOR 1150 palfrom 46 64
     else ifvarg DAMAGEHUEFACTOR 1149 ifvarl DAMAGEHUEFACTOR 1175 palfrom 47 64
     else ifvarg DAMAGEHUEFACTOR 1174 ifvarl DAMAGEHUEFACTOR 1200 palfrom 48 64
     else ifvarg DAMAGEHUEFACTOR 1199 ifvarl DAMAGEHUEFACTOR 1225 palfrom 49 64
     else ifvarg DAMAGEHUEFACTOR 1224 ifvarl DAMAGEHUEFACTOR 1250 palfrom 50 64
     else ifvarg DAMAGEHUEFACTOR 1249 ifvarl DAMAGEHUEFACTOR 1275 palfrom 51 64
     else ifvarg DAMAGEHUEFACTOR 1274 ifvarl DAMAGEHUEFACTOR 1300 palfrom 52 64
     else ifvarg DAMAGEHUEFACTOR 1299 ifvarl DAMAGEHUEFACTOR 1325 palfrom 53 64
     else ifvarg DAMAGEHUEFACTOR 1324 ifvarl DAMAGEHUEFACTOR 1350 palfrom 54 64
     else ifvarg DAMAGEHUEFACTOR 1349 ifvarl DAMAGEHUEFACTOR 1375 palfrom 55 64
     else ifvarg DAMAGEHUEFACTOR 1374 ifvarl DAMAGEHUEFACTOR 1400 palfrom 56 64
     else ifvarg DAMAGEHUEFACTOR 1399 ifvarl DAMAGEHUEFACTOR 1425 palfrom 57 64
     else ifvarg DAMAGEHUEFACTOR 1424 ifvarl DAMAGEHUEFACTOR 1450 palfrom 58 64
     else ifvarg DAMAGEHUEFACTOR 1449 ifvarl DAMAGEHUEFACTOR 1475 palfrom 59 64
     else ifvarg DAMAGEHUEFACTOR 1474 ifvarl DAMAGEHUEFACTOR 1500 palfrom 60 64
     else ifvarg DAMAGEHUEFACTOR 1499 ifvarl DAMAGEHUEFACTOR 1525 palfrom 61 64
     else ifvarg DAMAGEHUEFACTOR 1524 ifvarl DAMAGEHUEFACTOR 1550 palfrom 62 64
     else ifvarg DAMAGEHUEFACTOR 1549 ifvarl DAMAGEHUEFACTOR 1575 palfrom 63 64
     else ifvarg DAMAGEHUEFACTOR 1574 palfrom 64 64
     setvar DAMAGEHUEPAL 21
ends

state playerdamagehues-acidtype
     state calcdmgfactor

     ifvarg DAMAGEHUEFACTOR -1 ifvarl DAMAGEHUEFACTOR 25 palfrom 1 0 64
     else ifvarg DAMAGEHUEFACTOR 24 ifvarl DAMAGEHUEFACTOR 50 palfrom 2 0 64
     else ifvarg DAMAGEHUEFACTOR 49 ifvarl DAMAGEHUEFACTOR 75 palfrom 3 0 64
     else ifvarg DAMAGEHUEFACTOR 74 ifvarl DAMAGEHUEFACTOR 100 palfrom 4 0 64
     else ifvarg DAMAGEHUEFACTOR 99 ifvarl DAMAGEHUEFACTOR 125 palfrom 5 0 64
     else ifvarg DAMAGEHUEFACTOR 124 ifvarl DAMAGEHUEFACTOR 150 palfrom 6 0 64
     else ifvarg DAMAGEHUEFACTOR 149 ifvarl DAMAGEHUEFACTOR 175 palfrom 7 0 64
     else ifvarg DAMAGEHUEFACTOR 174 ifvarl DAMAGEHUEFACTOR 200 palfrom 8 0 64
     else ifvarg DAMAGEHUEFACTOR 199 ifvarl DAMAGEHUEFACTOR 225 palfrom 9 0 64
     else ifvarg DAMAGEHUEFACTOR 224 ifvarl DAMAGEHUEFACTOR 250 palfrom 10 0 64
     else ifvarg DAMAGEHUEFACTOR 249 ifvarl DAMAGEHUEFACTOR 275 palfrom 11 0 64
     else ifvarg DAMAGEHUEFACTOR 274 ifvarl DAMAGEHUEFACTOR 300 palfrom 12 0 64
     else ifvarg DAMAGEHUEFACTOR 299 ifvarl DAMAGEHUEFACTOR 325 palfrom 13 0 64
     else ifvarg DAMAGEHUEFACTOR 324 ifvarl DAMAGEHUEFACTOR 350 palfrom 14 0 64
     else ifvarg DAMAGEHUEFACTOR 349 ifvarl DAMAGEHUEFACTOR 375 palfrom 15 0 64
     else ifvarg DAMAGEHUEFACTOR 374 ifvarl DAMAGEHUEFACTOR 400 palfrom 16 0 64
     else ifvarg DAMAGEHUEFACTOR 399 ifvarl DAMAGEHUEFACTOR 425 palfrom 17 0 64
     else ifvarg DAMAGEHUEFACTOR 424 ifvarl DAMAGEHUEFACTOR 450 palfrom 18 0 64
     else ifvarg DAMAGEHUEFACTOR 449 ifvarl DAMAGEHUEFACTOR 475 palfrom 19 0 64
     else ifvarg DAMAGEHUEFACTOR 474 ifvarl DAMAGEHUEFACTOR 500 palfrom 20 0 64
     else ifvarg DAMAGEHUEFACTOR 499 ifvarl DAMAGEHUEFACTOR 525 palfrom 21 0 64
     else ifvarg DAMAGEHUEFACTOR 524 ifvarl DAMAGEHUEFACTOR 550 palfrom 22 0 64
     else ifvarg DAMAGEHUEFACTOR 549 ifvarl DAMAGEHUEFACTOR 575 palfrom 23 0 64
     else ifvarg DAMAGEHUEFACTOR 574 ifvarl DAMAGEHUEFACTOR 600 palfrom 24 0 64
     else ifvarg DAMAGEHUEFACTOR 599 ifvarl DAMAGEHUEFACTOR 625 palfrom 25 0 64
     else ifvarg DAMAGEHUEFACTOR 624 ifvarl DAMAGEHUEFACTOR 650 palfrom 26 0 64
     else ifvarg DAMAGEHUEFACTOR 649 ifvarl DAMAGEHUEFACTOR 675 palfrom 27 0 64
     else ifvarg DAMAGEHUEFACTOR 674 ifvarl DAMAGEHUEFACTOR 700 palfrom 28 0 64
     else ifvarg DAMAGEHUEFACTOR 699 ifvarl DAMAGEHUEFACTOR 725 palfrom 29 0 64
     else ifvarg DAMAGEHUEFACTOR 724 ifvarl DAMAGEHUEFACTOR 750 palfrom 30 0 64
     else ifvarg DAMAGEHUEFACTOR 749 ifvarl DAMAGEHUEFACTOR 775 palfrom 31 0 64
     else ifvarg DAMAGEHUEFACTOR 774 ifvarl DAMAGEHUEFACTOR 800 palfrom 32 0 64
     else ifvarg DAMAGEHUEFACTOR 799 ifvarl DAMAGEHUEFACTOR 825 palfrom 33 0 64
     else ifvarg DAMAGEHUEFACTOR 824 ifvarl DAMAGEHUEFACTOR 850 palfrom 34 0 64
     else ifvarg DAMAGEHUEFACTOR 849 ifvarl DAMAGEHUEFACTOR 875 palfrom 35 0 64
     else ifvarg DAMAGEHUEFACTOR 874 ifvarl DAMAGEHUEFACTOR 900 palfrom 36 0 64
     else ifvarg DAMAGEHUEFACTOR 899 ifvarl DAMAGEHUEFACTOR 925 palfrom 37 0 64
     else ifvarg DAMAGEHUEFACTOR 924 ifvarl DAMAGEHUEFACTOR 950 palfrom 38 0 64
     else ifvarg DAMAGEHUEFACTOR 949 ifvarl DAMAGEHUEFACTOR 975 palfrom 39 0 64
     else ifvarg DAMAGEHUEFACTOR 974 ifvarl DAMAGEHUEFACTOR 1000 palfrom 40 0 64
     else ifvarg DAMAGEHUEFACTOR 999 ifvarl DAMAGEHUEFACTOR 1025 palfrom 41 0 64
     else ifvarg DAMAGEHUEFACTOR 1024 ifvarl DAMAGEHUEFACTOR 1050 palfrom 42 0 64
     else ifvarg DAMAGEHUEFACTOR 1049 ifvarl DAMAGEHUEFACTOR 1075 palfrom 43 0 64
     else ifvarg DAMAGEHUEFACTOR 1074 ifvarl DAMAGEHUEFACTOR 1100 palfrom 44 0 64
     else ifvarg DAMAGEHUEFACTOR 1099 ifvarl DAMAGEHUEFACTOR 1125 palfrom 45 0 64
     else ifvarg DAMAGEHUEFACTOR 1124 ifvarl DAMAGEHUEFACTOR 1150 palfrom 46 0 64
     else ifvarg DAMAGEHUEFACTOR 1149 ifvarl DAMAGEHUEFACTOR 1175 palfrom 47 0 64
     else ifvarg DAMAGEHUEFACTOR 1174 ifvarl DAMAGEHUEFACTOR 1200 palfrom 48 0 64
     else ifvarg DAMAGEHUEFACTOR 1199 ifvarl DAMAGEHUEFACTOR 1225 palfrom 49 0 64
     else ifvarg DAMAGEHUEFACTOR 1224 ifvarl DAMAGEHUEFACTOR 1250 palfrom 50 0 64
     else ifvarg DAMAGEHUEFACTOR 1249 ifvarl DAMAGEHUEFACTOR 1275 palfrom 51 0 64
     else ifvarg DAMAGEHUEFACTOR 1274 ifvarl DAMAGEHUEFACTOR 1300 palfrom 52 0 64
     else ifvarg DAMAGEHUEFACTOR 1299 ifvarl DAMAGEHUEFACTOR 1325 palfrom 53 0 64
     else ifvarg DAMAGEHUEFACTOR 1324 ifvarl DAMAGEHUEFACTOR 1350 palfrom 54 0 64
     else ifvarg DAMAGEHUEFACTOR 1349 ifvarl DAMAGEHUEFACTOR 1375 palfrom 55 0 64
     else ifvarg DAMAGEHUEFACTOR 1374 ifvarl DAMAGEHUEFACTOR 1400 palfrom 56 0 64
     else ifvarg DAMAGEHUEFACTOR 1399 ifvarl DAMAGEHUEFACTOR 1425 palfrom 57 0 64
     else ifvarg DAMAGEHUEFACTOR 1424 ifvarl DAMAGEHUEFACTOR 1450 palfrom 58 0 64
     else ifvarg DAMAGEHUEFACTOR 1449 ifvarl DAMAGEHUEFACTOR 1475 palfrom 59 0 64
     else ifvarg DAMAGEHUEFACTOR 1474 ifvarl DAMAGEHUEFACTOR 1500 palfrom 60 0 64
     else ifvarg DAMAGEHUEFACTOR 1499 ifvarl DAMAGEHUEFACTOR 1525 palfrom 61 0 64
     else ifvarg DAMAGEHUEFACTOR 1524 ifvarl DAMAGEHUEFACTOR 1550 palfrom 62 0 64
     else ifvarg DAMAGEHUEFACTOR 1549 ifvarl DAMAGEHUEFACTOR 1575 palfrom 63 0 64
     else ifvarg DAMAGEHUEFACTOR 1574 palfrom 64 0 64
     setvar DAMAGEHUEPAL 22
ends

state playerdamagehues-electrictype
     state calcdmgfactor

     ifvarg DAMAGEHUEFACTOR -1 ifvarl DAMAGEHUEFACTOR 25 palfrom 1 64 64 64
     else ifvarg DAMAGEHUEFACTOR 24 ifvarl DAMAGEHUEFACTOR 50 palfrom 2 64 64 64
     else ifvarg DAMAGEHUEFACTOR 49 ifvarl DAMAGEHUEFACTOR 75 palfrom 3 64 64 64
     else ifvarg DAMAGEHUEFACTOR 74 ifvarl DAMAGEHUEFACTOR 100 palfrom 4 64 64 64
     else ifvarg DAMAGEHUEFACTOR 99 ifvarl DAMAGEHUEFACTOR 125 palfrom 5 64 64 64
     else ifvarg DAMAGEHUEFACTOR 124 ifvarl DAMAGEHUEFACTOR 150 palfrom 6 64 64 64
     else ifvarg DAMAGEHUEFACTOR 149 ifvarl DAMAGEHUEFACTOR 175 palfrom 7 64 64 64
     else ifvarg DAMAGEHUEFACTOR 174 ifvarl DAMAGEHUEFACTOR 200 palfrom 8 64 64 64
     else ifvarg DAMAGEHUEFACTOR 199 ifvarl DAMAGEHUEFACTOR 225 palfrom 9 64 64 64
     else ifvarg DAMAGEHUEFACTOR 224 ifvarl DAMAGEHUEFACTOR 250 palfrom 10 64 64 64
     else ifvarg DAMAGEHUEFACTOR 249 ifvarl DAMAGEHUEFACTOR 275 palfrom 11 64 64 64
     else ifvarg DAMAGEHUEFACTOR 274 ifvarl DAMAGEHUEFACTOR 300 palfrom 12 64 64 64
     else ifvarg DAMAGEHUEFACTOR 299 ifvarl DAMAGEHUEFACTOR 325 palfrom 13 64 64 64
     else ifvarg DAMAGEHUEFACTOR 324 ifvarl DAMAGEHUEFACTOR 350 palfrom 14 64 64 64
     else ifvarg DAMAGEHUEFACTOR 349 ifvarl DAMAGEHUEFACTOR 375 palfrom 15 64 64 64
     else ifvarg DAMAGEHUEFACTOR 374 ifvarl DAMAGEHUEFACTOR 400 palfrom 16 64 64 64
     else ifvarg DAMAGEHUEFACTOR 399 ifvarl DAMAGEHUEFACTOR 425 palfrom 17 64 64 64
     else ifvarg DAMAGEHUEFACTOR 424 ifvarl DAMAGEHUEFACTOR 450 palfrom 18 64 64 64
     else ifvarg DAMAGEHUEFACTOR 449 ifvarl DAMAGEHUEFACTOR 475 palfrom 19 64 64 64
     else ifvarg DAMAGEHUEFACTOR 474 ifvarl DAMAGEHUEFACTOR 500 palfrom 20 64 64 64
     else ifvarg DAMAGEHUEFACTOR 499 ifvarl DAMAGEHUEFACTOR 525 palfrom 21 64 64 64
     else ifvarg DAMAGEHUEFACTOR 524 ifvarl DAMAGEHUEFACTOR 550 palfrom 22 64 64 64
     else ifvarg DAMAGEHUEFACTOR 549 ifvarl DAMAGEHUEFACTOR 575 palfrom 23 64 64 64
     else ifvarg DAMAGEHUEFACTOR 574 ifvarl DAMAGEHUEFACTOR 600 palfrom 24 64 64 64
     else ifvarg DAMAGEHUEFACTOR 599 ifvarl DAMAGEHUEFACTOR 625 palfrom 25 64 64 64
     else ifvarg DAMAGEHUEFACTOR 624 ifvarl DAMAGEHUEFACTOR 650 palfrom 26 64 64 64
     else ifvarg DAMAGEHUEFACTOR 649 ifvarl DAMAGEHUEFACTOR 675 palfrom 27 64 64 64
     else ifvarg DAMAGEHUEFACTOR 674 ifvarl DAMAGEHUEFACTOR 700 palfrom 28 64 64 64
     else ifvarg DAMAGEHUEFACTOR 699 ifvarl DAMAGEHUEFACTOR 725 palfrom 29 64 64 64
     else ifvarg DAMAGEHUEFACTOR 724 ifvarl DAMAGEHUEFACTOR 750 palfrom 30 64 64 64
     else ifvarg DAMAGEHUEFACTOR 749 ifvarl DAMAGEHUEFACTOR 775 palfrom 31 64 64 64
     else ifvarg DAMAGEHUEFACTOR 774 ifvarl DAMAGEHUEFACTOR 800 palfrom 32 64 64 64
     else ifvarg DAMAGEHUEFACTOR 799 ifvarl DAMAGEHUEFACTOR 825 palfrom 33 64 64 64
     else ifvarg DAMAGEHUEFACTOR 824 ifvarl DAMAGEHUEFACTOR 850 palfrom 34 64 64 64
     else ifvarg DAMAGEHUEFACTOR 849 ifvarl DAMAGEHUEFACTOR 875 palfrom 35 64 64 64
     else ifvarg DAMAGEHUEFACTOR 874 ifvarl DAMAGEHUEFACTOR 900 palfrom 36 64 64 64
     else ifvarg DAMAGEHUEFACTOR 899 ifvarl DAMAGEHUEFACTOR 925 palfrom 37 64 64 64
     else ifvarg DAMAGEHUEFACTOR 924 ifvarl DAMAGEHUEFACTOR 950 palfrom 38 64 64 64
     else ifvarg DAMAGEHUEFACTOR 949 ifvarl DAMAGEHUEFACTOR 975 palfrom 39 64 64 64
     else ifvarg DAMAGEHUEFACTOR 974 ifvarl DAMAGEHUEFACTOR 1000 palfrom 40 64 64 64
     else ifvarg DAMAGEHUEFACTOR 999 ifvarl DAMAGEHUEFACTOR 1025 palfrom 41 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1024 ifvarl DAMAGEHUEFACTOR 1050 palfrom 42 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1049 ifvarl DAMAGEHUEFACTOR 1075 palfrom 43 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1074 ifvarl DAMAGEHUEFACTOR 1100 palfrom 44 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1099 ifvarl DAMAGEHUEFACTOR 1125 palfrom 45 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1124 ifvarl DAMAGEHUEFACTOR 1150 palfrom 46 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1149 ifvarl DAMAGEHUEFACTOR 1175 palfrom 47 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1174 ifvarl DAMAGEHUEFACTOR 1200 palfrom 48 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1199 ifvarl DAMAGEHUEFACTOR 1225 palfrom 49 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1224 ifvarl DAMAGEHUEFACTOR 1250 palfrom 50 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1249 ifvarl DAMAGEHUEFACTOR 1275 palfrom 51 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1274 ifvarl DAMAGEHUEFACTOR 1300 palfrom 52 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1299 ifvarl DAMAGEHUEFACTOR 1325 palfrom 53 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1324 ifvarl DAMAGEHUEFACTOR 1350 palfrom 54 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1349 ifvarl DAMAGEHUEFACTOR 1375 palfrom 55 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1374 ifvarl DAMAGEHUEFACTOR 1400 palfrom 56 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1399 ifvarl DAMAGEHUEFACTOR 1425 palfrom 57 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1424 ifvarl DAMAGEHUEFACTOR 1450 palfrom 58 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1449 ifvarl DAMAGEHUEFACTOR 1475 palfrom 59 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1474 ifvarl DAMAGEHUEFACTOR 1500 palfrom 60 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1499 ifvarl DAMAGEHUEFACTOR 1525 palfrom 61 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1524 ifvarl DAMAGEHUEFACTOR 1550 palfrom 62 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1549 ifvarl DAMAGEHUEFACTOR 1575 palfrom 63 64 64 64
     else ifvarg DAMAGEHUEFACTOR 1574 palfrom 64 64 64 64
     setvar DAMAGEHUEPAL 20
ends

state playerdamagehues-firetype
     state calcdmgfactor

     ifvarg DAMAGEHUEFACTOR -1 ifvarl DAMAGEHUEFACTOR 25 palfrom 1 64 32
     else ifvarg DAMAGEHUEFACTOR 24 ifvarl DAMAGEHUEFACTOR 50 palfrom 2 64 32
     else ifvarg DAMAGEHUEFACTOR 49 ifvarl DAMAGEHUEFACTOR 75 palfrom 3 64 32
     else ifvarg DAMAGEHUEFACTOR 74 ifvarl DAMAGEHUEFACTOR 100 palfrom 4 64 32
     else ifvarg DAMAGEHUEFACTOR 99 ifvarl DAMAGEHUEFACTOR 125 palfrom 5 64 32
     else ifvarg DAMAGEHUEFACTOR 124 ifvarl DAMAGEHUEFACTOR 150 palfrom 6 64 32
     else ifvarg DAMAGEHUEFACTOR 149 ifvarl DAMAGEHUEFACTOR 175 palfrom 7 64 32
     else ifvarg DAMAGEHUEFACTOR 174 ifvarl DAMAGEHUEFACTOR 200 palfrom 8 64 32
     else ifvarg DAMAGEHUEFACTOR 199 ifvarl DAMAGEHUEFACTOR 225 palfrom 9 64 32
     else ifvarg DAMAGEHUEFACTOR 224 ifvarl DAMAGEHUEFACTOR 250 palfrom 10 64 32
     else ifvarg DAMAGEHUEFACTOR 249 ifvarl DAMAGEHUEFACTOR 275 palfrom 11 64 32
     else ifvarg DAMAGEHUEFACTOR 274 ifvarl DAMAGEHUEFACTOR 300 palfrom 12 64 32
     else ifvarg DAMAGEHUEFACTOR 299 ifvarl DAMAGEHUEFACTOR 325 palfrom 13 64 32
     else ifvarg DAMAGEHUEFACTOR 324 ifvarl DAMAGEHUEFACTOR 350 palfrom 14 64 32
     else ifvarg DAMAGEHUEFACTOR 349 ifvarl DAMAGEHUEFACTOR 375 palfrom 15 64 32
     else ifvarg DAMAGEHUEFACTOR 374 ifvarl DAMAGEHUEFACTOR 400 palfrom 16 64 32
     else ifvarg DAMAGEHUEFACTOR 399 ifvarl DAMAGEHUEFACTOR 425 palfrom 17 64 32
     else ifvarg DAMAGEHUEFACTOR 424 ifvarl DAMAGEHUEFACTOR 450 palfrom 18 64 32
     else ifvarg DAMAGEHUEFACTOR 449 ifvarl DAMAGEHUEFACTOR 475 palfrom 19 64 32
     else ifvarg DAMAGEHUEFACTOR 474 ifvarl DAMAGEHUEFACTOR 500 palfrom 20 64 32
     else ifvarg DAMAGEHUEFACTOR 499 ifvarl DAMAGEHUEFACTOR 525 palfrom 21 64 32
     else ifvarg DAMAGEHUEFACTOR 524 ifvarl DAMAGEHUEFACTOR 550 palfrom 22 64 32
     else ifvarg DAMAGEHUEFACTOR 549 ifvarl DAMAGEHUEFACTOR 575 palfrom 23 64 32
     else ifvarg DAMAGEHUEFACTOR 574 ifvarl DAMAGEHUEFACTOR 600 palfrom 24 64 32
     else ifvarg DAMAGEHUEFACTOR 599 ifvarl DAMAGEHUEFACTOR 625 palfrom 25 64 32
     else ifvarg DAMAGEHUEFACTOR 624 ifvarl DAMAGEHUEFACTOR 650 palfrom 26 64 32
     else ifvarg DAMAGEHUEFACTOR 649 ifvarl DAMAGEHUEFACTOR 675 palfrom 27 64 32
     else ifvarg DAMAGEHUEFACTOR 674 ifvarl DAMAGEHUEFACTOR 700 palfrom 28 64 32
     else ifvarg DAMAGEHUEFACTOR 699 ifvarl DAMAGEHUEFACTOR 725 palfrom 29 64 32
     else ifvarg DAMAGEHUEFACTOR 724 ifvarl DAMAGEHUEFACTOR 750 palfrom 30 64 32
     else ifvarg DAMAGEHUEFACTOR 749 ifvarl DAMAGEHUEFACTOR 775 palfrom 31 64 32
     else ifvarg DAMAGEHUEFACTOR 774 ifvarl DAMAGEHUEFACTOR 800 palfrom 32 64 32
     else ifvarg DAMAGEHUEFACTOR 799 ifvarl DAMAGEHUEFACTOR 825 palfrom 33 64 32
     else ifvarg DAMAGEHUEFACTOR 824 ifvarl DAMAGEHUEFACTOR 850 palfrom 34 64 32
     else ifvarg DAMAGEHUEFACTOR 849 ifvarl DAMAGEHUEFACTOR 875 palfrom 35 64 32
     else ifvarg DAMAGEHUEFACTOR 874 ifvarl DAMAGEHUEFACTOR 900 palfrom 36 64 32
     else ifvarg DAMAGEHUEFACTOR 899 ifvarl DAMAGEHUEFACTOR 925 palfrom 37 64 32
     else ifvarg DAMAGEHUEFACTOR 924 ifvarl DAMAGEHUEFACTOR 950 palfrom 38 64 32
     else ifvarg DAMAGEHUEFACTOR 949 ifvarl DAMAGEHUEFACTOR 975 palfrom 39 64 32
     else ifvarg DAMAGEHUEFACTOR 974 ifvarl DAMAGEHUEFACTOR 1000 palfrom 40 64 32
     else ifvarg DAMAGEHUEFACTOR 999 ifvarl DAMAGEHUEFACTOR 1025 palfrom 41 64 32
     else ifvarg DAMAGEHUEFACTOR 1024 ifvarl DAMAGEHUEFACTOR 1050 palfrom 42 64 32
     else ifvarg DAMAGEHUEFACTOR 1049 ifvarl DAMAGEHUEFACTOR 1075 palfrom 43 64 32
     else ifvarg DAMAGEHUEFACTOR 1074 ifvarl DAMAGEHUEFACTOR 1100 palfrom 44 64 32
     else ifvarg DAMAGEHUEFACTOR 1099 ifvarl DAMAGEHUEFACTOR 1125 palfrom 45 64 32
     else ifvarg DAMAGEHUEFACTOR 1124 ifvarl DAMAGEHUEFACTOR 1150 palfrom 46 64 32
     else ifvarg DAMAGEHUEFACTOR 1149 ifvarl DAMAGEHUEFACTOR 1175 palfrom 47 64 32
     else ifvarg DAMAGEHUEFACTOR 1174 ifvarl DAMAGEHUEFACTOR 1200 palfrom 48 64 32
     else ifvarg DAMAGEHUEFACTOR 1199 ifvarl DAMAGEHUEFACTOR 1225 palfrom 49 64 32
     else ifvarg DAMAGEHUEFACTOR 1224 ifvarl DAMAGEHUEFACTOR 1250 palfrom 50 64 32
     else ifvarg DAMAGEHUEFACTOR 1249 ifvarl DAMAGEHUEFACTOR 1275 palfrom 51 64 32
     else ifvarg DAMAGEHUEFACTOR 1274 ifvarl DAMAGEHUEFACTOR 1300 palfrom 52 64 32
     else ifvarg DAMAGEHUEFACTOR 1299 ifvarl DAMAGEHUEFACTOR 1325 palfrom 53 64 32
     else ifvarg DAMAGEHUEFACTOR 1324 ifvarl DAMAGEHUEFACTOR 1350 palfrom 54 64 32
     else ifvarg DAMAGEHUEFACTOR 1349 ifvarl DAMAGEHUEFACTOR 1375 palfrom 55 64 32
     else ifvarg DAMAGEHUEFACTOR 1374 ifvarl DAMAGEHUEFACTOR 1400 palfrom 56 64 32
     else ifvarg DAMAGEHUEFACTOR 1399 ifvarl DAMAGEHUEFACTOR 1425 palfrom 57 64 32
     else ifvarg DAMAGEHUEFACTOR 1424 ifvarl DAMAGEHUEFACTOR 1450 palfrom 58 64 32
     else ifvarg DAMAGEHUEFACTOR 1449 ifvarl DAMAGEHUEFACTOR 1475 palfrom 59 64 32
     else ifvarg DAMAGEHUEFACTOR 1474 ifvarl DAMAGEHUEFACTOR 1500 palfrom 60 64 32
     else ifvarg DAMAGEHUEFACTOR 1499 ifvarl DAMAGEHUEFACTOR 1525 palfrom 61 64 32
     else ifvarg DAMAGEHUEFACTOR 1524 ifvarl DAMAGEHUEFACTOR 1550 palfrom 62 64 32
     else ifvarg DAMAGEHUEFACTOR 1549 ifvarl DAMAGEHUEFACTOR 1575 palfrom 63 64 32
     else ifvarg DAMAGEHUEFACTOR 1574 palfrom 64 64 32
     setvar DAMAGEHUEPAL 21
ends

state playerdamagehues-icetype
     state calcdmgfactor

     ifvarg DAMAGEHUEFACTOR -1 ifvarl DAMAGEHUEFACTOR 25 palfrom 1 0 0 64
     else ifvarg DAMAGEHUEFACTOR 24 ifvarl DAMAGEHUEFACTOR 50 palfrom 2 0 0 64
     else ifvarg DAMAGEHUEFACTOR 49 ifvarl DAMAGEHUEFACTOR 75 palfrom 3 0 0 64
     else ifvarg DAMAGEHUEFACTOR 74 ifvarl DAMAGEHUEFACTOR 100 palfrom 4 0 0 64
     else ifvarg DAMAGEHUEFACTOR 99 ifvarl DAMAGEHUEFACTOR 125 palfrom 5 0 0 64
     else ifvarg DAMAGEHUEFACTOR 124 ifvarl DAMAGEHUEFACTOR 150 palfrom 6 0 0 64
     else ifvarg DAMAGEHUEFACTOR 149 ifvarl DAMAGEHUEFACTOR 175 palfrom 7 0 0 64
     else ifvarg DAMAGEHUEFACTOR 174 ifvarl DAMAGEHUEFACTOR 200 palfrom 8 0 0 64
     else ifvarg DAMAGEHUEFACTOR 199 ifvarl DAMAGEHUEFACTOR 225 palfrom 9 0 0 64
     else ifvarg DAMAGEHUEFACTOR 224 ifvarl DAMAGEHUEFACTOR 250 palfrom 10 0 0 64
     else ifvarg DAMAGEHUEFACTOR 249 ifvarl DAMAGEHUEFACTOR 275 palfrom 11 0 0 64
     else ifvarg DAMAGEHUEFACTOR 274 ifvarl DAMAGEHUEFACTOR 300 palfrom 12 0 0 64
     else ifvarg DAMAGEHUEFACTOR 299 ifvarl DAMAGEHUEFACTOR 325 palfrom 13 0 0 64
     else ifvarg DAMAGEHUEFACTOR 324 ifvarl DAMAGEHUEFACTOR 350 palfrom 14 0 0 64
     else ifvarg DAMAGEHUEFACTOR 349 ifvarl DAMAGEHUEFACTOR 375 palfrom 15 0 0 64
     else ifvarg DAMAGEHUEFACTOR 374 ifvarl DAMAGEHUEFACTOR 400 palfrom 16 0 0 64
     else ifvarg DAMAGEHUEFACTOR 399 ifvarl DAMAGEHUEFACTOR 425 palfrom 17 0 0 64
     else ifvarg DAMAGEHUEFACTOR 424 ifvarl DAMAGEHUEFACTOR 450 palfrom 18 0 0 64
     else ifvarg DAMAGEHUEFACTOR 449 ifvarl DAMAGEHUEFACTOR 475 palfrom 19 0 0 64
     else ifvarg DAMAGEHUEFACTOR 474 ifvarl DAMAGEHUEFACTOR 500 palfrom 20 0 0 64
     else ifvarg DAMAGEHUEFACTOR 499 ifvarl DAMAGEHUEFACTOR 525 palfrom 21 0 0 64
     else ifvarg DAMAGEHUEFACTOR 524 ifvarl DAMAGEHUEFACTOR 550 palfrom 22 0 0 64
     else ifvarg DAMAGEHUEFACTOR 549 ifvarl DAMAGEHUEFACTOR 575 palfrom 23 0 0 64
     else ifvarg DAMAGEHUEFACTOR 574 ifvarl DAMAGEHUEFACTOR 600 palfrom 24 0 0 64
     else ifvarg DAMAGEHUEFACTOR 599 ifvarl DAMAGEHUEFACTOR 625 palfrom 25 0 0 64
     else ifvarg DAMAGEHUEFACTOR 624 ifvarl DAMAGEHUEFACTOR 650 palfrom 26 0 0 64
     else ifvarg DAMAGEHUEFACTOR 649 ifvarl DAMAGEHUEFACTOR 675 palfrom 27 0 0 64
     else ifvarg DAMAGEHUEFACTOR 674 ifvarl DAMAGEHUEFACTOR 700 palfrom 28 0 0 64
     else ifvarg DAMAGEHUEFACTOR 699 ifvarl DAMAGEHUEFACTOR 725 palfrom 29 0 0 64
     else ifvarg DAMAGEHUEFACTOR 724 ifvarl DAMAGEHUEFACTOR 750 palfrom 30 0 0 64
     else ifvarg DAMAGEHUEFACTOR 749 ifvarl DAMAGEHUEFACTOR 775 palfrom 31 0 0 64
     else ifvarg DAMAGEHUEFACTOR 774 ifvarl DAMAGEHUEFACTOR 800 palfrom 32 0 0 64
     else ifvarg DAMAGEHUEFACTOR 799 ifvarl DAMAGEHUEFACTOR 825 palfrom 33 0 0 64
     else ifvarg DAMAGEHUEFACTOR 824 ifvarl DAMAGEHUEFACTOR 850 palfrom 34 0 0 64
     else ifvarg DAMAGEHUEFACTOR 849 ifvarl DAMAGEHUEFACTOR 875 palfrom 35 0 0 64
     else ifvarg DAMAGEHUEFACTOR 874 ifvarl DAMAGEHUEFACTOR 900 palfrom 36 0 0 64
     else ifvarg DAMAGEHUEFACTOR 899 ifvarl DAMAGEHUEFACTOR 925 palfrom 37 0 0 64
     else ifvarg DAMAGEHUEFACTOR 924 ifvarl DAMAGEHUEFACTOR 950 palfrom 38 0 0 64
     else ifvarg DAMAGEHUEFACTOR 949 ifvarl DAMAGEHUEFACTOR 975 palfrom 39 0 0 64
     else ifvarg DAMAGEHUEFACTOR 974 ifvarl DAMAGEHUEFACTOR 1000 palfrom 40 0 0 64
     else ifvarg DAMAGEHUEFACTOR 999 ifvarl DAMAGEHUEFACTOR 1025 palfrom 41 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1024 ifvarl DAMAGEHUEFACTOR 1050 palfrom 42 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1049 ifvarl DAMAGEHUEFACTOR 1075 palfrom 43 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1074 ifvarl DAMAGEHUEFACTOR 1100 palfrom 44 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1099 ifvarl DAMAGEHUEFACTOR 1125 palfrom 45 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1124 ifvarl DAMAGEHUEFACTOR 1150 palfrom 46 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1149 ifvarl DAMAGEHUEFACTOR 1175 palfrom 47 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1174 ifvarl DAMAGEHUEFACTOR 1200 palfrom 48 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1199 ifvarl DAMAGEHUEFACTOR 1225 palfrom 49 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1224 ifvarl DAMAGEHUEFACTOR 1250 palfrom 50 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1249 ifvarl DAMAGEHUEFACTOR 1275 palfrom 51 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1274 ifvarl DAMAGEHUEFACTOR 1300 palfrom 52 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1299 ifvarl DAMAGEHUEFACTOR 1325 palfrom 53 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1324 ifvarl DAMAGEHUEFACTOR 1350 palfrom 54 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1349 ifvarl DAMAGEHUEFACTOR 1375 palfrom 55 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1374 ifvarl DAMAGEHUEFACTOR 1400 palfrom 56 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1399 ifvarl DAMAGEHUEFACTOR 1425 palfrom 57 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1424 ifvarl DAMAGEHUEFACTOR 1450 palfrom 58 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1449 ifvarl DAMAGEHUEFACTOR 1475 palfrom 59 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1474 ifvarl DAMAGEHUEFACTOR 1500 palfrom 60 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1499 ifvarl DAMAGEHUEFACTOR 1525 palfrom 61 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1524 ifvarl DAMAGEHUEFACTOR 1550 palfrom 62 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1549 ifvarl DAMAGEHUEFACTOR 1575 palfrom 63 0 0 64
     else ifvarg DAMAGEHUEFACTOR 1574 palfrom 64 0 0 64
     setvar DAMAGEHUEPAL 1
ends

state playerdamagehues-watertype
     state calcdmgfactor

     ifvarg DAMAGEHUEFACTOR -1 ifvarl DAMAGEHUEFACTOR 25 palfrom 1 24 24 64
     else ifvarg DAMAGEHUEFACTOR 24 ifvarl DAMAGEHUEFACTOR 50 palfrom 2 24 24 64
     else ifvarg DAMAGEHUEFACTOR 49 ifvarl DAMAGEHUEFACTOR 75 palfrom 3 24 24 64
     else ifvarg DAMAGEHUEFACTOR 74 ifvarl DAMAGEHUEFACTOR 100 palfrom 4 24 24 64
     else ifvarg DAMAGEHUEFACTOR 99 ifvarl DAMAGEHUEFACTOR 125 palfrom 5 24 24 64
     else ifvarg DAMAGEHUEFACTOR 124 ifvarl DAMAGEHUEFACTOR 150 palfrom 6 24 24 64
     else ifvarg DAMAGEHUEFACTOR 149 ifvarl DAMAGEHUEFACTOR 175 palfrom 7 24 24 64
     else ifvarg DAMAGEHUEFACTOR 174 ifvarl DAMAGEHUEFACTOR 200 palfrom 8 24 24 64
     else ifvarg DAMAGEHUEFACTOR 199 ifvarl DAMAGEHUEFACTOR 225 palfrom 9 24 24 64
     else ifvarg DAMAGEHUEFACTOR 224 ifvarl DAMAGEHUEFACTOR 250 palfrom 10 24 24 64
     else ifvarg DAMAGEHUEFACTOR 249 ifvarl DAMAGEHUEFACTOR 275 palfrom 11 24 24 64
     else ifvarg DAMAGEHUEFACTOR 274 ifvarl DAMAGEHUEFACTOR 300 palfrom 12 24 24 64
     else ifvarg DAMAGEHUEFACTOR 299 ifvarl DAMAGEHUEFACTOR 325 palfrom 13 24 24 64
     else ifvarg DAMAGEHUEFACTOR 324 ifvarl DAMAGEHUEFACTOR 350 palfrom 14 24 24 64
     else ifvarg DAMAGEHUEFACTOR 349 ifvarl DAMAGEHUEFACTOR 375 palfrom 15 24 24 64
     else ifvarg DAMAGEHUEFACTOR 374 ifvarl DAMAGEHUEFACTOR 400 palfrom 16 24 24 64
     else ifvarg DAMAGEHUEFACTOR 399 ifvarl DAMAGEHUEFACTOR 425 palfrom 17 24 24 64
     else ifvarg DAMAGEHUEFACTOR 424 ifvarl DAMAGEHUEFACTOR 450 palfrom 18 24 24 64
     else ifvarg DAMAGEHUEFACTOR 449 ifvarl DAMAGEHUEFACTOR 475 palfrom 19 24 24 64
     else ifvarg DAMAGEHUEFACTOR 474 ifvarl DAMAGEHUEFACTOR 500 palfrom 20 24 24 64
     else ifvarg DAMAGEHUEFACTOR 499 ifvarl DAMAGEHUEFACTOR 525 palfrom 21 24 24 64
     else ifvarg DAMAGEHUEFACTOR 524 ifvarl DAMAGEHUEFACTOR 550 palfrom 22 24 24 64
     else ifvarg DAMAGEHUEFACTOR 549 ifvarl DAMAGEHUEFACTOR 575 palfrom 23 24 24 64
     else ifvarg DAMAGEHUEFACTOR 574 ifvarl DAMAGEHUEFACTOR 600 palfrom 24 24 24 64
     else ifvarg DAMAGEHUEFACTOR 599 ifvarl DAMAGEHUEFACTOR 625 palfrom 25 24 24 64
     else ifvarg DAMAGEHUEFACTOR 624 ifvarl DAMAGEHUEFACTOR 650 palfrom 26 24 24 64
     else ifvarg DAMAGEHUEFACTOR 649 ifvarl DAMAGEHUEFACTOR 675 palfrom 27 24 24 64
     else ifvarg DAMAGEHUEFACTOR 674 ifvarl DAMAGEHUEFACTOR 700 palfrom 28 24 24 64
     else ifvarg DAMAGEHUEFACTOR 699 ifvarl DAMAGEHUEFACTOR 725 palfrom 29 24 24 64
     else ifvarg DAMAGEHUEFACTOR 724 ifvarl DAMAGEHUEFACTOR 750 palfrom 30 24 24 64
     else ifvarg DAMAGEHUEFACTOR 749 ifvarl DAMAGEHUEFACTOR 775 palfrom 31 24 24 64
     else ifvarg DAMAGEHUEFACTOR 774 ifvarl DAMAGEHUEFACTOR 800 palfrom 32 24 24 64
     else ifvarg DAMAGEHUEFACTOR 799 ifvarl DAMAGEHUEFACTOR 825 palfrom 33 24 24 64
     else ifvarg DAMAGEHUEFACTOR 824 ifvarl DAMAGEHUEFACTOR 850 palfrom 34 24 24 64
     else ifvarg DAMAGEHUEFACTOR 849 ifvarl DAMAGEHUEFACTOR 875 palfrom 35 24 24 64
     else ifvarg DAMAGEHUEFACTOR 874 ifvarl DAMAGEHUEFACTOR 900 palfrom 36 24 24 64
     else ifvarg DAMAGEHUEFACTOR 899 ifvarl DAMAGEHUEFACTOR 925 palfrom 37 24 24 64
     else ifvarg DAMAGEHUEFACTOR 924 ifvarl DAMAGEHUEFACTOR 950 palfrom 38 24 24 64
     else ifvarg DAMAGEHUEFACTOR 949 ifvarl DAMAGEHUEFACTOR 975 palfrom 39 24 24 64
     else ifvarg DAMAGEHUEFACTOR 974 ifvarl DAMAGEHUEFACTOR 1000 palfrom 40 24 24 64
     else ifvarg DAMAGEHUEFACTOR 999 ifvarl DAMAGEHUEFACTOR 1025 palfrom 41 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1024 ifvarl DAMAGEHUEFACTOR 1050 palfrom 42 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1049 ifvarl DAMAGEHUEFACTOR 1075 palfrom 43 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1074 ifvarl DAMAGEHUEFACTOR 1100 palfrom 44 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1099 ifvarl DAMAGEHUEFACTOR 1125 palfrom 45 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1124 ifvarl DAMAGEHUEFACTOR 1150 palfrom 46 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1149 ifvarl DAMAGEHUEFACTOR 1175 palfrom 47 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1174 ifvarl DAMAGEHUEFACTOR 1200 palfrom 48 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1199 ifvarl DAMAGEHUEFACTOR 1225 palfrom 49 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1224 ifvarl DAMAGEHUEFACTOR 1250 palfrom 50 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1249 ifvarl DAMAGEHUEFACTOR 1275 palfrom 51 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1274 ifvarl DAMAGEHUEFACTOR 1300 palfrom 52 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1299 ifvarl DAMAGEHUEFACTOR 1325 palfrom 53 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1324 ifvarl DAMAGEHUEFACTOR 1350 palfrom 54 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1349 ifvarl DAMAGEHUEFACTOR 1375 palfrom 55 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1374 ifvarl DAMAGEHUEFACTOR 1400 palfrom 56 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1399 ifvarl DAMAGEHUEFACTOR 1425 palfrom 57 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1424 ifvarl DAMAGEHUEFACTOR 1450 palfrom 58 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1449 ifvarl DAMAGEHUEFACTOR 1475 palfrom 59 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1474 ifvarl DAMAGEHUEFACTOR 1500 palfrom 60 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1499 ifvarl DAMAGEHUEFACTOR 1525 palfrom 61 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1524 ifvarl DAMAGEHUEFACTOR 1550 palfrom 62 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1549 ifvarl DAMAGEHUEFACTOR 1575 palfrom 63 24 24 64
     else ifvarg DAMAGEHUEFACTOR 1574 palfrom 64 24 24 64
     setvar DAMAGEHUEPAL 1
ends

state char_firedamage_misc
           ifvare CHARACTERSELECTED? 3 // Bubsy
           {
            ifvare BUBSYFORM? 1 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 5 }
           }
           else ifvare CHARACTERSELECTED? 4 // Ami
           {
            ifvare SECTORLOTAG 2 ifvare WATER? 2 divvar TEMPDAMAGEVAR 6
            ifvare SECTORLOTAG 1 ifvare WATER? 1 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 7 }

            ifvare AMIFORM? 0 { mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 } // 133% Damage
            else ifvare AMIFORM? 1 divvar TEMPDAMAGEVAR 2 // 50% Damage
            else ifvare AMIFORM? 2 divvar TEMPDAMAGEVAR 3 // 33% Damage
            ifvarand PLAYERSTATUS? 256
            {
             ifp pducking divvar TEMPDAMAGEVAR 25 // 4% Damage
             else divvar TEMPDAMAGEVAR 5 // 20% Damage
            }
            mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 // 133% Damage
           }
           else ifvare CHARACTERSELECTED? 6 // ESSence
           {
            ifvare ESSENCEFORM? 0 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 5 } // 40% Damage
           }
           else ifvare CHARACTERSELECTED? 7 divvar TEMPDAMAGEVAR 3 // Ted [33% Damage]
           else ifvare CHARACTERSELECTED? 9 { mulvar TEMPDAMAGEVAR 3 divvar TEMPDAMAGEVAR 5 } // Cybanis [60% Damage]
           else ifvare CHARACTERSELECTED? 11 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 3 } // Paula [66% Damage]
           else ifvare CHARACTERSELECTED? 13 // Minako
           {
            ifvare MINAKOFORM? 0 { mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 } // 133% Damage
            else ifvare MINAKOFORM? 1 divvar TEMPDAMAGEVAR 2 // 50% Damage
            else ifvare MINAKOFORM? 2 divvar TEMPDAMAGEVAR 3 // 33% Damage
            mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 3 // 66% Damage
           }
           else ifvare CHARACTERSELECTED? 14 divvar TEMPDAMAGEVAR 2 // "Mystery Lady" [50% Damage]
           else ifvare CHARACTERSELECTED? 15 divvar TEMPDAMAGEVAR 6 // Maken [17% Damage]
ends

state char_icedamage_misc
           ifvare CHARACTERSELECTED? 3 // Bubsy
           {
            ifvare BUBSYFORM? 0 { mulvar TEMPDAMAGEVAR 3 divvar TEMPDAMAGEVAR 2 } // 150% Damage
            else ifvare BUBSYFORM? 1 { mulvar TEMPDAMAGEVAR 5 divvar TEMPDAMAGEVAR 4 } // 125% Damage
           }
           else ifvare CHARACTERSELECTED? 4 // Ami
           {
            ifvare SECTORLOTAG 2 ifvare WATER? 2 divvar TEMPDAMAGEVAR 6
            ifvare SECTORLOTAG 1 ifvare WATER? 1 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 7 }

            ifvare AMIFORM? 0 { mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 } // 133% Damage
            else ifvare AMIFORM? 1 divvar TEMPDAMAGEVAR 2 // 50% Damage
            else ifvare AMIFORM? 2 divvar TEMPDAMAGEVAR 3 // 33% Damage
            ifvarand PLAYERSTATUS? 256
            {
             ifp pducking divvar TEMPDAMAGEVAR 25 // 4% Damage
             else divvar TEMPDAMAGEVAR 5 // 20% Damage
            }
            divvar TEMPDAMAGEVAR 10 // 10% Damage
           }
           else ifvare CHARACTERSELECTED? 6 // ESSence
           {
            ifvare ESSENCEFORM? 0 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 5 } // 40% Damage
            mulvar TEMPDAMAGEVAR 3 // 300% Damage
           }
           else ifvare CHARACTERSELECTED? 9 // Cybanis
           {
            mulvar TEMPDAMAGEVAR 3 divvar TEMPDAMAGEVAR 5 // 60% Damage
            mulvar TEMPDAMAGEVAR 2 // 200% Damage
           }
           else ifvare CHARACTERSELECTED? 10 // Nethra/Christina
           {
            ifvare NETHRAFORM? 0 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 3 } // 66% Damage
            else ifvare NETHRAFORM? 1 { mulvar TEMPDAMAGEVAR -2 sound ABSORB_DAMAGE } // 200% Absorbsion
           }
           else ifvare CHARACTERSELECTED? 13 // Minako
           {
            ifvare MINAKOFORM? 0 { mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 } // 133% Damage
            else ifvare MINAKOFORM? 1 divvar TEMPDAMAGEVAR 2 // 50% Damage
            else ifvare MINAKOFORM? 2 divvar TEMPDAMAGEVAR 3 // 33% Damage
           }
           else ifvare CHARACTERSELECTED? 14 divvar TEMPDAMAGEVAR 2 // "Mystery Lady" [50% Damage]
ends

state char_elecdamage_misc
           ifvare CHARACTERSELECTED? 3 // Bubsy
           {
            ifvare BUBSYFORM? 1 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 5 } // 40% Damage
           }
           else ifvare CHARACTERSELECTED? 4 // Ami
           {
            ifvare SECTORLOTAG 2 ifvare WATER? 2 divvar TEMPDAMAGEVAR 6
            ifvare SECTORLOTAG 1 ifvare WATER? 1 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 7 }

            ifvare AMIFORM? 0 { mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 } // 133% Damage
            else ifvare AMIFORM? 1 divvar TEMPDAMAGEVAR 2 // 50% Damage
            else ifvare AMIFORM? 2 divvar TEMPDAMAGEVAR 3 // 33% Damage
            ifvarand PLAYERSTATUS? 256
            {
             ifp pducking divvar TEMPDAMAGEVAR 25 // 4% Damage
             else divvar TEMPDAMAGEVAR 5 // 20% Damage
            }
            mulvar TEMPDAMAGEVAR 16 divvar TEMPDAMAGEVAR 15 // 107% Damage
           }
           else ifvare CHARACTERSELECTED? 6 // ESSence
           {
            ifvare ESSENCEFORM? 0 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 5 } // 40% Damage
           }
           else ifvare CHARACTERSELECTED? 8 { mulvar TEMPDAMAGEVAR 3 divvar TEMPDAMAGEVAR 5 } // Lisa [60% Damage]          
           else ifvare CHARACTERSELECTED? 9 { mulvar TEMPDAMAGEVAR 3 divvar TEMPDAMAGEVAR 5 } // Cybanis [60% Damage]
           else ifvare CHARACTERSELECTED? 10 // Nethra/Christina
           {
            ifvare NETHRAFORM? 0 { mulvar TEMPDAMAGEVAR -11 divvar TEMPDAMAGEVAR 2 sound ABSORB_DAMAGE } // 550% Absorbsion
            else ifvare NETHRAFORM? 1 { mulvar TEMPDAMAGEVAR 2 divvar TEMPDAMAGEVAR 3 } // 66% Damage
           }
           else ifvare CHARACTERSELECTED? 13 // Minako
           {
            ifvare MINAKOFORM? 0 { mulvar TEMPDAMAGEVAR 4 divvar TEMPDAMAGEVAR 3 } // 133% Damage
            else ifvare MINAKOFORM? 1 divvar TEMPDAMAGEVAR 2 // 50% Damage
            else ifvare MINAKOFORM? 2 divvar TEMPDAMAGEVAR 3 // 33% Damage
           }
           else ifvare CHARACTERSELECTED? 14 divvar TEMPDAMAGEVAR 2 // "Mystery Lady" [50% Damage]
ends

state stopsearchsounds
            stopsound DUKE_SEARCH
            stopsound DUKE_SEARCH2
            stopsound DUKE_SEARCH1A
            stopsound DUKE_SEARCH2A
            stopsound JACK_WALLPUSH1
            stopsound JACK_WALLPUSH2
            stopsound WANG_SEARCH1
            stopsound WANG_SEARCH2
            stopsound ESSENCE_WALLPUSH1
            stopsound ESSENCE_WALLPUSH2
            stopsound LISA_WALLPUSH1
            stopsound LISA_WALLPUSH2
            stopsound CYBANIS_WALLPUSH1
            stopsound CYBANIS_WALLPUSH2
            stopsound MAKEN_WALLPUSH1
            stopsound MAKEN_WALLPUSH2
ends

state setdroppedmoneyowner
  ifvarn RETURN -1 setactor[RETURN].owner THISACTOR
ends

state checkmoneyowner
  getactor[THISACTOR].owner TEMP3
  ifvarvarn THISACTOR TEMP3 { ifvarn RETURN -1 setactor[RETURN].owner TEMP3 }
ends

state pythagoras_hazard
  // next code gets distance between actortarget (x,y) and hazard (x,y), puts result in BLOODPOOLDISTANCE
  getactor[THISACTOR].x temp
  getactor[PYTHAGORASTARGET].x tempb

  subvarvar temp tempb
  mulvarvar temp temp
	
  getactor[THISACTOR].y tempc
  getactor[PYTHAGORASTARGET].y tempd

  subvarvar tempc tempd
  mulvarvar tempc tempc
	
  addvarvar temp tempc
  sqrt temp temp
  setvarvar PYTHAGORASDISTANCE temp
ends

state hazarddetectifdead
 ifvarn PYTHAGORASTARGET -1
 { 
  getactorvar[PYTHAGORASTARGET].DRIVERID temp
  ifvarn temp -1 { setvar PYTHAGORASTARGET -1 break } // For Vehicles only. If the target doesn't have a driver, the it takes damage individually.
  getactorvar[PYTHAGORASTARGET].ENEMYHP temp
  ifvarl temp 1 { setvar PYTHAGORASTARGET -1 break } // Makes it that if the current "target" is dead, set to -1 to search for a living one
  getactorvar[PYTHAGORASTARGET].SHRUNK? temp
  ifvare temp 1 { setvar PYTHAGORASTARGET -1 break } // Makes it that if the current "target" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[PYTHAGORASTARGET].FROZEN? temp
  ifvare temp 1 { setvar PYTHAGORASTARGET -1 break } // Makes it that if the current "target" is frozen, set to -1 to search for a non-frozen one
  getactorvar[PYTHAGORASTARGET].CLOAKED? temp
  ifvare temp 1 { setvar PYTHAGORASTARGET -1 break } // Makes it that if the current "target" is cloaked, set to -1 to search for a non-cloaked one
  state pythagoras_hazard
  ifvarg PYTHAGORASDISTANCE 844 { setvar PYTHAGORASTARGET -1 break }
 }
ends

state dukepainsounds
    ifrnd 40
    {
     stopsound DUKE_LONGTERM_PAIN1
     stopsound DUKE_LONGTERM_PAIN2
     stopsound DUKE_LONGTERM_PAIN3
     stopsound DUKE_LONGTERM_PAIN4
     stopsound DUKE_LONGTERM_PAIN5
     stopsound DUKE_LONGTERM_PAIN6
     stopsound DUKE_LONGTERM_PAIN7
    }

    ifvare PAINSOUNDSTYPE 0 // Sounds are based on CURRENTHITPOINTS amount when hit
    {
     ifvarl HPFACTOR 251 ifvarg HPFACTOR -1
     {
      randvar RNDVOICE 2
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound DUKE_LONGTERM_PAIN2
       ifvare RNDVOICE 1 sound DUKE_LONGTERM_PAIN3
       ifvare RNDVOICE 2 sound DUKE_LONGTERM_PAIN4
      }
     }
     else
     ifvarg HPFACTOR 250
     {
      randvar RNDVOICE 3
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound DUKE_LONGTERM_PAIN1
       ifvare RNDVOICE 1 sound DUKE_LONGTERM_PAIN5
       ifvare RNDVOICE 2 sound DUKE_LONGTERM_PAIN6
       ifvare RNDVOICE 3 sound DUKE_LONGTERM_PAIN7
      }
     }
    }
    else // Sounds are based on how much % of damage was taken in a single hit
    {
     ifvarg PAINSOUNDFACTOR -1 ifvarl PAINSOUNDFACTOR 501 // 751
     {
      randvar RNDVOICE 3
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound DUKE_LONGTERM_PAIN1
       ifvare RNDVOICE 1 sound DUKE_LONGTERM_PAIN5
       ifvare RNDVOICE 2 sound DUKE_LONGTERM_PAIN6
       ifvare RNDVOICE 3 sound DUKE_LONGTERM_PAIN7
      }
     }
     else ifvarg PAINSOUNDFACTOR 500 // 750
     {
      randvar RNDVOICE 2
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound DUKE_LONGTERM_PAIN2
       ifvare RNDVOICE 1 sound DUKE_LONGTERM_PAIN3
       ifvare RNDVOICE 2 sound DUKE_LONGTERM_PAIN4
      }
     }
    }
ends


state lowangpainsounds
    ifrnd 40
    {
     stopsound WANG_LONGTERM_PAIN1
     stopsound WANG_LONGTERM_PAIN2
     stopsound WANG_LONGTERM_PAIN3
     stopsound WANG_LONGTERM_PAIN4
     stopsound WANG_LONGTERM_PAIN5
     stopsound WANG_LONGTERM_PAIN6
     stopsound WANG_LONGTERM_PAIN7
     stopsound WANG_LONGTERM_PAIN8
    }

    ifvare PAINSOUNDSTYPE 0 // Sounds are based on CURRENTHITPOINTS amount when hit
    {
     randvar RNDVOICE 3
     ifvarl HPFACTOR 251 ifvarg HPFACTOR -1
     {
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound WANG_LONGTERM_PAIN1
       ifvare RNDVOICE 1 sound WANG_LONGTERM_PAIN2
       ifvare RNDVOICE 2 sound WANG_LONGTERM_PAIN3
       ifvare RNDVOICE 3 sound WANG_LONGTERM_PAIN4
      }
     }
     else
     ifvarg HPFACTOR 250
     {
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound WANG_LONGTERM_PAIN5
       ifvare RNDVOICE 1 sound WANG_LONGTERM_PAIN6
       ifvare RNDVOICE 2 sound WANG_LONGTERM_PAIN7
       ifvare RNDVOICE 3 sound WANG_LONGTERM_PAIN8
      }
     }
    }
    else // Sounds are based on how much % of damage was taken in a single hit
    {
     randvar RNDVOICE 3
     ifvarg PAINSOUNDFACTOR -1 ifvarl PAINSOUNDFACTOR 501 // 751
     {
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound WANG_LONGTERM_PAIN5
       ifvare RNDVOICE 1 sound WANG_LONGTERM_PAIN6
       ifvare RNDVOICE 2 sound WANG_LONGTERM_PAIN7
       ifvare RNDVOICE 3 sound WANG_LONGTERM_PAIN8
      }
     }
     else ifvarg PAINSOUNDFACTOR 500 // 750
     {
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound WANG_LONGTERM_PAIN1
       ifvare RNDVOICE 1 sound WANG_LONGTERM_PAIN2
       ifvare RNDVOICE 2 sound WANG_LONGTERM_PAIN3
       ifvare RNDVOICE 3 sound WANG_LONGTERM_PAIN4
      }
     }
    }
ends

state lisapainsounds
    ifrnd 40
    {
     stopsound LISA_PAINMINOR1
     stopsound LISA_PAINMINOR2
     stopsound LISA_PAINMINOR3
     stopsound LISA_PAINMINOR4
     stopsound LISA_PAINMODERATE1
     stopsound LISA_PAINMODERATE2
     stopsound LISA_PAINMODERATE3
     stopsound LISA_PAINMODERATE4
     stopsound LISA_PAINHIGH1
     stopsound LISA_PAINHIGH2
     stopsound LISA_PAINHIGH3
     stopsound LISA_PAINHIGH4
     stopsound LISA_PAINPERILOUS1
     stopsound LISA_PAINPERILOUS2
     stopsound LISA_PAINPERILOUS3
     stopsound LISA_PAINPERILOUS4
    }

    ifvare PAINSOUNDSTYPE 0 // Sounds are based on CURRENTHITPOINTS amount when hit
    {
     randvar RNDVOICE 3
     ifvarg HPFACTOR 750
     {
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound LISA_PAINMINOR1
       ifvare RNDVOICE 1 sound LISA_PAINMINOR2
       ifvare RNDVOICE 2 sound LISA_PAINMINOR3
       ifvare RNDVOICE 3 sound LISA_PAINMINOR4
      }
     }
     else
     ifvarl HPFACTOR 751 ifvarg HPFACTOR 500
     {
      ifrnd 203
      {
       ifvare RNDVOICE 0 sound LISA_PAINMODERATE1
       ifvare RNDVOICE 1 sound LISA_PAINMODERATE2
       ifvare RNDVOICE 2 sound LISA_PAINMODERATE3
       ifvare RNDVOICE 3 sound LISA_PAINMODERATE4
      }
     }
     else
     ifvarl HPFACTOR 501 ifvarg HPFACTOR 250
     {
      ifrnd 213
      {
       ifvare RNDVOICE 0 sound LISA_PAINHIGH1
       ifvare RNDVOICE 1 sound LISA_PAINHIGH2
       ifvare RNDVOICE 2 sound LISA_PAINHIGH3
       ifvare RNDVOICE 3 sound LISA_PAINHIGH4
      }
     }
     else ifvarl HPFACTOR 251 ifvarg HPFACTOR -1
     {
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound LISA_PAINPERILOUS1
       ifvare RNDVOICE 1 sound LISA_PAINPERILOUS2
       ifvare RNDVOICE 2 sound LISA_PAINPERILOUS3
       ifvare RNDVOICE 3 sound LISA_PAINPERILOUS4
      }
     }
    }
    else // Sounds are based on how much % of damage was taken in a single hit
    {
     randvar RNDVOICE 3
     ifvarg PAINSOUNDFACTOR -1 ifvarl PAINSOUNDFACTOR 251
     {
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound LISA_PAINMINOR1
       ifvare RNDVOICE 1 sound LISA_PAINMINOR2
       ifvare RNDVOICE 2 sound LISA_PAINMINOR3
       ifvare RNDVOICE 3 sound LISA_PAINMINOR4
      }
     }
     ifvarg PAINSOUNDFACTOR 250 ifvarl PAINSOUNDFACTOR 501
     {
      ifrnd 203
      {
       ifvare RNDVOICE 0 sound LISA_PAINMODERATE1
       ifvare RNDVOICE 1 sound LISA_PAINMODERATE2
       ifvare RNDVOICE 2 sound LISA_PAINMODERATE3
       ifvare RNDVOICE 3 sound LISA_PAINMODERATE4
      }
     }
     ifvarg PAINSOUNDFACTOR 500 ifvarl PAINSOUNDFACTOR 751
     {
      ifrnd 213
      {
       ifvare RNDVOICE 0 sound LISA_PAINHIGH1
       ifvare RNDVOICE 1 sound LISA_PAINHIGH2
       ifvare RNDVOICE 2 sound LISA_PAINHIGH3
       ifvare RNDVOICE 3 sound LISA_PAINHIGH4
      }
     }
     else ifvarg PAINSOUNDFACTOR 750
     {
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound LISA_PAINPERILOUS1
       ifvare RNDVOICE 1 sound LISA_PAINPERILOUS2
       ifvare RNDVOICE 2 sound LISA_PAINPERILOUS3
       ifvare RNDVOICE 3 sound LISA_PAINPERILOUS4
      }
     }
    }
ends

state makenpainsounds
    ifrnd 40
    {
     stopsound MAKEN_PAINMINOR1
     stopsound MAKEN_PAINMINOR2
     stopsound MAKEN_PAINMINOR3
     stopsound MAKEN_PAINMINOR4
     stopsound MAKEN_PAINMODERATE1
     stopsound MAKEN_PAINMODERATE2
     stopsound MAKEN_PAINMODERATE3
     stopsound MAKEN_PAINMODERATE4
     stopsound MAKEN_PAINHIGH1
     stopsound MAKEN_PAINHIGH2
     stopsound MAKEN_PAINHIGH3
     stopsound MAKEN_PAINHIGH4
     stopsound MAKEN_PAINPERILOUS1
     stopsound MAKEN_PAINPERILOUS2
     stopsound MAKEN_PAINPERILOUS3
     stopsound MAKEN_PAINPERILOUS4
    }

    ifvare PAINSOUNDSTYPE 0 // Sounds are based on CURRENTHITPOINTS amount when hit
    {
     randvar RNDVOICE 3
     ifvarg HPFACTOR 750
     {
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINMINOR1
       ifvare RNDVOICE 1 sound MAKEN_PAINMINOR2
       ifvare RNDVOICE 2 sound MAKEN_PAINMINOR3
       ifvare RNDVOICE 3 sound MAKEN_PAINMINOR4
      }
     }
     else
     ifvarl HPFACTOR 751 ifvarg HPFACTOR 500
     {
      ifrnd 203
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINMODERATE1
       ifvare RNDVOICE 1 sound MAKEN_PAINMODERATE2
       ifvare RNDVOICE 2 sound MAKEN_PAINMODERATE3
       ifvare RNDVOICE 3 sound MAKEN_PAINMODERATE4
      }
     }
     else
     ifvarl HPFACTOR 501 ifvarg HPFACTOR 250
     {
      ifrnd 213
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINHIGH1
       ifvare RNDVOICE 1 sound MAKEN_PAINHIGH2
       ifvare RNDVOICE 2 sound MAKEN_PAINHIGH3
       ifvare RNDVOICE 3 sound MAKEN_PAINHIGH4
      }
     }
     else ifvarl HPFACTOR 251 ifvarg HPFACTOR -1
     {
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINPERILOUS1
       ifvare RNDVOICE 1 sound MAKEN_PAINPERILOUS2
       ifvare RNDVOICE 2 sound MAKEN_PAINPERILOUS3
       ifvare RNDVOICE 3 sound MAKEN_PAINPERILOUS4
      }
     }
    }
    else // Sounds are based on how much % of damage was taken in a single hit
    {
     randvar RNDVOICE 3
     ifvarg PAINSOUNDFACTOR -1 ifvarl PAINSOUNDFACTOR 251
     {
      ifrnd 192
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINMINOR1
       ifvare RNDVOICE 1 sound MAKEN_PAINMINOR2
       ifvare RNDVOICE 2 sound MAKEN_PAINMINOR3
       ifvare RNDVOICE 3 sound MAKEN_PAINMINOR4
      }
     }
     ifvarg PAINSOUNDFACTOR 250 ifvarl PAINSOUNDFACTOR 501
     {
      ifrnd 203
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINMODERATE1
       ifvare RNDVOICE 1 sound MAKEN_PAINMODERATE2
       ifvare RNDVOICE 2 sound MAKEN_PAINMODERATE3
       ifvare RNDVOICE 3 sound MAKEN_PAINMODERATE4
      }
     }
     ifvarg PAINSOUNDFACTOR 500 ifvarl PAINSOUNDFACTOR 751
     {
      ifrnd 213
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINHIGH1
       ifvare RNDVOICE 1 sound MAKEN_PAINHIGH2
       ifvare RNDVOICE 2 sound MAKEN_PAINHIGH3
       ifvare RNDVOICE 3 sound MAKEN_PAINHIGH4
      }
     }
     else ifvarg PAINSOUNDFACTOR 750
     {
      ifrnd 224
      {
       ifvare RNDVOICE 0 sound MAKEN_PAINPERILOUS1
       ifvare RNDVOICE 1 sound MAKEN_PAINPERILOUS2
       ifvare RNDVOICE 2 sound MAKEN_PAINPERILOUS3
       ifvare RNDVOICE 3 sound MAKEN_PAINPERILOUS4
      }
     }
    }
ends

state characterpainsounds
        ifvare CHARACTERSELECTED? 1 state dukepainsounds
        else ifvare CHARACTERSELECTED? 5 state lowangpainsounds
        else ifvare CHARACTERSELECTED? 8 state lisapainsounds
        else ifvare CHARACTERSELECTED? 15 state makenpainsounds
ends

state checkpainfactor
        mulvar PAINSOUNDFACTOR 1000
        divvarvar PAINSOUNDFACTOR MAXHITPOINTS
ends

// ****************************************************
// MAP BEACON - By James Stanfield and Nuclear Showdown
// ****************************************************

state MAPBEACON
 setactor[THISACTOR].shade -127
 state shadepulse4
 setactor[THISACTOR].shade shade
 getuserdef[THISACTOR].overhead_on TEMP
 cstat 32800
 ifvare TEMP 2
 {
  getplayer[THISACTOR].zoom TEMP2
  subvar TEMP2 2048
  mulvar TEMP2 -1
  divvar TEMP2 20
  ifvarl TEMP2 32 setvar TEMP2 32 // ifvarl TEMP2 2 setvar TEMP2 2
  ifvarg TEMP2 128 setvar TEMP2 128 // ifvarg TEMP2 256 setvar TEMP2 256
  setactor[THISACTOR].xrepeat TEMP2
  setactor[THISACTOR].yrepeat TEMP2
  getplayer[THISACTOR].ang TEMP3
  setactor[THISACTOR].ang TEMP3
 }
ends

state bioshieldhitsounds
  sound ESHIELD_HIT
  ifvare ESHIELDADVANCEMENT 1 sound ESHIELD_HIT2
ends

state lisashield_misc
  ifvare CHARACTERSELECTED? 8
  {
   ifvare HAVEENERGYSHIELD? 1 
   {
    ifvare ENERGYSHIELDMODE 1 
    {
     ifvarg TEMPDAMAGEVAR 0
     {
      ifvarg CURRENTCELLS -1 ifvarg DAMAGEINCELL 0
      {
       setvarvar CELLDAMAGE TEMPDAMAGEVAR

       ifvare ESHIELDADVANCEMENT 1 { divvar CELLDAMAGE 2 divvar TEMPDAMAGEVAR 2 }

       setvarvar CELLDAMAGETEMP CELLDAMAGE setvar CELLDAMAGETIMER 0 // For the displays
       ifvarn ESHIELDDMGFACTOR 0 divvarvar CELLDAMAGE ESHIELDDMGFACTOR
       ifvarvarg CELLDAMAGE CURRENTCELLS setvarvar CELLDAMAGE CURRENTCELLS
       setvarvar tempc CELLDAMAGE
       mulvarvar tempc ESHIELDDMGFACTOR
       subvarvar TEMPDAMAGEVAR tempc
       subvarvar CURRENTCELLS CELLDAMAGE
       setvar CELLDAMAGELEFT 0
       ifvarg TEMPDAMAGEVAR 0 subvarvar CELLDAMAGETEMP TEMPDAMAGEVAR // For the displays

       // Now to Calculate to deal with remaining TEMPDAMAGEVAR
       ifvarg CURRENTCELLS 0 // 1 or more cells left
       {
        ifvarvarg TEMPDAMAGEVAR DAMAGEINCELL // Damage exceeds the remaining power in the current cell
        {
         setvarvar TEMP3 TEMPDAMAGEVAR
         setvar TEMPDAMAGEVAR 0
         addvarvar CELLDAMAGETEMP TEMP3
         subvarvar DAMAGEINCELL TEMP3
         ifvarl DAMAGEINCELL 1 { subvar CURRENTCELLS 1 addvarvar DAMAGEINCELL ESHIELDDMGFACTOR }
        }
        else // Damage is less than or equal to the remaining power in the current cell
        {
         setvarvar TEMP3 TEMPDAMAGEVAR
         addvarvar CELLDAMAGETEMP TEMPDAMAGEVAR
         subvarvar DAMAGEINCELL TEMPDAMAGEVAR
         setvar TEMPDAMAGEVAR 0
         ifvarl DAMAGEINCELL 1 { subvar CURRENTCELLS 1 addvarvar DAMAGEINCELL ESHIELDDMGFACTOR }
        }
       }
       else // 0 cells
       {
        ifvarvarg TEMPDAMAGEVAR DAMAGEINCELL // Damage exceeds the remaining power in the last cell
        {
         setvarvar TEMP3 TEMPDAMAGEVAR
         addvarvar CELLDAMAGETEMP DAMAGEINCELL
         subvarvar TEMPDAMAGEVAR DAMAGEINCELL
         setvar DAMAGEINCELL 0
        }
        else // Damage is less than the remaining power in the last cell
        {
         setvarvar TEMP3 TEMPDAMAGEVAR
         addvarvar CELLDAMAGETEMP TEMPDAMAGEVAR
         subvarvar DAMAGEINCELL TEMPDAMAGEVAR
         setvar TEMPDAMAGEVAR 0
        }
       }

       stopsound NODAMAGE
       ifvare ENERGYSHIELDMODE 1 { setvar sparkflag 1 state sparkstate }
       state bioshieldhitsounds
       palfrom 32 0 0 64
      }
     }
    }
   }
  }
  setvarvar FULLSHIELDDAMAGE CELLDAMAGE
  mulvarvar FULLSHIELDDAMAGE ESHIELDDMGFACTOR
  addvarvar FULLSHIELDDAMAGE TEMP3
ends

state 240outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 16 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 224outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 32 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 208outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 48 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 192outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 64 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 176outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 80 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 160outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 96 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 144outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 112 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 128outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 128 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 112outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 144 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 96outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 160 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 80outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 176 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 64outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 192 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 48outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 208 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 32outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 224 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state 16outof256rnd
  ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 240 else setvar RNDMIZERLIMIT 0 state rndmizer256
ends

state assesspickuprequirements
 ifvarn oldskoolmode 1 
 {
  ifvarand ACTORFLAGS 128 mulvar TEMPVAR 2 
  ifvarand ACTORFLAGS 256 mulvar TEMPVAR 4
 }
ends

state checkpickupamountflags
 ifvarn oldskoolmode 1
 {
  ifvarand ACTORFLAGS 128 mulvar ACTORPICKUPAMOUNT 2
  ifvarand ACTORFLAGS 256 mulvar ACTORPICKUPAMOUNT 4
 } 
ends

state itemdroptimer
 ifvare mainmenu 0
 {
  ifvare ITEMWASDROPPED? 1
  {
   subvar ITEMDROPTIMER 1
   ifvarl ITEMDROPTIMER 1 killit
  }
 }
ends

state checkmoneybadge
      // Money Badge
      setvar TEMP3 0
      ifvare PLAYEREQUIPSLOTITEM1 9 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM2 9 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM3 9 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM4 9 addvar TEMP3 2
      ifvarg TEMP3 0 mulvarvar ACTORPICKUPAMOUNT TEMP3

      // Pair of Loaded Dice
      ifvarvarg PARTYSIZE FIXEDDICEPAIRS setvarvar TEMP6 FIXEDDICEPAIRS else setvarvar TEMP6 PARTYSIZE
      mulvar TEMP6 2 // 2% per item  
      setvarvar TEMP4 ACTORPICKUPAMOUNT
      mulvarvar TEMP4 TEMP6
      divvar TEMP4 100
      addvarvar ACTORPICKUPAMOUNT TEMP4
ends

state checkforforcefields

setvar ARRAYPOSITION 0 // Wall IDs >.>
whilevarn ARRAYPOSITION 16383
{
 ifvarvarl ARRAYPOSITION NUMWALLS getwall[ARRAYPOSITION].lotag tempb
 ifvarvare tempb lotagsav
 { 
  getactorvar[ARRAYPOSITION].wall_array tempc
  ifvare tempc 0
  {
    ifvarvarl ARRAYPOSITION NUMWALLS getwall[ARRAYPOSITION].overpicnum tempd
    ifvare tempd BIGFORCE
    {
     setwall[ARRAYPOSITION].overpicnum 0
     setwall[ARRAYPOSITION].cstat 0   
     setactorvar[ARRAYPOSITION].wall_array 1
    }
    else
    ifvare tempd W_FORCEFIELD // W_FORCEFIELD (on)
    {
     setwall[ARRAYPOSITION].overpicnum 0
     setwall[ARRAYPOSITION].cstat 0   
     setactorvar[ARRAYPOSITION].wall_array 2
    }
    else
    ifvare tempd W_FORCEFIELDBLANK // W_FORCEFIELDBLANK (off)
    {
     setwall[ARRAYPOSITION].overpicnum 0
     setwall[ARRAYPOSITION].cstat 0   
     setactorvar[ARRAYPOSITION].wall_array 2
    }
  }
  else
  ifvare tempc 1
  {
    ifvarvarl ARRAYPOSITION NUMWALLS getwall[ARRAYPOSITION].overpicnum tempd
    ifvare tempd 0
    {
     setwall[ARRAYPOSITION].overpicnum BIGFORCE
     setwall[ARRAYPOSITION].cstat 209
     setactorvar[ARRAYPOSITION].wall_array 0
    }
  }
  else
  ifvare tempc 2
  {
    ifvarvarl ARRAYPOSITION NUMWALLS getwall[ARRAYPOSITION].overpicnum tempd
    ifvare tempd 0
    {
     setwall[ARRAYPOSITION].overpicnum W_FORCEFIELD
     setwall[ARRAYPOSITION].cstat 209
     setactorvar[ARRAYPOSITION].wall_array 0
    }
  }
 }
 addvar ARRAYPOSITION 1
 ifvarg ARRAYPOSITION 16383 break
}
ends

state pickupexplosion
     ifactor RPGSPRITE hitradius 2670 40 160 360 640
     else ifactor RPGAMMO hitradius 2670 40 160 360 640
     else ifactor DEVISTATORSPRITE hitradius 2225 30 120 270 360
     else ifactor DEVISTATORAMMO hitradius 2225 30 120 270 360
     else ifactor HBOMBAMMO hitradius 3560 35 140 315 560
     else ifactor ICONOFTHEDEFENDER hitradius 890 50 200 450 800
     else ifactor QUADDAMAGE hitradius 890 50 200 450 800
     else ifactor REGENITEM hitradius 890 50 200 450 800
     else ifactor APREGENITEM hitradius 890 50 200 450 800
     else ifactor VAMPIREITEM hitradius 890 50 200 450 800
     else hitradius 1780 25 100 225 400

     espawn EXPLOSION2
     sound RPG_EXPLODE
     killit
ends

state activationflag
      ifvarand ACTORFLAGS 512 // Activate Objects
      {
       getplayer[THISACTOR].i temp
       operateactivators lotagsav 0 // temp 
       operatemasterswitches lotagsav
       operaterespawns lotagsav
       state checkforforcefields
      }

      ifvarand ACTORFLAGS 4096 // Booby-Trapped Pickup
      {
       redefinequote 335 ^10BOOBY-TRAPPED!! D:
       setvarvar fta fta_normal setvar ftq 335
       state pickupexplosion
      }
ends

state checkexplodeflag
      ifvarand ACTORFLAGS 8192
      {
       redefinequote 335 ^10BOOBY-TRAPPED!! D:
       setvarvar fta fta_normal setvar ftq 335
       state pickupexplosion
       break
      }
ends

state quickcalc
 setvar CALCVAR3 1000
 whilevarvarn CALCVAR1 CALCVAR2
 {  
  addvarvar CALCVAR3 CALCVAR4
  addvar CALCVAR1 1
 }
ends

state resetenemytimers
     setactorvar[THISACTOR].ENEMYQUADTIME 0
     setactorvar[THISACTOR].ENEMYINVULNTIME 0
     setactorvar[THISACTOR].ENEMYREGENTIME 0
     setactorvar[THISACTOR].ENEMYAPREGENTIME 0
     setactorvar[THISACTOR].ENEMYVAMPIRETIME 0
     setactorvar[THISACTOR].ENEMYBOOTSAMOUNT 0
     setactorvar[THISACTOR].ENEMYAIRTANKAMOUNT 0
ends

state setexpranklimits
    ifvarl EXPPTSTEMP 0 setvar EXPPTSTEMP 0
    ifvarg EXPPTSTEMP 9163600 setvar EXPPTSTEMP 9163600
    ifvarl RANKPOINTSTEMP -2000000 setvar RANKPOINTSTEMP -2000000
    ifvarg RANKPOINTSTEMP 2000000 setvar RANKPOINTSTEMP 2000000
ends

state expmulti // Affects EXP and RANK rewards
      ifvare TEMPVAR 0
      {
       getactor[THISACTOR].htowner temp
       ifvarvarn temp PLAYERID { setvar EXPPTSTEMP 0 setvar RANKPOINTSTEMP 0 break }
      }
      setvar TEMPVAR 0

      ifvare oldskoolmode 1
      {
       setvar EXPPTSTEMP 0
       setvar RANKPOINTSTEMP 0
       break
      }

      state setexpranklimits

 	ifvare SKILLLEVEL 0 mulvar EXPPTSTEMP 150 // EXP: 25%, RANK: 100%
 	ifvare SKILLLEVEL 1 mulvar EXPPTSTEMP 187 // EXP: 50%, RANK: 120%
	ifvare SKILLLEVEL 2 mulvar EXPPTSTEMP 225 // EXP: 100%, RANK: 140%
	ifvare SKILLLEVEL 3 mulvar EXPPTSTEMP 262 // EXP: 175%, RANK: 160%
	ifvare SKILLLEVEL 4 mulvar EXPPTSTEMP 300 // EXP: 275%, RANK: 180%
	ifvare SKILLLEVEL 5 mulvar EXPPTSTEMP 300 // EXP: 400%, RANK: 200%
	ifvare SKILLLEVEL 6 mulvar EXPPTSTEMP 262 // EXP: 550%, RANK: 220%
	ifvare SKILLLEVEL 7 mulvar EXPPTSTEMP 225 // EXP: 725%, RANK: 240%
	ifvare SKILLLEVEL 8 mulvar EXPPTSTEMP 225 // EXP: 900%, RANK: 260%
	ifvare SKILLLEVEL 9 mulvar EXPPTSTEMP 262 // EXP: 1100%, RANK: 280%
      divvar EXPPTSTEMP 100

      setvar tempe 5
      addvarvar tempe SKILLLEVEL
      mulvarvar RANKPOINTSTEMP tempe
      divvar RANKPOINTSTEMP 5
      state setexpranklimits

      setvar tempe 1
      addvarvar tempe DISPLAYEPISODE
      mulvarvar EXPPTSTEMP tempe
      divvar EXPPTSTEMP 2
      setvar tempe 4
      addvarvar tempe DISPLAYEPISODE
      mulvarvar RANKPOINTSTEMP tempe
      divvar RANKPOINTSTEMP 5
      state setexpranklimits

      setvar tempe 16
      setvarvar tempf DISPLAYLEVEL
      mulvar tempf 4
      addvarvar tempe tempf
      mulvarvar EXPPTSTEMP tempe
      divvar EXPPTSTEMP 20
      setvar tempe 19
      addvarvar tempe DISPLAYLEVEL
      mulvarvar RANKPOINTSTEMP tempe
      divvar RANKPOINTSTEMP 20
      state setexpranklimits

	ifvare DISPLAYEPISODE 1 ifvare DISPLAYLEVEL 8 { mulvar EXPPTSTEMP 4 mulvar RANKPOINTSTEMP 3 } // EXP: 16x, RANK: 4x

	ifvare CHARACTERSELECTED? 6 { mulvar RANKPOINTSTEMP 11 divvar RANKPOINTSTEMP 8 } // ESSence gets 37.5% more RANK
	ifvare CHARACTERSELECTED? 7 { mulvar RANKPOINTSTEMP 3 divvar RANKPOINTSTEMP 2 } // Ted gets 50% more RANK
	ifvare CHARACTERSELECTED? 11 { mulvar RANKPOINTSTEMP 5 divvar RANKPOINTSTEMP 4 } // Paula gets 25% more RANK
	ifvare CHARACTERSELECTED? 15 { mulvar RANKPOINTSTEMP 5 divvar RANKPOINTSTEMP 4 } // Maken gets 25% more RANK
      state setexpranklimits

      // Support System
      setvar DAMAGEMODIFIER 100
      state support-rankbonus
      ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
      ifvarg DAMAGEMODIFIER 1000 setvar DAMAGEMODIFIER 1000
      mulvarvar RANKPOINTSTEMP DAMAGEMODIFIER
      divvar RANKPOINTSTEMP 100
      state setexpranklimits

      // Rank Badge
      setvar TEMP3 0
      ifvare PLAYEREQUIPSLOTITEM1 8 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM2 8 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM3 8 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM4 8 addvar TEMP3 2
      ifvarg TEMP3 0 mulvarvar RANKPOINTSTEMP TEMP3
      state setexpranklimits

//***************************************************************
//*Increases the Experience Multiplier for Higher Level Monsters*
//***************************************************************
      setvarvar ENEMYLEVELEXPCALC ENEMYLEVEL
      ifvarg ENEMYLEVEL 0 ifvarl ENEMYLEVEL 11 mulvar ENEMYLEVELEXPCALC 11 // Light Blue Star
      else ifvarg ENEMYLEVEL 10 ifvarl ENEMYLEVEL 21 mulvar ENEMYLEVELEXPCALC 17 // Dark Blue Star
      else ifvarg ENEMYLEVEL 20 ifvarl ENEMYLEVEL 31 mulvar ENEMYLEVELEXPCALC 24 // Light Green Star
      else ifvarg ENEMYLEVEL 30 ifvarl ENEMYLEVEL 41 mulvar ENEMYLEVELEXPCALC 32 // Dark Green Star
      else ifvarg ENEMYLEVEL 40 ifvarl ENEMYLEVEL 51 mulvar ENEMYLEVELEXPCALC 41 // White Star
      else ifvarg ENEMYLEVEL 50 ifvarl ENEMYLEVEL 61 mulvar ENEMYLEVELEXPCALC 50 // Gray Star
      else ifvarg ENEMYLEVEL 60 ifvarl ENEMYLEVEL 71 mulvar ENEMYLEVELEXPCALC 60 // Gold Star
      else ifvarg ENEMYLEVEL 70 ifvarl ENEMYLEVEL 81 mulvar ENEMYLEVELEXPCALC 71 // Copper Star
      else ifvarg ENEMYLEVEL 80 ifvarl ENEMYLEVEL 91 mulvar ENEMYLEVELEXPCALC 83 // Light Red Star
      else ifvarg ENEMYLEVEL 90 ifvarl ENEMYLEVEL 100 mulvar ENEMYLEVELEXPCALC 96 // Dark Red Star
      else ifvare ENEMYLEVEL 100 mulvar ENEMYLEVELEXPCALC 124 // Night-Vision Star
      divvar ENEMYLEVELEXPCALC 5 // 10
      addvar ENEMYLEVELEXPCALC 100
      mulvarvar EXPPTSTEMP ENEMYLEVELEXPCALC
      divvar EXPPTSTEMP 100
      state setexpranklimits

//*********************************************************************************************
//*Determines a Bonus/Handicap to EXP gain by comparing the Monster's Level to the Character's*
//*********************************************************************************************
      setvarvar EXPFACTOR1 ENEMYLEVEL
      mulvar EXPFACTOR1 10
      setvarvar EXPFACTOR2 PLAYERLEVEL
      ifvarn EXPFACTOR2 0 divvarvar EXPFACTOR1 EXPFACTOR2
      ifvarl EXPFACTOR1 1 setvar EXPFACTOR1 1
      ifvarg EXPFACTOR1 250 setvar EXPFACTOR1 250
      mulvarvar EXPPTSTEMP EXPFACTOR1      
      divvar EXPPTSTEMP 10
      state setexpranklimits

//********************************************
//*Elite Monsters Sextuple EXP and Rank Gains*
//********************************************

      ifvarand ACTORFLAGS 512
      {
       mulvar EXPPTSTEMP 10
       mulvar RANKPOINTSTEMP 10
      }
      state setexpranklimits

      ifvare SHRUNK? 1 { divvar EXPPTSTEMP 6 divvar RANKPOINTSTEMP 6 ifvarl EXPPTSTEMP 1 setvar EXPPTSTEMP 1 }

      ifvare PUBLICBETA? 0 divvar EXPPTSTEMP 4 // ifvarl EXPPTSTEMP 1 setvar EXPPTSTEMP 1
      ifvare PUBLICBETA? 0 divvar RANKPOINTSTEMP 4 // ifvarl RANKPOINTSTEMP 1 setvar RANKPOINTSTEMP 1

//***********************************************************************
//*Divide EXP among the number of people in your group[and people alive]*
//***********************************************************************
   ifvarg EXPPTSTEMP 0
   {
    setvar TEMPVAR 0
    ifvare DUKE? 1 { setvar CHARACTERARRAY 1 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare JACK? 1 { setvar CHARACTERARRAY 2 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare BUBSY? 1 { setvar CHARACTERARRAY 3 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare AMI? 1 { setvar CHARACTERARRAY 4 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare LOWANG? 1 { setvar CHARACTERARRAY 5 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare ESSENCE? 1 { setvar CHARACTERARRAY 6 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare TED? 1 { setvar CHARACTERARRAY 7 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare LISA? 1 { setvar CHARACTERARRAY 8 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare CYBANIS? 1 { setvar CHARACTERARRAY 9 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare NETHRA? 1 { setvar CHARACTERARRAY 10 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare PAULA? 1 { setvar CHARACTERARRAY 11 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare LORI? 1 { setvar CHARACTERARRAY 12 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare MINAKO? 1 { setvar CHARACTERARRAY 13 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare MYSTERY1? 1 { setvar CHARACTERARRAY 14 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }
    ifvare MAKEN? 1 { setvar CHARACTERARRAY 15 getactorvar[CHARACTERARRAY].CHARACTERHP temp ifvarg temp 0 addvar TEMPVAR 1 }

    ifvare TEMPVAR 1 divvar EXPPTSTEMP 1
    ifvare TEMPVAR 2 divvar EXPPTSTEMP 1
    ifvare TEMPVAR 3 divvar EXPPTSTEMP 2
    ifvare TEMPVAR 4 divvar EXPPTSTEMP 2
    ifvare TEMPVAR 5 divvar EXPPTSTEMP 2
    ifvare TEMPVAR 6 divvar EXPPTSTEMP 3
    ifvare TEMPVAR 7 divvar EXPPTSTEMP 3
    ifvare TEMPVAR 8 divvar EXPPTSTEMP 3
    ifvare TEMPVAR 9 divvar EXPPTSTEMP 3
    ifvare TEMPVAR 10 divvar EXPPTSTEMP 4
    ifvare TEMPVAR 11 divvar EXPPTSTEMP 4
    ifvare TEMPVAR 12 divvar EXPPTSTEMP 4
    ifvare TEMPVAR 13 divvar EXPPTSTEMP 4
    ifvare TEMPVAR 14 divvar EXPPTSTEMP 4
    ifvare TEMPVAR 15 divvar EXPPTSTEMP 5

    state setexpranklimits
   }

//***********************************************
//*Always Gain at least the enemy's Level in EXP*
//***********************************************
    ifvarg ENEMYLEVEL 0 { ifvarvarl EXPPTSTEMP ENEMYLEVEL setvarvar EXPPTSTEMP ENEMYLEVEL }

   ifvare FOUNDASECRET 1
   {
    ifvare RANKPOINTSTEMP 0 setvar RANKPOINTSTEMP 1
    setvar FOUNDASECRET 0
   }
   state setexpranklimits

   ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
   mulvar TEMP6 2 // 2% per item  

   // addlogvar RANKPOINTSTEMP
   setvarvar TEMP7 RANKPOINTSTEMP
   mulvarvar TEMP7 TEMP6
   divvar TEMP7 100
   addvarvar RANKPOINTSTEMP TEMP7
   // addlogvar RANKPOINTSTEMP

   ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
   mulvar TEMP6 2 // 2% per item  
   addvar TEMP6 100

   setvar TEMP7 2000000
   // addlogvar TEMP7
   mulvarvar TEMP7 TEMP6
   divvar TEMP7 100
   // addlogvar TEMP7

   ifvarl EXPPTSTEMP 0 setvar EXPPTSTEMP 0
   ifvarg EXPPTSTEMP 9163600 setvar EXPPTSTEMP 9163600
   ifvarl RANKPOINTSTEMP -2000000 setvar RANKPOINTSTEMP -2000000
   ifvarvarg RANKPOINTSTEMP TEMP7 setvarvar RANKPOINTSTEMP TEMP7

   ifvarn RANKPOINTSTEMP 0 { setvarvar DISPLAYRANKPOINTS RANKPOINTSTEMP setvar RANKDISPLAYTIMER 0 }
ends


state inactiveexp_checkdoubloons
       ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
       mulvar TEMP6 2 // 2% per item  
       // addlogvar INACTIVEXPPTSTEMP
       setvarvar TEMP7 INACTIVEXPPTSTEMP
       mulvarvar TEMP7 TEMP6
       divvar TEMP7 100
       addvarvar INACTIVEXPPTSTEMP TEMP7
       // addlogvar INACTIVEXPPTSTEMP

       ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
       mulvar TEMP6 2 // 2% per item  
       addvar TEMP6 100
       setvar TEMP7 9163600
       // addlogvar TEMP7
       mulvarvar TEMP7 TEMP6
       divvar TEMP7 100
       // addlogvar TEMP7

       ifvarl INACTIVEXPPTSTEMP 0 setvar INACTIVEXPPTSTEMP 0
       ifvarvarg INACTIVEXPPTSTEMP TEMP7 setvarvar INACTIVEXPPTSTEMP TEMP7
ends


state exp_checksupportequip
       setvar DAMAGEMODIFIER 100
       // Support System
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTJACK tempb
       ifvarg tempb 0 addvar DAMAGEMODIFIER 4 // "C" Support w/ Jack
       ifvarg tempb 1 addvar DAMAGEMODIFIER 6 // "B" Support w/ Jack
       ifvarg tempb 2 addvar DAMAGEMODIFIER 9 // "A" Support w/ Jack
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Jack
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Jack

       ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
       ifvarg DAMAGEMODIFIER 234 setvar DAMAGEMODIFIER 234
       mulvarvar INACTIVEXPPTSTEMP DAMAGEMODIFIER
       divvar INACTIVEXPPTSTEMP 100
       ifvarl INACTIVEXPPTSTEMP 0 setvar INACTIVEXPPTSTEMP 0
       ifvarg INACTIVEXPPTSTEMP 9163600 setvar INACTIVEXPPTSTEMP 9163600

       // EXP Badge
       setvar TEMP3 0
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM1 tempb
       ifvare tempb 7 addvar TEMP3 2
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM2 tempb
       ifvare tempb 7 addvar TEMP3 2
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM3 tempb
       ifvare tempb 7 addvar TEMP3 2
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM4 tempb
       ifvare tempb 7 addvar TEMP3 2
       ifvarg TEMP3 0 mulvarvar INACTIVEXPPTSTEMP TEMP3
       ifvarl INACTIVEXPPTSTEMP 0 setvar INACTIVEXPPTSTEMP 0
       ifvarg INACTIVEXPPTSTEMP 9163600 setvar INACTIVEXPPTSTEMP 9163600

       state inactiveexp_checkdoubloons

       getactorvar[CHARACTERARRAY].CHARACTEREXPPTS temp
       addvarvar temp INACTIVEXPPTSTEMP
       ifvarl temp 0 setvar temp 0
       ifvarg temp 9163600 setvar temp 9163600
       setactorvar[CHARACTERARRAY].CHARACTEREXPPTS temp
ends

state exp_given
   addvarvar RANKPOINTS RANKPOINTSTEMP
   ifvarvarl RANKPOINTS RANKPOINTSLOWEST setvarvar RANKPOINTS RANKPOINTSLOWEST
   ifvarvarg RANKPOINTS RANKPOINTSHIGHEST setvarvar RANKPOINTS RANKPOINTSHIGHEST

// New Segment for full-party EXP Gain here
   ifvarg EXPPTSTEMP 0
   {
    setvarvar TEMPVAR EXPPTSTEMP
 // This is the % factor of EXP. This is subject to change, and will likely be based on skill-level
    ifvare SKILLLEVEL 0 mulvar TEMPVAR 70
    ifvare SKILLLEVEL 1 mulvar TEMPVAR 65
    ifvare SKILLLEVEL 2 mulvar TEMPVAR 60
    ifvare SKILLLEVEL 3 mulvar TEMPVAR 55
    ifvare SKILLLEVEL 4 mulvar TEMPVAR 50
    ifvare SKILLLEVEL 5 mulvar TEMPVAR 50
    ifvare SKILLLEVEL 6 mulvar TEMPVAR 45
    ifvare SKILLLEVEL 7 mulvar TEMPVAR 40
    ifvare SKILLLEVEL 8 mulvar TEMPVAR 35
    ifvare SKILLLEVEL 9 mulvar TEMPVAR 30
 // End % factors
    divvar TEMPVAR 100
    ifvarl TEMPVAR 1 setvar TEMPVAR 1
    ifvarg TEMPVAR 9163600 setvar TEMPVAR 9163600
 // This is the % factor of EXP. This is subject to change, and will likely be based on skill-level
 ifvarg PARTYSIZE 1
 {
  ifvarg PARTYALIVE 1
  {
    ifvare SKILLLEVEL 0 mulvar EXPPTSTEMP 130
    ifvare SKILLLEVEL 1 mulvar EXPPTSTEMP 135
    ifvare SKILLLEVEL 2 mulvar EXPPTSTEMP 140
    ifvare SKILLLEVEL 3 mulvar EXPPTSTEMP 145
    ifvare SKILLLEVEL 4 mulvar EXPPTSTEMP 150
    ifvare SKILLLEVEL 5 mulvar EXPPTSTEMP 150
    ifvare SKILLLEVEL 6 mulvar EXPPTSTEMP 155
    ifvare SKILLLEVEL 7 mulvar EXPPTSTEMP 160
    ifvare SKILLLEVEL 8 mulvar EXPPTSTEMP 165
    ifvare SKILLLEVEL 9 mulvar EXPPTSTEMP 170
    divvar EXPPTSTEMP 100
    ifvarl EXPPTSTEMP 1 setvar EXPPTSTEMP 1
    ifvarg EXPPTSTEMP 9163600 setvar EXPPTSTEMP 9163600
  }
 }
 // End % factors
    ifvare DUKE? 1
    {
     setvar CHARACTERARRAY 1
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 1
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      } 
     } 
    }

    ifvare JACK? 1 
    {
     setvar CHARACTERARRAY 2
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 2
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       mulvar INACTIVEXPPTSTEMP 5
       divvar INACTIVEXPPTSTEMP 4

       setvar DAMAGEMODIFIER 100
       // Support System
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTDUKE tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Duke
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Duke
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTBUBSY tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Bubsy
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Bubsy
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTAMI tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Ami
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Ami
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTLOWANG tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Lo Wang
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Lo Wang
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTESSENCE tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ ESSence
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ ESSence
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTTED tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Ted
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Ted
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTLISA tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Lisa
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Lisa
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTCYBANIS tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Cybanis
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Cybanis
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTNETHRA tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Nethra
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Nethra
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTPAULA tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Paula
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Paula
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTLORI tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Lori
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Lori
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTMINAKO tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Minako
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Minako
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTMYSTERY1 tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ "Mystery Lady"
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ "Mystery Lady"
       getactorvar[CHARACTERARRAY].CHARACTERSUPPORTMAKEN tempb
       ifvarg tempb 3 addvar DAMAGEMODIFIER 12 // "S" Support w/ Maken
       ifvarg tempb 4 addvar DAMAGEMODIFIER 36 // "*" Support w/ Maken
       ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
       ifvarg DAMAGEMODIFIER 234 setvar DAMAGEMODIFIER 234
       mulvarvar INACTIVEXPPTSTEMP DAMAGEMODIFIER
       divvar INACTIVEXPPTSTEMP 100
       ifvarl INACTIVEXPPTSTEMP 0 setvar INACTIVEXPPTSTEMP 0
       ifvarg INACTIVEXPPTSTEMP 9163600 setvar INACTIVEXPPTSTEMP 9163600

       // EXP Badge
       setvar TEMP3 0
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM1 tempb
       ifvare tempb 7 addvar TEMP3 2
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM2 tempb
       ifvare tempb 7 addvar TEMP3 2
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM3 tempb
       ifvare tempb 7 addvar TEMP3 2
       getactorvar[CHARACTERARRAY].CHARACTEREQUIPSLOTITEM4 tempb
       ifvare tempb 7 addvar TEMP3 2
       ifvarg TEMP3 0 mulvarvar INACTIVEXPPTSTEMP TEMP3
       ifvarl INACTIVEXPPTSTEMP 0 setvar INACTIVEXPPTSTEMP 0
       ifvarg INACTIVEXPPTSTEMP 9163600 setvar INACTIVEXPPTSTEMP 9163600

       state inactiveexp_checkdoubloons

       getactorvar[CHARACTERARRAY].CHARACTEREXPPTS temp
       addvarvar temp INACTIVEXPPTSTEMP 
       ifvarl temp 0 setvar temp 0
       ifvarg temp 9163600 setvar temp 9163600
       setactorvar[CHARACTERARRAY].CHARACTEREXPPTS temp
      } 
     } 
    }

    ifvare BUBSY? 1 
    { 
     setvar CHARACTERARRAY 3
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 3
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare AMI? 1
    {
     setvar CHARACTERARRAY 4
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 4
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare LOWANG? 1
    {
     setvar CHARACTERARRAY 5
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 5
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare ESSENCE? 1
    {
     setvar CHARACTERARRAY 6
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 6 
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare TED? 1
    {
     setvar CHARACTERARRAY 7
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 7
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      } 
     }
    }

    ifvare LISA? 1
    {
     setvar CHARACTERARRAY 8
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 8
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare CYBANIS? 1 
    { 
     setvar CHARACTERARRAY 9
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     { 
      ifvarn CHARACTERSELECTED? 9 
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       mulvar INACTIVEXPPTSTEMP 11
       divvar INACTIVEXPPTSTEMP 8
       state exp_checksupportequip
      } 
     } 
    }

    ifvare NETHRA? 1
    {
     setvar CHARACTERARRAY 10
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 10 
      { 
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare PAULA? 1
    {
     setvar CHARACTERARRAY 11
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 11 
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare LORI? 1 
    {
     setvar CHARACTERARRAY 12
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 12 
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       mulvar INACTIVEXPPTSTEMP 3
       divvar INACTIVEXPPTSTEMP 2
       state exp_checksupportequip
      } 
     } 
    }

    ifvare MINAKO? 1
    {
     setvar CHARACTERARRAY 13
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 13
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare MYSTERY1? 1
    {
     setvar CHARACTERARRAY 14
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 14 
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       state exp_checksupportequip
      }
     }
    }

    ifvare MAKEN? 1 
    {
     setvar CHARACTERARRAY 15
     getactorvar[CHARACTERARRAY].CHARACTERHP temp
     ifvarg temp 0
     {
      ifvarn CHARACTERSELECTED? 15
      {
       setvarvar INACTIVEXPPTSTEMP TEMPVAR
       mulvar INACTIVEXPPTSTEMP 5
       divvar INACTIVEXPPTSTEMP 4
       state exp_checksupportequip
      } 
     } 
    }


   }
// End full-party EXP Gain here

	ifvare CHARACTERSELECTED? 2 { mulvar EXPPTSTEMP 5 divvar EXPPTSTEMP 4 } // Jack gets 25% more EXP
	ifvare CHARACTERSELECTED? 9 { mulvar EXPPTSTEMP 11 divvar EXPPTSTEMP 8 } // Cybanis gets 37.5% more EXP
	ifvare CHARACTERSELECTED? 12 { mulvar EXPPTSTEMP 3 divvar EXPPTSTEMP 2 } // Lori gets 50% more EXP
	ifvare CHARACTERSELECTED? 15 { mulvar EXPPTSTEMP 5 divvar EXPPTSTEMP 4 } // Maken gets 25% more EXP

      // Support System
      setvar DAMAGEMODIFIER 100
      state support-expbonus-main
      ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
      ifvarg DAMAGEMODIFIER 234 setvar DAMAGEMODIFIER 234
      mulvarvar EXPPTSTEMP DAMAGEMODIFIER
      divvar EXPPTSTEMP 100
      ifvarl EXPPTSTEMP 0 setvar EXPPTSTEMP 0
      ifvarg EXPPTSTEMP 9163600 setvar EXPPTSTEMP 9163600

      // EXP Badge
      setvar TEMP3 0
      ifvare PLAYEREQUIPSLOTITEM1 7 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM2 7 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM3 7 addvar TEMP3 2
      ifvare PLAYEREQUIPSLOTITEM4 7 addvar TEMP3 2
      ifvarg TEMP3 0 mulvarvar EXPPTSTEMP TEMP3
      ifvarl EXPPTSTEMP 0 setvar EXPPTSTEMP 0
      ifvarg EXPPTSTEMP 9163600 setvar EXPPTSTEMP 9163600

      ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
      mulvar TEMP6 2 // 2% per item  
      // addlogvar EXPPTSTEMP
      setvarvar TEMP7 EXPPTSTEMP
      mulvarvar TEMP7 TEMP6
      divvar TEMP7 100
      addvarvar EXPPTSTEMP TEMP7
      // addlogvar EXPPTSTEMP

      ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
      mulvar TEMP6 2 // 2% per item  
      addvar TEMP6 100
      setvar TEMP7 9163600
      // addlogvar TEMP7
      mulvarvar TEMP7 TEMP6
      divvar TEMP7 100
      // addlogvar TEMP7

      ifvarl EXPPTSTEMP 0 setvar EXPPTSTEMP 0
      ifvarvarg EXPPTSTEMP TEMP7 setvarvar EXPPTSTEMP TEMP7

      addvarvar EXPPTS EXPPTSTEMP 

      ifvarl EXPPTSTEMP 0 setvar EXPPTSTEMP 0
      ifvarg EXPPTSTEMP 9163600 setvar EXPPTSTEMP 9163600
      ifvarg EXPPTSTEMP 0
      {
       setvarvar DISPLAYEXPPOINTS EXPPTSTEMP
       setvarvar DISPLAYEXPPOINTSOTHERS TEMPVAR

       ifvarvarg PARTYSIZE RAREPIRATEDOUBLOONS setvarvar TEMP6 RAREPIRATEDOUBLOONS else setvarvar TEMP6 PARTYSIZE
       mulvar TEMP6 2 // 2% per item  
       // addlogvar DISPLAYEXPPOINTSOTHERS
       setvarvar TEMP7 DISPLAYEXPPOINTSOTHERS
       mulvarvar TEMP7 TEMP6
       divvar TEMP7 100
       addvarvar DISPLAYEXPPOINTSOTHERS TEMP7
       // addlogvar DISPLAYEXPPOINTSOTHERS

       setvar EXPDISPLAYTIMER 0
      }

    setvar RANKPOINTSTEMP 0
    setvar EXPPTSTEMP 0
    setvar TEMPVAR 0
ends

state jibfood
  sound SQUISHED
  guts JIBS6 3
  killit
ends

state civjibs
	guts JIBS2 1
	guts JIBS3 2
	guts JIBS4 3
	guts JIBS5 2
ends

state prolougeendeffect
ends

state echeckquadtime
 ifvarg ENEMYQUADTIME 0 sound QUADDAMAGE3
ends

state echeckvampiretime
  ifvarg ENEMYVAMPIRETIME 0 sound SHOOT_VAMPIREITEM
ends

state fireshotgun_angleeffect
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot SHOTGUN ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state firechaingun_angleeffect
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot CHAINGUN ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state fireshotspark1_angleeffect
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot SHOTSPARK1 ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state firegrowspark_angleeffect
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot GROWSPARK ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state firecoolexplosion1_angleeffect
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot COOLEXPLOSION1 ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state firezapper1_angleeffect	
      sound ZAPPER1_FIRE
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot ZAPPER1 ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state firezapper2_angleeffect
      sound ZAPPER2_FIRE
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot ZAPPER2 ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state firezapper3_angleeffect
      sound ZAPPER3_FIRE
      getactorvar[THISACTOR].ACTORANGLE TEMPVAR4 eshoot ZAPPER3 ifvarn RETURN -1 { setactorvar[RETURN].ACTORANGLE TEMPVAR4 }
ends

state pigshotgun
      state fireshotgun_angleeffect
      state fireshotgun_angleeffect
      state fireshotgun_angleeffect
      state fireshotgun_angleeffect
ends

state pigsargeattack1
        state echeckquadtime
        state echeckvampiretime
        sound PIG_ATTACK
        sound PIG_ATTACK
        sound PIG_ATTACK
        state pigshotgun
        state pigshotgun
        state pigshotgun
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE 192
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 10
        setactor[RETURN].yrepeat 10
        setactor[RETURN].extra 64
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE 96
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 15
        setactor[RETURN].yrepeat 15
        setactor[RETURN].extra 96
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE 0
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 20
        setactor[RETURN].yrepeat 20
        setactor[RETURN].extra 128
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE -96
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 15
        setactor[RETURN].yrepeat 15
        setactor[RETURN].extra 96
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE -192
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 10
        setactor[RETURN].yrepeat 10
        setactor[RETURN].extra 64
ends

state pigsargeattack2
        state echeckquadtime
        state echeckvampiretime
        sound PIG_ATTACK
        sound PIG_ATTACK
        sound PIG_ATTACK
        state pigshotgun
        state pigshotgun
        state pigshotgun
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE 128
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 10
        setactor[RETURN].yrepeat 10
        setactor[RETURN].extra 64
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE 64
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 15
        setactor[RETURN].yrepeat 15
        setactor[RETURN].extra 96         
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE 0
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 20
        setactor[RETURN].yrepeat 20
        setactor[RETURN].extra 128
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE -64
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 15
        setactor[RETURN].yrepeat 15
        setactor[RETURN].extra 96
        eshoot RPG // _NOAIM
        getactor[RETURN].ang ATTACKANGLE 
        addvar ATTACKANGLE -128
        setactor[RETURN].ang ATTACKANGLE 
        setactor[RETURN].xrepeat 10
        setactor[RETURN].yrepeat 10
        setactor[RETURN].extra 64
ends

state eggawards
     ifspritepal 9 nullop
     else
     {
      randvar RANKPOINTSTEMP EGGRANKPOINTSRAND 
      addvar RANKPOINTSTEMP EGGRANKPOINTSSOLID 
      randvar EXPPTSTEMP EGGEXPERIENCERAND
      addvar EXPPTSTEMP EGGEXPERIENCE
      state expmulti
      state exp_given
      addkills 1
      state resetenemytimers
     }
ends

state liztroopawards
    ifspritepal 11 nullop
    else ifspritepal 10 nullop
    else ifspritepal 14
    {
     randvar RANKPOINTSTEMP SHRINKTROOPRANKPOINTSRAND 
     addvar RANKPOINTSTEMP SHRINKTROOPRANKPOINTSSOLID 
     randvar EXPPTSTEMP SHRINKTROOPEXPERIENCERAND
     addvar EXPPTSTEMP SHRINKTROOPEXPERIENCE
    } 
    else ifspritepal 17
    {
     randvar RANKPOINTSTEMP ZERMANRANKPOINTSRAND 
     addvar RANKPOINTSTEMP ZERMANRANKPOINTSSOLID 
     randvar EXPPTSTEMP ZERMANEXPERIENCERAND
     addvar EXPPTSTEMP ZERMANEXPERIENCE
    } 
    else ifspritepal 19
    {
     randvar RANKPOINTSTEMP RAVAGERCAPTAINRANKPOINTSRAND 
     addvar RANKPOINTSTEMP RAVAGERCAPTAINRANKPOINTSSOLID 
     randvar EXPPTSTEMP RAVAGERCAPTAINEXPERIENCERAND
     addvar EXPPTSTEMP RAVAGERCAPTAINEXPERIENCE
    } 
    else ifspritepal 21
    {
     randvar RANKPOINTSTEMP CAPTAINRANKPOINTSRAND 
     addvar RANKPOINTSTEMP CAPTAINRANKPOINTSSOLID 
     randvar EXPPTSTEMP CAPTAINEXPERIENCERAND
     addvar EXPPTSTEMP CAPTAINEXPERIENCE
    } 
    else 
    {
     randvar RANKPOINTSTEMP TROOPRANKPOINTSRAND 
     addvar RANKPOINTSTEMP TROOPRANKPOINTSSOLID 
     randvar EXPPTSTEMP TROOPEXPERIENCERAND
     addvar EXPPTSTEMP TROOPEXPERIENCE
    }
    ifvare ENEMYBOMBER? 1
    {
     ifpdistl 1780
     {
      randvar TEMPVAR 1
      addvar TEMPVAR 2
      mulvarvar EXPPTSTEMP TEMPVAR
     }
    }
ends

state lizmanawards
    ifspritepal 9 nullop
    else ifspritepal 6
    { 
     randvar RANKPOINTSTEMP BIOLIZRANKPOINTSRAND 
     addvar RANKPOINTSTEMP BIOLIZRANKPOINTSSOLID 
     randvar EXPPTSTEMP BIOLIZEXPERIENCERAND
     addvar EXPPTSTEMP BIOLIZEXPERIENCE
    }
    else ifspritepal 19
    { 
     randvar RANKPOINTSTEMP LASERLIZRANKPOINTSRAND 
     addvar RANKPOINTSTEMP LASERLIZRANKPOINTSSOLID 
     randvar EXPPTSTEMP LASERLIZEXPERIENCERAND
     addvar EXPPTSTEMP LASERLIZEXPERIENCE
    }
    else ifspritepal 17
    { 
     randvar RANKPOINTSTEMP FERTANGRANKPOINTSRAND 
     addvar RANKPOINTSTEMP FERTANGRANKPOINTSSOLID 
     randvar EXPPTSTEMP FERTANGEXPERIENCERAND
     addvar EXPPTSTEMP FERTANGEXPERIENCE
    }
    else
    { 
     randvar RANKPOINTSTEMP LIZRANKPOINTSRAND 
     addvar RANKPOINTSTEMP LIZRANKPOINTSSOLID 
     randvar EXPPTSTEMP LIZEXPERIENCERAND
     addvar EXPPTSTEMP LIZEXPERIENCE
    }
ends

// state droneawards
// ends

state octabrainawards
     ifspritepal 9 nullop
     else ifspritepal 14 
     {
      randvar RANKPOINTSTEMP OCTANINERANKPOINTSRAND 
      addvar RANKPOINTSTEMP OCTANINERANKPOINTSSOLID 
      randvar EXPPTSTEMP OCTANINEEXPERIENCE
      addvar EXPPTSTEMP OCTANINEEXPERIENCE
     }
     else 
     {
      randvar RANKPOINTSTEMP OCTARANKPOINTSRAND 
      addvar RANKPOINTSTEMP OCTARANKPOINTSSOLID 
      randvar EXPPTSTEMP OCTAEXPERIENCE
      addvar EXPPTSTEMP OCTAEXPERIENCE
     }
ends

state pigcopawards
    ifspritepal 9 nullop
    else ifspritepal 21
    { 
     randvar RANKPOINTSTEMP PIGCAPTAINRANKPOINTSRAND 
     addvar RANKPOINTSTEMP PIGCAPTAINRANKPOINTSSOLID 
     randvar EXPPTSTEMP PIGCAPTAINEXPERIENCERAND
     addvar EXPPTSTEMP PIGCAPTAINEXPERIENCE
    }
    else ifspritepal 14
    { 
     randvar RANKPOINTSTEMP PIGSARGEANTRANKPOINTSRAND 
     addvar RANKPOINTSTEMP PIGSARGEANTRANKPOINTSSOLID 
     randvar EXPPTSTEMP PIGSARGEANTEXPERIENCERAND
     addvar EXPPTSTEMP PIGSARGEANTEXPERIENCE
    }
    else ifspritepal 24
    {
     randvar RANKPOINTSTEMP RAMONERANKPOINTSRAND 
     addvar RANKPOINTSTEMP RAMONERANKPOINTSSOLID 
     randvar EXPPTSTEMP RAMONEEXPERIENCERAND
     addvar EXPPTSTEMP RAMONEEXPERIENCE
    }
    else
    {
     randvar RANKPOINTSTEMP PIGCOPRANKPOINTSRAND 
     addvar RANKPOINTSTEMP PIGCOPRANKPOINTSSOLID 
     randvar EXPPTSTEMP PIGCOPEXPERIENCERAND
     addvar EXPPTSTEMP PIGCOPEXPERIENCE
    }
ends

state boss1awards
    ifspritepal 9 nullop
    else ifspritepal 10 nullop
    else ifspritepal 0 
    {
     randvar RANKPOINTSTEMP BOSS1RANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS1RANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS1EXPERIENCERAND
     addvar EXPPTSTEMP BOSS1EXPERIENCE
    }
    else ifspritepal 3
    {
     randvar RANKPOINTSTEMP BOSS1RANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS1RANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS1EXPERIENCERAND
     addvar EXPPTSTEMP BOSS1EXPERIENCE
    }
    else ifspritepal 24 
    {
     randvar RANKPOINTSTEMP BOSS1ESSRANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS1ESSRANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS1ESSEXPERIENCERAND
     addvar EXPPTSTEMP BOSS1ESSEXPERIENCE
    }
    else
    {
     randvar RANKPOINTSTEMP BOSS1PALRANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS1PALRANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS1PALEXPERIENCERAND
     addvar EXPPTSTEMP BOSS1PALEXPERIENCE
    }
ends

state boss2awards
    ifspritepal 10 nullop
    else ifspritepal 0 
    {
     randvar RANKPOINTSTEMP BOSS2RANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS2RANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS2EXPERIENCERAND
     addvar EXPPTSTEMP BOSS2EXPERIENCE
    }
    else ifspritepal 3
    {
     randvar RANKPOINTSTEMP BOSS2RANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS2RANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS2EXPERIENCERAND
     addvar EXPPTSTEMP BOSS2EXPERIENCE
    }
    else ifspritepal 9 // Special Prolouge Boss should not give EXP, and triggers a special effect when he dies.
    { 
     state prolougeendeffect
    }
    else ifspritepal 24 
    {
     randvar RANKPOINTSTEMP BOSS2MEGARANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS2MEGARANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS2MEGAEXPERIENCERAND
     addvar EXPPTSTEMP BOSS2MEGAEXPERIENCE
    }
    else
    {
     randvar RANKPOINTSTEMP BOSS2PALRANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS2PALRANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS2PALEXPERIENCERAND
     addvar EXPPTSTEMP BOSS2PALEXPERIENCE
    }
ends

state boss3awards
    ifspritepal 9 nullop
    else ifspritepal 10 nullop
    else ifspritepal 0 
    {
     randvar RANKPOINTSTEMP BOSS3RANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS3RANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS3EXPERIENCERAND
     addvar EXPPTSTEMP BOSS3EXPERIENCE
    }
    else ifspritepal 3
    {
     randvar RANKPOINTSTEMP BOSS3RANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS3RANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS3EXPERIENCERAND
     addvar EXPPTSTEMP BOSS3EXPERIENCE
    }
    else ifspritepal 24 
    {
     randvar RANKPOINTSTEMP BOSS3VOIDRANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS3VOIDRANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS3VOIDEXPERIENCERAND
     addvar EXPPTSTEMP BOSS3VOIDEXPERIENCE
    }
    else
    {
     randvar RANKPOINTSTEMP BOSS3PALRANKPOINTSRAND 
     addvar RANKPOINTSTEMP BOSS3PALRANKPOINTSSOLID 
     randvar EXPPTSTEMP BOSS3PALEXPERIENCERAND
     addvar EXPPTSTEMP BOSS3PALEXPERIENCE
    }
ends

state boss4awards
     ifspritepal 9 nullop
     else ifspritepal 10 nullop
     else ifspritepal 24
     {
      randvar RANKPOINTSTEMP BOSS4FAKERANKPOINTSRAND 
      addvar RANKPOINTSTEMP BOSS4FAKERANKPOINTSSOLID 
      randvar EXPPTSTEMP BOSS4FAKEEXPERIENCERAND
      addvar EXPPTSTEMP BOSS4FAKEEXPERIENCE
     }
     else ifspritepal 0
     {
      randvar RANKPOINTSTEMP BOSS4RANKPOINTSRAND 
      addvar RANKPOINTSTEMP BOSS4RANKPOINTSSOLID 
      randvar EXPPTSTEMP BOSS4EXPERIENCERAND
      addvar EXPPTSTEMP BOSS4EXPERIENCE
     }
     else ifspritepal 3
     {
      randvar RANKPOINTSTEMP BOSS4RANKPOINTSRAND 
      addvar RANKPOINTSTEMP BOSS4RANKPOINTSSOLID 
      randvar EXPPTSTEMP BOSS4EXPERIENCERAND
      addvar EXPPTSTEMP BOSS4EXPERIENCE
     }
     else
     {
      randvar RANKPOINTSTEMP BOSS4PALRANKPOINTSRAND 
      addvar RANKPOINTSTEMP BOSS4PALRANKPOINTSSOLID 
      randvar EXPPTSTEMP BOSS4PALEXPERIENCERAND
      addvar EXPPTSTEMP BOSS4PALEXPERIENCE
     } 
ends

state commanderawards
    ifspritepal 9 nullop
    else ifspritepal 14
    {
     randvar RANKPOINTSTEMP GENERALRANKPOINTSRAND 
     addvar RANKPOINTSTEMP GENERALRANKPOINTSSOLID 
     randvar EXPPTSTEMP GENERALEXPERIENCERAND
     addvar EXPPTSTEMP GENERALEXPERIENCE
    }
    else ifspritepal 25
    {
     randvar RANKPOINTSTEMP LEADERRANKPOINTSRAND 
     addvar RANKPOINTSTEMP LEADERRANKPOINTSSOLID 
     randvar EXPPTSTEMP LEADEREXPERIENCERAND
     addvar EXPPTSTEMP LEADEREXPERIENCE
    }
    else ifspritepal 24 
    {
     randvar RANKPOINTSTEMP BAALORANKPOINTSRAND 
     addvar RANKPOINTSTEMP BAALORANKPOINTSSOLID 
     randvar EXPPTSTEMP BAALOEXPERIENCERAND
     addvar EXPPTSTEMP BAALOEXPERIENCE
    }
    else
    {
     randvar RANKPOINTSTEMP COMMANDERRANKPOINTSRAND 
     addvar RANKPOINTSTEMP COMMANDERRANKPOINTSSOLID 
     randvar EXPPTSTEMP COMMANDEREXPERIENCERAND
     addvar EXPPTSTEMP COMMANDEREXPERIENCE
    }
ends

// state tankawards
// ends

// state boss4awards
// ends

state newbeastawards
    ifspritepal 9 nullop
    else ifspritepal 17
    {
     randvar RANKPOINTSTEMP NEWBEAST2LRANKPOINTSRAND 
     addvar RANKPOINTSTEMP NEWBEAST2LRANKPOINTSSOLID 
     randvar EXPPTSTEMP NEWBEAST2LEXPERIENCERAND
     addvar EXPPTSTEMP NEWBEAST2LEXPERIENCE
    }
    else ifspritepal 20
    {
     randvar RANKPOINTSTEMP NEWBEAST2GRANKPOINTSRAND 
     addvar RANKPOINTSTEMP NEWBEAST2GRANKPOINTSSOLID 
     randvar EXPPTSTEMP NEWBEAST2GEXPERIENCERAND
     addvar EXPPTSTEMP NEWBEAST2GEXPERIENCE
    }
    else
    {
     randvar RANKPOINTSTEMP NEWBEASTRANKPOINTSRAND 
     addvar RANKPOINTSTEMP NEWBEASTRANKPOINTSSOLID 
     randvar EXPPTSTEMP NEWBEASTEXPERIENCERAND
     addvar EXPPTSTEMP NEWBEASTEXPERIENCE
    }
ends

state sharkawards
        ifspritepal 24
        {
         randvar RANKPOINTSTEMP BLOODSHARKRANKPOINTSRAND 
         addvar RANKPOINTSTEMP BLOODSHARKRANKPOINTSSOLID 
         randvar EXPPTSTEMP BLOODSHARKEXPERIENCERAND
         addvar EXPPTSTEMP BLOODSHARKEXPERIENCE
        }
        else
        {
         randvar RANKPOINTSTEMP SHARKRANKPOINTSRAND 
         addvar RANKPOINTSTEMP SHARKRANKPOINTSSOLID 
         randvar EXPPTSTEMP SHARKEXPERIENCERAND
         addvar EXPPTSTEMP SHARKEXPERIENCE
        }
        state expmulti
ends

state invulnflash
 palfrom 32 64 64 64
ends

state nullflash
 palfrom 0 0 0 0
ends

state checkkillerofciv
        ifactor FEM10
        {
         addvar CIVILIANSKILLED_LEVEL 2
         addvar CIVILIANSKILLED_GAME 2
        }
        else
        {
         addvar CIVILIANSKILLED_LEVEL 1
         addvar CIVILIANSKILLED_GAME 1
        }

        getactor[THISACTOR].htowner TEMP
        ifvarvarn TEMP THISACTOR
        {
         ifvarvarn TEMP PLAYERID
         {
          ifactor FEM10 redefinequote 130 ^102 CIVILIANS WERE KILLED BY AN ENEMY!
          else redefinequote 130 ^10A CIVILIAN WAS KILLED BY AN ENEMY!
          setvarvar fta fta_normal setvar ftq 130
          divvar RANKPOINTSTEMP 6
         }
         else
         {
          ifactor FEM10 redefinequote 130 ^10YOU JUST KILLED 2 CIVILIANS, RETARD!
          else redefinequote 130 ^10YOU JUST KILLED A CIVILIAN, RETARD!
          setvarvar fta fta_normal setvar ftq 130
         }
        }
        else
        {
         ifactor FEM10 redefinequote 130 ^102 CIVILIANS JUST COMMITED SUICIDE...?
         else redefinequote 130 ^10A CIVILIAN JUST COMMITED SUICIDE...?
         setvarvar fta fta_normal setvar ftq 130
         setvar RANKPOINTSTEMP 0
        }
ends

state civiliankilled
        state civjibs
        randvar RANKPOINTSTEMP CIVILIANKILLRANKPOINTSRAND 
        addvar RANKPOINTSTEMP CIVILIANKILLRANKPOINTSSOLID 
        setvar TEMPVAR 1
        state checkkillerofciv
        state expmulti
        state exp_given
        state jibfood
ends

// REMAKING THE INVULNERABILITY BIO-AURAS >_>

define INVULNICON 6143

state invulnauraseek
      canseespr THISACTOR INVULNAURATARGET temp
ends

state invulnkillplayer
         setactor[INVULNAURATARGET].extra 0 // TODO: LEAVE-THIS

         ifvare CHARACTERSELECTED? 8
         {
          ifvare HAVEENERGYSHIELD? 1
          {
           ifvare ENERGYSHIELDMODE 1
           {
            ifvarg CURRENTCELLS -1 ifvarg DAMAGEINCELL 0
            {
             setvar CURRENTCELLS 0
             setvar DAMAGEINCELL 0
             state bioshieldhitsounds
            }
           }
          }
         }
         setvar FIRSTAIDCURRENT 0
         setvar CURRENTARMORPOINTS 0
         setvar CURRENTHITPOINTS 0
         setactor[INVULNAURATARGET].htextra 1
         setactor[INVULNAURATARGET].htowner THISACTOR
         setactor[INVULNAURATARGET].htpicnum INVULNICON
         palfrom 64 64
ends

state dealinvulndmg
     ifvare CHEATGOD 0
     {
      getactorvar[INVULNAURATARGET].INVULNTIME tempb
      ifvare tempb 0
      {
       state invulnauraseek
       ifvare temp 1
       {
        ifvare DEATHSWITCHDELAY 0
        {
         ifvare CHARACTERSELECTED? 8
         {
          ifvare HAVEENERGYSHIELD? 1
          {
           ifvare ENERGYSHIELDMODE 1
           {
            setvarvar TEMPVAR5 CURRENTBIOSHIELDPOWER
            divvarvar TEMPVAR5 MAXHITPOINTS
            ifvarg TEMPVAR5 15
            {
             setvar CURRENTCELLS 0
             setvar DAMAGEINCELL 0
             setvar FIRSTAIDCURRENT 0
             setvar CURRENTARMORPOINTS 0
             setvar CURRENTHITPOINTS 1
             setvar DEATHCHARACTERVAR 0
             setvar DEATHSWITCHDELAY 39
             state bioshieldhitsounds
             setactorvar[THISACTOR].ENEMYFIRSTAID 0
             setactorvar[THISACTOR].ENEMYAP 0
             setactorvar[THISACTOR].ENEMYHP 1
             redefinequote 321 ^23SAVED BY THE BIO-CELLULAR ENERGY SHIELD!
             setvarvar fta fta_normal setvar ftq 321
             palfrom 63 64
            }
            else state invulnkillplayer
           }
           else state invulnkillplayer
          }
          else state invulnkillplayer
         }
         else state invulnkillplayer
        }
       }
      }
      else
      {
       soundonce INVULNITEM3
       palfrom 32 64 64 64
      }
     }
     else
     {
      soundonce INVULNITEM3
      palfrom 32 64 64 64
     }
ends

state invulnauradetect
ifvare mainmenu 0
{
 ifvarn INVULNAURATARGET -1
 { 
  ifvarvare INVULNAURATARGET PARENTID { setvar INVULNAURATARGET -1 break }
  getactor[INVULNAURATARGET].picnum temp
  ifvare temp APLAYER getactorvar[INVULNAURATARGET].CURRENTHITPOINTS tempc else getactorvar[INVULNAURATARGET].ENEMYHP tempc

  ifvarl tempc 1 { setvar INVULNAURATARGET -1 break } // Makes it that if the current "seeker" is dead, set to -1 to search for a living one
  getactorvar[INVULNAURATARGET].SHRUNK? tempd
  ifvare tempd 1 { setvar INVULNAURATARGET -1 break } // Makes it that if the current "seeker" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[INVULNAURATARGET].FROZEN? tempd
  ifvare tempd 1 { setvar INVULNAURATARGET -1 break } // Makes it that if the current "seeker" is frozen, set to -1 to search for a non-frozen one
  getactorvar[INVULNAURATARGET].CLOAKED? tempd
  ifvare tempd 1 { setvar INVULNAURATARGET -1 break } // Makes it that if the current "seeker" is cloaked, set to -1 to search for a non-cloaked one

  // Attempt to inflict a killing blow if target is alive
  ifvarg tempc 0
  {
   getactor[INVULNAURATARGET].picnum tempe
   ifvarn tempe APLAYER
   {
     getactorvar[INVULNAURATARGET].SKILLSET? tempb
     ifvarn tempb 0
     {
      getactorvar[INVULNAURATARGET].ENEMYINVULNTIME tempb
      ifvare tempb 0 // If they have no Invuln, KILL 'EM! XD
      {
       state invulnauraseek
       ifvare temp 1
       {
         setactor[INVULNAURATARGET].htowner THISACTOR
         setactor[INVULNAURATARGET].htextra 1
         setactor[INVULNAURATARGET].htpicnum INVULNICON
       }
      }
      else soundonce INVULNITEM3
     }
     else
     {
      setvar INVULNAURATARGET -1
      break 
     }
   }
   else
   ifvare tempe APLAYER
   {
    getactorvar[PLAYERID].VEHICLEID tempvehicleid
    ifvare tempvehicleid -1
    {
     ifvare CHARACTERSELECTED? 10
     {
      ifvare PUBLICBETA? 0
      {
       ifrnd 1 { ifrnd 32 state dealinvulndmg }
      }
      else state dealinvulndmg
     }
     else
     ifvare CHARACTERSELECTED? 14
     {
      ifvare PUBLICBETA? 0 nullop else state dealinvulndmg
     }
     else state dealinvulndmg
    }
    else
    {
     getactorvar[tempvehicleid].ENEMYINVULNTIME tempb
     ifvare tempb 0
     {
      setactorvar[tempvehicleid].ENEMYHP 0
      setactor[tempvehicleid].htowner THISACTOR
      setactor[tempvehicleid].htextra 1
      setactor[tempvehicleid].htpicnum INVULNICON
      ifvare CHARACTERSELECTED? 10
      {
       ifvare PUBLICBETA? 0
       {
        ifrnd 1 { ifrnd 32 state dealinvulndmg }
       }
       else state dealinvulndmg
      }
      else
      ifvare CHARACTERSELECTED? 14
      {
       ifvare PUBLICBETA? 0 nullop else state dealinvulndmg
      }
      else state dealinvulndmg
     }
     else soundonce INVULNITEM3
    }
   }
  }
 }
}
ends

state invulntarget_player
   addvar FINDNEAR_INTERVAL 1
   ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
   {
    findnearactorzvar BOSS4 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar BOSS3 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar BOSS2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar BOSS1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar SCORPIONTANK INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar TANK INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar COMMANDER INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar NEWBEAST INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar OCTABRAIN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DRONE INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar PIGCOP INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar LIZMAN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar RECON INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar LIZTROOP INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ROTATEGUN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar SHARK INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar EGG INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar GREENSLIME INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    setvar FINDNEAR_INTERVAL 0
   }
ends

state invulntarget_civilians
   addvar FINDNEAR_INTERVAL 1
   ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
   {
    findnearactorzvar BOSS4 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar BOSS3 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar BOSS2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar BOSS1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar SCORPIONTANK INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar TANK INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar COMMANDER INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar NEWBEAST INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar OCTABRAIN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DRONE INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar PIGCOP INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar LIZMAN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar RECON INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar LIZTROOP INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ROTATEGUN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar SHARK INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar EGG INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar GREENSLIME INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    setvar FINDNEAR_INTERVAL 0
   }
ends

state invulntarget_monsters
   addvar FINDNEAR_INTERVAL 1
   ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
   {
    findnearactorzvar PRESIDENTCLINTON INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearspritezvar APLAYER INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar PODFEM1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar NAKED1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM3 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM4 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM5 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM6 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM7 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM9 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar FEM10 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar TOUGHGAL INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar WOMAN INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ROBOTDOG INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ROBOTDOG2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar STAND1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DEALER INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar STAND3 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar STAND4 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE3 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE5 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE6 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE7 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar DANCE9 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar WOLFDUDE INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar COP1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar PUNKDUDE INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar COP2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar SITTINGDUDE INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ANIMEGIRL1 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ANIMEGIRL2 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ANIMEGIRL3 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    ifvare INVULNAURATARGET -1 findnearactorzvar ANIMEGIRL4 INVULNAURARANGEXY INVULNAURARANGEZ INVULNAURATARGET state invulnauradetect
    setvar FINDNEAR_INTERVAL 0
   }
ends

state invulnicon
 ifvare oldskoolmode 0
 {
  getactor[PARENTID].x TESTX 
  getactor[PARENTID].y TESTY
  getactor[PARENTID].z TESTZ
  getactor[PARENTID].picnum TEMP
  ifvare TEMP APLAYER
  {
   subvar TESTZ 512
  }
  setactor[THISACTOR].x TESTX
  setactor[THISACTOR].y TESTY 
  setactor[THISACTOR].z TESTZ
  getactor[PARENTID].xrepeat TESTXREPEAT1 
  getactor[PARENTID].yrepeat TESTYREPEAT1 
  getactorvar[PARENTID].ACTORSHEIGHT INVULNAURARANGEZ
  mulvarvar INVULNAURARANGEZ TESTYREPEAT1
  mulvar INVULNAURARANGEZ 4
  setvar INVULNAURARANGEXY 844
  addvarvar INVULNAURARANGEXY TESTXREPEAT1
  addvar INVULNAURARANGEZ 1688
  addvarvar INVULNAURARANGEZ TESTYREPEAT1
  addvarvar INVULNAURARANGEZ TESTYREPEAT1

  getactor[PARENTID].picnum TEMP
  ifvare TEMP APLAYER
  {
   getactorvar[PLAYERID].VEHICLEID tempvehicleid
   ifvare tempvehicleid -1
   {
    getactorvar[PARENTID].INVULNTIME TEMP
    ifvarg TEMP 0
    {
     setactor[THISACTOR].cstat 32768 // Sets Invisible
     state invulntarget_player
    }
    else setactor[THISACTOR].cstat 32768 // Sets Invisible
   }
   else
   {
    getactorvar[tempvehicleid].ENEMYINVULNTIME TEMP
    ifvarg TEMP 0
    {
     setactor[THISACTOR].cstat 32768 // Sets Invisible
     state invulntarget_player
    }
    else setactor[THISACTOR].cstat 32768 // Sets Invisible
   }
  }
  else
  {
   getactorvar[PARENTID].ENEMYINVULNTIME TEMP
   ifvarg TEMP 0
   {
    setactor[THISACTOR].cstat 32768 // Sets Invisible
    getactor[PARENTID].picnum TEMP
    ifvare TEMP ROTATEGUN state invulntarget_monsters
    ifvare TEMP SHARK state invulntarget_monsters
    ifvare TEMP LIZTROOP state invulntarget_monsters
    ifvare TEMP PIGCOP state invulntarget_monsters
    ifvare TEMP RECON state invulntarget_monsters
    ifvare TEMP LIZMAN state invulntarget_monsters
    ifvare TEMP OCTABRAIN state invulntarget_monsters
    ifvare TEMP DRONE state invulntarget_monsters
    ifvare TEMP NEWBEAST state invulntarget_monsters
    ifvare TEMP COMMANDER state invulntarget_monsters
    ifvare TEMP TANK state invulntarget_monsters
    ifvare TEMP SCORPIONTANK state invulntarget_monsters
    ifvare TEMP BOSS1 state invulntarget_monsters
    ifvare TEMP BOSS2 state invulntarget_monsters
    ifvare TEMP BOSS3 state invulntarget_monsters
    ifvare TEMP BOSS4 state invulntarget_monsters
    ifvare TEMP PRESIDENTCLINTON state invulntarget_civilians
    ifvare TEMP ROBOTDOG state invulntarget_civilians
    ifvare TEMP ROBOTDOG2 state invulntarget_civilians
    ifvare TEMP PODFEM1 state invulntarget_civilians
    ifvare TEMP NAKED1 state invulntarget_civilians
    ifvare TEMP FEM1 state invulntarget_civilians
    ifvare TEMP FEM2 state invulntarget_civilians
    ifvare TEMP FEM3 state invulntarget_civilians
    ifvare TEMP FEM4 state invulntarget_civilians
    ifvare TEMP FEM5 state invulntarget_civilians
    ifvare TEMP FEM6 state invulntarget_civilians
    ifvare TEMP FEM7 state invulntarget_civilians
    ifvare TEMP FEM9 state invulntarget_civilians
    ifvare TEMP FEM10 state invulntarget_civilians
    ifvare TEMP TOUGHGAL state invulntarget_civilians
    ifvare TEMP WOMAN state invulntarget_civilians
    ifvare TEMP DANCE1 state invulntarget_civilians
    ifvare TEMP DANCE2 state invulntarget_civilians
    ifvare TEMP DANCE3 state invulntarget_civilians
    ifvare TEMP DANCE5 state invulntarget_civilians
    ifvare TEMP DANCE6 state invulntarget_civilians
    ifvare TEMP DANCE7 state invulntarget_civilians
    ifvare TEMP DANCE9 state invulntarget_civilians
    ifvare TEMP STAND1 state invulntarget_civilians
    ifvare TEMP DEALER state invulntarget_civilians
    ifvare TEMP STAND3 state invulntarget_civilians
    ifvare TEMP STAND4 state invulntarget_civilians
    ifvare TEMP WOLFDUDE state invulntarget_civilians
    ifvare TEMP COP1 state invulntarget_civilians
    ifvare TEMP PUNKDUDE state invulntarget_civilians
    ifvare TEMP COP2 state invulntarget_civilians
    ifvare TEMP SITTINGDUDE state invulntarget_civilians
    ifvare TEMP ANIMEGIRL1 state invulntarget_civilians
    ifvare TEMP ANIMEGIRL2 state invulntarget_civilians
    ifvare TEMP ANIMEGIRL3 state invulntarget_civilians
    ifvare TEMP ANIMEGIRL4 state invulntarget_civilians
   }
   else setactor[THISACTOR].cstat 32768 // Sets Invisible
  }
 }
 else setactor[THISACTOR].cstat 32768 // Sets Invisible
ends

//******************
//******************
//******************
//******************

state randomshrapnel
    randvar RANDOMIZER 4
    ifvare RANDOMIZER 0 debris SCRAP1 1
    ifvare RANDOMIZER 1 debris SCRAP2 1
    ifvare RANDOMIZER 2 debris SCRAP3 1
    ifvare RANDOMIZER 3 debris SCRAP4 1
    ifvare RANDOMIZER 4 debris SCRAP5 1
ends

state trashcancode
 ifhitweapon
 { 
  ifwasweapon SHRINKER nullop
  else ifwasweapon SHRINKSPARK nullop
  else
  {
   ifdead
   {
    state randomshrapnel
    state randomshrapnel
    ifrnd 224 state randomshrapnel
    ifrnd 192 state randomshrapnel
    ifrnd 192 state randomshrapnel
    ifrnd 160 state randomshrapnel
    ifrnd 128 state randomshrapnel
    ifrnd 128 state randomshrapnel
    ifrnd 96 state randomshrapnel
    ifrnd 64 state randomshrapnel
    ifrnd 64 state randomshrapnel
    ifrnd 32 state randomshrapnel
    paper 1
    paper 1
    ifrnd 224 paper 1
    ifrnd 192 paper 1
    ifrnd 192 paper 1
    ifrnd 160 paper 1
    ifrnd 128 paper 1
    ifrnd 128 paper 1
    ifrnd 96 paper 1
    ifrnd 64 paper 1
    ifrnd 64 paper 1
    ifrnd 32 paper 1
    mail 1
    mail 1
    ifrnd 224 mail 1
    ifrnd 192 mail 1
    ifrnd 192 mail 1
    ifrnd 160 mail 1
    ifrnd 128 mail 1
    ifrnd 128 mail 1
    ifrnd 96 mail 1
    ifrnd 64 mail 1
    ifrnd 64 mail 1
    ifrnd 32 mail 1
    ifrnd 128 spawn RAT
    ifrnd 128 spawn RAT
    ifrnd 96 spawn RAT
    ifrnd 96 spawn RAT
    ifrnd 64 spawn RAT
    ifrnd 64 spawn RAT
    ifrnd 32 spawn RAT
    ifrnd 32 spawn RAT
    ifrnd 64 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 64 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 32 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 32 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 16 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 16 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 8 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 8 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 32 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 16 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 16 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 8 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 8 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 16 { espawn DIME setactor[RETURN].pal 3 }
    ifrnd 8 { espawn DIME setactor[RETURN].pal 3 }
    ifrnd 8 { espawn DIME setactor[RETURN].pal 3 }
    ifrnd 8 { espawn QUARTER setactor[RETURN].pal 3 }
    ifvarg TEMP -1 ifvarl TEMP 13 nullop
    else
    {
     espawnvar TEMP
     setactor[RETURN].pal TEMP2
     getactorvar[THISACTOR].ACTORFLAGS TEMP3
     setactorvar[RETURN].ACTORFLAGS TEMP3
     getactorvar[THISACTOR].lotagsav TEMP4
     setactorvar[RETURN].lotagsav TEMP4
    }
    killit
   }
  }
 }
ends

state trashbagcode
 ifhitweapon
 { 
  ifwasweapon SHRINKER nullop
  else ifwasweapon SHRINKSPARK nullop
  else
  {
   ifdead
   {
    state randomshrapnel
    ifrnd 224 state randomshrapnel
    ifrnd 192 state randomshrapnel
    ifrnd 160 state randomshrapnel
    ifrnd 128 state randomshrapnel
    ifrnd 96 state randomshrapnel
    ifrnd 64 state randomshrapnel
    ifrnd 32 state randomshrapnel
    paper 1
    ifrnd 224 paper 1
    ifrnd 192 paper 1
    ifrnd 160 paper 1
    ifrnd 128 paper 1
    ifrnd 96 paper 1
    ifrnd 64 paper 1
    ifrnd 32 paper 1
    mail 1
    ifrnd 224 mail 1
    ifrnd 192 mail 1
    ifrnd 160 mail 1
    ifrnd 128 mail 1
    ifrnd 96 mail 1
    ifrnd 64 mail 1
    ifrnd 32 mail 1
    ifrnd 96 spawn RAT
    ifrnd 96 spawn RAT
    ifrnd 64 spawn RAT
    ifrnd 64 spawn RAT
    ifrnd 32 spawn RAT
    ifrnd 32 spawn RAT
    ifrnd 64 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 32 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 16 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 8 { espawn PENNY setactor[RETURN].pal 3 }
    ifrnd 16 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 8 { espawn NICKEL setactor[RETURN].pal 3 }
    ifrnd 16 { espawn DIME setactor[RETURN].pal 3 }
    ifrnd 8 { espawn DIME setactor[RETURN].pal 3 }
    ifrnd 8 { espawn QUARTER setactor[RETURN].pal 3 }
    ifvarg TEMP -1 ifvarl TEMP 13 nullop
    else
    {
     espawnvar TEMP
     setactor[RETURN].pal TEMP2
     getactorvar[THISACTOR].ACTORFLAGS TEMP3
     setactorvar[RETURN].ACTORFLAGS TEMP3
     getactorvar[THISACTOR].lotagsav TEMP4
     setactorvar[RETURN].lotagsav TEMP4
    }
    killit
   }
  }
 }
ends

state tileshuffle_1
   ifvarg WORLDTILESHUFFLES 8 nullop else jump TEMPVAR3
ends

state tileshuffle_2
   ifvarg WORLDTILESHUFFLES 8 setvar TITLESCREEN 0 else jump TEMPVAR3
ends

state getworldtile
 getcurraddress TEMPVAR3
 randvar TITLESCREEN 192
 addvar WORLDTILESHUFFLES 1

  ifvare TITLESCREEN 0 state tileshuffle_1
// Set #1 (1-32)
  else ifvare TITLESCREEN 1 { ifvarand WORLDTILEBITFIELD1 1 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 2 { ifvarand WORLDTILEBITFIELD1 2 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 3 { ifvarand WORLDTILEBITFIELD1 4 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 4 { ifvarand WORLDTILEBITFIELD1 8 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 5 { ifvarand WORLDTILEBITFIELD1 16 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 6 { ifvarand WORLDTILEBITFIELD1 32 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 7 { ifvarand WORLDTILEBITFIELD1 64 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 8 { ifvarand WORLDTILEBITFIELD1 128 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 9 { ifvarand WORLDTILEBITFIELD1 256 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 10 { ifvarand WORLDTILEBITFIELD1 512 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 11 { ifvarand WORLDTILEBITFIELD1 1024 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 12 { ifvarand WORLDTILEBITFIELD1 2048 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 13 { ifvarand WORLDTILEBITFIELD1 4096 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 14 { ifvarand WORLDTILEBITFIELD1 8192 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 15 { ifvarand WORLDTILEBITFIELD1 16384 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 16 { ifvarand WORLDTILEBITFIELD1 32768 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 17 { ifvarand WORLDTILEBITFIELD1 65536 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 18 { ifvarand WORLDTILEBITFIELD1 131072 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 19 { ifvarand WORLDTILEBITFIELD1 262144 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 20 { ifvarand WORLDTILEBITFIELD1 524288 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 21 { ifvarand WORLDTILEBITFIELD1 1048576 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 22 { ifvarand WORLDTILEBITFIELD1 2097152 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 23 { ifvarand WORLDTILEBITFIELD1 4194304 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 24 { ifvarand WORLDTILEBITFIELD1 8388608 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 25 { ifvarand WORLDTILEBITFIELD1 16777216 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 26 { ifvarand WORLDTILEBITFIELD1 33554432 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 27 { ifvarand WORLDTILEBITFIELD1 67108864 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 28 { ifvarand WORLDTILEBITFIELD1 134217728 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 29 { ifvarand WORLDTILEBITFIELD1 268435456 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 30 { ifvarand WORLDTILEBITFIELD1 536870912 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 31 { ifvarand WORLDTILEBITFIELD1 1073741824 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 32 { ifvarand WORLDTILEBITFIELD1 2147483648 state tileshuffle_1 else state tileshuffle_2 }
// Set #2 (33-64)
  else ifvare TITLESCREEN 33 { ifvarand WORLDTILEBITFIELD2 1 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 34 { ifvarand WORLDTILEBITFIELD2 2 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 35 { ifvarand WORLDTILEBITFIELD2 4 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 36 { ifvarand WORLDTILEBITFIELD2 8 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 37 { ifvarand WORLDTILEBITFIELD2 16 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 38 { ifvarand WORLDTILEBITFIELD2 32 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 39 { ifvarand WORLDTILEBITFIELD2 64 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 40 { ifvarand WORLDTILEBITFIELD2 128 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 41 { ifvarand WORLDTILEBITFIELD2 256 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 42 { ifvarand WORLDTILEBITFIELD2 512 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 43 { ifvarand WORLDTILEBITFIELD2 1024 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 44 { ifvarand WORLDTILEBITFIELD2 2048 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 45 { ifvarand WORLDTILEBITFIELD2 4096 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 46 { ifvarand WORLDTILEBITFIELD2 8192 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 47 { ifvarand WORLDTILEBITFIELD2 16384 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 48 { ifvarand WORLDTILEBITFIELD2 32768 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 49 { ifvarand WORLDTILEBITFIELD2 65536 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 50 { ifvarand WORLDTILEBITFIELD2 131072 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 51 { ifvarand WORLDTILEBITFIELD2 262144 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 52 { ifvarand WORLDTILEBITFIELD2 524288 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 53 { ifvarand WORLDTILEBITFIELD2 1048576 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 54 { ifvarand WORLDTILEBITFIELD2 2097152 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 55 { ifvarand WORLDTILEBITFIELD2 4194304 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 56 { ifvarand WORLDTILEBITFIELD2 8388608 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 57 { ifvarand WORLDTILEBITFIELD2 16777216 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 58 { ifvarand WORLDTILEBITFIELD2 33554432 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 59 { ifvarand WORLDTILEBITFIELD2 67108864 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 60 { ifvarand WORLDTILEBITFIELD2 134217728 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 61 { ifvarand WORLDTILEBITFIELD2 268435456 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 62 { ifvarand WORLDTILEBITFIELD2 536870912 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 63 { ifvarand WORLDTILEBITFIELD2 1073741824 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 64 { ifvarand WORLDTILEBITFIELD2 2147483648 state tileshuffle_1 else state tileshuffle_2 }
// Set #3 (65-96)
  else ifvare TITLESCREEN 65 { ifvarand WORLDTILEBITFIELD3 1 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 66 { ifvarand WORLDTILEBITFIELD3 2 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 67 { ifvarand WORLDTILEBITFIELD3 4 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 68 { ifvarand WORLDTILEBITFIELD3 8 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 69 { ifvarand WORLDTILEBITFIELD3 16 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 70 { ifvarand WORLDTILEBITFIELD3 32 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 71 { ifvarand WORLDTILEBITFIELD3 64 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 72 { ifvarand WORLDTILEBITFIELD3 128 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 73 { ifvarand WORLDTILEBITFIELD3 256 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 74 { ifvarand WORLDTILEBITFIELD3 512 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 75 { ifvarand WORLDTILEBITFIELD3 1024 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 76 { ifvarand WORLDTILEBITFIELD3 2048 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 77 { ifvarand WORLDTILEBITFIELD3 4096 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 78 { ifvarand WORLDTILEBITFIELD3 8192 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 79 { ifvarand WORLDTILEBITFIELD3 16384 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 80 { ifvarand WORLDTILEBITFIELD3 32768 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 81 { ifvarand WORLDTILEBITFIELD3 65536 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 82 { ifvarand WORLDTILEBITFIELD3 131072 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 83 { ifvarand WORLDTILEBITFIELD3 262144 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 84 { ifvarand WORLDTILEBITFIELD3 524288 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 85 { ifvarand WORLDTILEBITFIELD3 1048576 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 86 { ifvarand WORLDTILEBITFIELD3 2097152 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 87 { ifvarand WORLDTILEBITFIELD3 4194304 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 88 { ifvarand WORLDTILEBITFIELD3 8388608 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 89 { ifvarand WORLDTILEBITFIELD3 16777216 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 90 { ifvarand WORLDTILEBITFIELD3 33554432 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 91 { ifvarand WORLDTILEBITFIELD3 67108864 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 92 { ifvarand WORLDTILEBITFIELD3 134217728 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 93 { ifvarand WORLDTILEBITFIELD3 268435456 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 94 { ifvarand WORLDTILEBITFIELD3 536870912 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 95 { ifvarand WORLDTILEBITFIELD3 1073741824 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 96 { ifvarand WORLDTILEBITFIELD3 2147483648 state tileshuffle_1 else state tileshuffle_2 }
// Set #4 (97-128)
  else ifvare TITLESCREEN 97 { ifvarand WORLDTILEBITFIELD4 1 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 98 { ifvarand WORLDTILEBITFIELD4 2 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 99 { ifvarand WORLDTILEBITFIELD4 4 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 100 { ifvarand WORLDTILEBITFIELD4 8 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 101 { ifvarand WORLDTILEBITFIELD4 16 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 102 { ifvarand WORLDTILEBITFIELD4 32 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 103 { ifvarand WORLDTILEBITFIELD4 64 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 104 { ifvarand WORLDTILEBITFIELD4 128 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 105 { ifvarand WORLDTILEBITFIELD4 256 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 106 { ifvarand WORLDTILEBITFIELD4 512 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 107 { ifvarand WORLDTILEBITFIELD4 1024 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 108 { ifvarand WORLDTILEBITFIELD4 2048 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 109 { ifvarand WORLDTILEBITFIELD4 4096 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 110 { ifvarand WORLDTILEBITFIELD4 8192 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 111 { ifvarand WORLDTILEBITFIELD4 16384 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 112 { ifvarand WORLDTILEBITFIELD4 32768 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 113 { ifvarand WORLDTILEBITFIELD4 65536 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 114 { ifvarand WORLDTILEBITFIELD4 131072 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 115 { ifvarand WORLDTILEBITFIELD4 262144 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 116 { ifvarand WORLDTILEBITFIELD4 524288 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 117 { ifvarand WORLDTILEBITFIELD4 1048576 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 118 { ifvarand WORLDTILEBITFIELD4 2097152 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 119 { ifvarand WORLDTILEBITFIELD4 4194304 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 120 { ifvarand WORLDTILEBITFIELD4 8388608 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 121 { ifvarand WORLDTILEBITFIELD4 16777216 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 122 { ifvarand WORLDTILEBITFIELD4 33554432 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 123 { ifvarand WORLDTILEBITFIELD4 67108864 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 124 { ifvarand WORLDTILEBITFIELD4 134217728 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 125 { ifvarand WORLDTILEBITFIELD4 268435456 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 126 { ifvarand WORLDTILEBITFIELD4 536870912 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 127 { ifvarand WORLDTILEBITFIELD4 1073741824 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 128 { ifvarand WORLDTILEBITFIELD4 2147483648 state tileshuffle_1 else state tileshuffle_2 }
// Set #5 (129-160)
  else ifvare TITLESCREEN 129 { ifvarand WORLDTILEBITFIELD5 1 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 130 { ifvarand WORLDTILEBITFIELD5 2 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 131 { ifvarand WORLDTILEBITFIELD5 4 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 132 { ifvarand WORLDTILEBITFIELD5 8 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 133 { ifvarand WORLDTILEBITFIELD5 16 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 134 { ifvarand WORLDTILEBITFIELD5 32 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 135 { ifvarand WORLDTILEBITFIELD5 64 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 136 { ifvarand WORLDTILEBITFIELD5 128 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 137 { ifvarand WORLDTILEBITFIELD5 256 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 138 { ifvarand WORLDTILEBITFIELD5 512 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 139 { ifvarand WORLDTILEBITFIELD5 1024 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 140 { ifvarand WORLDTILEBITFIELD5 2048 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 141 { ifvarand WORLDTILEBITFIELD5 4096 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 142 { ifvarand WORLDTILEBITFIELD5 8192 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 143 { ifvarand WORLDTILEBITFIELD5 16384 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 144 { ifvarand WORLDTILEBITFIELD5 32768 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 145 { ifvarand WORLDTILEBITFIELD5 65536 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 146 { ifvarand WORLDTILEBITFIELD5 131072 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 147 { ifvarand WORLDTILEBITFIELD5 262144 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 148 { ifvarand WORLDTILEBITFIELD5 524288 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 149 { ifvarand WORLDTILEBITFIELD5 1048576 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 150 { ifvarand WORLDTILEBITFIELD5 2097152 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 151 { ifvarand WORLDTILEBITFIELD5 4194304 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 152 { ifvarand WORLDTILEBITFIELD5 8388608 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 153 { ifvarand WORLDTILEBITFIELD5 16777216 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 154 { ifvarand WORLDTILEBITFIELD5 33554432 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 155 { ifvarand WORLDTILEBITFIELD5 67108864 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 156 { ifvarand WORLDTILEBITFIELD5 134217728 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 157 { ifvarand WORLDTILEBITFIELD5 268435456 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 158 { ifvarand WORLDTILEBITFIELD5 536870912 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 159 { ifvarand WORLDTILEBITFIELD5 1073741824 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 160 { ifvarand WORLDTILEBITFIELD5 2147483648 state tileshuffle_1 else state tileshuffle_2 }
// Set #6 (161-192)
  else ifvare TITLESCREEN 161 { ifvarand WORLDTILEBITFIELD6 1 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 162 { ifvarand WORLDTILEBITFIELD6 2 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 163 { ifvarand WORLDTILEBITFIELD6 4 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 164 { ifvarand WORLDTILEBITFIELD6 8 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 165 { ifvarand WORLDTILEBITFIELD6 16 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 166 { ifvarand WORLDTILEBITFIELD6 32 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 167 { ifvarand WORLDTILEBITFIELD6 64 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 168 { ifvarand WORLDTILEBITFIELD6 128 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 169 { ifvarand WORLDTILEBITFIELD6 256 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 170 { ifvarand WORLDTILEBITFIELD6 512 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 171 { ifvarand WORLDTILEBITFIELD6 1024 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 172 { ifvarand WORLDTILEBITFIELD6 2048 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 173 { ifvarand WORLDTILEBITFIELD6 4096 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 174 { ifvarand WORLDTILEBITFIELD6 8192 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 175 { ifvarand WORLDTILEBITFIELD6 16384 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 176 { ifvarand WORLDTILEBITFIELD6 32768 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 177 { ifvarand WORLDTILEBITFIELD6 65536 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 178 { ifvarand WORLDTILEBITFIELD6 131072 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 179 { ifvarand WORLDTILEBITFIELD6 262144 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 180 { ifvarand WORLDTILEBITFIELD6 524288 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 181 { ifvarand WORLDTILEBITFIELD6 1048576 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 182 { ifvarand WORLDTILEBITFIELD6 2097152 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 183 { ifvarand WORLDTILEBITFIELD6 4194304 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 184 { ifvarand WORLDTILEBITFIELD6 8388608 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 185 { ifvarand WORLDTILEBITFIELD6 16777216 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 186 { ifvarand WORLDTILEBITFIELD6 33554432 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 187 { ifvarand WORLDTILEBITFIELD6 67108864 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 188 { ifvarand WORLDTILEBITFIELD6 134217728 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 189 { ifvarand WORLDTILEBITFIELD6 268435456 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 190 { ifvarand WORLDTILEBITFIELD6 536870912 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 191 { ifvarand WORLDTILEBITFIELD6 1073741824 state tileshuffle_1 else state tileshuffle_2 }
  else ifvare TITLESCREEN 192 { ifvarand WORLDTILEBITFIELD6 2147483648 state tileshuffle_1 else state tileshuffle_2 }

  ifvarg WORLDTILESHUFFLES 8 break
ends

state initialize_worldtile
 ifvare SKILLSET? 0
 {
  sizeat 8 12
  setactor[THISACTOR].shade -63 // Full-Brightness
  setactor[THISACTOR].cstat 1040 // Vertically Flat + Hitscannable
  setactor[THISACTOR].ang 0 // Starts the angle at 0
  setvar SKILLSET? 1  
 }
ends

state spin_worldtile
  getactor[THISACTOR].ang WORLDTILEANG
  addvar WORLDTILEANG 32
  setactor[THISACTOR].ang WORLDTILEANG
ends

state grab_worldtile
       savegamevar WORLDTILEBITFIELD1
       savegamevar WORLDTILEBITFIELD2
       savegamevar WORLDTILEBITFIELD3
       savegamevar WORLDTILEBITFIELD4
       savegamevar WORLDTILEBITFIELD5
       savegamevar WORLDTILEBITFIELD6
       sound TELEPORTER
       globalsound YEAH
       setvarvar fta fta_normal setvar ftq 410
       spawn TRANSPORTERBEAM
       setvar WORLDTILESHUFFLES 0
       state getworldtile
       killit
ends

state grabinventory
            ifvarand ACTORFLAGS 2 nullop
            else
            {
	  	setvarvar fta fta_normal setvar ftq 335
             globalsound FOUND_INVENTORY
             palfrom 32 0 32
            }
            setvar WORLDTILESHUFFLES 0
            state getworldtile
            state activationflag
            killit
ends

state grabequippable
            ifvarand ACTORFLAGS 2 nullop
            else
            {
	  	setvarvar fta fta_normal setvar ftq 335
             globalsound GRAB_EQUIPMENT
             palfrom 32 0 32
            }
            setvar WORLDTILESHUFFLES 0
            state getworldtile
            state activationflag
            killit
ends

state monsterpainsounds1
 ifvare temp ROTATEGUN debris SCRAP1 4
 else ifvare temp LIZTROOP soundonce PRED_PAIN
 else ifvare temp LIZTROOPSTAYPUT soundonce PRED_PAIN
 else ifvare temp LIZTROOPJETPACK soundonce PRED_PAIN
 else ifvare temp LIZTROOPSHOOT soundonce PRED_PAIN
 else ifvare temp LIZTROOPDUCKING soundonce PRED_PAIN
 else ifvare temp LIZTROOPRUNNING soundonce PRED_PAIN
 else ifvare temp LIZTROOPONTOILET soundonce PRED_PAIN
 else ifvare temp LIZTROOPJUSTSIT soundonce PRED_PAIN
 else ifvare temp LIZMAN soundonce CAPT_PAIN
 else ifvare temp LIZMANSTAYPUT soundonce CAPT_PAIN
 else ifvare temp LIZMANSPITTING soundonce CAPT_PAIN
 else ifvare temp LIZMANJUMP soundonce CAPT_PAIN
 else ifvare temp DRONE soundonce DRON_PAIN
 else
 ifvare temp OCTABRAIN
 {
  getactor[TEMP5].pal temp
  ifvare temp 14 soundonce NINE_PAIN
  else soundonce OCTA_PAIN  
 }
 else
 ifvare temp OCTABRAINSTAYPUT
 {
  getactor[TEMP5].pal temp
  ifvare temp 14 soundonce NINE_PAIN
  else soundonce OCTA_PAIN  
 }
 else ifvare temp PIGCOP soundonce PIG_PAIN
 else ifvare temp PIGCOPSTAYPUT soundonce PIG_PAIN
 else ifvare temp PIGCOPDIVE soundonce PIG_PAIN
 else ifvare temp BOSS1 soundonce BOS1_PAIN
 else ifvare temp BOSS1STAYPUT soundonce BOS1_PAIN
 else ifvare temp BOSS1SHOOT soundonce BOS1_PAIN
 else ifvare temp BOSS1LOB soundonce BOS1_PAIN
 else ifvare temp BOSS2 soundonce BOS2_PAIN
 else ifvare temp BOSS2STAYPUT soundonce BOS2_PAIN
 else ifvare temp BOSS2SHOOT soundonce BOS2_PAIN
 else ifvare temp BOSS2BREATH soundonce BOS2_PAIN
 else ifvare temp BOSS3 soundonce BOS3_PAIN
 else ifvare temp BOSS3STAYPUT soundonce BOS3_PAIN
 else ifvare temp BOSS3LOB soundonce BOS3_PAIN
 else
 ifvare temp COMMANDER
 {
  getactor[TEMP5].pal temp
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 416
  ifvare temp 25 setplayer[THISACTOR].sound_pitch -416
  soundonce COMM_PAIN
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 0
  ifvare temp 25 setplayer[THISACTOR].sound_pitch 0
 }
 else 
 ifvare temp COMMANDERSTAYPUT
 {
  getactor[TEMP5].pal temp
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 416
  ifvare temp 25 setplayer[THISACTOR].sound_pitch -416
  soundonce COMM_PAIN
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 0
  ifvare temp 25 setplayer[THISACTOR].sound_pitch 0
 }
 else ifvare temp BOSS4 soundonce BOS4_PAIN
 else ifvare temp BOSS4STAYPUT soundonce BOS4_PAIN
 else ifvare temp NEWBEAST soundonce NEWBEAST_PAIN
 else ifvare temp NEWBEASTHANG soundonce NEWBEAST_PAIN
 else ifvare temp NEWBEASTJUMP soundonce NEWBEAST_PAIN
 else ifvare temp NEWBEASTSTAYPUT soundonce NEWBEAST_PAIN
ends

state enemybloodpooldamagesnds
getactorvar[PYTHAGORASTARGET].ENEMYHP temp
ifvarg temp 0
{
 getactor[PYTHAGORASTARGET].picnum temp
 state monsterpainsounds1
}
ends

state bloodpooldamagemonster
    getactor[THISACTOR].xrepeat temp
    getactor[THISACTOR].yrepeat tempb
    ifvarg temp 6 
    {
     ifvarg tempb 6
     {
      getactor[THISACTOR].cstat TEMP
      ifvarand TEMP 32 // Flat?
      {
       getactor[THISACTOR].pal TEMP
       ifvarand TEMP 22
       {
        getactorvar[PYTHAGORASTARGET].ENEMYINVULNTIME TEMP
        ifvarl TEMP 1
        {
         getactor[PYTHAGORASTARGET].picnum tempc
         ifvare tempc TANK setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         else ifvare tempc EMPTYTANK setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         else ifvare tempc SCORPIONTANK setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         else ifvare tempc BOSS1 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
         else ifvare tempc BOSS2 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
         else ifvare tempc BOSS3 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
         else ifvare tempc BOSS4 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
         else setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          getactorvar[PYTHAGORASTARGET].ENEMYBOOTSAMOUNT TEMP
          ifvarg TEMP 0
          {
           subvar TEMP 1
           ifvarl TEMP 1
           {
            debris SCRAP1 1
            debris SCRAP2 1
            debris SCRAP3 1
            setvar TEMP 0
           }
           setactorvar[PYTHAGORASTARGET].ENEMYBOOTSAMOUNT TEMP
          }
          else
          {
           getactorvar[PYTHAGORASTARGET].ENEMYHP TEMP
           getactor[PYTHAGORASTARGET].picnum tempc
           ifvare tempc TANK
           {
            randvar tempe 2
            mulvar tempe 1
            addvar tempe 1
           }
           else
           ifvare tempc EMPTYTANK
           {
            randvar tempe 2
            mulvar tempe 1
            addvar tempe 1
           }
           else
           ifvare tempc SCORPIONTANK
           {
            randvar tempe 2
            mulvar tempe 1
            addvar tempe 1
           }
           else
           ifvare tempc BOSS1
           {
            randvar tempe 1
            mulvar tempe 1
            addvar tempe 0
           }
           else
           ifvare tempc BOSS2
           {
            randvar tempe 1
            mulvar tempe 1
            addvar tempe 0
           }
           else
           ifvare tempc BOSS3
           {
            randvar tempe 1
            mulvar tempe 1
            addvar tempe 0
           }
           else
           ifvare tempc BOSS4
           {
            randvar tempe 1
            mulvar tempe 1
            addvar tempe 0
           }
           else
           {
            randvar tempe 3
            mulvar tempe 1
            addvar tempe 1
           }
           subvarvar TEMP tempe
           ifvarg tempe 0
           {
            setvarvar SHOWDAMAGE tempe
            setvar SHOWDAMAGETYPE 0
            setvarvar SHOWDAMAGEACTORID PYTHAGORASTARGET
            state showdamage
           }
           ifvarl TEMP 1
           {
            setvar TEMP 0
            setactor[PYTHAGORASTARGET].htowner THISACTOR
            setactor[PYTHAGORASTARGET].htpicnum NEWBLOODPOOL
           }
           setactorvar[PYTHAGORASTARGET].ENEMYHP TEMP
           ifvarg tempe 0 
           {
            setactorvar[PYTHAGORASTARGET].ENEMYHPDAMAGED? 1
            state enemybloodpooldamagesnds
           }
          }
         }
        }
        else
        {
         ifrnd 16 sound INVULNITEM3
        }
       }
      }
     }
    }
ends

state getspritecenterz
 getactor[THISACTOR].xrepeat OBJECTXREPEAT
 getactor[THISACTOR].yrepeat OBJECTYREPEAT
 getactor[THISACTOR].z OBJECTZ

 setvarvar OBJECTDIFF OBJECTHEIGHT
 mulvarvar OBJECTDIFF OBJECTYREPEAT
 ifactor NEWPLUG mulvar OBJECTDIFF 2
 else { mulvar OBJECTDIFF 3 divvar OBJECTDIFF 2 }

 setvarvar OBJECTDIFF2 OBJECTHEIGHT
 mulvarvar OBJECTDIFF2 OBJECTYREPEAT
 ifactor NEWPLUG mulvar OBJECTDIFF2 4
 else { mulvar OBJECTDIFF2 13 divvar OBJECTDIFF2 2 }

 setvarvar OBJECTCENTERZ OBJECTZ
 addvarvar OBJECTCENTERZ OBJECTDIFF
ends

state setupvendingquanity // Also puts a MUSICANDSFX sprite along the wall with Cola/Snack machine textures to give off an ambient humming
   ifvarvarl ARRAYPOSITION NUMWALLS getwall[ARRAYPOSITION].hitag temp
   ifvarg temp 0
   {
    setactorvar[ARRAYPOSITION].VENDINGQUANITY temp
    setwall[ARRAYPOSITION].hitag 0
   }
   else
   {
    setactorvar[ARRAYPOSITION].VENDINGQUANITY 64
    setwall[ARRAYPOSITION].hitag 0
   }

   getwall[ARRAYPOSITION].x TEMP
   getwall[ARRAYPOSITION].y TEMP2
   getwall[ARRAYPOSITION].point2 ARRAYPOSITION2
   getwall[ARRAYPOSITION2].x TEMP4
   getwall[ARRAYPOSITION2].y TEMP5
   addvarvar TEMP TEMP4
   divvar TEMP 2
   addvarvar TEMP2 TEMP5
   divvar TEMP2 2

   espawn MUSICANDSFX
   setactor[RETURN].xrepeat 32
   setactor[RETURN].yrepeat 32
   setactor[RETURN].hitag 4096
   setactor[RETURN].lotag 918

   setactor[RETURN].x TEMP
   setactor[RETURN].y TEMP2
   getwall[ARRAYPOSITION].nextwall TEMP4
   getwall[TEMP4].nextsector TEMP4 // getactor[RETURN].sectnum TEMP4
   getsector[TEMP4].floorz TEMP5
   setactor[RETURN].z TEMP5
   setactor[RETURN].sectnum TEMP4

   setactorvar[RETURN].MUSICANDSFX_LINKTYPE 1
   setactorvar[RETURN].MUSICANDSFX_LINKID ARRAYPOSITION
   getwall[ARRAYPOSITION].picnum TEMP3
   setactorvar[RETURN].MUSICANDSFX_LINKPICNUM TEMP3

//   addlogvar TEMP
//   addlogvar TEMP2
//   addlogvar TEMP3
//   addlogvar TEMP4
//   addlogvar TEMP5
//   addlogvar RETURN
ends

state setupatmsounds // Sets a MUSICANDSFX sprite along an wall with an ATM texture to give off an ambient humming
  getwall[ARRAYPOSITION].lotag TEMP6
//  ifvare TEMP6 16384 addlogvar TEMP6
  ifvarn TEMP6 16384
  {
   getwall[ARRAYPOSITION].x TEMP
   getwall[ARRAYPOSITION].y TEMP2
   getwall[ARRAYPOSITION].point2 ARRAYPOSITION2
   getwall[ARRAYPOSITION2].x TEMP4
   getwall[ARRAYPOSITION2].y TEMP5
   addvarvar TEMP TEMP4
   divvar TEMP 2
   addvarvar TEMP2 TEMP5
   divvar TEMP2 2

   espawn MUSICANDSFX
   setactor[RETURN].xrepeat 32
   setactor[RETURN].yrepeat 32
   setactor[RETURN].hitag 1280
   setactor[RETURN].lotag 923

   setactor[RETURN].x TEMP
   setactor[RETURN].y TEMP2
   getwall[ARRAYPOSITION].nextwall TEMP4
   getwall[TEMP4].nextsector TEMP4 // getactor[RETURN].sectnum TEMP4
   getsector[TEMP4].floorz TEMP5
   setactor[RETURN].z TEMP5
   setactor[RETURN].sectnum TEMP4

   setactorvar[RETURN].MUSICANDSFX_LINKTYPE 1
   setactorvar[RETURN].MUSICANDSFX_LINKID ARRAYPOSITION
   getwall[ARRAYPOSITION].picnum TEMP3
   setactorvar[RETURN].MUSICANDSFX_LINKPICNUM TEMP3 // ATM

//   addlogvar TEMP
//   addlogvar TEMP2
//   addlogvar TEMP3
//   addlogvar TEMP4
//   addlogvar TEMP5
//   addlogvar RETURN
  }
ends

state setupmilkfridge
  getwall[ARRAYPOSITION].lotag TEMP6
//  ifvare TEMP6 16384 addlogvar TEMP6
  ifvarn TEMP6 16384
  {
   getwall[ARRAYPOSITION].x TEMP
   getwall[ARRAYPOSITION].y TEMP2
   getwall[ARRAYPOSITION].point2 ARRAYPOSITION2
   getwall[ARRAYPOSITION2].x TEMP4
   getwall[ARRAYPOSITION2].y TEMP5
   addvarvar TEMP TEMP4
   divvar TEMP 2
   addvarvar TEMP2 TEMP5
   divvar TEMP2 2

   espawn MUSICANDSFX
   setactor[RETURN].xrepeat 32
   setactor[RETURN].yrepeat 32
   setactor[RETURN].hitag 4096
   setactor[RETURN].lotag 925

   setactor[RETURN].x TEMP
   setactor[RETURN].y TEMP2
   getwall[ARRAYPOSITION].nextwall TEMP4
   getwall[TEMP4].nextsector TEMP4 // getactor[RETURN].sectnum TEMP4
   getsector[TEMP4].floorz TEMP5
   setactor[RETURN].z TEMP5
   setactor[RETURN].sectnum TEMP4

   setactorvar[RETURN].MUSICANDSFX_LINKTYPE 1
   setactorvar[RETURN].MUSICANDSFX_LINKID ARRAYPOSITION
   getwall[ARRAYPOSITION].picnum TEMP3
   setactorvar[RETURN].MUSICANDSFX_LINKPICNUM TEMP3 // ATM

//   addlogvar TEMP
//   addlogvar TEMP2
//   addlogvar TEMP3
//   addlogvar TEMP4
//   addlogvar TEMP5
//   addlogvar RETURN
  }
ends


state maxcivsincrease
 ifactor DEALER nullop
 else
 {
  addvar MAX_CIVILIANSSAVED_GAME 1
  addvar MAX_CIVILIANSSAVED_LEVEL 1
 }
 addvar MAX_CIVILIANSKILLED_GAME 1
 addvar MAX_CIVILIANSKILLED_LEVEL 1
ends

state swapscreen1
   randvar tempe 62
   ifvare tempe 0 setwall[ARRAYPOSITION].picnum 10496
   else ifvare tempe 1 setwall[ARRAYPOSITION].picnum 10497
   else ifvare tempe 2 setwall[ARRAYPOSITION].picnum 10498
   else ifvare tempe 3 setwall[ARRAYPOSITION].picnum 10499
   else ifvare tempe 4 setwall[ARRAYPOSITION].picnum 10500
   else ifvare tempe 5 setwall[ARRAYPOSITION].picnum 10501
   else ifvare tempe 6 setwall[ARRAYPOSITION].picnum 10502
   else ifvare tempe 7 setwall[ARRAYPOSITION].picnum 10503
   else ifvare tempe 8 setwall[ARRAYPOSITION].picnum 10504
   else ifvare tempe 9 setwall[ARRAYPOSITION].picnum 10505
   else ifvare tempe 10 setwall[ARRAYPOSITION].picnum 10506
   else ifvare tempe 11 setwall[ARRAYPOSITION].picnum 10544
   else ifvare tempe 12 setwall[ARRAYPOSITION].picnum 10545
   else ifvare tempe 13 setwall[ARRAYPOSITION].picnum 10546
   else ifvare tempe 14 setwall[ARRAYPOSITION].picnum 10547
   else ifvare tempe 15 setwall[ARRAYPOSITION].picnum 10548
   else ifvare tempe 16 setwall[ARRAYPOSITION].picnum 10549
   else ifvare tempe 17 setwall[ARRAYPOSITION].picnum 10550
   else ifvare tempe 18 setwall[ARRAYPOSITION].picnum 10551
   else ifvare tempe 19 setwall[ARRAYPOSITION].picnum 10552
   else ifvare tempe 20 setwall[ARRAYPOSITION].picnum 10553
   else ifvare tempe 21 setwall[ARRAYPOSITION].picnum 10554
   else ifvare tempe 22 setwall[ARRAYPOSITION].picnum 10555
   else ifvare tempe 23 setwall[ARRAYPOSITION].picnum 10556
   else ifvare tempe 24 setwall[ARRAYPOSITION].picnum 10557
   else ifvare tempe 25 setwall[ARRAYPOSITION].picnum 10558
   else ifvare tempe 26 setwall[ARRAYPOSITION].picnum 10559
   else ifvare tempe 27 setwall[ARRAYPOSITION].picnum 10560
   else ifvare tempe 28 setwall[ARRAYPOSITION].picnum 10561
   else ifvare tempe 29 setwall[ARRAYPOSITION].picnum 10562
   else ifvare tempe 30 setwall[ARRAYPOSITION].picnum 10563
   else ifvare tempe 31 setwall[ARRAYPOSITION].picnum 10564
   else ifvare tempe 32 setwall[ARRAYPOSITION].picnum 10565
   else ifvare tempe 33 setwall[ARRAYPOSITION].picnum 10566
   else ifvare tempe 34 setwall[ARRAYPOSITION].picnum 10567
   else ifvare tempe 35 setwall[ARRAYPOSITION].picnum 10568
   else ifvare tempe 36 setwall[ARRAYPOSITION].picnum 10569
   else ifvare tempe 37 setwall[ARRAYPOSITION].picnum 10570
   else ifvare tempe 38 setwall[ARRAYPOSITION].picnum 10571
   else ifvare tempe 39 setwall[ARRAYPOSITION].picnum 10572
   else ifvare tempe 40 setwall[ARRAYPOSITION].picnum 10573
   else ifvare tempe 41 setwall[ARRAYPOSITION].picnum 10574
   else ifvare tempe 42 setwall[ARRAYPOSITION].picnum 10575
   else ifvare tempe 43 setwall[ARRAYPOSITION].picnum 10576
   else ifvare tempe 44 setwall[ARRAYPOSITION].picnum 10577
   else ifvare tempe 45 setwall[ARRAYPOSITION].picnum 10578
   else ifvare tempe 46 setwall[ARRAYPOSITION].picnum 10579
   else ifvare tempe 47 setwall[ARRAYPOSITION].picnum 10580
   else ifvare tempe 48 setwall[ARRAYPOSITION].picnum 10581
   else ifvare tempe 49 setwall[ARRAYPOSITION].picnum 10582
   else ifvare tempe 50 setwall[ARRAYPOSITION].picnum 10583
   else ifvare tempe 51 setwall[ARRAYPOSITION].picnum 10584
   else ifvare tempe 52 setwall[ARRAYPOSITION].picnum 10585
   else ifvare tempe 53 setwall[ARRAYPOSITION].picnum 10586
   else ifvare tempe 54 setwall[ARRAYPOSITION].picnum 10587
   else ifvare tempe 55 setwall[ARRAYPOSITION].picnum 10588
   else ifvare tempe 56 setwall[ARRAYPOSITION].picnum 10589
   else ifvare tempe 57 setwall[ARRAYPOSITION].picnum 10590
   else ifvare tempe 58 setwall[ARRAYPOSITION].picnum 10591
   else ifvare tempe 59 setwall[ARRAYPOSITION].picnum 10592
   else ifvare tempe 60 setwall[ARRAYPOSITION].picnum 10593
   else ifvare tempe 61 setwall[ARRAYPOSITION].picnum 10594
   else ifvare tempe 62 setwall[ARRAYPOSITION].picnum 10595
ends

state initializer
 ifvare GLOBALPLAYERINIT 0
 {
  state setarrayvars
  setvar GLOBALPLAYERINIT 1
 }
 readgamevar debugtoggle
 readgamevar statusdisplaytoggle
 readgamevar dmgdisplaytoggle
 readgamevar lifebartogglemode
 readgamevar automedikittoggle
 readgamevar automantletoggle
 readgamevar footstepsndtoggle
 readgamevar normalhitscantoggle
 readgamevar vehiclepickuptoggle
 readgamevar rpgdmgdisplaytoggle

 readgamevar WORLDTILEBITFIELD1
 readgamevar WORLDTILEBITFIELD2
 readgamevar WORLDTILEBITFIELD3
 readgamevar WORLDTILEBITFIELD4
 readgamevar WORLDTILEBITFIELD5
 readgamevar WORLDTILEBITFIELD6
 setvar WORLDTILESHUFFLES 0
 state getworldtile

setvar ARRAYPOSITION 0
whilevarn ARRAYPOSITION 16383
{
// Wall IDs <.<
 ifvarl ARRAYPOSITION 16384
 {
  ifvarvarl ARRAYPOSITION NUMWALLS getwall[ARRAYPOSITION].picnum tempb else setvar tempb -1
  ifvarn tempb -1
  {
   ifvare tempb 866
   {
    /*
    gettimedate temp tempb tempc tempd tempe TEMP TEMP2 TEMP3
    addvar tempe 1
    */
    randvar tempe 4
    addvar tempe 5
    ifvare tempe 5 setwall[ARRAYPOSITION].picnum 6254 // May
    else ifvare tempe 6 setwall[ARRAYPOSITION].picnum 6255 // June
    else ifvare tempe 7 setwall[ARRAYPOSITION].picnum 6256 // July
    else ifvare tempe 8 setwall[ARRAYPOSITION].picnum 6257 // August
    else ifvare tempe 9 setwall[ARRAYPOSITION].picnum 6271 // September
   }
   else ifvare tempb 867 state setupatmsounds
   else ifvare tempb 1212 state setupvendingquanity
   else ifvare tempb 1215 state setupvendingquanity
   else ifvare tempb 4181 state setupmilkfridge // W_MILKSHELF
   else
   ifvare tempb 6258
   {
    /*
    gettimedate temp tempb tempc tempd tempe TEMP TEMP2 TEMP3
    addvar tempe 1
    */
    randvar tempe 4
    addvar tempe 5
    ifvare tempe 5 setwall[ARRAYPOSITION].picnum 6254 // May
    else ifvare tempe 6 setwall[ARRAYPOSITION].picnum 6255 // June
    else ifvare tempe 7 setwall[ARRAYPOSITION].picnum 6256 // July
    else ifvare tempe 8 setwall[ARRAYPOSITION].picnum 6257 // August
    else ifvare tempe 9 setwall[ARRAYPOSITION].picnum 6271 // September
   }
   else ifvarg tempb 7639 ifvarl tempb 7680 state setupvendingquanity
   else ifvare tempb 10750 state swapscreen1
  }
 }

// Sector IDs >.>
 ifvarl ARRAYPOSITION 4096 // Only 4096 sectors can be on a map [ID#s 0-4095]
 {
  // Check the floor tile
  ifvarvarl ARRAYPOSITION NUMSECTORS getsector[ARRAYPOSITION].floorpicnum tempb
  ifvare tempb FLOORSLIME
  {
   setsector[ARRAYPOSITION].floorpicnum NEWFLOORSLIME
   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB 0
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
   setactorvar[ARRAYPOSITION].FLOORHEATRATIO 0
  }
  else
  ifvare tempb HURTRAIL
  {
   setsector[ARRAYPOSITION].floorpicnum NEWHURTRAIL
   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB 0
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
   setactorvar[ARRAYPOSITION].FLOORHEATRATIO 0
  }
  else
  ifvare tempb FLOORPLASMA
  {
   setsector[ARRAYPOSITION].floorpicnum NEWFLOORPLASMA
   // Set up frozen floors >.>
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0
   { 
    ifvare FREEZINGMODE? 0 { randvar TEMPVAR 400 addvar TEMPVAR 1000 } // 1000 to 1400 HP
    else { randvar TEMPVAR 80 addvar TEMPVAR 200 } // 1400 to 2000 HP
   }
   else setvar TEMPVAR 1

   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA NEWFLOORPLASMA
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB NEWFLOORPLASMAFROZE
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   getsector[ARRAYPOSITION].lotag TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0 setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 1 else setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
  }
  else
  ifvare tempb PURPLELAVA
  {
   setsector[ARRAYPOSITION].floorpicnum NEWPURPLELAVA
   setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
   setactorvar[ARRAYPOSITION].FLOORHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB 0
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   setactorvar[ARRAYPOSITION].FLOORHEATRATIO 0
  }
  else
  ifvare tempb NEWFLOORPLASMA
  {
   // Set up frozen floors >.>
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0
   { 
    ifvare FREEZINGMODE? 0 { randvar TEMPVAR 400 addvar TEMPVAR 1000 } // 1000 to 1400 HP
    else { randvar TEMPVAR 80 addvar TEMPVAR 200 } // 200 to 280 HP
   }
   else setvar TEMPVAR 1

   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA NEWFLOORPLASMA
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB NEWFLOORPLASMAFROZE
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   getsector[ARRAYPOSITION].lotag TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0 setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 1 else setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
  }
  else
  ifvare tempb HOTLAVA
  {
   // Set up frozen floors >.>
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0
   { 
    ifvare FREEZINGMODE? 0 { randvar TEMPVAR 1000 addvar TEMPVAR 2500 } // 2500 to 3500 HP
    else { randvar TEMPVAR 200 addvar TEMPVAR 500 } // 500 to 700 HP
   }
   else setvar TEMPVAR 1

   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA HOTLAVA
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB HOTLAVAFROZE
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   getsector[ARRAYPOSITION].lotag TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0 setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 1 else setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
  }
  else
  ifvare tempb MEGALAVA
  {
   // Set up frozen floors >.>
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0
   { 
    ifvare FREEZINGMODE? 0 { randvar TEMPVAR 1600 addvar TEMPVAR 4000 } // 4000 to 5600 HP
    else { randvar TEMPVAR 320 addvar TEMPVAR 800 } // 800 to 1120 HP
   }
   else setvar TEMPVAR 1

   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA MEGALAVA
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB MEGALAVAFROZE
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   getsector[ARRAYPOSITION].lotag TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0 setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 1 else setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
  }
  else
  ifvare tempb ULTRALAVA
  {
   // Set up frozen floors >.>
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0
   { 
    ifvare FREEZINGMODE? 0 { randvar TEMPVAR 3000 addvar TEMPVAR 7000 } // 7000 to 10000 HP
    else { randvar TEMPVAR 600 addvar TEMPVAR 1400 } // 1400 to 2000 HP
   }
   else setvar TEMPVAR 1

   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA ULTRALAVA
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB ULTRALAVAFROZE
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   getsector[ARRAYPOSITION].lotag TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0 setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 1 else setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
  }
  else
  ifvare tempb HYPERMAGMA
  {
   // Set up frozen floors >.>
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0
   { 
    ifvare FREEZINGMODE? 0 { randvar TEMPVAR 4500 addvar TEMPVAR 10500 } // 10500 to 15000 HP
    else { randvar TEMPVAR 900 addvar TEMPVAR 2100 } // 2100 to 3000 HP
   }
   else setvar TEMPVAR 1

   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORHEALTH TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA HYPERMAGMA
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB HYPERMAGMAFROZE
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   getsector[ARRAYPOSITION].lotag TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA TEMPVAR
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   getactorvar[ARRAYPOSITION].SUBMERGABLESECTOR? tempf
   ifvare tempf 0 setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 1 else setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
  }
  else
  {
   setactorvar[ARRAYPOSITION].FLOORMAXHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORHEALTH 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERB 0
   setactorvar[ARRAYPOSITION].FLOORFREEZETIME 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA 0
   setactorvar[ARRAYPOSITION].FLOORTEMPLOTAGB 0
   setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
   setactorvar[ARRAYPOSITION].FLOORFREEZABLE? 0
   setactorvar[ARRAYPOSITION].FLOORHEATRATIO 0
  }

  // Check the ceiling tile
  ifvarvarl ARRAYPOSITION NUMSECTORS getsector[ARRAYPOSITION].ceilingpicnum tempb
  ifvare tempb FLOORSLIME setsector[ARRAYPOSITION].ceilingpicnum NEWFLOORSLIME
  else ifvare tempb HURTRAIL setsector[ARRAYPOSITION].ceilingpicnum NEWHURTRAIL
  else ifvare tempb FLOORPLASMA setsector[ARRAYPOSITION].ceilingpicnum NEWFLOORPLASMA
  else ifvare tempb PURPLELAVA setsector[ARRAYPOSITION].ceilingpicnum NEWPURPLELAVA

  setactorvar[ARRAYPOSITION].SECTORISASECRET? 0
  setactorvar[ARRAYPOSITION].SECTOREXTRA 0

  // Check the Hitag
  ifvarvarl ARRAYPOSITION NUMSECTORS getsector[ARRAYPOSITION].hitag tempb
  ifvarvarl ARRAYPOSITION NUMSECTORS setactorvar[ARRAYPOSITION].SECTOREXTRA tempb

  // Check the Lotag
  ifvarvarl ARRAYPOSITION NUMSECTORS getsector[ARRAYPOSITION].lotag tempb
  ifvare tempb 32767 { addvar MAX_SECRETSFOUND_LEVEL 1 addvar MAX_SECRETSFOUND_GAME 1 }

  setactorvar[ARRAYPOSITION].SECTORISASECRET? tempb
 }

// Thing IDs -.-
 ifvarl ARRAYPOSITION 16384
 {
  getactor[ARRAYPOSITION].statnum tempc
  ifvarn tempc 1024
  {
   getactor[ARRAYPOSITION].picnum tempc
   ifvare tempc SHARK state load_shark
   else ifvare tempc ROTATEGUN state load_rotategun 
   else ifvare tempc LIZTROOP state load_liztroop   
   else ifvare tempc LIZTROOPSTAYPUT state load_liztroop   
   else ifvare tempc LIZTROOPJETPACK state load_liztroop   
   else ifvare tempc LIZTROOPDUCKING state load_liztroop   
   else ifvare tempc LIZTROOPRUNNING state load_liztroop   
   else ifvare tempc LIZTROOPSHOOT state load_liztroop   
   else ifvare tempc LIZTROOPONTOILET state load_liztroop   
   else ifvare tempc LIZTROOPJUSTSIT state load_liztroop   
   else ifvare tempc PIGCOP state load_pigcop  
   else ifvare tempc PIGCOPDIVE state load_pigcop
   else ifvare tempc PIGCOPSTAYPUT state load_pigcop
   else ifvare tempc LIZMAN state load_lizman
   else ifvare tempc LIZMANSTAYPUT state load_lizman
   else ifvare tempc LIZMANSPITTING state load_lizman
   else ifvare tempc LIZMANJUMP state load_lizman
   else ifvare tempc DRONE state load_drone
   else ifvare tempc OCTABRAIN state load_octabrain
   else ifvare tempc OCTABRAINSTAYPUT state load_octabrain
   else ifvare tempc BOSS1 state load_boss1
   else ifvare tempc BOSS1STAYPUT state load_boss1
   else ifvare tempc BOSS1SHOOT state load_boss1
   else ifvare tempc BOSS1LOB state load_boss1
   else ifvare tempc BOSS2 state load_boss2
   else ifvare tempc BOSS2STAYPUT state load_boss2
   else ifvare tempc BOSS2SHOOT state load_boss2
   else ifvare tempc BOSS2BREATH state load_boss2
   else ifvare tempc BOSS3 state load_boss3
   else ifvare tempc BOSS3STAYPUT state load_boss3
   else ifvare tempc BOSS3LOB state load_boss3
   else ifvare tempc COMMANDER state load_commander
   else ifvare tempc COMMANDERSTAYPUT state load_commander
   else ifvare tempc TANK state load_tank
   else ifvare tempc BOSS4 state load_boss4
   else ifvare tempc BOSS4STAYPUT state load_boss4
   else ifvare tempc NEWBEAST state load_newbeast
   else ifvare tempc NEWBEASTSTAYPUT state load_newbeast
   else ifvare tempc NEWBEASTJUMP state load_newbeast
   else ifvare tempc NEWBEASTHANG state load_newbeast
   else ifvare tempc SCORPIONTANK state load_scorpiontank
 // Civilians [Tallies]
   else ifvare tempc FEM1 state maxcivsincrease
   else ifvare tempc FEM2 state maxcivsincrease
   else ifvare tempc FEM3 state maxcivsincrease
   else ifvare tempc FEM4 state maxcivsincrease
   else ifvare tempc FEM5 state maxcivsincrease
   else ifvare tempc FEM6 state maxcivsincrease
   else ifvare tempc FEM7 state maxcivsincrease
   else ifvare tempc FEM9 state maxcivsincrease
   else ifvare tempc FEM10 { state maxcivsincrease state maxcivsincrease }
   else ifvare tempc TOUGHGAL state maxcivsincrease
   else ifvare tempc NAKED1 state maxcivsincrease
   else ifvare tempc PODFEM1 state maxcivsincrease
  }
 }

// End
 addvar ARRAYPOSITION 1
 ifvarg ARRAYPOSITION 16383 break
}
ends


state checkfloors-freezetimer
   getactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE tempc
   ifvare tempc 0 // Unfrozen
   {
    getactorvar[ARRAYPOSITION].FLOORHEALTH tempd
    getactorvar[ARRAYPOSITION].FLOORMAXHEALTH tempe
    ifvarg tempe 0
    {
     setvarvar tempf tempd
     mulvar tempf 100
     divvarvar tempf tempe
     setactorvar[ARRAYPOSITION].FLOORHEATRATIO tempf
    }
    ifvarvarl tempd tempe
    {
     ifvare mainmenu 0
     {
      addvar tempd 1
      ifvare tempb NEWFLOORPLASMA { ifrnd 16 addvar tempd 1 }
      ifvare tempb HOTLAVA { ifrnd 64 addvar tempd 1 }
      ifvare tempb MEGALAVA { ifrnd 96 addvar tempd 1 }
      ifvare tempb ULTRALAVA { ifrnd 128 addvar tempd 1 }
      ifvare tempb HYPERMAGMA { ifrnd 224 addvar tempd 1 }
     }
     ifvarvarg tempd tempe setvarvar tempd tempe
     setactorvar[ARRAYPOSITION].FLOORHEALTH tempd
    }
   }
   else // Frozen
   {
    setactorvar[ARRAYPOSITION].FLOORHEATRATIO 0
    getactorvar[ARRAYPOSITION].FLOORFREEZETIME tempd
    subvar tempd 1
    ifvare mainmenu 0
    {
     ifvare tempb NEWFLOORPLASMA { ifrnd 16 subvar tempd 1 }
     ifvare tempb HOTLAVA { ifrnd 64 subvar tempd 1 }
     ifvare tempb MEGALAVA { ifrnd 96 subvar tempd 1 }
     ifvare tempb ULTRALAVA { ifrnd 128 subvar tempd 1 }
     ifvare tempb HYPERMAGMA { ifrnd 224 subvar tempd 1 }
     ifvarl tempd 0 setvar tempd 0
     setactorvar[ARRAYPOSITION].FLOORFREEZETIME tempd
    }
    ifvare tempd 0
    {
     getactorvar[ARRAYPOSITION].FLOORTEMPFREEZENUMBERA tempe
     setsector[ARRAYPOSITION].floorpicnum tempe
     getactorvar[ARRAYPOSITION].FLOORTEMPLOTAGA tempe
     setsector[ARRAYPOSITION].lotag tempe
     getactorvar[ARRAYPOSITION].FLOORMAXHEALTH tempe
     divvar tempe 2     
     setactorvar[ARRAYPOSITION].FLOORHEALTH tempe
     setactorvar[ARRAYPOSITION].FLOORTEMPFREEZESTATE 0
     ifrnd 85 sound LANDLAVA_HEAVY
     else ifrnd 128 sound LANDLAVA_LIGHT
     else sound LANDLAVA
    }
   }
ends

state checkfloors-freeze
// Sector IDs >.>
setvar ARRAYPOSITION 0
whilevarvarn ARRAYPOSITION NUMSECTORS
{
// ifvarl ARRAYPOSITION NUMSECTORS // Only 4096 sectors can be on a map [ID#s 0-4095]
// {
  // Check the floor tile
  ifvarvarl ARRAYPOSITION NUMSECTORS getsector[ARRAYPOSITION].floorpicnum tempb
  ifvare tempb NEWFLOORPLASMA state checkfloors-freezetimer
  else ifvare tempb NEWFLOORPLASMAFROZE state checkfloors-freezetimer
  else ifvare tempb HOTLAVA state checkfloors-freezetimer
  else ifvare tempb HOTLAVAFROZE state checkfloors-freezetimer
  else ifvare tempb MEGALAVA state checkfloors-freezetimer
  else ifvare tempb MEGALAVAFROZE state checkfloors-freezetimer
  else ifvare tempb ULTRALAVA state checkfloors-freezetimer
  else ifvare tempb ULTRALAVAFROZE state checkfloors-freezetimer
  else ifvare tempb HYPERMAGMA state checkfloors-freezetimer
  else ifvare tempb HYPERMAGMAFROZE state checkfloors-freezetimer
// }
 addvar ARRAYPOSITION 1
 ifvarvarg ARRAYPOSITION NUMSECTORS break
}
ends

state determineitemmultipliers
  ifrnd 240 nullop
  else
  {
   ifrnd 212 
   {
    getactorvar[RETURN].ACTORFLAGS TEMPVAR
    ifvarand TEMPVAR 128 nullop else addvar TEMPVAR 128
    setactorvar[RETURN].ACTORFLAGS TEMPVAR
   }
   else
   {
    ifrnd 212
    {
     getactorvar[RETURN].ACTORFLAGS TEMPVAR
     ifvarand TEMPVAR 256 nullop else addvar TEMPVAR 256
     setactorvar[RETURN].ACTORFLAGS TEMPVAR
    }
    else
    {
     getactorvar[RETURN].ACTORFLAGS TEMPVAR
     ifvarand TEMPVAR 384 nullop else addvar TEMPVAR 384
     setactorvar[RETURN].ACTORFLAGS TEMPVAR
    }
   }
  }
ends

state determinebonussizes
  ifrnd 240 nullop
  else
  {
   ifrnd 212 setactor[RETURN].pal 3
   else setactor[RETURN].pal 9
  }
ends

state scatterdrops
   ifvarn RETURN -1
   {
    setactorvar[RETURN].ITEMDROPPEDTIME 13
    getactor[RETURN].picnum temp
    ifvarg temp 0 ifvarl temp 11 nullop
    else
    {
     getactor[RETURN].x RANDOMSPAWNX
     ifactor ENERGYCELL_MEDIUM { randvar RANDOMMOVEMENT 56 addvar RANDOMMOVEMENT 8 }
     else ifactor ENERGYCELL_LARGE { randvar RANDOMMOVEMENT 84 addvar RANDOMMOVEMENT 12 }
     else { randvar RANDOMMOVEMENT 28 addvar RANDOMMOVEMENT 4 }
     ifrnd 128 addvarvar RANDOMSPAWNX RANDOMMOVEMENT else subvarvar RANDOMSPAWNX RANDOMMOVEMENT
     setactor[RETURN].x RANDOMSPAWNX
 
     getactor[RETURN].y RANDOMSPAWNY
     ifactor ENERGYCELL_MEDIUM { randvar RANDOMMOVEMENT 56 addvar RANDOMMOVEMENT 8 }
     else ifactor ENERGYCELL_LARGE { randvar RANDOMMOVEMENT 84 addvar RANDOMMOVEMENT 12 }
     else { randvar RANDOMMOVEMENT 28 addvar RANDOMMOVEMENT 4 }
     ifrnd 128 addvarvar RANDOMSPAWNY RANDOMMOVEMENT else subvarvar RANDOMSPAWNY RANDOMMOVEMENT
     setactor[RETURN].y RANDOMSPAWNY
    }
    state determineitemmultipliers
   }
ends

state celldrops
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn ENERGYCELL_LARGE state scatterdrops }
    else ifrnd 32 { espawn ENERGYCELL_MEDIUM state scatterdrops }
    else { espawn ENERGYCELL_SMALL state scatterdrops }    
   }
ends

state ammochange
 ifvare FLAGSSET? 0
 {
  ifvarand ACTORFLAGS 128 setvar FLAGSSET? 1 
  ifvarand ACTORFLAGS 256 setvar FLAGSSET? 1 
  ifvare PUBLICBETA? 1
  {
   ifvare LISA? 1
   {
    ifrnd 16 
    { 
     ifrnd 4
     {
      getactorvar[THISACTOR].ACTORFLAGS TEMP2
      espawn ENERGYCELL_LARGE
      setactorvar[RETURN].ACTORFLAGS TEMP2
      killit 
     }
     else
     ifrnd 32
     {
      getactorvar[THISACTOR].ACTORFLAGS TEMP2
      espawn ENERGYCELL_MEDIUM
      setactorvar[RETURN].ACTORFLAGS TEMP2
      killit 
     }
     else
     {
      getactorvar[THISACTOR].ACTORFLAGS TEMP2
      espawn ENERGYCELL_SMALL
      setactorvar[RETURN].ACTORFLAGS TEMP2
      killit 
     }    
    }
    else setvar FLAGSSET? 1 
   }
   else setvar FLAGSSET? 1 
  }
 }
ends

state checkrandomhealitem
 ifvare FLAGSSET? 0
 {
  ifvare PUBLICBETA? 1
  {
   ifvare oldskoolmode 0
   {
    ifrnd 12
    {
     ifrnd 64 // Energy Items
     {
      ifrnd 192
      {
       getactorvar[THISACTOR].ACTORFLAGS TEMP2
       espawn SMALLENERGYDRINK
       setactorvar[RETURN].ACTORFLAGS TEMP2
       killit 
      }
      else 
      {
       ifrnd 192
       {
        getactorvar[THISACTOR].ACTORFLAGS TEMP2
        espawn LARGEENERGYDRINK
        setactorvar[RETURN].ACTORFLAGS TEMP2
        killit
       }
       else
       {
        getactorvar[THISACTOR].ACTORFLAGS TEMP2
        espawn HYPERENERGYDRINK
        setactorvar[RETURN].ACTORFLAGS TEMP2
        killit
       }
      }
     }
     else // Status Items
     {
      ifrnd 85 
      {
       getactorvar[THISACTOR].ACTORFLAGS TEMP2
       espawn EYEDROP
       setactorvar[RETURN].ACTORFLAGS TEMP2
       killit 
      }
      else 
      ifrnd 128
      {
       getactorvar[THISACTOR].ACTORFLAGS TEMP2
       espawn ANTIDOTE
       setactorvar[RETURN].ACTORFLAGS TEMP2
       killit
      }
      else
      {
       getactorvar[THISACTOR].ACTORFLAGS TEMP2
       espawn FOGHORN
       setactorvar[RETURN].ACTORFLAGS TEMP2
       killit
      }
     }
    }
    else setvar FLAGSSET? 1
   }
   else setvar FLAGSSET? 1
  }
 }
ends


state checkactorheight
   ifactor LIZTROOP { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPSTAYPUT { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPJETPACK { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPSHOOT { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPDUCKING { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPONTOILET { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPJUSTSIT { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor LIZTROOPRUNNING { setvar ACTORSHEIGHT 88 setvar ACTORSWIDTH 56 }
   else ifactor SHARK { setvar ACTORSHEIGHT 44 setvar ACTORSWIDTH 56 }
   else ifactor OCTABRAIN { setvar ACTORSHEIGHT 95 setvar ACTORSWIDTH 64 }
   else ifactor OCTABRAINSTAYPUT { setvar ACTORSHEIGHT 95 setvar ACTORSWIDTH 64 }
   else ifactor SCORPIONTANK { setvar ACTORSHEIGHT 90 setvar ACTORSWIDTH 128 }
   else ifactor DRONE { setvar ACTORSHEIGHT 40 setvar ACTORSWIDTH 56 }
   else ifactor COMMANDER { setvar ACTORSHEIGHT 83 setvar ACTORSWIDTH 96 }
   else ifactor COMMANDERSTAYPUT { setvar ACTORSHEIGHT 83 setvar ACTORSWIDTH 96 }
   else ifactor TANK { setvar ACTORSHEIGHT 74 setvar ACTORSWIDTH 88 }
   else ifactor EMPTYTANK { setvar ACTORSHEIGHT 74 setvar ACTORSWIDTH 88 }
   else ifactor PIGCOP { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor PIGCOPSTAYPUT { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor PIGCOPDIVE { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor RECON { setvar ACTORSHEIGHT 60 setvar ACTORSWIDTH 88 }
   else ifactor LIZMAN { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor LIZMANSTAYPUT { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor LIZMANSPITTING { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor LIZMANJUMP { setvar ACTORSHEIGHT 87 setvar ACTORSWIDTH 64 }
   else ifactor ROTATEGUN { setvar ACTORSHEIGHT 19 setvar ACTORSWIDTH 40 }
   else ifactor BOSS1 { setvar ACTORSHEIGHT 134 setvar ACTORSWIDTH 128 }
   else ifactor BOSS1STAYPUT { setvar ACTORSHEIGHT 134 setvar ACTORSWIDTH 128 }
   else ifactor BOSS1SHOOT { setvar ACTORSHEIGHT 134 setvar ACTORSWIDTH 128 }
   else ifactor BOSS1LOB { setvar ACTORSHEIGHT 134 setvar ACTORSWIDTH 128 }
   else ifactor BOSS2 { setvar ACTORSHEIGHT 140 setvar ACTORSWIDTH 128 }
   else ifactor BOSS2STAYPUT { setvar ACTORSHEIGHT 140 setvar ACTORSWIDTH 128 }
   else ifactor BOSS2SHOOT { setvar ACTORSHEIGHT 140 setvar ACTORSWIDTH 128 }
   else ifactor BOSS2BREATH { setvar ACTORSHEIGHT 140 setvar ACTORSWIDTH 128 }
   else ifactor BOSS3 { setvar ACTORSHEIGHT 132 setvar ACTORSWIDTH 128 }
   else ifactor BOSS3STAYPUT { setvar ACTORSHEIGHT 132 setvar ACTORSWIDTH 128 }
   else ifactor BOSS3LOB { setvar ACTORSHEIGHT 132 setvar ACTORSWIDTH 128 }
   else ifactor NEWBEAST { setvar ACTORSHEIGHT 117 setvar ACTORSWIDTH 72 }
   else ifactor NEWBEASTSTAYPUT { setvar ACTORSHEIGHT 117 setvar ACTORSWIDTH 72 }
   else ifactor NEWBEASTHANG { setvar ACTORSHEIGHT 117 setvar ACTORSWIDTH 72 }
   else ifactor NEWBEASTJUMP { setvar ACTORSHEIGHT 117 setvar ACTORSWIDTH 72 }
   else ifactor BOSS4 { setvar ACTORSHEIGHT 164 setvar ACTORSWIDTH 120 }
   else ifactor BOSS4STAYPUT { setvar ACTORSHEIGHT 164 setvar ACTORSWIDTH 120 }
   else ifactor APLAYER { setvar ACTORSHEIGHT 84 setvar ACTORSWIDTH 48 }
// Duke3D NPC actors
   else ifactor PODFEM1 { setvar ACTORSHEIGHT 115 setvar ACTORSWIDTH 72 }
   else ifactor NAKED1 { setvar ACTORSHEIGHT 102 setvar ACTORSWIDTH 88 }
   else ifactor FEM1 { setvar ACTORSHEIGHT 95 setvar ACTORSWIDTH 40 }
   else ifactor FEM2 { setvar ACTORSHEIGHT 96 setvar ACTORSWIDTH 40 }
   else ifactor FEM3 { setvar ACTORSHEIGHT 90 setvar ACTORSWIDTH 32 }
   else ifactor FEM4 { setvar ACTORSHEIGHT 110 setvar ACTORSWIDTH 56 }
   else ifactor FEM5 { setvar ACTORSHEIGHT 164 setvar ACTORSWIDTH 56 }
   else ifactor FEM6 { setvar ACTORSHEIGHT 91 setvar ACTORSWIDTH 136 }
   else ifactor FEM7 { setvar ACTORSHEIGHT 94 setvar ACTORSWIDTH 40 }
   else ifactor FEM9 { setvar ACTORSHEIGHT 113 setvar ACTORSWIDTH 96 }
   else ifactor FEM10 { setvar ACTORSHEIGHT 57 setvar ACTORSWIDTH 72 }
   else ifactor TOUGHGAL { setvar ACTORSHEIGHT 92 setvar ACTORSWIDTH 40 }
   else ifactor WOMAN { setvar ACTORSHEIGHT 97 setvar ACTORSWIDTH 40 }
   else ifactor ROBOTDOG { setvar ACTORSHEIGHT 38 setvar ACTORSWIDTH 24 }
   else ifactor ROBOTDOG2 { setvar ACTORSHEIGHT 35 setvar ACTORSWIDTH 40 }
// Extraneous NPC actors
   else ifactor PRESIDENTCLINTON { setvar ACTORSHEIGHT 163 setvar ACTORSWIDTH 112 }
   else ifactor DANCE1 { setvar ACTORSHEIGHT 156 setvar ACTORSWIDTH 56 }
   else ifactor DANCE2 { setvar ACTORSHEIGHT 128 setvar ACTORSWIDTH 48 }
   else ifactor DANCE3 { setvar ACTORSHEIGHT 154 setvar ACTORSWIDTH 56 }
   else ifactor DANCE5 { setvar ACTORSHEIGHT 164 setvar ACTORSWIDTH 64 }
   else ifactor DANCE6 { setvar ACTORSHEIGHT 174 setvar ACTORSWIDTH 72 }
   else ifactor DANCE7 { setvar ACTORSHEIGHT 166 setvar ACTORSWIDTH 56 }
   else ifactor DANCE9 { setvar ACTORSHEIGHT 147 setvar ACTORSWIDTH 112 }
   else ifactor STAND1 { setvar ACTORSHEIGHT 170 setvar ACTORSWIDTH 56 }
   else ifactor DEALER { setvar ACTORSHEIGHT 129 setvar ACTORSWIDTH 56 }
   else ifactor STAND3 { setvar ACTORSHEIGHT 127 setvar ACTORSWIDTH 40 }
   else ifactor STAND4 { setvar ACTORSHEIGHT 162 setvar ACTORSWIDTH 56 }
   else ifactor WOLFDUDE { setvar ACTORSHEIGHT 66 setvar ACTORSWIDTH 32 }
   else ifactor COP1 { setvar ACTORSHEIGHT 130 setvar ACTORSWIDTH 40 }
   else ifactor PUNKDUDE { setvar ACTORSHEIGHT 197 setvar ACTORSWIDTH 64 }
   else ifactor COP2 { setvar ACTORSHEIGHT 177 setvar ACTORSWIDTH 48 }
   else ifactor SITTINGDUDE { setvar ACTORSHEIGHT 120 setvar ACTORSWIDTH 64 }
   else ifactor ANIMEGIRL1 { setvar ACTORSHEIGHT 168 setvar ACTORSWIDTH 103 }
   else ifactor ANIMEGIRL2 { setvar ACTORSHEIGHT 175 setvar ACTORSWIDTH 50 }
   else ifactor ANIMEGIRL3 { setvar ACTORSHEIGHT 120 setvar ACTORSWIDTH 118 }
   else ifactor ANIMEGIRL4 { setvar ACTORSHEIGHT 132 setvar ACTORSWIDTH 77 }
ends

state rankstarplayer
 ifvare STARCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn PLAYERLEVEL 0
   {
    espawn LEVELRANKSTAR
    setactorvar[THISACTOR].STARCHILD RETURN
    setactorvar[RETURN].STARPARENT THISACTOR
   }
  }
 }

 ifvare HPBARCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn MAXHITPOINTS 0
   {
    espawn HPLIFEMETER // HPLIFEMETER represents the actor for HP Bars
    setactorvar[THISACTOR].HPBARCHILD RETURN
    setactorvar[RETURN].HPBARPARENT THISACTOR
   }
  }
 }

 ifvare APBARCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn MAXARMORPOINTS 0
   {
    espawn APLIFEMETER // APLIFEMETER represents the actor for AP Bars
    setactorvar[THISACTOR].APBARCHILD RETURN
    setactorvar[RETURN].APBARPARENT THISACTOR
   }
  }
 }

 ifvare POWERUPSTRIPCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn POWERUPBITFIELD 0
   {
    espawn POWERUPICONSTRIP
    setactorvar[THISACTOR].POWERUPSTRIPCHILD RETURN
    setactorvar[RETURN].POWERUPSTRIPPARENT THISACTOR
   }
  }
 }

 ifvare POINTERICONCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvare RADARARROWSET? 0 // Sets the arrow immediately instead of waiting for the actor to see you
   {
    espawn POINTERARROW // POINTERARROW is for when the actor can be seen on the Mercury Computer's Radar
    setactorvar[THISACTOR].POINTERICONCHILD RETURN
    setactorvar[RETURN].POINTERICONPARENT THISACTOR
    setvar RADARARROWSET? 1
   }
  }
 }
 state checkactorheight
ends

state rankstarbeta
ifvarg ENEMYHP 0
{
 ifvare STARCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn ENEMYLEVEL 0
   {
    espawn LEVELRANKSTAR
    setactorvar[THISACTOR].STARCHILD RETURN
    setactorvar[RETURN].STARPARENT THISACTOR
   }
  }
 }

 ifvare HPBARCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn ENEMYMAXHP 0
   {
    espawn HPLIFEMETER // HPLIFEMETER represents the actor for HP Bars
    setactorvar[THISACTOR].HPBARCHILD RETURN
    setactorvar[RETURN].HPBARPARENT THISACTOR
   }
  }
 }

 ifvare APBARCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn ENEMYMAXAP 0
   {
    espawn APLIFEMETER // APLIFEMETER represents the actor for AP Bars
    setactorvar[THISACTOR].APBARCHILD RETURN
    setactorvar[RETURN].APBARPARENT THISACTOR
   }
  }
 }

 ifvare POWERUPSTRIPCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn ENEMYPOWERUPBITFIELD 0
   {
    espawn POWERUPICONSTRIP
    setactorvar[THISACTOR].POWERUPSTRIPCHILD RETURN
    setactorvar[RETURN].POWERUPSTRIPPARENT THISACTOR
   }
  }
 }

 ifvare POINTERICONCHILD -1
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvare RADARARROWSET? 0 // Sets the arrow immediately instead of waiting for the actor to see you
   {
    ifvare debugtoggle 1
    {
     espawn POINTERARROW // POINTERARROW is for when the actor can be seen on the Mercury Computer's Radar
     setactorvar[THISACTOR].POINTERICONCHILD RETURN
     setactorvar[RETURN].POINTERICONPARENT THISACTOR
     setvar RADARARROWSET? 1
    }
    else
    ifvare HAVEMERCURYCOMPUTER? 1
    {
     espawn POINTERARROW // POINTERARROW is for when the actor can be seen on the Mercury Computer's Radar
     setactorvar[THISACTOR].POINTERICONCHILD RETURN
     setactorvar[RETURN].POINTERICONPARENT THISACTOR
     setvar RADARARROWSET? 1
    }
   }
  }
/*
  else
  {
   ifvare RADARARROWSET? 0 // Sets the arrow immediately instead of waiting for the actor to see you
   {
     espawn POINTERARROW // POINTERARROW is for when the actor can be seen on the Mercury Computer's Radar
     setactorvar[THISACTOR].POINTERICONCHILD RETURN
     setactorvar[RETURN].POINTERICONPARENT THISACTOR
     setvar RADARARROWSET? 1
   }
  }
*/
 }
 state checkactorheight
}
ends

state getcharactergender
 ifvarg CHARACTERSELECTED? 0 ifvarl CHARACTERSELECTED? 4 setvar GENDER? 0
 ifvare CHARACTERSELECTED? 4 setvar GENDER? 1
 ifvarg CHARACTERSELECTED? 4 ifvarl CHARACTERSELECTED? 8 setvar GENDER? 0
 ifvare CHARACTERSELECTED? 8 setvar GENDER? 1
 ifvare CHARACTERSELECTED? 9 setvar GENDER? 0
 ifvarg CHARACTERSELECTED? 9 ifvarl CHARACTERSELECTED? 16 setvar GENDER? 1
ends

state calculateaveragelevel
 setvar AVERAGELEVEL 0
 ifvare DUKE? 1
 {
  setvar CHARACTERARRAY 1
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare JACK? 1
 {
  setvar CHARACTERARRAY 2
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare BUBSY? 1
 {
  setvar CHARACTERARRAY 3
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare AMI? 1
 {
  setvar CHARACTERARRAY 4
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare LOWANG? 1
 {
  setvar CHARACTERARRAY 5
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare ESSENCE? 1
 {
  setvar CHARACTERARRAY 6
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare TED? 1
 {
  setvar CHARACTERARRAY 7
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare LISA? 1
 {
  setvar CHARACTERARRAY 8
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare CYBANIS? 1
 {
  setvar CHARACTERARRAY 9
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare NETHRA? 1 
 {
  setvar CHARACTERARRAY 10
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare PAULA? 1 
 {
  setvar CHARACTERARRAY 11
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare LORI? 1
 {
  setvar CHARACTERARRAY 12
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare MINAKO? 1
 {
  setvar CHARACTERARRAY 13
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare MYSTERY1? 1
 {
  setvar CHARACTERARRAY 14
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvare MAKEN? 1 
 {
  setvar CHARACTERARRAY 15
  getactorvar[CHARACTERARRAY].CHARACTERLEVEL templevel1
  addvarvar AVERAGELEVEL templevel1
 }
 ifvarn PARTYSIZE 0 divvarvar AVERAGELEVEL PARTYSIZE
ends

state playerabsorbdamage
      setvarvar ABSORBEDDAMAGE PLAYERDAMAGE
      addvarvar CURRENTHITPOINTS PLAYERDAMAGE
      ifvarvarg CURRENTHITPOINTS MAXHITPOINTSATOMIC setvarvar CURRENTHITPOINTS MAXHITPOINTSATOMIC
      setvarvar TEMPHEALTH ABSORBEDDAMAGE
      state showhealing_playerhp

      setactor[PLAYERID].htextra -1
      stopsound NODAMAGE
      globalsound ABSORB_DAMAGE
      palfrom 32 64 64 64
      setvar PLAYERDAMAGE 0 
      qsprintf 336 337 ABSORBEDDAMAGE
      setvarvar fta fta_normal setvar ftq 336
ends

state calcplayermaxhealthatomic
  setvarvar MAXHITPOINTSATOMIC MAXHITPOINTS
  mulvar MAXHITPOINTSATOMIC 2
  ifvarvarg MAXHITPOINTSATOMIC STATLIMITATOMIC setvarvar MAXHITPOINTSATOMIC STATLIMITATOMIC
ends

state calcplayermaxarmoratomic
  setvarvar MAXARMORPOINTSATOMIC MAXARMORPOINTS
  mulvar MAXARMORPOINTSATOMIC 2
  ifvarvarg MAXARMORPOINTSATOMIC STATLIMITATOMIC setvarvar MAXARMORPOINTSATOMIC STATLIMITATOMIC
ends

state checkenemypickuphealth
 getactorvar[ITEMSEEK].ENEMYHP ITEMSEEKB
ends

state resetitemtarget
 setactorvar[ITEMSEEK].ITEMTARGET -1
ends

state fullpower_alterations
  getactorvar[CHARACTERARRAY].CHARACTERMAXHP TEMP7 mulvar TEMP7 2
  setactorvar[CHARACTERARRAY].CHARACTERFA TEMP7
  getactorvar[CHARACTERARRAY].CHARACTERMAXHP TEMP7 mulvar TEMP7 2
  setactorvar[CHARACTERARRAY].CHARACTERHP TEMP7
  getactorvar[CHARACTERARRAY].CHARACTERMAXEP TEMP7 mulvar TEMP7 2
  setactorvar[CHARACTERARRAY].CHARACTEREP TEMP7
  getactorvar[CHARACTERARRAY].CHARACTERMAXAP TEMP7 mulvar TEMP7 2
  setactorvar[CHARACTERARRAY].CHARACTERAP TEMP7
  setactorvar[CHARACTERARRAY].CHARACTERAPABSORB 1000
ends

state fullpower
  setvar CONTINUES? 5
  setvar BUBSYLIVES 8
  setvar CHARACTERARRAY 1 state fullpower_alterations
  setvar CHARACTERARRAY 2 state fullpower_alterations
  setvar CHARACTERARRAY 3 state fullpower_alterations
  setvar CHARACTERARRAY 4 state fullpower_alterations
  setvar CHARACTERARRAY 5 state fullpower_alterations
  setvar CHARACTERARRAY 6 state fullpower_alterations
  setvar CHARACTERARRAY 7 state fullpower_alterations
  setvar CHARACTERARRAY 8 state fullpower_alterations
  setvar CHARACTERARRAY 9 state fullpower_alterations
  setvar CHARACTERARRAY 10 state fullpower_alterations
  setvar CHARACTERARRAY 11 state fullpower_alterations
  setvar CHARACTERARRAY 12 state fullpower_alterations
  setvar CHARACTERARRAY 13 state fullpower_alterations
  setvar CHARACTERARRAY 14 state fullpower_alterations
  setvar CHARACTERARRAY 15 state fullpower_alterations
  setvarvar FIRSTAIDCURRENT MAXHITPOINTSATOMIC
  setvarvar CURRENTHITPOINTS MAXHITPOINTSATOMIC
  setvarvar CURRENTENERGYPOINTS MAXENERGYPOINTSATOMIC
  setvarvar CURRENTARMORPOINTS MAXARMORPOINTSATOMIC
  setvar ARMORPERCENT 1000
ends

state neardeath_alterations
  setactorvar[CHARACTERARRAY].CHARACTERFA 0
  setactorvar[CHARACTERARRAY].CHARACTERHP 0
  setactorvar[CHARACTERARRAY].CHARACTEREP 0
  setactorvar[CHARACTERARRAY].CHARACTERAP 0
  setactorvar[CHARACTERARRAY].CHARACTERAPABSORB 0
ends

state neardeath
  setvar CONTINUES? 0
  setvar BUBSYLIVES 0
  setvar CHARACTERARRAY 1 state neardeath_alterations
  setvar CHARACTERARRAY 2 state neardeath_alterations
  setvar CHARACTERARRAY 3 state neardeath_alterations
  setvar CHARACTERARRAY 4 state neardeath_alterations
  setvar CHARACTERARRAY 5 state neardeath_alterations
  setvar CHARACTERARRAY 6 state neardeath_alterations
  setvar CHARACTERARRAY 7 state neardeath_alterations
  setvar CHARACTERARRAY 8 state neardeath_alterations
  setvar CHARACTERARRAY 9 state neardeath_alterations
  setvar CHARACTERARRAY 10 state neardeath_alterations
  setvar CHARACTERARRAY 11 state neardeath_alterations
  setvar CHARACTERARRAY 12 state neardeath_alterations
  setvar CHARACTERARRAY 13 state neardeath_alterations
  setvar CHARACTERARRAY 14 state neardeath_alterations
  setvar CHARACTERARRAY 15 state neardeath_alterations
  setvar FIRSTAIDCURRENT 0
  setvar CURRENTHITPOINTS 1
  setvar CURRENTENERGYPOINTS 0
  setvar CURRENTARMORPOINTS 0
  setvar ARMORPERCENT 0
ends

state instantdeath_alterations
  setactorvar[CHARACTERARRAY].CHARACTERFA 0
  setactorvar[CHARACTERARRAY].CHARACTERHP 0
  setactorvar[CHARACTERARRAY].CHARACTEREP 0
  setactorvar[CHARACTERARRAY].CHARACTERAP 0
  setactorvar[CHARACTERARRAY].CHARACTERAPABSORB 0
ends

state killallcharacters // for "instant death" situations [bottomless pit, space sectors, or just goofing around :P]
  setvar CONTINUES? 0
  setvar BUBSYLIVES 0
  setvar CHARACTERARRAY 1 state instantdeath_alterations
  setvar CHARACTERARRAY 2 state instantdeath_alterations
  setvar CHARACTERARRAY 3 state instantdeath_alterations
  setvar CHARACTERARRAY 4 state instantdeath_alterations
  setvar CHARACTERARRAY 5 state instantdeath_alterations
  setvar CHARACTERARRAY 6 state instantdeath_alterations
  setvar CHARACTERARRAY 7 state instantdeath_alterations
  setvar CHARACTERARRAY 8 state instantdeath_alterations
  setvar CHARACTERARRAY 9 state instantdeath_alterations
  setvar CHARACTERARRAY 10 state instantdeath_alterations
  setvar CHARACTERARRAY 11 state instantdeath_alterations
  setvar CHARACTERARRAY 12 state instantdeath_alterations
  setvar CHARACTERARRAY 13 state instantdeath_alterations
  setvar CHARACTERARRAY 14 state instantdeath_alterations
  setvar CHARACTERARRAY 15 state instantdeath_alterations
  setvar FIRSTAIDCURRENT 0
  setvar CURRENTHITPOINTS 0
  setvar CURRENTENERGYPOINTS 0
  setvar CURRENTARMORPOINTS 0
  setvar ARMORPERCENT 0
ends

state useswitchcheckwall
  ifvarn hitwall -1 getwall[hitwall].overpicnum hitwalloverpicnum
  ifvare hitwalloverpicnum W_FORCEFIELD setvar TEMP2 0
  else ifvare hitwalloverpicnum W_FORCEFIELDBLANK setvar TEMP2 0
  else ifvare hitwalloverpicnum BIGFORCE setvar TEMP2 0
  else setvar TEMP2 1
ends

state rotateprojectilestraight
  getactor[THISACTOR].x ROTATEXORIGIN
  getactor[THISACTOR].y ROTATEYORIGIN
  getplayer[THISACTOR].ang TEMP
  setvarvar ROTATEXPOINT ROTATEXORIGIN
  addvar ROTATEXPOINT 256 // 384 // NOTE: APPEARANTLY ROTATEXPOINT IS THE KEY HERE FOR PROPER FRONT ALIGNMENT
  setvarvar ROTATEYPOINT ROTATEYORIGIN
  subvar ROTATEYPOINT 0
  rotatepoint ROTATEXORIGIN ROTATEYORIGIN ROTATEXPOINT ROTATEYPOINT TEMP ROTATEXRETURN ROTATEYRETURN
  setactor[RETURN].x ROTATEXRETURN
  setactor[RETURN].y ROTATEYRETURN
ends

state rotateprojectileleft
  getactor[THISACTOR].x ROTATEXORIGIN
  getactor[THISACTOR].y ROTATEYORIGIN
  getplayer[THISACTOR].ang TEMP
  setvarvar ROTATEXPOINT ROTATEXORIGIN
  addvar ROTATEXPOINT 256 // 384 // NOTE: APPEARANTLY ROTATEXPOINT IS THE KEY HERE FOR PROPER FRONT ALIGNMENT
  setvarvar ROTATEYPOINT ROTATEYORIGIN
  subvar ROTATEYPOINT 128
  rotatepoint ROTATEXORIGIN ROTATEYORIGIN ROTATEXPOINT ROTATEYPOINT TEMP ROTATEXRETURN ROTATEYRETURN
  setactor[RETURN].x ROTATEXRETURN
  setactor[RETURN].y ROTATEYRETURN
ends

state rotateprojectileright
  getactor[THISACTOR].x ROTATEXORIGIN
  getactor[THISACTOR].y ROTATEYORIGIN
  getplayer[THISACTOR].ang TEMP
  setvarvar ROTATEXPOINT ROTATEXORIGIN
  addvar ROTATEXPOINT 256 // 384 // NOTE: APPEARANTLY ROTATEXPOINT IS THE KEY HERE FOR PROPER FRONT ALIGNMENT
  setvarvar ROTATEYPOINT ROTATEYORIGIN
  addvar ROTATEYPOINT 128
  rotatepoint ROTATEXORIGIN ROTATEYORIGIN ROTATEXPOINT ROTATEYPOINT TEMP ROTATEXRETURN ROTATEYRETURN
  setactor[RETURN].x ROTATEXRETURN
  setactor[RETURN].y ROTATEYRETURN
ends

state rotatepointtest
				getplayer[THISACTOR].posx ROTATEXORIGIN
				getplayer[THISACTOR].posy ROTATEYORIGIN
				setvarvar ROTATEXPOINT ROTATEXORIGIN
				setvarvar ROTATEYPOINT ROTATEYORIGIN
				ifvare ROTATEXINTERVAL 0 { setvar ROTATEXALTER 0 setvar ROTATEYALTER 0 }
				else ifvare ROTATEXINTERVAL 1 { setvar ROTATEXALTER 32 setvar ROTATEYALTER 32 }
				else ifvare ROTATEXINTERVAL 2 { setvar ROTATEXALTER 64 setvar ROTATEYALTER 64 }
				else ifvare ROTATEXINTERVAL 3 { setvar ROTATEXALTER 96 setvar ROTATEYALTER 96 }
				else ifvare ROTATEXINTERVAL 4 { setvar ROTATEXALTER 128 setvar ROTATEYALTER 128 }
				else ifvare ROTATEXINTERVAL 5 { setvar ROTATEXALTER 160 setvar ROTATEYALTER 160 }
				else ifvare ROTATEXINTERVAL 6 { setvar ROTATEXALTER 196 setvar ROTATEYALTER 196 }
				else ifvare ROTATEXINTERVAL 7 { setvar ROTATEXALTER 224 setvar ROTATEYALTER 224 }
				else ifvare ROTATEXINTERVAL 8 { setvar ROTATEXALTER 256 setvar ROTATEYALTER 256 }
				else ifvare ROTATEXINTERVAL 9 { setvar ROTATEXALTER 224 setvar ROTATEYALTER 224 }
				else ifvare ROTATEXINTERVAL 10 { setvar ROTATEXALTER 196 setvar ROTATEYALTER 196 }
				else ifvare ROTATEXINTERVAL 11 { setvar ROTATEXALTER 160 setvar ROTATEYALTER 160 }
				else ifvare ROTATEXINTERVAL 12 { setvar ROTATEXALTER 128 setvar ROTATEYALTER 128 }
				else ifvare ROTATEXINTERVAL 13 { setvar ROTATEXALTER 96 setvar ROTATEYALTER 96 }
				else ifvare ROTATEXINTERVAL 14 { setvar ROTATEXALTER 64 setvar ROTATEYALTER 64 }
				else ifvare ROTATEXINTERVAL 15 { setvar ROTATEXALTER 32 setvar ROTATEYALTER 32 }
				else ifvare ROTATEXINTERVAL 16 { setvar ROTATEXALTER 0 setvar ROTATEYALTER 0 }
				else ifvare ROTATEXINTERVAL 17 { setvar ROTATEXALTER -32 setvar ROTATEYALTER -32 }
				else ifvare ROTATEXINTERVAL 18 { setvar ROTATEXALTER -64 setvar ROTATEYALTER -64 }
				else ifvare ROTATEXINTERVAL 19 { setvar ROTATEXALTER -96 setvar ROTATEYALTER -96 }
				else ifvare ROTATEXINTERVAL 20 { setvar ROTATEXALTER -128 setvar ROTATEYALTER -128 }
				else ifvare ROTATEXINTERVAL 21 { setvar ROTATEXALTER -160 setvar ROTATEYALTER -160 }
				else ifvare ROTATEXINTERVAL 22 { setvar ROTATEXALTER -196 setvar ROTATEYALTER -196 }
				else ifvare ROTATEXINTERVAL 23 { setvar ROTATEXALTER -224 setvar ROTATEYALTER -224 }
				else ifvare ROTATEXINTERVAL 24 { setvar ROTATEXALTER -256 setvar ROTATEYALTER -256 }
				else ifvare ROTATEXINTERVAL 25 { setvar ROTATEXALTER -224 setvar ROTATEYALTER -224 }
				else ifvare ROTATEXINTERVAL 26 { setvar ROTATEXALTER -196 setvar ROTATEYALTER -196 }
				else ifvare ROTATEXINTERVAL 27 { setvar ROTATEXALTER -160 setvar ROTATEYALTER -160 }
				else ifvare ROTATEXINTERVAL 28 { setvar ROTATEXALTER -128 setvar ROTATEYALTER -128 }
				else ifvare ROTATEXINTERVAL 29 { setvar ROTATEXALTER -96 setvar ROTATEYALTER -96 }
				else ifvare ROTATEXINTERVAL 30 { setvar ROTATEXALTER -64 setvar ROTATEYALTER -64 }
				else ifvare ROTATEXINTERVAL 31 { setvar ROTATEXALTER -32 setvar ROTATEYALTER -32 }
				addvar ROTATEXINTERVAL 1
				ifvarg ROTATEXINTERVAL 30 setvar ROTATEXINTERVAL 0
				addvarvar ROTATEXPOINT ROTATEXALTER
				addvarvar ROTATEYPOINT ROTATEYALTER
				addvar ROTATEANGLE 96
				rotatepoint ROTATEXORIGIN ROTATEYORIGIN ROTATEXPOINT ROTATEYPOINT ROTATEANGLE ROTATEXRETURN ROTATEYRETURN

				getplayer[THISACTOR].posz ROTATEZORIGIN
				addvar ROTATEZORIGIN 8144
				setvarvar ROTATEZPOINT ROTATEZORIGIN
				setvarvar ROTATEZALTER ROTATEZINTERVAL
				mulvar ROTATEZALTER 1024
				subvarvar ROTATEZPOINT ROTATEZALTER
				setvarvar ROTATEZRETURN ROTATEZPOINT

				espawn EXPLOSION2 sound PIPEBOMB_EXPLODE sound ICE_EXPLODE
				setactor[RETURN].pal 1
				setactor[RETURN].x ROTATEXRETURN
				setactor[RETURN].y ROTATEYRETURN
				setactor[RETURN].z ROTATEZRETURN
				setactor[RETURN].xrepeat 16
				setactor[RETURN].yrepeat 16
				setactor[RETURN].cstat 642
ends

state rotatepointtest2
				getplayer[THISACTOR].posx ROTATEXORIGIN
				getplayer[THISACTOR].posy ROTATEYORIGIN
				setvarvar ROTATEXPOINT ROTATEXORIGIN
				setvarvar ROTATEYPOINT ROTATEYORIGIN
				ifvare ROTATEYINTERVAL 0 { setvar ROTATEXALTER 0 setvar ROTATEYALTER 0 }
				else ifvare ROTATEYINTERVAL 1 { setvar ROTATEXALTER -32 setvar ROTATEYALTER -32 }
				else ifvare ROTATEYINTERVAL 2 { setvar ROTATEXALTER -64 setvar ROTATEYALTER -64 }
				else ifvare ROTATEYINTERVAL 3 { setvar ROTATEXALTER -96 setvar ROTATEYALTER -96 }
				else ifvare ROTATEYINTERVAL 4 { setvar ROTATEXALTER -128 setvar ROTATEYALTER -128 }
				else ifvare ROTATEYINTERVAL 5 { setvar ROTATEXALTER -160 setvar ROTATEYALTER -160 }
				else ifvare ROTATEYINTERVAL 6 { setvar ROTATEXALTER -196 setvar ROTATEYALTER -196 }
				else ifvare ROTATEYINTERVAL 7 { setvar ROTATEXALTER -224 setvar ROTATEYALTER -224 }
				else ifvare ROTATEYINTERVAL 8 { setvar ROTATEXALTER -256 setvar ROTATEYALTER -256 }
				else ifvare ROTATEYINTERVAL 9 { setvar ROTATEXALTER -224 setvar ROTATEYALTER -224 }
				else ifvare ROTATEYINTERVAL 10 { setvar ROTATEXALTER -196 setvar ROTATEYALTER -196 }
				else ifvare ROTATEYINTERVAL 11 { setvar ROTATEXALTER -160 setvar ROTATEYALTER -160 }
				else ifvare ROTATEYINTERVAL 12 { setvar ROTATEXALTER -128 setvar ROTATEYALTER -128 }
				else ifvare ROTATEYINTERVAL 13 { setvar ROTATEXALTER -96 setvar ROTATEYALTER -96 }
				else ifvare ROTATEYINTERVAL 14 { setvar ROTATEXALTER -64 setvar ROTATEYALTER -64 }
				else ifvare ROTATEYINTERVAL 15 { setvar ROTATEXALTER -32 setvar ROTATEYALTER -32 }
				else ifvare ROTATEYINTERVAL 16 { setvar ROTATEXALTER 0 setvar ROTATEYALTER 0 }
				else ifvare ROTATEYINTERVAL 17 { setvar ROTATEXALTER 32 setvar ROTATEYALTER 32 }
				else ifvare ROTATEYINTERVAL 18 { setvar ROTATEXALTER 64 setvar ROTATEYALTER 64 }
				else ifvare ROTATEYINTERVAL 19 { setvar ROTATEXALTER 96 setvar ROTATEYALTER 96 }
				else ifvare ROTATEYINTERVAL 20 { setvar ROTATEXALTER 128 setvar ROTATEYALTER 128 }
				else ifvare ROTATEYINTERVAL 21 { setvar ROTATEXALTER 160 setvar ROTATEYALTER 160 }
				else ifvare ROTATEYINTERVAL 22 { setvar ROTATEXALTER 196 setvar ROTATEYALTER 196 }
				else ifvare ROTATEYINTERVAL 23 { setvar ROTATEXALTER 224 setvar ROTATEYALTER 224 }
				else ifvare ROTATEYINTERVAL 24 { setvar ROTATEXALTER 256 setvar ROTATEYALTER 256 }
				else ifvare ROTATEYINTERVAL 25 { setvar ROTATEXALTER 224 setvar ROTATEYALTER 224 }
				else ifvare ROTATEYINTERVAL 26 { setvar ROTATEXALTER 196 setvar ROTATEYALTER 196 }
				else ifvare ROTATEYINTERVAL 27 { setvar ROTATEXALTER 160 setvar ROTATEYALTER 160 }
				else ifvare ROTATEYINTERVAL 28 { setvar ROTATEXALTER 128 setvar ROTATEYALTER 128 }
				else ifvare ROTATEYINTERVAL 29 { setvar ROTATEXALTER 96 setvar ROTATEYALTER 96 }
				else ifvare ROTATEYINTERVAL 30 { setvar ROTATEXALTER 64 setvar ROTATEYALTER 64 }
				else ifvare ROTATEYINTERVAL 31 { setvar ROTATEXALTER 32 setvar ROTATEYALTER 32 }
				addvar ROTATEYINTERVAL 1
				ifvarg ROTATEYINTERVAL 30 setvar ROTATEYINTERVAL 0
				addvarvar ROTATEXPOINT ROTATEXALTER
				addvarvar ROTATEYPOINT ROTATEYALTER
				addvar ROTATEANGLE 96
				rotatepoint ROTATEXORIGIN ROTATEYORIGIN ROTATEXPOINT ROTATEYPOINT ROTATEANGLE ROTATEXRETURN ROTATEYRETURN

				getplayer[THISACTOR].posz ROTATEZORIGIN
				addvar ROTATEZORIGIN 8144
				setvarvar ROTATEZPOINT ROTATEZORIGIN
				setvarvar ROTATEZALTER ROTATEZINTERVAL
				mulvar ROTATEZALTER 1024
				subvarvar ROTATEZPOINT ROTATEZALTER
				setvarvar ROTATEZRETURN ROTATEZPOINT

				espawn EXPLOSION2 sound PIPEBOMB_EXPLODE sound ICE_EXPLODE
				setactor[RETURN].pal 1
				setactor[RETURN].x ROTATEXRETURN
				setactor[RETURN].y ROTATEYRETURN
				setactor[RETURN].z ROTATEZRETURN
				setactor[RETURN].xrepeat 16
				setactor[RETURN].yrepeat 16
				setactor[RETURN].cstat 642

				addvar ROTATEZINTERVAL 1
ends

//***************************
//*Status Ailments [Players]*
//***************************

state addhaste
 ifvarand PLAYERSTATUS? 2 
 { 
  randvar TEMP 390
  addvar TEMP 390
  addvarvar PLAYERHASTETIMER TEMP
 } 
 else 
 {
  addvar PLAYERSTATUS? 2 
  randvar TEMP 390
  addvar TEMP 390
  addvarvar PLAYERHASTETIMER TEMP
  ifvarand PLAYERSTATUS? 4 { subvar PLAYERSTATUS? 4 setvar PLAYERSLOWTIMER 0 } 
  redefinequote 335 ^22TIME HAS SLOWED DOWN AROUND YOU!
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removehaste
 ifvare PLAYERHASTETIMER 0 redefinequote 335 ^22HASTE HAS WORN OFF!
 else redefinequote 335 ^10YOU ARE NO LONGER HASTED!

 ifvarand PLAYERSTATUS? 2 { subvar PLAYERSTATUS? 2 setvar PLAYERHASTETIMER 0 } // removes Haste status
 setvarvar fta fta_normal setvar ftq 335
ends

state addslow
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 nullop
    else
    {
     ifvare DEATHSWITCHDELAY 0
     {
      ifvarand PLAYERSTATUS? 4 
      { 
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERSLOWTIMER TEMP
      } 
      else 
      { 
       addvar PLAYERSTATUS? 4 
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERSLOWTIMER TEMP
       ifvarand PLAYERSTATUS? 2 { subvar PLAYERSTATUS? 2 setvar PLAYERHASTETIMER 0 } 
       redefinequote 335 ^10TIME HAS SPED UP AROUND YOU!
       setvarvar fta fta_normal setvar ftq 335
      }
     }
    }
   }
  }
 } // ifvarvarl TEMPMOD DAMAGEMODIFIER
ends

state addslow_overridevehicle
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvare DEATHSWITCHDELAY 0
    {
     ifvarand PLAYERSTATUS? 4 
     { 
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERSLOWTIMER TEMP
     } 
     else 
     { 
      addvar PLAYERSTATUS? 4 
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERSLOWTIMER TEMP
      ifvarand PLAYERSTATUS? 2 { subvar PLAYERSTATUS? 2 setvar PLAYERHASTETIMER 0 } 
      redefinequote 335 ^10TIME HAS SPED UP AROUND YOU!
      setvarvar fta fta_normal setvar ftq 335
     }
    }
   }
  }
 } // ifvarvarl TEMPMOD DAMAGEMODIFIER
ends

state removeslow
 ifvarand PLAYERSTATUS? 4
 {
  ifvare PLAYERSLOWTIMER 0 redefinequote 335 ^22SLOW HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER SLOWED!

  subvar PLAYERSTATUS? 4
  setvar PLAYERSLOWTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state addpoison
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 nullop
    else
    {
     ifvare DEATHSWITCHDELAY 0
     {
      ifvarand PLAYERSTATUS? 8 
      { 
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERPOISONTIMER TEMP
      } 
      else 
      { 
       addvar PLAYERSTATUS? 8
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERPOISONTIMER TEMP
       redefinequote 335 ^10YOU HAVE BEEN POISONED!
       setvarvar fta fta_normal setvar ftq 335
      }
     }
    }
   }
  }
 }
ends

state addpoison_overridevehicle
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvare DEATHSWITCHDELAY 0
    {
     ifvarand PLAYERSTATUS? 8 
     { 
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERPOISONTIMER TEMP
     } 
     else 
     { 
      addvar PLAYERSTATUS? 8
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERPOISONTIMER TEMP
      redefinequote 335 ^10YOU HAVE BEEN POISONED!
      setvarvar fta fta_normal setvar ftq 335
     }
    }
   }
  }
 }
ends

state removepoison
 ifvarand PLAYERSTATUS? 8
 {
  ifvare PLAYERPOISONTIMER 0 redefinequote 335 ^22POISON HAS WORN OFF!
  else redefinequote 335 ^22YOU HAVE CURED POISON!

  subvar PLAYERSTATUS? 8 // removes Poison status
  setvar PLAYERPOISONTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state adddimness
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 nullop
    else
    {
     ifvare DEATHSWITCHDELAY 0
     {
      ifvarand PLAYERSTATUS? 16 
      { 
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERDIMNESSTIMER TEMP
      } 
      else 
      { 
       addvar PLAYERSTATUS? 16
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERDIMNESSTIMER TEMP
       redefinequote 335 ^10YOUR SIGHT HAS BEEN DIMMED!
       setvarvar fta fta_normal setvar ftq 335
      }
     }
    }
   }
  }
 }
ends

state adddimness_overridevehicle
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvare DEATHSWITCHDELAY 0
    {
     ifvarand PLAYERSTATUS? 16 
     { 
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERDIMNESSTIMER TEMP
     } 
     else 
     { 
      addvar PLAYERSTATUS? 16
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERDIMNESSTIMER TEMP
      redefinequote 335 ^10YOUR SIGHT HAS BEEN DIMMED!
      setvarvar fta fta_normal setvar ftq 335
     }
    }
   }
  }
 }
ends

state removedimness
 ifvarand PLAYERSTATUS? 16
 {
  ifvare PLAYERDIMNESSTIMER 0 redefinequote 335 ^22DIMNESS HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER DIMMED!

  subvar PLAYERSTATUS? 16
  setvar PLAYERDIMNESSTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state addconfusion
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 nullop
    else
    {
     ifvare DEATHSWITCHDELAY 0
     {
      ifvarand PLAYERSTATUS? 128 
      { 
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERCONFUSIONTIMER TEMP
      } 
      else 
      { 
       addvar PLAYERSTATUS? 128 
       randvar TEMP 390
       addvar TEMP 390
       addvarvar PLAYERCONFUSIONTIMER TEMP
       redefinequote 335 ^10YOU HAVE BEEN CONFUSED!
       setvarvar fta fta_normal setvar ftq 335
      }
     }
    }
   }
  }
 }
ends

state addconfusion_overridevehicle
 //****************
 //*Support System*
 //****************
 setvar DAMAGEMODIFIER 1000

 //**Ailment Support / Maken**
 state support-ailmentresist

 ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
 randvar TEMPMOD 1000
 ifvarvarl TEMPMOD DAMAGEMODIFIER
 { // ifvarvarl TEMPMOD DAMAGEMODIFIER
  ifvare CHEATGOD 1 nullop
  else
  {
   ifvarg INVULNTIME 1 nullop
   else
   {
    ifvare DEATHSWITCHDELAY 0
    {
     ifvarand PLAYERSTATUS? 128 
     { 
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERCONFUSIONTIMER TEMP
     } 
     else 
     { 
      addvar PLAYERSTATUS? 128 
      randvar TEMP 390
      addvar TEMP 390
      addvarvar PLAYERCONFUSIONTIMER TEMP
      redefinequote 335 ^10YOU HAVE BEEN CONFUSED!
      setvarvar fta fta_normal setvar ftq 335
     }
    }
   }
  }
 }
ends

state removeconfusion
 ifvarand PLAYERSTATUS? 128
 {
  ifvare PLAYERCONFUSIONTIMER 0 redefinequote 335 ^22CONFUSION HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER CONFUSED!

  subvar PLAYERSTATUS? 128
  setvar PLAYERCONFUSIONTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removedamageshell
 ifvarand PLAYERSTATUS? 512
 {
  ifvare PLAYERSHELLTIMER 0 redefinequote 335 ^22DAMAGE SHELL HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER SHELLED!

  subvar PLAYERSTATUS? 512
  setvar PLAYERSHELLTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removeblitzkrieg
 ifvarand PLAYERSTATUS? 2048
 {
  ifvare PLAYERBLITZKRIEGTIMER 0 redefinequote 335 ^22TRIAD BLITZKRIEG HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER BLITZKRIEGED!

  subvar PLAYERSTATUS? 2048
  setvar PLAYERBLITZKRIEGTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removebooster
 ifvarand PLAYERSTATUS? 4096
 {
  ifvare PLAYERBOOSTERTIMER 0 redefinequote 335 ^22TRIAD BOOSTER HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER BOOSTED!

  subvar PLAYERSTATUS? 4096
  setvar PLAYERBOOSTERTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removebloodlusting
 ifvarand PLAYERSTATUS? 8192
 {
  ifvare PLAYERBLOODLUSTTIMER 0 redefinequote 335 ^22BLOODLUSTING HAS WORN OFF!
  else redefinequote 335 ^22YOU ARE NO LONGER BLOODLUSTED!

  subvar PLAYERSTATUS? 8192
  setvar PLAYERBLOODLUSTTIMER 0
  setvarvar fta fta_normal setvar ftq 335
 }
ends

//*******************************
//*End Status Ailments [Players]*
//******************************



//***********************************
//*Status Ailments [Monsters/Actors]*
//***********************************

state addhaste_actor
 ifvarand ACTORSTATUS? 2 
 { 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 624
   addvar TEMP 624
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORHASTETIMER TEMP
 } 
 else 
 {
  addvar ACTORSTATUS? 2 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 624
   addvar TEMP 624
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORHASTETIMER TEMP
  ifvarand ACTORSTATUS? 4 { subvar ACTORSTATUS? 4 setvar ACTORSLOWTIMER 0 } 
  redefinequote 335 ^10AN ENEMY HAS BECOME HASTENED!
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removehaste_actor
 redefinequote 335 ^22AN ENEMY'S HASTINESS HAS WORN OFF! :D

 ifvarand ACTORSTATUS? 2 { subvar ACTORSTATUS? 2 setvar ACTORHASTETIMER 0 } // removes Haste Status
 setvarvar fta fta_normal setvar ftq 335
ends

state addslow_actor
 ifvarand ACTORSTATUS? 4 
 { 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORSLOWTIMER TEMP
 } 
 else 
 { 
  addvar ACTORSTATUS? 4 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORSLOWTIMER TEMP
  ifvarand ACTORSTATUS? 2 { subvar ACTORSTATUS? 2 setvar ACTORHASTETIMER 0 } 
  redefinequote 335 ^22AN ENEMY HAS BECOME SLOWED DOWN!
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removeslow_actor
   redefinequote 335 ^10AN ENEMY'S SLOWNESS HAS WORN OFF! D:

   ifvarand ACTORSTATUS? 4 { subvar ACTORSTATUS? 4 setvar ACTORSLOWTIMER 0 }
   setvarvar fta fta_normal setvar ftq 335
ends

state addpoison_actor
 ifvarand ACTORSTATUS? 8 
 { 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORPOISONTIMER TEMP
 } 
 else 
 { 
  addvar ACTORSTATUS? 8
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORPOISONTIMER TEMP
  redefinequote 335 ^22AN ENEMY HAS BECOME POISONED!
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removepoison_actor
  redefinequote 335 ^10AN ENEMY'S POISON HAS WORN OFF! :(

  ifvarand ACTORSTATUS? 8 { subvar ACTORSTATUS? 8 setvar ACTORPOISONTIMER 0 }
  setvarvar fta fta_normal setvar ftq 335
ends

state adddimness_actor
 ifvarand ACTORSTATUS? 16 
 { 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORDIMNESSTIMER TEMP
 } 
 else 
 { 
  addvar ACTORSTATUS? 16
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORDIMNESSTIMER TEMP
  redefinequote 335 ^22AN ENEMY'S SIGHT HAS BEEN DIMMED!
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removedimness_actor
  redefinequote 335 ^10AN ENEMY'S DIMNESS HAS WORN OFF! :(
  ifvarand ACTORSTATUS? 16 { subvar ACTORSTATUS? 16 setvar ACTORDIMNESSTIMER 0 }
  setvarvar fta fta_normal setvar ftq 335
ends

state addconfusion_actor
 ifvarand ACTORSTATUS? 128 
 { 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar ACTORCONFUSIONTIMER TEMP
 } 
 else 
 { 
  addvar ACTORSTATUS? 128 
  ifvarand ACTORFLAGS 512
  {   
   randvar TEMP 156
   addvar TEMP 156
  }
  else
  {
   randvar TEMP 390
   addvar TEMP 390
  }
  addvarvar PLAYERCONFUSIONTIMER TEMP
  redefinequote 335 ^22AN ENEMY HAS BEEN CONFUSED!
  setvarvar fta fta_normal setvar ftq 335
 }
ends

state removeconfusion_actor
  redefinequote 335 ^10AN ENEMY'S CONFUSION HAS WORN OFF! :(
  ifvarand ACTORSTATUS? 128 { subvar ACTORSTATUS? 128 setvar ACTORCONFUSIONTIMER 0 }
  setvarvar fta fta_normal setvar ftq 335
ends

state removedamageshell_actor
   redefinequote 335 ^22AN ENEMY'S DAMAGE-SHELL HAS WORN OFF! :)
  ifvarand ACTORSTATUS? 512 { subvar ACTORSTATUS? 512 setvar ACTORSHELLTIMER 0 }
  setvarvar fta fta_normal setvar ftq 335
ends

//***************************************
//*End Status Ailments [Monsters/Actors]*
//***************************************

state nullgendamage
 setvar GENERALDAMAGE 0
ends

state getactorxyrepeat
    getactor[THISACTOR].xrepeat ACTORX
    getactor[THISACTOR].yrepeat ACTORY
ends


state fourfreezers
             shoot FREEZEBLAST
             shoot FREEZEBLAST
             shoot FREEZEBLAST
             shoot FREEZEBLAST
ends

state fourexpanders
            state firegrowspark_angleeffect 
            state firegrowspark_angleeffect 
            state firegrowspark_angleeffect 
            state firegrowspark_angleeffect 
ends

state fourlasers
            shoot FIRELASER 
            shoot FIRELASER 
            shoot FIRELASER 
            shoot FIRELASER 
ends

state fourrockets
         eshoot RPG // _NOAIM
         eshoot RPG // _NOAIM
         eshoot RPG // _NOAIM
         eshoot RPG // _NOAIM
ends

state threerockets
     eshoot RPG // _NOAIM
     eshoot RPG // _NOAIM
     eshoot RPG // _NOAIM
ends

state liztroopattack
          state echeckquadtime
          state echeckvampiretime
          ifspritepal 14 
          { 
           ifrnd 128 
           { 
            sound PRED_ATTACK 
            sound SHRINKER_FIRE 
            shoot SHRINKER 
           } 
           else 
           { 
            sound PRED_ATTACK 
            sound EXPANDERSHOOT 
            state fourexpanders
           } 
          } 
          else ifspritepal 19 
          { 
           sound PRED_ATTACK 
           sound RPG_SHOOT 
           ifrnd 128 eshoot MORTER else eshoot RPG // _NOAIM
          } 
          else ifspritepal 17 
          { 
           ifrnd 64 
           { 
            sound PRED_ATTACK 
            sound PRED_ATTACK 
            state fourlasers
            state fourlasers
           }
           else 
           ifrnd 85 
           { 
            sound CAT_FIRE 
            sound CAT_FIRE 
            sound PRED_ATTACK 
            sound PRED_ATTACK 
            state fourfreezers
            state fourfreezers
            state fourfreezers
            state fourfreezers
           }
           else 
           ifrnd 128 
           { 
            ifrnd 128 
            { 
             sound PRED_ATTACK 
             sound SHRINKER_FIRE 
             shoot SHRINKER 
            } 
            else 
            { 
             sound PRED_ATTACK 
             sound EXPANDERSHOOT 
             state fourexpanders
             state fourexpanders
            } 
           }
           else 
           { 
            sound PRED_ATTACK 
            sound RPG_SHOOT 
            ifrnd 96 shoot MORTER 
            else state fourrockets
           }
          } 
          else 
          ifspritepal 21
          { 
           ifrnd 224
           {
            sound PRED_ATTACK 
            shoot FIRELASER 
            shoot FIRELASER 
           }
           else
           {
            sound PISTOL_FIRE
            state fireshotspark1_angleeffect
            state fireshotspark1_angleeffect
           }
          }
          else 
          ifspritepal 10
          { 
           ifrnd 224
           {
            sound PRED_ATTACK 
            shoot FIRELASER 
            shoot FIRELASER 
           }
           else
           {
            sound PISTOL_FIRE
            state fireshotspark1_angleeffect
            state fireshotspark1_angleeffect
           }
          }
          else 
          { 
           sound PRED_ATTACK 
           shoot FIRELASER 
          }
ends

state getmeleedmg // For Fire/Steam
        setvar MELEEATTACK? 1
        setvarvar ATTACKINGACTOR THISACTOR
        getactor[THISACTOR].ang ATTACKERANGLE
        setactor[PLAYERID].htextra MELEEDAMAGE
        getactor[THISACTOR].picnum MELEEATTACKER
        getactor[THISACTOR].pal MELEEATTACKERPAL
        setvarvar MELEEATTACKERID THISACTOR
        setvarvar ATTACKINGACTOR -1
ends

state getmeleedmg2 // For Monsters
        setvar MELEEATTACK? 1
        setvarvar ATTACKINGACTOR THISACTOR
        ifvarn ATTACKINGACTOR -1 getactorvar[ATTACKINGACTOR].ENEMYQUADTIME ATTACKERQUADTIME
        ifvarg ATTACKERQUADTIME 0 mulvar MELEEDAMAGE 4
        getactor[THISACTOR].ang ATTACKERANGLE
        setactor[PLAYERID].htextra MELEEDAMAGE
        getactor[THISACTOR].picnum MELEEATTACKER
        getactor[THISACTOR].pal MELEEATTACKERPAL
        setvarvar MELEEATTACKERID THISACTOR
        setvarvar ATTACKINGACTOR -1
ends

state getmeleedmg3 // For Monsters
        setvar MELEEATTACK? 1
        setvarvar ATTACKINGACTOR THISACTOR
        ifvarn ATTACKINGACTOR -1 getactorvar[ATTACKINGACTOR].ENEMYQUADTIME ATTACKERQUADTIME
        ifvarg ATTACKERQUADTIME 0 mulvar MELEEDAMAGE 4
        getactor[THISACTOR].ang ATTACKERANGLE
        getactor[THISACTOR].picnum MELEEATTACKER
        getactor[THISACTOR].pal MELEEATTACKERPAL
        setvarvar MELEEATTACKERID THISACTOR
        setvarvar ATTACKINGACTOR -1
ends

state meleerandomdmg
      setactor[PLAYERID].htpicnum KNEE
	ifrnd 128 addvarvar MELEEDAMAGE MELEEDAMAGEVAR else subvarvar MELEEDAMAGE MELEEDAMAGEVAR
ends

state queenselfheal
// Self-Heal with discharges
        ifspritepal 24
        {
         randvar temp 24
         addvar temp 24
         setvarvar TEMP temp
         ifrnd 128
         {
          randvar tempb 12
          addvar tempb 12
          addvarvar TEMP tempb
         }
         ifrnd 85
         {
          randvar tempc 6
          addvar tempc 6
          addvarvar TEMP tempc
         }
         ifrnd 64
         {
          randvar tempd 3
          addvar tempd 3
          addvarvar TEMP tempd
         }
         ifrnd 53
         {
          randvar tempe 1
          addvar tempe 1
          addvarvar TEMP tempe
         }
         setvarvar TEMP3 ENEMYMAXHP
         ifvarg SKILLLEVEL -1
         ifvarl SKILLLEVEL 3
         {
          randvar TEMP2 2
          addvar TEMP2 10
         }
         else
         ifvarg SKILLLEVEL 2
         ifvarl SKILLLEVEL 6
         {
          randvar TEMP2 3
          addvar TEMP2 11
         }
         else
         ifvarg SKILLLEVEL 5
         ifvarl SKILLLEVEL 9
         {
          randvar TEMP2 5
          addvar TEMP2 12
         }
         else
         ifvare SKILLLEVEL 9
         {
          randvar TEMP2 7
          addvar TEMP2 14
         }
         mulvarvar TEMP3 TEMP2
         divvar TEMP3 1000
         ifvarl TEMP3 1 setvar TEMP3 1
         addvarvar TEMP TEMP3

         ifvarg ENEMYQUADTIME 1 mulvar TEMP 4

         ifvarvarl ENEMYHP ENEMYMAXHPATOMIC
         {
          addvarvar ENEMYHP TEMP
          ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
          ifvarg TEMP 0
          {
           setvarvar ITEMSEEKC TEMP setvarvar ITEMSEEK THISACTOR
           state showhealing_actorhp

           setvar ENEMYHPDAMAGED? -1
           sound ABSORB_DAMAGE
          }
         } 
        }
        else
        ifspritepal 0
        {
         randvar temp 18
         addvar temp 18
         setvarvar TEMP temp
         ifrnd 128
         {
          randvar tempb 9
          addvar tempb 9
          addvarvar TEMP tempb
         }
         ifrnd 85
         {
          randvar tempc 4
          addvar tempc 4
          addvarvar TEMP tempc
         }
         ifrnd 64
         {
          randvar tempd 2
          addvar tempd 2
          addvarvar TEMP tempd
         }
         ifrnd 53
         {
          randvar tempe 1
          addvar tempe 1
          addvarvar TEMP tempe
         }

         setvarvar TEMP3 ENEMYMAXHP
         ifvarg SKILLLEVEL -1
         ifvarl SKILLLEVEL 3
         {
          randvar TEMP2 1
          addvar TEMP2 7
         }
         else
         ifvarg SKILLLEVEL 2
         ifvarl SKILLLEVEL 6
         {
          randvar TEMP2 1
          addvar TEMP2 8
         }
         else
         ifvarg SKILLLEVEL 5
         ifvarl SKILLLEVEL 9
         {
          randvar TEMP2 2
          addvar TEMP2 9
         }
         else
         ifvare SKILLLEVEL 9
         {
          randvar TEMP2 3
          addvar TEMP2 11
         }
         mulvarvar TEMP3 TEMP2
         divvar TEMP3 1000
         ifvarl TEMP3 1 setvar TEMP3 1
         addvarvar TEMP TEMP3

         ifvarg ENEMYQUADTIME 1 mulvar TEMP 4

         ifvarvarl ENEMYHP ENEMYMAXHPATOMIC
         {
          addvarvar ENEMYHP TEMP
          ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
          ifvarg TEMP 0
          {
           setvarvar ITEMSEEKC TEMP setvarvar ITEMSEEK THISACTOR
           state showhealing_actorhp

           setvar ENEMYHPDAMAGED? -1
           sound ABSORB_DAMAGE
          }
         } 
        }
        else
        ifspritepal 3
        {
         randvar temp 18
         addvar temp 18
         setvarvar TEMP temp
         ifrnd 128
         {
          randvar tempb 9
          addvar tempb 9
          addvarvar TEMP tempb
         }
         ifrnd 85
         {
          randvar tempc 4
          addvar tempc 4
          addvarvar TEMP tempc
         }
         ifrnd 64
         {
          randvar tempd 2
          addvar tempd 2
          addvarvar TEMP tempd
         }
         ifrnd 53
         {
          randvar tempe 1
          addvar tempe 1
          addvarvar TEMP tempe
         }

         setvarvar TEMP3 ENEMYMAXHP
         ifvarg SKILLLEVEL -1
         ifvarl SKILLLEVEL 3
         {
          randvar TEMP2 1
          addvar TEMP2 7
         }
         else
         ifvarg SKILLLEVEL 2
         ifvarl SKILLLEVEL 6
         {
          randvar TEMP2 1
          addvar TEMP2 8
         }
         else
         ifvarg SKILLLEVEL 5
         ifvarl SKILLLEVEL 9
         {
          randvar TEMP2 2
          addvar TEMP2 9
         }
         else
         ifvare SKILLLEVEL 9
         {
          randvar TEMP2 3
          addvar TEMP2 11
         }
         mulvarvar TEMP3 TEMP2
         divvar TEMP3 1000
         ifvarl TEMP3 1 setvar TEMP3 1
         addvarvar TEMP TEMP3

         ifvarg ENEMYQUADTIME 1 mulvar TEMP 4

         ifvarvarl ENEMYHP ENEMYMAXHPATOMIC
         {
          addvarvar ENEMYHP TEMP
          ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
          ifvarg TEMP 0
          {
           setvarvar ITEMSEEKC TEMP setvarvar ITEMSEEK THISACTOR
           state showhealing_actorhp

           setvar ENEMYHPDAMAGED? -1
           sound ABSORB_DAMAGE
          }
         } 
        }
        else
        ifspritepal 9
        {
         randvar temp 18
         addvar temp 18
         setvarvar TEMP temp
         ifrnd 128
         {
          randvar tempb 9
          addvar tempb 9
          addvarvar TEMP tempb
         }
         ifrnd 85
         {
          randvar tempc 4
          addvar tempc 4
          addvarvar TEMP tempc
         }
         ifrnd 64
         {
          randvar tempd 2
          addvar tempd 2
          addvarvar TEMP tempd
         }
         ifrnd 53
         {
          randvar tempe 1
          addvar tempe 1
          addvarvar TEMP tempe
         }

         setvarvar TEMP3 ENEMYMAXHP
         ifvarg SKILLLEVEL -1
         ifvarl SKILLLEVEL 3
         {
          randvar TEMP2 1
          addvar TEMP2 7
         }
         else
         ifvarg SKILLLEVEL 2
         ifvarl SKILLLEVEL 6
         {
          randvar TEMP2 1
          addvar TEMP2 8
         }
         else
         ifvarg SKILLLEVEL 5
         ifvarl SKILLLEVEL 9
         {
          randvar TEMP2 2
          addvar TEMP2 9
         }
         else
         ifvare SKILLLEVEL 9
         {
          randvar TEMP2 3
          addvar TEMP2 11
         }
         mulvarvar TEMP3 TEMP2
         divvar TEMP3 1000
         ifvarl TEMP3 1 setvar TEMP3 1
         addvarvar TEMP TEMP3

         ifvarg ENEMYQUADTIME 1 mulvar TEMP 4

         ifvarvarl ENEMYHP ENEMYMAXHPATOMIC
         {
          addvarvar ENEMYHP TEMP
          ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
          ifvarg TEMP 0
          {
           setvarvar ITEMSEEKC TEMP setvarvar ITEMSEEK THISACTOR
           state showhealing_actorhp

           setvar ENEMYHPDAMAGED? -1
           sound ABSORB_DAMAGE
          }
         } 
        }
        else
        {
         randvar temp 12
         addvar temp 12
         setvarvar TEMP temp
         ifrnd 128
         {
          randvar tempb 6
          addvar tempb 6
          addvarvar TEMP tempb
         }
         ifrnd 85
         {
          randvar tempc 3
          addvar tempc 3
          addvarvar TEMP tempc
         }
         ifrnd 64
         {
          randvar tempd 1
          addvar tempd 1
          addvarvar TEMP tempd
         }

         setvarvar TEMP3 ENEMYMAXHP
         ifvarg SKILLLEVEL -1
         ifvarl SKILLLEVEL 3
         {
          randvar TEMP2 1
          addvar TEMP2 4
         }
         else
         ifvarg SKILLLEVEL 2
         ifvarl SKILLLEVEL 6
         {
          randvar TEMP2 1
          addvar TEMP2 5
         }
         else
         ifvarg SKILLLEVEL 5
         ifvarl SKILLLEVEL 9
         {
          randvar TEMP2 2
          addvar TEMP2 6
         }
         else
         ifvare SKILLLEVEL 9
         {
          randvar TEMP2 3
          addvar TEMP2 7
         }
         mulvarvar TEMP3 TEMP2
         divvar TEMP3 1000
         ifvarl TEMP3 1 setvar TEMP3 1
         addvarvar TEMP TEMP3

         ifvarg ENEMYQUADTIME 1 mulvar TEMP 4

         ifvarvarl ENEMYHP ENEMYMAXHPATOMIC
         {
          addvarvar ENEMYHP TEMP
          ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
          ifvarg TEMP 0
          {
           setvarvar ITEMSEEKC TEMP setvarvar ITEMSEEK THISACTOR
           state showhealing_actorhp

           setvar ENEMYHPDAMAGED? -1
           sound ABSORB_DAMAGE
          }
         } 
        }
ends

state queenshootzappers
        state echeckquadtime
        state echeckvampiretime
        getsector[THISACTOR].lotag ENEMYSECTORLOTAG

        ifvare ENEMYSECTORLOTAG 2
        {
         ifspritepal 24 ifrnd 32 shoot ZAPPER3
         else ifspritepal 0 ifrnd 32 shoot ZAPPER1
         else ifspritepal 3 ifrnd 32 shoot ZAPPER1
         else ifspritepal 9 ifrnd 32 shoot ZAPPER1
         else ifrnd 32 shoot ZAPPER2
        }
        else
        {
         ifspritepal 24 ifrnd 128 shoot ZAPPER3
         else ifspritepal 0 ifrnd 128 shoot ZAPPER1
         else ifspritepal 3 ifrnd 128 shoot ZAPPER1
         else ifspritepal 9 ifrnd 128 shoot ZAPPER1
         else ifrnd 128 shoot ZAPPER2
        }

        ifvare SECTORLOTAG 2 // If the player is in the water
        {
         state meleerandomdmg
         ifspritepal 0 mulvar MELEEDAMAGE 4
         ifspritepal 3 mulvar MELEEDAMAGE 4
         ifspritepal 9 mulvar MELEEDAMAGE 4
         ifspritepal 24 mulvar MELEEDAMAGE 20
         ifvarg CURRENTHITPOINTS 0 state getmeleedmg3

         ifvare CHARACTERSELECTED? 10 
         {
          ifvare NETHRAFORM? 0 
          { 
           state calcplayermaxhealthatomic
           mulvar MELEEDAMAGE 2 
           setvarvar ABSORBEDDAMAGE MELEEDAMAGE
           addvarvar CURRENTHITPOINTS MELEEDAMAGE
           ifvarvarg CURRENTHITPOINTS MAXHITPOINTSATOMIC setvarvar CURRENTHITPOINTS MAXHITPOINTSATOMIC
           setvar PLAYERHPDAMAGED? -1
           setactor[PLAYERID].htextra -1
           stopsound NODAMAGE
           setvarvar TEMPHEALTH ABSORBEDDAMAGE
           state showhealing_playerhp

           globalsound ABSORB_DAMAGE
           palfrom 32 64 64 64
           setvar MELEEDAMAGE 0
           qsprintf 336 337 ABSORBEDDAMAGE
           setvarvar fta fta_normal setvar ftq 336
          }
          else
          {
           setactor[PLAYERID].htextra MELEEDAMAGE
 
           setvarvar TEMPDAMAGEVAR MELEEDAMAGE
           state char_elecdamage_misc
           setvarvar MELEEDAMAGE TEMPDAMAGEVAR

           //****************
           //*Support System*
           //****************
           ifvarg MELEEDAMAGE 0
           {
            setvar DAMAGEMODIFIER 1000
 
            //**Electric Support / Nethra**
            state support-electricresist
            state damagemod-enemy-melee       
           }

           //*********************************
           //*Support System [ESSence Support*
           //*********************************
           ifvarg MELEEDAMAGE 0
           {
            setvar DAMAGEMODIFIER 1000
            //**Overall Support / ESSence**
            state support-overallresist
            state damagemod-enemy-melee          
           }
 
           //******************
           //*Equipment System*
           //******************
           ifvarg MELEEDAMAGE 0
           {
            setvar DAMAGEMODIFIER 1000
            // Equipment Slot #1
            ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
            // Equipment Slot #2
            ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
            // Equipment Slot #3
            ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
            // Equipment Slot #4
            ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
            state damagemod-enemy-melee        
           }

          }
         }
         else
         {
          setactor[PLAYERID].htextra MELEEDAMAGE

          setvarvar TEMPDAMAGEVAR MELEEDAMAGE
          state char_elecdamage_misc
          setvarvar MELEEDAMAGE TEMPDAMAGEVAR

          //****************
          //*Support System*
          //****************
          ifvarg MELEEDAMAGE 0
          {
           setvar DAMAGEMODIFIER 1000

           //**Electrical Support / Nethra**
           state support-electricresist
           state damagemod-enemy-melee       
          }

          //*********************************
          //*Support System [ESSence Support*
          //*********************************
          ifvarg MELEEDAMAGE 0
          {
           setvar DAMAGEMODIFIER 1000
           //**Overall Support / ESSence**
           state support-overallresist
           state damagemod-enemy-melee          
          }

          //******************
          //*Equipment System*
          //******************
          ifvarg MELEEDAMAGE 0
          {
           setvar DAMAGEMODIFIER 1000
           // Equipment Slot #1
           ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
           // Equipment Slot #2
           ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
           // Equipment Slot #3
           ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
           // Equipment Slot #4
           ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -250 // Plasma Ring
           state damagemod-enemy-melee        
          }

         }
         ifvarg INVULNTIME 0 state invulnflash 
         else ifvare CHEATGOD 1 state invulnflash 
         else ifvarl MELEEDAMAGE 1 state nullflash
         else
         {
          ifvarg CURRENTHITPOINTS 0 // ifp palive
          {
           ifrnd 128 sound SHORT_CIRCUIT
           getactorvar[PLAYERID].VEHICLEID tempvehicleid
           ifvare tempvehicleid -1
           {
            setvarvar DAMAGEHUEFACTOR MELEEDAMAGE
            state playerdamagehues-electrictype
           }
           else palfrom 16 32 0 0 
          }
         }
        }
ends

state stoppainsounds
   stopsound DUKE_LONGTERM_PAIN
   stopsound DUKE_LONGTERM_PAIN1
   stopsound DUKE_LONGTERM_PAIN2
   stopsound DUKE_LONGTERM_PAIN3
   stopsound DUKE_LONGTERM_PAIN4
   stopsound DUKE_LONGTERM_PAIN5
   stopsound DUKE_LONGTERM_PAIN6
   stopsound DUKE_LONGTERM_PAIN7
   stopsound DUKE_LONGTERM_PAIN8
   stopsound WANG_LONGTERM_PAIN1
   stopsound WANG_LONGTERM_PAIN2
   stopsound WANG_LONGTERM_PAIN3
   stopsound WANG_LONGTERM_PAIN4
   stopsound WANG_LONGTERM_PAIN5
   stopsound WANG_LONGTERM_PAIN6
   stopsound WANG_LONGTERM_PAIN7
   stopsound WANG_LONGTERM_PAIN8
   stopsound LISA_PAINMINOR1
   stopsound LISA_PAINMINOR2
   stopsound LISA_PAINMINOR3
   stopsound LISA_PAINMINOR4
   stopsound LISA_PAINMODERATE1
   stopsound LISA_PAINMODERATE2
   stopsound LISA_PAINMODERATE3
   stopsound LISA_PAINMODERATE4
   stopsound LISA_PAINHIGH1
   stopsound LISA_PAINHIGH2
   stopsound LISA_PAINHIGH3
   stopsound LISA_PAINHIGH4
   stopsound LISA_PAINPERILOUS1
   stopsound LISA_PAINPERILOUS2
   stopsound LISA_PAINPERILOUS3
   stopsound LISA_PAINPERILOUS4
ends

state deflectshrinker
 ifvare oldskoolmode 0
 {
  state stoppainsounds
  setactor[THISACTOR].htextra -1
  getactor[THISACTOR].htang ATTACKANGLE
  addvar ATTACKANGLE 1024 // Flips the direction of the attack backwards
  ifvarg ATTACKANGLE 2047 subvar ATTACKANGLE 2048
  sound ENERGY_REFLECT
  eshoot SHRINKER
  setactor[RETURN].ang ATTACKANGLE
 // OFF-LIMITS
  setactor[RETURN].extra 0
 // END OFF-LIMITS
 }
ends

state fivepistols
  state fireshotspark1_angleeffect
  state fireshotspark1_angleeffect
  state fireshotspark1_angleeffect
  state fireshotspark1_angleeffect
  state fireshotspark1_angleeffect
ends

state fivechainguns
  state firechaingun_angleeffect
  state firechaingun_angleeffect
  state firechaingun_angleeffect
  state firechaingun_angleeffect
  state firechaingun_angleeffect
ends

state medikitvehicle_ratios
              ifvarvarl TEMPHEALTH tempb ifvarg ACTORPICKUPAMOUNT 0
              {
               ifactor DONUTS2 { setvar TEMP7 50 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor COLA { setvar TEMP7 100 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor DONUTS { setvar TEMP7 150 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor SWMEDIKIT { setvar TEMP7 200 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor SIXPAK { setvar TEMP7 300 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor SWBIGMEDIKIT { setvar TEMP7 500 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor MEDPACK { setvar TEMP7 750 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }
               ifactor SURGERYKIT { setvar TEMP7 1000 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 }

               subvar ACTORPICKUPAMOUNT 1
               addvar tempe 1
              }
ends

state medikitvehicle
              // TEMP4 = Maximum HP % to reach
              // tempb = becomes the % of health needed to heal to reach TEMP4 [tempb - TEMPARMOR = tempb]
	  	 setvar tempb 1000
              setvar TEMP4 1000
	  	 setvarvar TEMPARMOR TEMPVAR4
              mulvar TEMPARMOR 1000
	  	 divvarvar TEMPARMOR TEMPVAR5
              subvarvar tempb TEMPARMOR
              // addlogvar tempb
              // addlogvar TEMP4

	  	 setvar TEMPHEALTH 0
              setvar ACTORPICKUPAMOUNT 1
              state checkpickupamountflags state checkdoublepickupbonus
	  	 setvar tempe 0

              setvar TEMPVAR3 10
              whilevarn TEMPVAR3 0
              {
               state medikitvehicle_ratios
               subvar TEMPVAR3 1
              }

	  	 mulvarvar TEMPHEALTH TEMPVAR5
	  	 divvar TEMPHEALTH 1000
 	  	 addvarvar TEMPVAR4 TEMPHEALTH
              ifvarvarg TEMPVAR4 TEMPVAR5 setvarvar TEMPVAR4 TEMPVAR5
              setactorvar[tempvehicleid].ENEMYHP TEMPVAR4
              setactorvar[tempvehicleid].ENEMYMAXHP TEMPVAR5

	  	 ifactor COLA addvarvar SMALLMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor SWMEDIKIT addvarvar SWMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor SIXPAK addvarvar LARGEMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor SWBIGMEDIKIT addvarvar SWBIGMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor MEDPACK addvarvar MEDPACKS ACTORPICKUPAMOUNT
	  	 ifactor SURGERYKIT addvarvar SURGERYKITS ACTORPICKUPAMOUNT

              ifvarand ACTORFLAGS 2 setvar VEHICLEHPDAMAGED? -1
              setvar WORLDTILESHUFFLES 0
              state getworldtile
              globalsound VEHICLE_HEAL
ends

state medikitplayer_pickupamount
             ifvarvarl TEMPHEALTH tempb ifvarg ACTORPICKUPAMOUNT 0
             {
              ifactor DONUTS2 { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 75 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 50 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
	  	 ifactor COLA { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 150 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 100 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
              ifactor DONUTS { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 225 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 150 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
	  	 ifactor SWMEDIKIT { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 300 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 200 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
	  	 ifactor SIXPAK { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 450 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 300 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
	  	 ifactor SWBIGMEDIKIT { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 750 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 500 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
	  	 ifactor MEDPACK { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 1125 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 750 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }
	  	 ifactor SURGERYKIT { ifvare CHARACTERSELECTED? 13 { setvar TEMP7 1500 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } else { setvar TEMP7 1000 state checksecretrecipes addvarvar TEMPHEALTH TEMP7 } }

              subvar ACTORPICKUPAMOUNT 1
              addvar tempe 1
             }
ends

state medikitplayer
              state gotmedsyoureallyneeded

              // TEMP4 = Maximum HP % to reach
              // tempb = becomes the % of health needed to heal to reach TEMP4 [tempb - TEMPARMOR = tempb]
	  	 ifactor SURGERYKIT
              {
               ifvare CHARACTERSELECTED? 13 { setvar tempb 1500 setvar TEMP4 1500 }
               else { setvar tempb 1000 setvar TEMP4 1000 }
              }
              else
	  	 ifactor MEDPACK
              {
               ifvare CHARACTERSELECTED? 13 { setvar tempb 1125 setvar TEMP4 1125 }
               else { setvar tempb 1000 setvar TEMP4 1000 }
              }
              else { setvar tempb 1000 setvar TEMP4 1000 }
	  	 setvarvar TEMPARMOR CURRENTHITPOINTS
              mulvar TEMPARMOR 1000
	  	 divvarvar TEMPARMOR MAXHITPOINTS
              subvarvar tempb TEMPARMOR

              setvar TEMPHEALTH 0
              setvar ACTORPICKUPAMOUNT 1
              state checkpickupamountflags state checkdoublepickupbonus
	  	 setvar tempe 0

              setvar TEMPVAR5 10
              whilevarn TEMPVAR5 0
              {
               state medikitplayer_pickupamount
               subvar TEMPVAR5 1
              }

	  	 mulvarvar TEMPHEALTH MAXHITPOINTS
	  	 divvar TEMPHEALTH 1000
 	  	 addvarvar CURRENTHITPOINTS TEMPHEALTH // Adds the actual heal value to the current player health
              state showhealing_playerhp

	  	 ifactor SURGERYKIT
              {
               ifvare CHARACTERSELECTED? 13
               {
 	  	   setvarvar tempb MAXHITPOINTS
 	  	   mulvar tempb 1500
 	  	   divvar tempb 1000
  	  	   ifvarvarg CURRENTHITPOINTS tempb setvarvar CURRENTHITPOINTS tempb
               }
               else
               {
  	   	   ifvarvarg CURRENTHITPOINTS MAXHITPOINTS setvarvar CURRENTHITPOINTS MAXHITPOINTS
               }
              }
              else
	  	 ifactor MEDPACK
              {
               ifvare CHARACTERSELECTED? 13
               {
 	  	   setvarvar tempb MAXHITPOINTS
 	  	   mulvar tempb 1125
 	  	   divvar tempb 1000
  	  	   ifvarvarg CURRENTHITPOINTS tempb setvarvar CURRENTHITPOINTS tempb
               }
               else
               {
  	   	   ifvarvarg CURRENTHITPOINTS MAXHITPOINTS setvarvar CURRENTHITPOINTS MAXHITPOINTS
               }
              }
              else
              {
  	  	  ifvarvarg CURRENTHITPOINTS MAXHITPOINTS setvarvar CURRENTHITPOINTS MAXHITPOINTS
              }

	  	 ifactor COLA addvarvar SMALLMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor SWMEDIKIT addvarvar SWMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor SIXPAK addvarvar LARGEMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor SWBIGMEDIKIT addvarvar SWBIGMEDIKITS ACTORPICKUPAMOUNT
	  	 ifactor MEDPACK addvarvar MEDPACKS ACTORPICKUPAMOUNT
	  	 ifactor SURGERYKIT addvarvar SURGERYKITS ACTORPICKUPAMOUNT

              ifvarand ACTORFLAGS 2 setvar PLAYERHPDAMAGED? -1
              setvar WORLDTILESHUFFLES 0
              state getworldtile
              globalsound USE_MEDIKITITEM
ends

state getitemseekerspeciesquote
             ifactor ROTATEGUN setvar ITEMSEEKSPECIESTYPE 0
             ifactor SHARK setvar ITEMSEEKSPECIESTYPE 0
             ifactor LIZTROOP setvar ITEMSEEKSPECIESTYPE 0
             ifactor LIZMAN setvar ITEMSEEKSPECIESTYPE 0
             ifactor DRONE setvar ITEMSEEKSPECIESTYPE 0
             ifactor OCTABRAIN setvar ITEMSEEKSPECIESTYPE 0
             ifactor PIGCOP setvar ITEMSEEKSPECIESTYPE 0
             ifactor BOSS1 setvar ITEMSEEKSPECIESTYPE 0
             ifactor BOSS2 setvar ITEMSEEKSPECIESTYPE 0
             ifactor BOSS3 setvar ITEMSEEKSPECIESTYPE 0
             ifactor COMMANDER setvar ITEMSEEKSPECIESTYPE 0
             ifactor TANK setvar ITEMSEEKSPECIESTYPE 0
             ifactor BOSS4 setvar ITEMSEEKSPECIESTYPE 0
             ifactor NEWBEAST setvar ITEMSEEKSPECIESTYPE 0
             ifactor SCORPIONTANK setvar ITEMSEEKSPECIESTYPE 0
             ifactor PRESIDENTCLINTON setvar ITEMSEEKSPECIESTYPE 1
             ifactor ROBOTDOG setvar ITEMSEEKSPECIESTYPE 1
             ifactor ROBOTDOG2 setvar ITEMSEEKSPECIESTYPE 1
             ifactor NAKED1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor PODFEM1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM2 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM3 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM4 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM5 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM6 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM7 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM9 setvar ITEMSEEKSPECIESTYPE 1
             ifactor FEM10 setvar ITEMSEEKSPECIESTYPE 1
             ifactor TOUGHGAL setvar ITEMSEEKSPECIESTYPE 1
             ifactor WOMAN setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE2 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE3 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE5 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE6 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE7 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DANCE9 setvar ITEMSEEKSPECIESTYPE 1
             ifactor DEALER setvar ITEMSEEKSPECIESTYPE 1
             ifactor STAND1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor STAND3 setvar ITEMSEEKSPECIESTYPE 1
             ifactor STAND4 setvar ITEMSEEKSPECIESTYPE 1
             ifactor COP1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor COP2 setvar ITEMSEEKSPECIESTYPE 1
             ifactor PUNKDUDE setvar ITEMSEEKSPECIESTYPE 1
             ifactor SITTINGDUDE setvar ITEMSEEKSPECIESTYPE 1
             ifactor WOLFDUDE setvar ITEMSEEKSPECIESTYPE 1
             ifactor ANIMEGIRL1 setvar ITEMSEEKSPECIESTYPE 1
             ifactor ANIMEGIRL2 setvar ITEMSEEKSPECIESTYPE 1
             ifactor ANIMEGIRL3 setvar ITEMSEEKSPECIESTYPE 1
             ifactor ANIMEGIRL4 setvar ITEMSEEKSPECIESTYPE 1

             ifactor EMPTYTANK setvar ITEMSEEKSPECIESTYPE 2
ends

state getitemseekerspecies
             getactor[ITEMSEEK].picnum ITEMSEEKSPECIES
             ifvare ITEMSEEKSPECIES ROTATEGUN setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES SHARK setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES LIZTROOP setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES LIZMAN setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES DRONE setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES OCTABRAIN setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES PIGCOP setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES BOSS1 setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES BOSS2 setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES BOSS3 setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES COMMANDER setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES TANK setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES BOSS4 setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES NEWBEAST setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES SCORPIONTANK setvar ITEMSEEKSPECIESTYPE 0
             ifvare ITEMSEEKSPECIES PRESIDENTCLINTON setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES ROBOTDOG setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES ROBOTDOG2 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES NAKED1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES PODFEM1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM2 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM3 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM4 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM5 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM6 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM7 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM9 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES FEM10 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES TOUGHGAL setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES WOMAN setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE2 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE3 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE5 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE6 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE7 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DANCE9 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES DEALER setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES STAND1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES STAND3 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES STAND4 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES COP1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES COP2 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES PUNKDUDE setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES SITTINGDUDE setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES WOLFDUDE setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES ANIMEGIRL1 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES ANIMEGIRL2 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES ANIMEGIRL3 setvar ITEMSEEKSPECIESTYPE 1
             ifvare ITEMSEEKSPECIES ANIMEGIRL4 setvar ITEMSEEKSPECIESTYPE 1

             ifvare ITEMSEEKSPECIES EMPTYTANK setvar ITEMSEEKSPECIESTYPE 2
ends

state moneyfs
       state checkexplodeflag
       ifvarand ACTORFLAGS 2 nullop
       else
       {
        palfrom 16 0 64 
        sound MONEYSOUND
       }
ends

state moneycalc
 ifvarg CENTS 99
 {
  setvarvar TEMP2 CENTS
  divvar TEMP2 100
  addvarvar DOLLARS TEMP2
  setvarvar TEMP3 CENTS
  modvar TEMP3 100
  setvarvar CENTS TEMP3
 }

 ifvarl CENTS 0
 {
  ifvarg DOLLARS 0
  {
   addvar CENTS 100
   subvar DOLLARS 1
  }
  else setvar CENTS 0
 }
ends

state bubblesounds
    ifrnd 85 sound BUBBLES1
    else ifrnd 128 sound BUBBLES2
    else sound BUBBLES3
ends

state jetpacksmoke
    espawn SMALLSMOKE
    getactor[THISACTOR].x TEMP
    setactor[RETURN].x TEMP
    getactor[THISACTOR].y TEMP
    setactor[RETURN].y TEMP
    getactor[THISACTOR].xrepeat temp
    getactorvar[THISACTOR].ACTORSHEIGHT tempc
    setvarvar tempb temp
    mulvar tempb 46
    divvar tempb 100
    setvarvar tempd tempc
    mulvarvar tempd tempb
    mulvar tempd 4
    getactor[THISACTOR].z TEMP
    subvarvar TEMP tempd
    setactor[RETURN].z TEMP
    ifrnd 128 setactor[RETURN].cstat 2 else setactor[RETURN].cstat 514
ends

state jetpackbubbles
    espawn WATERBUBBLE
    state bubblesounds
    getactor[THISACTOR].x TEMP
    setactor[RETURN].x TEMP
    getactor[THISACTOR].y TEMP
    setactor[RETURN].y TEMP
    getactor[THISACTOR].xrepeat temp
    getactorvar[THISACTOR].ACTORSHEIGHT tempc
    setvarvar tempb temp
    mulvar tempb 46
    divvar tempb 100
    setvarvar tempd tempc
    mulvarvar tempd tempb
    mulvar tempd 4
    getactor[THISACTOR].z TEMP
    subvarvar TEMP tempd
    setactor[RETURN].z TEMP
    ifrnd 128 setactor[RETURN].cstat 2 else setactor[RETURN].cstat 514
ends

state drownbubbles
    espawn WATERBUBBLE
    getactor[THISACTOR].x TEMP
    setactor[RETURN].x TEMP
    getactor[THISACTOR].y TEMP
    setactor[RETURN].y TEMP
    getactor[THISACTOR].xrepeat temp
    getactorvar[THISACTOR].ACTORSHEIGHT tempc
    setvarvar tempb tempc
    mulvar tempb 9
    divvar tempb 10
    setvarvar tempd tempb
    mulvarvar tempd temp
    mulvar tempd 4
    getactor[THISACTOR].z TEMP
    subvarvar TEMP tempd
    setactor[RETURN].z TEMP
ends

state enemyunderwater // State for allowing monsters to have their own set of 'lungs' underwater, and for effecting Damage from drowning.
getsector[THISACTOR].lotag ENEMYSECTORLOTAG

ifvare ENEMYSECTORLOTAG 2 // If the monster is underwater...
{
 ifactor EGG nullop
 else ifactor SHARK nullop
 else ifactor ROTATEGUN nullop
 else ifactor DRONE nullop
 else ifactor EMPTYTANK nullop
 else ifactor TANK nullop
 else ifactor SCORPIONTANK nullop
 else ifactor OCTABRAIN nullop
 else ifactor NEWBEAST nullop
 else ifactor BOSS4 nullop
 else
 {
  ifvarg ENEMYAIRTANKAMOUNT 0
  {
   ifvarvarl ENEMYAIRTIME ENEMYMAXAIRTIME
   {
    setvarvar TEMPVAR5 ENEMYMAXAIRTIME
    divvar TEMPVAR5 130
    addvarvar ENEMYAIRTIME TEMPVAR5 // This prevents the monster from continuing to drown if they pick up a Scuba Gear with no breath left. Also emulates a 'transfer' of missing air from a scuba tank to the monster.
    subvarvar ENEMYAIRTANKAMOUNT TEMPVAR5 // This prevents the monster from continuing to drown if they pick up a Scuba Gear with no breath left. Also emulates a 'transfer' of missing air from a scuba tank to the monster.
   }
   else ifvarvare ENEMYAIRTIME ENEMYMAXAIRTIME nullop
   else ifvarvarg ENEMYAIRTIME ENEMYMAXAIRTIME
   {
    setvarvar TEMPVAR5 ENEMYAIRTIME
    subvarvar TEMPVAR5 ENEMYMAXAIRTIME
    subvarvar ENEMYAIRTIME TEMPVAR5 // For making sure none of the airtank tics are wasted when quick-filling the air bar
    addvarvar ENEMYAIRTANKAMOUNT TEMPVAR5 // For making sure none of the airtank tics are wasted when quick-filling the air bar
   }
  }

  ifvarl ENEMYINVULNTIME 1 // If the monster has no Invulnerability time, then they need to breathe...
  {
   ifvarl ENEMYAIRTANKAMOUNT 1 // If the monster has no scuba tank energy
   {
    ifvarg ENEMYAIRTIME 0 // If the enemy has airtime left in their lungs
    {
     ifvare mainmenu 0 ifvare FROZEN? 0 subvar ENEMYAIRTIME 1 // Minus air supply by 1 per tic
     setvar DROWNDMGFACTOR 10
    }
    else // If the monster has <0 airtime left, start the drowning counter
    {
     ifvare mainmenu 0 addvar ENEMYDROWNTIME 1 // Increment Drown meter 1 per tic
     ifvare ENEMYDROWNTIME 8 // if 8 tics of the drown meter count...
     {
      setvarvar ENEMYBASEDROWNDMG ENEMYMAXHP
      randvar ENEMYEXTRADROWNDMG 3
      addvarvar DROWNDMGFACTOR ENEMYEXTRADROWNDMG

      mulvarvar ENEMYBASEDROWNDMG DROWNDMGFACTOR
      divvar ENEMYBASEDROWNDMG 1000

      setvarvar ENEMYTOTALDROWNDMG ENEMYBASEDROWNDMG
      addvarvar ENEMYTOTALDROWNDMG ENEMYEXTRADROWNDMG

      subvarvar ENEMYHP ENEMYTOTALDROWNDMG 
      state showdamage_actor-drownhp
      ifvarl ENEMYHP 0 setvar ENEMYHP 0
      ifvarg ENEMYHP -1 
      {
       ifrnd 192
       {
        ifrnd 128 { stopsound SOMEONE_DROWNING1 stopsound SOMEONE_DROWNING2 }
        ifrnd 128 sound SOMEONE_DROWNING1 else sound SOMEONE_DROWNING2
       }
       ifvarl ENEMYHP 0
       {
        stopsound SOMEONE_DROWNING1
        stopsound SOMEONE_DROWNING2
        stopsound SOMEONE_DROWNED1
        stopsound SOMEONE_DROWNED2
        ifrnd 128 globalsound SOMEONE_DROWNED1 else globalsound SOMEONE_DROWNED2
        setactor[THISACTOR].extra 0
        setactor[THISACTOR].htowner THISACTOR
        setactor[THISACTOR].htpicnum SHOTSPARK1
        setactor[THISACTOR].htextra 8000

        setvarvar tempe THISACTOR 
        ifvarl THISACTOR 16383 addvar tempe 1 else subvar tempe 1
       }
      }
      else
      {
       stopsound SOMEONE_DROWNING1
       stopsound SOMEONE_DROWNING2
       stopsound SOMEONE_DROWNED1
       stopsound SOMEONE_DROWNED2
       ifrnd 128 globalsound SOMEONE_DROWNED1 else globalsound SOMEONE_DROWNED2
       setactor[THISACTOR].extra 0
       setactor[THISACTOR].htowner THISACTOR
       setactor[THISACTOR].htpicnum SHOTSPARK1
       setactor[THISACTOR].htextra 8000

       setvarvar tempe THISACTOR 
       ifvarl THISACTOR 16383 addvar tempe 1 else subvar tempe 1
      }
      state drownbubbles
      state drownbubbles
      setvar ENEMYDROWNTIME 0 // Reset the drown meter count to prevent cheap drown deaths
     }
    }
   }
   else // If the monster does have Scuba Tank energy
   {
    ifvare mainmenu 0 ifvare FROZEN? 0 subvar ENEMYAIRTANKAMOUNT 1  // Decrease Scuba energy by 1 per tic
   }
  }
 }
}
else // If the monster is NOT underwater
{
 setvar ENEMYBASEDROWNDMG 0
 setvar ENEMYEXTRADROWNDMG 0 // Resets the Extra Drown Damage increments
 setvar ENEMYTOTALDROWNDMG 0
 setvar ENEMYDROWNTIME 0 // Reset Drown counter
 ifvarvarl ENEMYAIRTIME ENEMYMAXAIRTIME // If the monster's airtime is not at it's maximum
 {
  setvarvar ENEMYTEMPAIR ENEMYMAXAIRTIME
  divvar ENEMYTEMPAIR 130
  addvarvar ENEMYAIRTIME ENEMYTEMPAIR // Restore air time by [Enemy's Airtime/130] per tic
 }
 ifvarvarg ENEMYAIRTIME ENEMYMAXAIRTIME setvarvar ENEMYAIRTIME ENEMYMAXAIRTIME // If the monster's airtime goes over maximum
}
ends

state monsterpainsounds2
ifactor ROTATEGUN debris SCRAP1 4 
 else ifactor LIZTROOP soundonce PRED_PAIN
 else ifactor LIZTROOPSTAYPUT soundonce PRED_PAIN
 else ifactor LIZTROOPJETPACK soundonce PRED_PAIN
 else ifactor LIZTROOPSHOOT soundonce PRED_PAIN
 else ifactor LIZTROOPDUCKING soundonce PRED_PAIN
 else ifactor LIZTROOPRUNNING soundonce PRED_PAIN
 else ifactor LIZTROOPONTOILET soundonce PRED_PAIN
 else ifactor LIZTROOPJUSTSIT soundonce PRED_PAIN
 else ifactor LIZMAN soundonce CAPT_PAIN
 else ifactor LIZMANSTAYPUT soundonce CAPT_PAIN
 else ifactor LIZMANSPITTING soundonce CAPT_PAIN
 else ifactor LIZMANJUMP soundonce CAPT_PAIN
 else ifactor DRONE soundonce DRON_PAIN
 else
 ifactor OCTABRAIN
 {
  getactor[THISACTOR].pal temp
  ifvare temp 14 soundonce NINE_PAIN
  else soundonce OCTA_PAIN  
 }
 else
 ifactor OCTABRAINSTAYPUT
 {
  getactor[THISACTOR].pal temp
  ifvare temp 14 soundonce NINE_PAIN
  else soundonce OCTA_PAIN  
 }
 else ifactor PIGCOP soundonce PIG_PAIN
 else ifactor PIGCOPSTAYPUT soundonce PIG_PAIN
 else ifactor PIGCOPDIVE soundonce PIG_PAIN
 else ifactor BOSS1 soundonce BOS1_PAIN
 else ifactor BOSS1STAYPUT soundonce BOS1_PAIN
 else ifactor BOSS1SHOOT soundonce BOS1_PAIN
 else ifactor BOSS1LOB soundonce BOS1_PAIN
 else ifactor BOSS2 soundonce BOS2_PAIN
 else ifactor BOSS2STAYPUT soundonce BOS2_PAIN
 else ifactor BOSS2SHOOT soundonce BOS2_PAIN
 else ifactor BOSS2BREATH soundonce BOS2_PAIN
 else ifactor BOSS3 soundonce BOS3_PAIN
 else ifactor BOSS3STAYPUT soundonce BOS3_PAIN
 else ifactor BOSS3LOB soundonce BOS3_PAIN
 else
 ifactor COMMANDER
 {
  getactor[THISACTOR].pal temp
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 416
  ifvare temp 25 setplayer[THISACTOR].sound_pitch -416
  soundonce COMM_PAIN
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 0
  ifvare temp 25 setplayer[THISACTOR].sound_pitch 0
 }
 else
 ifactor COMMANDERSTAYPUT
 {
  getactor[THISACTOR].pal temp
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 416
  ifvare temp 25 setplayer[THISACTOR].sound_pitch -416
  soundonce COMM_PAIN
  ifvare temp 14 setplayer[THISACTOR].sound_pitch 0
  ifvare temp 25 setplayer[THISACTOR].sound_pitch 0
 }
 else ifactor BOSS4 soundonce BOS4_PAIN
 else ifactor BOSS4STAYPUT soundonce BOS4_PAIN
 else ifactor NEWBEAST soundonce NEWBEAST_PAIN
 else ifactor NEWBEASTHANG soundonce NEWBEAST_PAIN
 else ifactor NEWBEASTJUMP soundonce NEWBEAST_PAIN
 else ifactor NEWBEASTSTAYPUT soundonce NEWBEAST_PAIN
ends

state enemyfloordamagesounds
 ifvarg ENEMYHP 0 state monsterpainsounds2
ends

state enemybootscheck
        subvarvar ENEMYBOOTSAMOUNT TEMPVAR
        ifvarl ENEMYBOOTSAMOUNT 1
        {
         debris SCRAP1 1
         debris SCRAP2 1
         debris SCRAP3 1
         setvar ENEMYBOOTSAMOUNT 0
        }
ends

state enemycheckhealthdmgflr
  setvarvar TEMPFLRDMG ENEMYHP
ends

state enemycheckdamagefloor
 ifvarl TEMP6 1 state showdamage_actor-dmgflrhp
 setvar FLOORDAMAGETEMP 0
 ifvarg TEMPFLRDMG -1
 {
  setvarvar ENEMYHP TEMPFLRDMG
  setvarvar tempb ENEMYHP
  ifvarl TEMPFLRDMG 0
  {
   setvarvar ENEMYHP 0
   setactor[THISACTOR].extra 0
   setactor[THISACTOR].htpicnum RPG
   setvarvar tempe THISACTOR 
   ifvarl THISACTOR 16383 addvar tempe 1 else subvar tempe 1
   setactor[THISACTOR].htowner THISACTOR // tempe
   setactor[THISACTOR].htextra 1
   setvarvar tempc ENEMYHP
  }
 }
 else
 {
  setvarvar ENEMYHP 0
  setactor[THISACTOR].extra 0
  setactor[THISACTOR].htpicnum RPG
  setvarvar tempe THISACTOR 
  ifvarl THISACTOR 16383 addvar tempe 1 else subvar tempe 1
  setactor[THISACTOR].htowner THISACTOR // tempe
  setactor[THISACTOR].htextra 1
  setvarvar tempc ENEMYHP
 }
ends

state check-heatratio-enemy
  getactor[THISACTOR].sectnum tempf
  getactorvar[tempf].FLOORHEATRATIO tempg
  mulvarvar FLOORDAMAGETEMP tempg
  divvar FLOORDAMAGETEMP 100
ends

state enemyelitecheckdmgflr
  ifvarand ACTORFLAGS 512 // Elite Monsters Suffer 6.3% to 12.5% Sector-Based Damage
  {
   randvar TEMP 62
   addvar TEMP 63
   mulvarvar FLOORDAMAGETEMP TEMP
   divvar FLOORDAMAGETEMP 1000
   ifvarl FLOORDAMAGETEMP 1 { ifrnd 128 setvar FLOORDAMAGETEMP 0 else setvar FLOORDAMAGETEMP 1 }
  }

  getactor[THISACTOR].sectnum tempf
  getsector[tempf].floorpicnum tempg
  ifvare tempg NEWFLOORPLASMA state check-heatratio-enemy
  else ifvare tempg HOTLAVA state check-heatratio-enemy
  else ifvare tempg MEGALAVA state check-heatratio-enemy
  else ifvare tempg ULTRALAVA state check-heatratio-enemy
  else ifvare tempg HYPERMAGMA state check-heatratio-enemy

ends

state enemydealflrdmg
     ifvare SHRUNK? 1
     {
      ifrnd 128 mulvar FLOORDAMAGETEMP 5 else mulvar FLOORDAMAGETEMP 4
     }
     subvarvar TEMPFLRDMG FLOORDAMAGETEMP 
     ifvarg FLOORDAMAGETEMP 0 setvar ENEMYHPDAMAGED? 1
     state enemyfloordamagesounds
     state enemycheckdamagefloor
ends

state enemydmgflr_hpmaxcalcend
        ifvarl tempe 1 setvar tempe 1
        addvarvar FLOORDAMAGETEMP tempe
        state enemyelitecheckdmgflr
        state enemydealflrdmg
ends

 state enemynewfloorslime_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 setvar tempd 0
        ifvare SKILLLEVEL 8 setvar tempd 0
        ifvare SKILLLEVEL 7 setvar tempd 0
        ifvare SKILLLEVEL 6 setvar tempd 0
        ifvare SKILLLEVEL 5 setvar tempd 0
        ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 1 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
       }
       else setvar tempd 1 // 0.1%
       mulvarvar tempe tempd
 ends

state enemy-newfloorslime
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1 // Prevents enemies from being able to take damage from damagefloors/sectors when the menu is open
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 4
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 2 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewfloorslime_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 4 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 2
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 1
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 0
         state enemynewfloorslime_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
         ifrnd 4 state addpoison_actor
        }
       }
      }
      else ifrnd 2 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
       {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 16
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          subvar ENEMYBOOTSAMOUNT 1 
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 3 
          mulvar FLOORDAMAGETEMP 1 
          addvar FLOORDAMAGETEMP 1
          state enemynewfloorslime_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
          ifrnd 4 state addpoison_actor
         }
        }
       }
       else
       {
        ifrnd 16 sound INVULNITEM3
       }
      }
     break

     case BOOTS
      ifrnd 16
      {
       setvar FLOORDAMAGETEMP 1
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     // Drones and Turrents are machines and therefore poisoning cannot be done to them.
     case DRONE
     case ROTATEGUN
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 16
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewfloorslime_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 16 sound INVULNITEM3
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 16
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewfloorslime_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
         ifrnd 4 state addpoison_actor
        }
       }
      }
      else ifrnd 16 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemynewhurtrail_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 setvar tempd 0
        ifvare SKILLLEVEL 8 setvar tempd 0
        ifvare SKILLLEVEL 7 setvar tempd 0
        ifvare SKILLLEVEL 6 setvar tempd 0
        ifvare SKILLLEVEL 5 setvar tempd 0
        ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 1 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
       }
       else setvar tempd 1 // 0.1%
       mulvarvar tempe tempd
 ends

state enemy-newhurtrail
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 8
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 2 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewhurtrail_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
         sound SHORT_CIRCUIT
        }
       }
      }
      else ifrnd 8 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 4
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 1
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 0
         state enemynewhurtrail_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
         sound SHORT_CIRCUIT
        }
       }
      }
      else ifrnd 4 sound INVULNITEM3
     break

     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 4
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 12
         mulvar FLOORDAMAGETEMP 4
         addvar FLOORDAMAGETEMP 4
//
         setvarvar tempe ENEMYMAXHP
         ifvare DMGFLRTYPE 0
         {
          ifvare SKILLLEVEL 9 setvar tempd 0
          ifvare SKILLLEVEL 8 setvar tempd 0
          ifvare SKILLLEVEL 7 setvar tempd 0
          ifvare SKILLLEVEL 6 setvar tempd 0
          ifvare SKILLLEVEL 5 setvar tempd 0
          ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 0 }
          ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
          ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
          ifvare SKILLLEVEL 1 { randvar tempd 1 addvar tempd 1 }
          ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
         }
         else setvar tempd 1 // 0.1%
         mulvarvar tempe tempd
         divvar tempe 2250
//
         ifvare SHRUNK? 1
         {
          ifrnd 128 mulvar FLOORDAMAGETEMP 5 else mulvar FLOORDAMAGETEMP 4
         }
         addvarvar TEMPFLRDMG FLOORDAMAGETEMP 
         ifvarg FLOORDAMAGETEMP 0 soundonce ABSORB_DAMAGE

         setvarvar ITEMSEEK THISACTOR
         setvarvar ITEMSEEKC FLOORDAMAGETEMP
         state showhealing_actorhp
         setvarvar TEMP6 FLOORDAMAGETEMP

         setvar ENEMYHPDAMAGED? -1
         state enemycheckdamagefloor
         sound SHORT_CIRCUIT
        }
       }
      }
      else ifrnd 4 sound INVULNITEM3
     break

     case NEWBEAST
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 32
       {
        state enemycheckhealthdmgflr 
        randvar FLOORDAMAGETEMP 3 
        mulvar FLOORDAMAGETEMP 1 
        addvar FLOORDAMAGETEMP 1
//
        setvarvar tempe ENEMYMAXHP
        ifvare DMGFLRTYPE 0
        {
         ifvare SKILLLEVEL 9 setvar tempd 0
         ifvare SKILLLEVEL 8 setvar tempd 0
         ifvare SKILLLEVEL 7 setvar tempd 0
         ifvare SKILLLEVEL 6 setvar tempd 0
         ifvare SKILLLEVEL 5 setvar tempd 0
         ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 0 }
         ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
         ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
         ifvare SKILLLEVEL 1 { randvar tempd 1 addvar tempd 1 }
         ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
        }
        else setvar tempd 1 // 0.1%
        mulvarvar tempe tempd
        divvar tempe 1000
//
        ifspritepal 17 { mulvar FLOORDAMAGETEMP 5 divvar FLOORDAMAGETEMP 2 }
        else ifspritepal 20 mulvar FLOORDAMAGETEMP 4
        getactor[THISACTOR].extra temp
        ifvarg temp -1 
        {
         ifvare SHRUNK? 1
         {
          ifrnd 128 mulvar FLOORDAMAGETEMP 5 else mulvar FLOORDAMAGETEMP 4
         }
         addvarvar TEMPFLRDMG FLOORDAMAGETEMP
         ifvarg FLOORDAMAGETEMP 0 soundonce ABSORB_DAMAGE

         setvarvar ITEMSEEK THISACTOR
         setvarvar ITEMSEEKC FLOORDAMAGETEMP
         state showhealing_actorhp
         setvarvar TEMP6 FLOORDAMAGETEMP

         setvar ENEMYHPDAMAGED? -1
         state enemycheckdamagefloor
         sound SHORT_CIRCUIT
        }      
       }
      }
      else ifrnd 32 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 32
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          subvar ENEMYBOOTSAMOUNT 1 
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 3 
          mulvar FLOORDAMAGETEMP 1 
          addvar FLOORDAMAGETEMP 1
          state enemynewhurtrail_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
          sound SHORT_CIRCUIT
         }
        }
       }
       else ifrnd 32 sound INVULNITEM3
      }
     break

     case DRONE
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 32
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         ifspritepal 25 { mulvar FLOORDAMAGETEMP 5 divvar FLOORDAMAGETEMP 4 } else mulvar FLOORDAMAGETEMP 2
         state enemynewhurtrail_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
         sound SHORT_CIRCUIT
        }
       }
      }
      else ifrnd 32 sound INVULNITEM3
     break

     case BOOTS
      ifrnd 32
      {
       setvar FLOORDAMAGETEMP 1
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 32
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewhurtrail_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
         sound SHORT_CIRCUIT
        }
       }
      }
      else ifrnd 32 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemynewfloorplasma_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 setvar tempd 0
        ifvare SKILLLEVEL 8 setvar tempd 0
        ifvare SKILLLEVEL 7 setvar tempd 0
        ifvare SKILLLEVEL 6 setvar tempd 0
        ifvare SKILLLEVEL 5 setvar tempd 0
        ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 1 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
       }
       else setvar tempd 1 // 0.1%
       mulvarvar tempe tempd
 ends

state enemy-newfloorplasma
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 8
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 2 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewfloorplasma_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 8 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 4
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 1
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 0
         state enemynewfloorplasma_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 4 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 32
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          subvar ENEMYBOOTSAMOUNT 1 
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 3 
          mulvar FLOORDAMAGETEMP 1 
          addvar FLOORDAMAGETEMP 1
          state enemynewfloorplasma_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 32 sound INVULNITEM3
      }
     break

     case BOOTS
      ifrnd 32
      {
       setvar FLOORDAMAGETEMP 1
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 32
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3 
         mulvar FLOORDAMAGETEMP 1 
         addvar FLOORDAMAGETEMP 1
         state enemynewfloorplasma_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 32 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemynewpurplelava_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 setvar tempd 0
        ifvare SKILLLEVEL 8 setvar tempd 0
        ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
        ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 2 }
        ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 2 }
        ifvare SKILLLEVEL 1 { randvar tempd 2 addvar tempd 2 }
        ifvare SKILLLEVEL 0 { randvar tempd 2 addvar tempd 2 }
       }
       else setvar tempd 2 // 0.1%
       mulvarvar tempe tempd
 ends

state enemy-newpurplelava
  ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1

  ifvare ENEMYDAMAGEFLOORTIMER 1
  {
    ifvarl ENEMYBOOTSAMOUNT 1 setvar FLOORDAMAGETEMP 1
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 64
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        {  
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         setvar FLOORDAMAGETEMP 1
         state enemynewpurplelava_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 64 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 32
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        {  
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         setvar FLOORDAMAGETEMP 1
         state enemynewpurplelava_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
         ifrnd 12 state addpoison_actor
        }
       }
      }
      else ifrnd 32 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      { 
       ifvarl ENEMYINVULNTIME 1
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        {  
         subvar ENEMYBOOTSAMOUNT 1 
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         setvar FLOORDAMAGETEMP 1
         state enemynewpurplelava_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
         ifrnd 12 state addpoison_actor
        }
       }
       else sound INVULNITEM3
      }
     break

     case BOOTS
      setvar FLOORDAMAGETEMP 1
      subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
     break

     // Drones and Turrents are machines and therefore poisoning cannot be done to them.
     case DRONE
     case ROTATEGUN
      ifvarl ENEMYINVULNTIME 1
      {
       ifvarg ENEMYBOOTSAMOUNT 0 
       {  
        subvar ENEMYBOOTSAMOUNT 1 
        state enemybootscheck
       } 
       else 
       { 
        state enemycheckhealthdmgflr 
        setvar FLOORDAMAGETEMP 1
        state enemynewpurplelava_hpmaxcalc
        divvar tempe 1000
        state enemydmgflr_hpmaxcalcend
       }
      }
      else sound INVULNITEM3
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifvarg ENEMYBOOTSAMOUNT 0 
       {  
        subvar ENEMYBOOTSAMOUNT 1 
        state enemybootscheck
       } 
       else 
       { 
        state enemycheckhealthdmgflr 
        setvar FLOORDAMAGETEMP 1
        state enemynewpurplelava_hpmaxcalc
        divvar tempe 1000
        state enemydmgflr_hpmaxcalcend
        ifrnd 12 state addpoison_actor
       }
      }
      else sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
  }
ends

 state enemyhotlava_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 randvar tempd 1
        ifvare SKILLLEVEL 8 randvar tempd 1
        ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 2 }
        ifvare SKILLLEVEL 6 { randvar tempd 2 addvar tempd 1 }
        ifvare SKILLLEVEL 5 { randvar tempd 2 addvar tempd 2 }
        ifvare SKILLLEVEL 4 { randvar tempd 3 addvar tempd 3 }
        ifvare SKILLLEVEL 3 { randvar tempd 4 addvar tempd 4 }
        ifvare SKILLLEVEL 2 { randvar tempd 6 addvar tempd 6 }
        ifvare SKILLLEVEL 1 { randvar tempd 9 addvar tempd 9 }
        ifvare SKILLLEVEL 0 { randvar tempd 14 addvar tempd 13 }
       }
       else setvar tempd 13 // 1.3%
       mulvarvar tempe tempd
 ends

state enemy-hotlava
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 16
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 1
         addvar TEMPVAR 5
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3
         mulvar FLOORDAMAGETEMP 6
         addvar FLOORDAMAGETEMP 5
         state enemyhotlava_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 16 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 8
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 1
         addvar TEMPVAR 5
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 1
         mulvar FLOORDAMAGETEMP 5
         addvar FLOORDAMAGETEMP 2
         state enemyhotlava_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 8 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 64
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          randvar TEMPVAR 1
          addvar TEMPVAR 5
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 4 
          mulvar FLOORDAMAGETEMP 9 
          addvar FLOORDAMAGETEMP 9
          state enemyhotlava_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 64 sound INVULNITEM3
      }
     break

     case BOOTS
      ifrnd 64
      {
       randvar FLOORDAMAGETEMP 1
       addvar FLOORDAMAGETEMP 5
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 64
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 1
         addvar TEMPVAR 5
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 4 
         mulvar FLOORDAMAGETEMP 9 
         addvar FLOORDAMAGETEMP 9
         state enemyhotlava_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 64 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemyamoebaacid_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 setvar tempd 0
        ifvare SKILLLEVEL 8 setvar tempd 0
        ifvare SKILLLEVEL 7 randvar tempd 1
        ifvare SKILLLEVEL 6 randvar tempd 1
        ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 4 { randvar tempd 2 addvar tempd 1 }
        ifvare SKILLLEVEL 3 { randvar tempd 2 addvar tempd 2 }
        ifvare SKILLLEVEL 2 { randvar tempd 3 addvar tempd 3 }
        ifvare SKILLLEVEL 1 { randvar tempd 5 addvar tempd 4 }
        ifvare SKILLLEVEL 0 { randvar tempd 7 addvar tempd 6 }
       }
       else { randvar tempd 1 addvar tempd 6 } // 0.6% to 0.7%
       mulvarvar tempe tempd
 ends

state enemy-amoebaacid
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 10
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 1
         addvar TEMPVAR 2
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3
         mulvar FLOORDAMAGETEMP 3
         addvar FLOORDAMAGETEMP 2
         state enemyamoebaacid_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 10 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 5
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 1
         addvar TEMPVAR 2
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 1
         mulvar FLOORDAMAGETEMP 2
         addvar FLOORDAMAGETEMP 1
         state enemyamoebaacid_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 5 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 40
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          randvar TEMPVAR 1
          addvar TEMPVAR 2
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 4
          mulvar FLOORDAMAGETEMP 4
          addvar FLOORDAMAGETEMP 4
          state enemyamoebaacid_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 40 sound INVULNITEM3
      }
     break

     case BOOTS
      ifrnd 40
      {
       randvar FLOORDAMAGETEMP 1
       addvar FLOORDAMAGETEMP 2
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 40
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 1
         addvar TEMPVAR 2
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 4
         mulvar FLOORDAMAGETEMP 4
         addvar FLOORDAMAGETEMP 4
         state enemyamoebaacid_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 40 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemymegalava_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
        ifvare SKILLLEVEL 8 { randvar tempd 2 addvar tempd 1 }
        ifvare SKILLLEVEL 7 { randvar tempd 3 addvar tempd 2 }
        ifvare SKILLLEVEL 6 { randvar tempd 4 addvar tempd 3 }
        ifvare SKILLLEVEL 5 { randvar tempd 5 addvar tempd 5 }
        ifvare SKILLLEVEL 4 { randvar tempd 8 addvar tempd 7 }
        ifvare SKILLLEVEL 3 { randvar tempd 10 addvar tempd 10 }
        ifvare SKILLLEVEL 2 { randvar tempd 15 addvar tempd 15 }
        ifvare SKILLLEVEL 1 { randvar tempd 23 addvar tempd 22 }
        ifvare SKILLLEVEL 0 { randvar tempd 34 addvar tempd 33 }
       }
       else { randvar tempd 1 addvar tempd 33 } // 3.3% to 3.4%
       mulvarvar tempe tempd
 ends

state enemy-megalava
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 24
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 2
         addvar TEMPVAR 7
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3
         mulvar FLOORDAMAGETEMP 50
         addvar FLOORDAMAGETEMP 42
         state enemymegalava_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 24 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 12
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 2
         addvar TEMPVAR 7
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 2
         mulvar FLOORDAMAGETEMP 38
         addvar FLOORDAMAGETEMP 20
         state enemymegalava_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 12 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 96
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          randvar TEMPVAR 2
          addvar TEMPVAR 7
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 5
          mulvar FLOORDAMAGETEMP 75
          addvar FLOORDAMAGETEMP 75
          state enemymegalava_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 96 sound INVULNITEM3
      }
     break

     case BOOTS
      ifrnd 96
      {
       randvar FLOORDAMAGETEMP 2
       addvar FLOORDAMAGETEMP 7
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 96
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 2
         addvar TEMPVAR 7
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 5
         mulvar FLOORDAMAGETEMP 75
         addvar FLOORDAMAGETEMP 75
         state enemymegalava_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 96 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemyultramagma_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 { randvar tempd 5 addvar tempd 5 }
        ifvare SKILLLEVEL 8 { randvar tempd 8 addvar tempd 7 }
        ifvare SKILLLEVEL 7 { randvar tempd 10 addvar tempd 10 }
        ifvare SKILLLEVEL 6 { randvar tempd 15 addvar tempd 15 }
        ifvare SKILLLEVEL 5 { randvar tempd 20 addvar tempd 20 }
        ifvare SKILLLEVEL 4 { randvar tempd 30 addvar tempd 30 }
        ifvare SKILLLEVEL 3 { randvar tempd 40 addvar tempd 40 }
        ifvare SKILLLEVEL 2 { randvar tempd 60 addvar tempd 60 }
        ifvare SKILLLEVEL 1 { randvar tempd 90 addvar tempd 90 }
        ifvare SKILLLEVEL 0 { randvar tempd 135 addvar tempd 135 }
       }
       else setvar tempd 135 // 13.5%
       mulvarvar tempe tempd
 ends

state enemy-ultramagma
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 32
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 3
         addvar TEMPVAR 12
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3
         mulvar FLOORDAMAGETEMP 160
         addvar FLOORDAMAGETEMP 133
         state enemyultramagma_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 32 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 16
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 3
         addvar TEMPVAR 12
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 2
         mulvar FLOORDAMAGETEMP 120
         addvar FLOORDAMAGETEMP 64
         state enemyultramagma_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 16 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14 nullop
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 128
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          randvar TEMPVAR 3
          addvar TEMPVAR 12
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 5
          mulvar FLOORDAMAGETEMP 240
          addvar FLOORDAMAGETEMP 240
          state enemyultramagma_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 128 sound INVULNITEM3
      }
     break

     case BOOTS
      ifrnd 128
      {
       randvar FLOORDAMAGETEMP 3
       addvar FLOORDAMAGETEMP 12
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 128
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 3
         addvar TEMPVAR 12
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 5
         mulvar FLOORDAMAGETEMP 240
         addvar FLOORDAMAGETEMP 240
         state enemyultramagma_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 128 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

 state enemyhypermagma_hpmaxcalc
       setvarvar tempe ENEMYMAXHP
       ifvare DMGFLRTYPE 0
       {
        ifvare SKILLLEVEL 9 { randvar tempd 20 addvar tempd 20 }
        ifvare SKILLLEVEL 8 { randvar tempd 32 addvar tempd 32 }
        ifvare SKILLLEVEL 7 { randvar tempd 40 addvar tempd 40 }
        ifvare SKILLLEVEL 6 { randvar tempd 60 addvar tempd 60 }
        ifvare SKILLLEVEL 5 { randvar tempd 80 addvar tempd 80 }
        ifvare SKILLLEVEL 4 { randvar tempd 120 addvar tempd 120 }
        ifvare SKILLLEVEL 3 { randvar tempd 160 addvar tempd 160 }
        ifvare SKILLLEVEL 2 { randvar tempd 240 addvar tempd 240 }
        ifvare SKILLLEVEL 1 { randvar tempd 360 addvar tempd 360 }
        ifvare SKILLLEVEL 0 { randvar tempd 540 addvar tempd 540 }
       }
       else setvar tempd 540 // 54.0%
       mulvarvar tempe tempd
 ends

state enemy-hypermagma
  iffloordistl 16
  {
   ifvare mainmenu 0 addvar ENEMYDAMAGEFLOORTIMER 1
   
   ifvare ENEMYDAMAGEFLOORTIMER 1
   {
    getactor[THISACTOR].picnum TEMPVAR4
    switch TEMPVAR4
     case EMPTYTANK
     case TANK
     case SCORPIONTANK
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 56
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 6
         addvar TEMPVAR 28
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 4
         mulvar FLOORDAMAGETEMP 533
         addvar FLOORDAMAGETEMP 443
         state enemyhypermagma_hpmaxcalc
         divvar tempe 1500
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 56 sound INVULNITEM3
     break

     case BOSS1
     case BOSS2
     case BOSS3
     case BOSS4
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 28
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 6
         addvar TEMPVAR 28
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 3
         mulvar FLOORDAMAGETEMP 400
         addvar FLOORDAMAGETEMP 214
         state enemyhypermagma_hpmaxcalc
         divvar tempe 2250
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 28 sound INVULNITEM3
     break

     case OCTABRAIN
      ifspritepal 14
      { 
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 28
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          randvar TEMPVAR 6
          addvar TEMPVAR 28
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 3
          mulvar FLOORDAMAGETEMP 400
          addvar FLOORDAMAGETEMP 400
          state enemyhypermagma_hpmaxcalc
          divvar tempe 4000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 28 sound INVULNITEM3
      }
      else
      {
       ifvarl ENEMYINVULNTIME 1
       {
        ifrnd 224
        {
         ifvarg ENEMYBOOTSAMOUNT 0 
         { 
          randvar TEMPVAR 6
          addvar TEMPVAR 28
          state enemybootscheck
         } 
         else 
         { 
          state enemycheckhealthdmgflr 
          randvar FLOORDAMAGETEMP 6
          mulvar FLOORDAMAGETEMP 800
          addvar FLOORDAMAGETEMP 800
          state enemyhypermagma_hpmaxcalc
          divvar tempe 1000
          state enemydmgflr_hpmaxcalcend
         }
        }
       }
       else ifrnd 224 sound INVULNITEM3
      }
     break

     case BOOTS
      ifrnd 224
      {
       randvar FLOORDAMAGETEMP 6
       addvar FLOORDAMAGETEMP 28
       subvarvar POWERUPBENEFIT FLOORDAMAGETEMP 
      }
     break

     default
      ifvarl ENEMYINVULNTIME 1
      {
       ifrnd 224
       {
        ifvarg ENEMYBOOTSAMOUNT 0 
        { 
         randvar TEMPVAR 6
         addvar TEMPVAR 28
         state enemybootscheck
        } 
        else 
        { 
         state enemycheckhealthdmgflr 
         randvar FLOORDAMAGETEMP 6
         mulvar FLOORDAMAGETEMP 800
         addvar FLOORDAMAGETEMP 800
         state enemyhypermagma_hpmaxcalc
         divvar tempe 1000
         state enemydmgflr_hpmaxcalcend
        }
       }
      }
      else ifrnd 224 sound INVULNITEM3
     break
    endswitch 

    setvar ENEMYDAMAGEFLOORTIMER 0
   }
  }
ends

state enemytileemulationhurt
getactor[THISACTOR].sectnum TEMPVAR
getactorvar[TEMPVAR].SECTOREXTRA ENEMYTILEEMUL

ifvare ENEMYSECTORLOTAG 2
{
  ifvare CLOAKED? 0
  {
   ifvare ENEMYTILEEMUL 5385 state enemy-newfloorslime // NEWFLOORSLIME [Slime]
   else ifvare ENEMYTILEEMUL 5388 state enemy-newhurtrail // NEWHURTRAIL [Electric Chair/Electrified Floors]
   else ifvare ENEMYTILEEMUL 5389 state enemy-newfloorplasma // NEWFLOORPLASMA [Lava]   
   else ifvare ENEMYTILEEMUL 5395 state enemy-newpurplelava // NEWPURPLELAVA [Superlava]
   else ifvare ENEMYTILEEMUL 3780 state enemy-hotlava // HOTLAVA
   else ifvare ENEMYTILEEMUL 3796 state enemy-amoebaacid // AMOEBAACID
   else ifvare ENEMYTILEEMUL 4091 state enemy-megalava // MEGALAVA
   else ifvare ENEMYTILEEMUL 5401 state enemy-ultramagma // ULTRALAVA
   else ifvare ENEMYTILEEMUL 5443 state enemy-hypermagma // HYPERMAGMA
   else // non-damagefloor
   {
    setvar ENEMYDAMAGEFLOORTIMER 0
    setvar FLOORDAMAGETEMP 0
   } 
  }
}
else // Out of Water
{
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y
  updatesector x y TEMP
  getflorzofslope TEMP x y tempb
  getactor[THISACTOR].z tempc
  addvar tempc 256
  setvarvar tempe tempb
  addvar tempe -8
  addvar tempb 8
  getsector[THISACTOR].lotag temp
  ifvare temp 1 addvar tempb 6144

  ifvare CLOAKED? 0
  {
   ifvare ENEMYTILEEMUL 5395 state enemy-newpurplelava
   else ifvarvarl tempc tempb ifvarvarg tempc tempe 
   {
    ifvare ENEMYTILEEMUL 5385 state enemy-newfloorslime // NEWFLOORSLIME [Slime]
    else ifvare ENEMYTILEEMUL 5388 state enemy-newhurtrail // NEWHURTRAIL [Electric Chair/Electrified Floors]
    else ifvare ENEMYTILEEMUL 5389 state enemy-newfloorplasma // NEWFLOORPLASMA [Lava]
    else ifvare ENEMYTILEEMUL 3780 state enemy-hotlava // HOTLAVA
    else ifvare ENEMYTILEEMUL 3796 state enemy-amoebaacid // AMOEBAACID
    else ifvare ENEMYTILEEMUL 4091 state enemy-megalava // MEGALAVA
    else ifvare ENEMYTILEEMUL 5401 state enemy-ultramagma // ULTRALAVA
    else ifvare ENEMYTILEEMUL 5443 state enemy-hypermagma // HYPERMAGMA
    else // non-damagefloor
    {
     setvar ENEMYDAMAGEFLOORTIMER 0
     setvar FLOORDAMAGETEMP 0
    }
   } // ifvarvarl tempc tempd ifvarvarg tempc tempe 
  } // ifvare CLOAKED? 0
}

ends

state enemyceilinghurt

getsector[THISACTOR].ceilingpicnum ENEMYCEILINGTILE
ifvare ENEMYSECTORLOTAG 2
{
  ifvare CLOAKED? 0
  {
   ifvare ENEMYCEILINGTILE 5385 state enemy-newfloorslime // NEWFLOORSLIME [Slime]
   else ifvare ENEMYCEILINGTILE 5388 state enemy-newhurtrail // NEWHURTRAIL [Electric Chair/Electrified Floors]
   else ifvare ENEMYCEILINGTILE 5389 state enemy-newfloorplasma // NEWFLOORPLASMA [Lava]
   else ifvare ENEMYCEILINGTILE 5395 state enemy-newpurplelava // NEWPURPLELAVA [Superlava]
   else ifvare ENEMYCEILINGTILE 3780 state enemy-hotlava // HOTLAVA
   else ifvare ENEMYCEILINGTILE 3796 state enemy-amoebaacid // AMOEBAACID
   else ifvare ENEMYCEILINGTILE 4091 state enemy-megalava // MEGALAVA
   else ifvare ENEMYCEILINGTILE 5401 state enemy-ultramagma // ULTRALAVA
   else ifvare ENEMYCEILINGTILE 5443 state enemy-hypermagma // HYPERMAGMA
   else // non-damagefloor
   {
    setvar ENEMYDAMAGEFLOORTIMER 0
    setvar FLOORDAMAGETEMP 0
   } 
  }
}
ends

state enemyfloorhurt // State for allowing monsters/actors to take damage from damagefloors[lava/floorslime/purplelava/hurtrail/etc]

getsector[THISACTOR].floorpicnum ENEMYFLOORTILE
//ifvarl ENEMYINVULNTIME 1 // Prevents enemies with invuln from taking damage[and from being killed by an Invuln Player if standing in a damaging sector with Invuln themselves]
//{
 getactor[THISACTOR].x x
 getactor[THISACTOR].y y
 updatesector x y TEMP
 getflorzofslope TEMP x y tempb
 getactor[THISACTOR].z tempc
 addvar tempc 256
 setvarvar tempe tempb
 addvar tempe -8
 addvar tempb 8
 getsector[THISACTOR].lotag temp
 ifvare temp 1 addvar tempb 6144

 ifvare CLOAKED? 0
 {
  ifvare ENEMYFLOORTILE 5395 state enemy-newpurplelava // NEWPURPLELAVA [Superlava]
  else ifvarvarl tempc tempb ifvarvarg tempc tempe 
  {
   ifvare ENEMYFLOORTILE 5385 state enemy-newfloorslime // NEWFLOORSLIME [Slime]
   else ifvare ENEMYFLOORTILE 5388 state enemy-newhurtrail // NEWHURTRAIL [Electric Chair/Electrified Floors]
   else ifvare ENEMYFLOORTILE 5389 state enemy-newfloorplasma // NEWFLOORPLASMA [Lava]
   else ifvare ENEMYFLOORTILE 3780 state enemy-hotlava // HOTLAVA
   else ifvare ENEMYFLOORTILE 3796 state enemy-amoebaacid // AMOEBAACID
   else ifvare ENEMYFLOORTILE 4091 state enemy-megalava // MEGALAVA
   else ifvare ENEMYFLOORTILE 5401 state enemy-ultramagma // ULTRALAVA
   else ifvare ENEMYFLOORTILE 5443 state enemy-hypermagma // HYPERMAGMA
   else // non-damagefloor
   {
    setvar ENEMYDAMAGEFLOORTIMER 0
    setvar FLOORDAMAGETEMP 0
   }
  } // ifvarvarl tempc tempd ifvarvarg tempc tempe 
 } // ifvare CLOAKED? 0
//}

 state enemyceilinghurt

 state enemytileemulationhurt
ends

state enemyfirstaidstationcheck
    setvar ITEMFATARGET -1
    ifvarn ITEMTARGET -1
    {
      // Otherwise so far all other items are fair game to all monster species
      getactor[THISACTOR].picnum TEMP
      ifvare TEMP BOSS2
      {
       getactor[THISACTOR].pal TEMP
       ifvare TEMP 0
       {
        getactor[ITEMTARGET].sectnum TEMP
        getsector[TEMP].lotag TEMP
        ifvarn TEMP 3
        {
         setvar ITEMTARGET -1
         break
        }
        else
        {
         ifactornotstayput
         {
          getactorvar[ITEMTARGET].HEALPANEL_CHARGES TEMP
          ifvarl TEMP 1
          {
           setvar ITEMTARGET -1
           break
          }
          else setvarvar ITEMFATARGET ITEMTARGET
         }
         else
         {
          getactor[THISACTOR].sectnum TEMP2
          getactor[ITEMTARGET].sectnum TEMP3
          ifvarvarn TEMP2 TEMP3
          {
           setvar ITEMTARGET -1
           break
          }
          else setvarvar ITEMFATARGET ITEMTARGET
         }
        }
       }
       else
       {
        ifactornotstayput
        {
         getactorvar[ITEMTARGET].HEALPANEL_CHARGES TEMP
         ifvarl TEMP 1
         {
          setvar ITEMTARGET -1
          break
         }
         else setvarvar ITEMFATARGET ITEMTARGET
        }
        else
        {
         getactor[THISACTOR].sectnum TEMP2
         getactor[ITEMTARGET].sectnum TEMP3
         ifvarvarn TEMP2 TEMP3
         {
          setvar ITEMTARGET -1
          break
         }
         else setvarvar ITEMFATARGET ITEMTARGET
        }
       }
      }
      else
      {
       ifactornotstayput
       {
        getactorvar[ITEMTARGET].HEALPANEL_CHARGES TEMP
        ifvarl TEMP 1
        {
         setvar ITEMTARGET -1
         break
        }
        else setvarvar ITEMFATARGET ITEMTARGET
       }
       else
       {
        getactor[THISACTOR].sectnum TEMP2
        getactor[ITEMTARGET].sectnum TEMP3
        ifvarvarn TEMP2 TEMP3
        {
         setvar ITEMTARGET -1
         break
        }
        else setvarvar ITEMFATARGET ITEMTARGET
       }
      }
    }
ends

state enemyitemcheckstayput
   ifvarn ITEMTARGET -1 getactorvar[ITEMTARGET].ACTORFLAGS TEMP
   ifvarand TEMP 16
   {
    setvar ITEMTARGET -1
    break
   }
/*
   else
   ifvarand TEMP 8192 // Enemies will not try to grab items that are fully booby-trapped
   {
    setvar ITEMTARGET -1
    break
   }
*/
   else
   {
    ifvarn ITEMTARGET -1
    {
     getactorvar[ITEMTARGET].ITEMDROPPEDTIME TEMP4
     ifvarl TEMP4 1 // Checks to see if the item is still recovering from being dropped by a player
     {
      // Only LIZTROOPs will look for Jetpacks
      getactor[ITEMTARGET].picnum TEMP
      ifvare TEMP JETPACK
      {
       getactor[THISACTOR].picnum TEMP
       ifvarn TEMP LIZTROOP // Stops the search for a jetpack if the creature is not a LIZTROOP
       {
        setvar ITEMTARGET -1
        break
       }
       else // If it is a LIZTROOP, make sure it is not stayput and the jetpack is in a different sector from it.
       {
        ifactornotstayput nullop
        else
        {
         getactor[THISACTOR].sectnum TEMP2
         getactor[ITEMTARGET].sectnum TEMP3
         ifvarvarn TEMP2 TEMP3
         {
          setvar ITEMTARGET -1
          break
         }
        }
       }
      }

      // Otherwise so far all other items are fair game to all monster species
      getactor[THISACTOR].picnum TEMP
      ifvare TEMP BOSS2
      {
       getactor[THISACTOR].pal TEMP
       ifvare TEMP 0
       {
        getactor[ITEMTARGET].sectnum TEMP
        getsector[TEMP].lotag TEMP
        ifvarn TEMP 3
        {
         setvar ITEMTARGET -1
         break
        }
        else
        {
         ifactornotstayput nullop
         else
         {
          getactor[THISACTOR].sectnum TEMP2
          getactor[ITEMTARGET].sectnum TEMP3
          ifvarvarn TEMP2 TEMP3
          {
           setvar ITEMTARGET -1
           break
          }
         }
        }
       }
       else
       {
        ifactornotstayput nullop
        else
        {
         getactor[THISACTOR].sectnum TEMP2
         getactor[ITEMTARGET].sectnum TEMP3
         ifvarvarn TEMP2 TEMP3
         {
          setvar ITEMTARGET -1
          break
         }
        }
       }
      }
      else
      {
       ifactornotstayput nullop
       else
       {
        getactor[THISACTOR].sectnum TEMP2
        getactor[ITEMTARGET].sectnum TEMP3
        ifvarvarn TEMP2 TEMP3
        {
         setvar ITEMTARGET -1
         break
        }
       }
      }
     }
     else
     {
      setvar ITEMTARGET -1
      break
     }
    }
   }
ends

state enemyitemzsetup1
      getactor[ITEMTARGET].z ITEMTARGETZ
      getactor[THISACTOR].z ITEMSEEKERZ
      subvar ITEMTARGETZ 4096
      setactor[ITEMTARGET].z ITEMTARGETZ
      subvar ITEMSEEKERZ 8192
      setactor[THISACTOR].z ITEMSEEKERZ
      canseespr THISACTOR ITEMTARGET CANSEEITEM?
      addvar ITEMTARGETZ 4096
      setactor[ITEMTARGET].z ITEMTARGETZ
      addvar ITEMSEEKERZ 8192
      setactor[THISACTOR].z ITEMSEEKERZ
ends

state enemyitemzsetup2

      getactor[ITEMTARGET].x ITEMTARGETX
      getactor[ITEMTARGET].y ITEMTARGETY
      getactor[THISACTOR].x ITEMSEEKERX
      getactor[THISACTOR].y ITEMSEEKERY
      subvarvar ITEMTARGETX ITEMSEEKERX
      subvarvar ITEMTARGETY ITEMSEEKERY
      getangle ITEMSEEKERANGLE ITEMTARGETX ITEMTARGETY
      ifvarand ACTORSTATUS? 128
      {
       setvarvar TEMPVAR4 ITEMSEEKERANGLE
       subvarvar TEMPVAR4 ACTORANGLE
       subvarvar ITEMSEEKERANGLE TEMPVAR4
      }
      setactor[THISACTOR].ang ITEMSEEKERANGLE
      
ends

state resetplayeritems
  setvar QUADTIME 0
  setvar INVULNTIME 0
  setvar REGENTIME 0
  setvar APREGENTIME 0
  setvar VAMPIRETIME 0
ends

state enemyhealzsetup2
      getactor[HEALSEEK].x HEALTARGETX
      getactor[HEALSEEK].y HEALTARGETY
      getactor[THISACTOR].x HEALSEEKERX
      getactor[THISACTOR].y HEALSEEKERY
      subvarvar HEALTARGETX HEALSEEKERX
      subvarvar HEALTARGETY HEALSEEKERY
      getangle HEALSEEKERANGLE HEALTARGETX HEALTARGETY
      setactor[THISACTOR].ang HEALSEEKERANGLE
ends

state healdetectifdead
 ifvarn HEALSEEK -1
 { 
  // ifvare HEALSEEKB THISACTOR { setvar HEALSEEK -1 break } // Makes the actor unable to heal themself if un-commented

  getactor[HEALSEEK].pal HEALSEEKB
  ifvarg HEALSEEKB 8 ifvarl HEALSEEKB 12 { setvar HEALSEEK -1 break } // Makes it that if the current target is an "old-skool" monster, set to -1 to search for a non-"old-skool" one

  getactorvar[HEALSEEK].ENEMYHP ENEMYSHEALTH
  ifvarl ENEMYSHEALTH 1 { setvar HEALSEEK -1 break } // Makes it that if the current target is dead, set to -1 to search for a living one

  getactorvar[HEALSEEK].ENEMYHP TEMP
  getactorvar[HEALSEEK].ENEMYMAXHP TEMP2
  setvarvar TEMP3 TEMP
  mulvar TEMP3 1000
  divvarvar TEMP3 TEMP2
  setvarvar HEALSEEKRATIO TEMP3

  ifvare HEALTYPE 0 { ifvarg TEMP3 999 { setvar HEALSEEK -1 break } } // For normal types of healing with the usual 100% HP limit
  ifvare HEALTYPE 1 { ifvarg TEMP3 1332 { setvar HEALSEEK -1 break } } // If Heal Life [Lesser] is used, check to see if enemy has less than 133% of their HP and cancel if they have more.
  ifvare HEALTYPE 2 { ifvarg TEMP3 1666 { setvar HEALSEEK -1 break } } // If Heal Life [Greater] is used, check to see if enemy has less than 133% of their HP and cancel if they have more.

  getactorvar[HEALSEEK].FROZEN? HEALSEEKB
  ifvare HEALSEEKB 1 { setvar HEALSEEK -1 break } // Makes it that if the current target is frozen, set to -1 to search for a non-frozen one

  getactorvar[HEALSEEK].CLOAKED? HEALSEEKB
  ifvare HEALSEEKB 1 { setvar HEALSEEK -1 break } // Makes it that if the current target is cloaked, set to -1 to search for a non-cloaked one

  canseespr THISACTOR HEALSEEK HEALSEEKB
  ifvare HEALSEEKB 0 { setvar HEALSEEK -1 break } // Makes it the healer needs to see his/her target.
 }
ends

state itemdetectifdead
ifvarand ACTORFLAGS 16 setvar ITEMSEEK -1
else
{
 ifvarn ITEMSEEK -1
 { 
  getactor[ITEMSEEK].pal ITEMSEEKD
  ifvarg ITEMSEEKD 8 ifvarl ITEMSEEKD 12 { setvar ITEMSEEK -1 break } // Makes it that if the current "seeker" is "old-skool", set to -1 to search for a non-"old-skool" one
  getactorvar[ITEMSEEK].ENEMYHP ENEMYSHEALTH
  ifvarl ENEMYSHEALTH 1 { setvar ITEMSEEK -1 break } // Makes it that if the current "seeker" is dead, set to -1 to search for a living one
  getactorvar[ITEMSEEK].SHRUNK? ITEMSEEKD
  ifvare ITEMSEEKD 1 { setvar ITEMSEEK -1 break } // Makes it that if the current "seeker" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[ITEMSEEK].FROZEN? ITEMSEEKD
  ifvare ITEMSEEKD 1 { setvar ITEMSEEK -1 break } // Makes it that if the current "seeker" is frozen, set to -1 to search for a non-frozen one
  getactorvar[ITEMSEEK].CLOAKED? ITEMSEEKD
  ifvare ITEMSEEKD 1 { setvar ITEMSEEK -1 break } // Makes it that if the current "seeker" is cloaked, set to -1 to search for a non-cloaked one
  canseespr THISACTOR ITEMSEEK ITEMSEEKD
  ifvare ITEMSEEKD 0 { setvar ITEMSEEK -1 break } // Makes it the monster and the item need a line of sight.
 }
}
ends

state itemseekingliztroop // For allowing LIZTROOP to grab jetpacks to replenish their own
ifvarand ACTORFLAGS 16 setvar ITEMSEEK -1
else
{
 addvar FINDNEAR_INTERVAL 1
 ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
 {
  findnearactorz LIZTROOP ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  setvar FINDNEAR_INTERVAL 0
 }
}
ends

state itemseekingactor
ifvarand ACTORFLAGS 16 setvar ITEMSEEK -1
else
{
 addvar FINDNEAR_INTERVAL 1
 ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
 {
  // List in the order of top to low priority
  findnearactorz BOSS4 BOSSRETRIEVEDISTANCE BOSSZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz BOSS2 BOSSRETRIEVEDISTANCE BOSSZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz BOSS3 BOSSRETRIEVEDISTANCE BOSSZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz BOSS1 BOSSRETRIEVEDISTANCE BOSSZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz SCORPIONTANK BOSSRETRIEVEDISTANCE BOSSZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz TANK BOSSRETRIEVEDISTANCE BOSSZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz COMMANDER ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz NEWBEAST ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz OCTABRAIN ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DRONE ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz LIZMAN ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz PIGCOP ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz LIZTROOP ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ROTATEGUN ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz SHARK ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  // NPCs
  ifvare ITEMSEEK -1 findnearactorz PRESIDENTCLINTON ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ROBOTDOG ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ROBOTDOG2 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz PODFEM1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz NAKED1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM2 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM3 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM4 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM5 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM6 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM7 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM9 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz FEM10 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz TOUGHGAL ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz WOMAN ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE2 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE3 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE5 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE6 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE7 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DANCE9 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz STAND1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz DEALER ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz STAND3 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz STAND4 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz WOLFDUDE ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz COP1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz PUNKDUDE ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz COP2 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz SITTINGDUDE ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ANIMEGIRL1 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ANIMEGIRL2 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ANIMEGIRL3 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  ifvare ITEMSEEK -1 findnearactorz ANIMEGIRL4 ENEMYRETRIEVEDISTANCE ENEMYZRETRIEVEDISTANCE ITEMSEEK state itemdetectifdead
  setvar FINDNEAR_INTERVAL 0
 }
}
ends

state actorseekingsuperatom
  ifvare ITEMTARGET -1 
  {   
   setvar TEMP5 0
   ifvarvarl ENEMYHP ENEMYMAXHPATOMIC addvar TEMP5 1
   ifvarvarl ENEMYAP ENEMYMAXAPATOMIC addvar TEMP5 1
   ifvarvarl ENEMYCURRENTFIRSTAID ENEMYMAXHPATOMIC addvar TEMP5 1
   ifvarand ACTORSTATUS? 16
   {
    ifvarg TEMP5 0 { findnearactorz SUPERATOM ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput }
   }
   else
   {
    ifvarg TEMP5 0 { findnearactorz SUPERATOM ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput }
   }
  }
ends

state actorseekingitem
 addvar FINDNEAR_INTERVAL 1
 ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
 {
  ifvarand ACTORSTATUS? 16
  {
   // List in the order of top to low priority
   findnearactorz ICONOFTHEDEFENDER ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz VAMPIREITEM ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz REGENITEM ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz APREGENITEM ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz QUADDAMAGE ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarand ACTORSTATUS? 128 findnearactorz FOGHORN ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarand ACTORSTATUS? 8 findnearactorz ANTIDOTE ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarand ACTORSTATUS? 16 findnearactorz EYEDROP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz AIRTIMEBONUS ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYMAXHP STATLIMIT ifvarvarl ENEMYMAXAP STATLIMIT findnearactorz MAXHPAPUP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYMAXAP STATLIMIT findnearactorz MAXAPUP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYMAXHP STATLIMIT findnearactorz MAXHPUP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ACTORATTACK STATLIMIT ifvarvarl ACTORDEFENSE STATLIMIT findnearactorz ATKDEFUP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ACTORDEFENSE STATLIMIT findnearactorz DEFUP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ACTORATTACK STATLIMIT findnearactorz ATKUP ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   state actorseekingsuperatom //  ifvare ITEMTARGET -1 ifvarvarl ENEMYHP STATLIMITATOMIC ifvarvarl ENEMYHP ENEMYMAXHPATOMIC findnearactorz SUPERATOM ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput

   ifvare ITEMTARGET -1 ifvarvarl ENEMYAP STATLIMITATOMIC ifvarvarl ENEMYAP ENEMYMAXAPATOMIC findnearactorz SUPERSHIELD ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYCURRENTFIRSTAID ENEMYMAXHP findnearactorz FIRSTAID ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYAP ENEMYMAXAP findnearactorz COLORSHIELD ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYAP ENEMYMAXAP findnearactorz SHIELD ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP STATLIMITATOMIC ifvarvarl ENEMYHP ENEMYMAXHPATOMIC findnearactorz FORTUNECOOKIE ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP STATLIMITATOMIC ifvarvarl ENEMYHP ENEMYMAXHPATOMIC findnearactorz ATOMICHEALTH ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarl ENEMYJETPACKAMOUNT JETPACK_AMOUNT findnearactorz JETPACK ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarl ENEMYBOOTSAMOUNT BOOT_AMOUNT findnearactorz BOOTS ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarl ENEMYAIRTANKAMOUNT SCUBA_AMOUNT findnearactorz AIRTANK ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SURGERYKIT ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz MEDPACK ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SWBIGMEDIKIT ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SIXPAK ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SWMEDIKIT ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz COLA ENEMYSEEKDISTANCEDIM ENEMYSEEKZDISTANCEDIM ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz FIRSTAIDPANEL_ON ENEMYSEEKDISTANCEDIM 422 ITEMTARGET state enemyfirstaidstationcheck
  }
  else
  {
   // List in the order of top to low priority
   findnearactorz ICONOFTHEDEFENDER ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz VAMPIREITEM ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz REGENITEM ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz APREGENITEM ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz QUADDAMAGE ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarand ACTORSTATUS? 8 findnearactorz ANTIDOTE ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 findnearactorz AIRTIMEBONUS ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYMAXHP STATLIMIT ifvarvarl ENEMYMAXAP STATLIMIT findnearactorz MAXHPAPUP ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYMAXAP STATLIMIT findnearactorz MAXAPUP ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYMAXHP STATLIMIT findnearactorz MAXHPUP ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ACTORATTACK STATLIMIT ifvarvarl ACTORDEFENSE STATLIMIT findnearactorz ATKDEFUP ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ACTORDEFENSE STATLIMIT findnearactorz DEFUP ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ACTORATTACK STATLIMIT findnearactorz ATKUP ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   state actorseekingsuperatom //  ifvare ITEMTARGET -1 ifvarvarl ENEMYHP STATLIMITATOMIC ifvarvarl ENEMYHP ENEMYMAXHPATOMIC findnearactorz SUPERATOM ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput

   ifvare ITEMTARGET -1 ifvarvarl ENEMYAP STATLIMITATOMIC ifvarvarl ENEMYAP ENEMYMAXAPATOMIC findnearactorz SUPERSHIELD ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYCURRENTFIRSTAID ENEMYMAXHP findnearactorz FIRSTAID ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYAP ENEMYMAXAP findnearactorz COLORSHIELD ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYAP ENEMYMAXAP findnearactorz SHIELD ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP STATLIMITATOMIC ifvarvarl ENEMYHP ENEMYMAXHPATOMIC findnearactorz FORTUNECOOKIE ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP STATLIMITATOMIC ifvarvarl ENEMYHP ENEMYMAXHPATOMIC findnearactorz ATOMICHEALTH ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarl ENEMYJETPACKAMOUNT JETPACK_AMOUNT findnearactorz JETPACK ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarl ENEMYBOOTSAMOUNT BOOT_AMOUNT findnearactorz BOOTS ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarl ENEMYAIRTANKAMOUNT SCUBA_AMOUNT findnearactorz AIRTANK ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SURGERYKIT ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz MEDPACK ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SWBIGMEDIKIT ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SIXPAK ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz SWMEDIKIT ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz COLA ENEMYSEEKDISTANCE ENEMYSEEKZDISTANCE ITEMTARGET state enemyitemcheckstayput
   ifvare ITEMTARGET -1 ifvarvarl ENEMYHP ENEMYMAXHP findnearactorz FIRSTAIDPANEL_ON ENEMYSEEKDISTANCE 4220 ITEMTARGET state enemyfirstaidstationcheck
  }
  setvar FINDNEAR_INTERVAL 0
 }
ends

state playerstealjustbeforemonster
 // List in the order of top to low priority
 findnearactorz BOSS4 BOSSSTOLENDISTANCE BOSSZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz BOSS2 BOSSSTOLENDISTANCE BOSSZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz BOSS3 BOSSSTOLENDISTANCE BOSSZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz BOSS1 BOSSSTOLENDISTANCE BOSSZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz SCORPIONTANK BOSSSTOLENDISTANCE BOSSZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz TANK BOSSSTOLENDISTANCE BOSSZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz COMMANDER ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz NEWBEAST ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz OCTABRAIN ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz DRONE ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz LIZMAN ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz PIGCOP ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz LIZTROOP ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz ROTATEGUN ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvare ITEMSEEK -1 findnearactorz SHARK ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE ITEMSEEK state itemdetectifdead
 ifvarn ITEMSEEK -1
 {
  getactorvar[ITEMSEEK].ITEMTARGET TEMPVAR
  ifvarn TEMPVAR -1
  {
   ifvare CHARACTERSELECTED? 8 globalsound LISA_STEALITEM
   ifvare CHARACTERSELECTED? 15 globalsound MAKEN_STEALITEM
  }
 }
ends

state monsterstealjustbeforeplayer
 findnearspritez APLAYER ENEMYSTOLENDISTANCE ENEMYZSTOLENDISTANCE TEMPVAR
 ifvarn TEMPVAR -1
 {
  ifvarg CURRENTHITPOINTS 0
  {
   ifvare CHARACTERSELECTED? 8 globalsound LISA_ITEMSTOLEN
   ifvare CHARACTERSELECTED? 15 globalsound MAKEN_ITEMSTOLEN
  }
 }
ends

state enemygrabitemflash
           ifvarand ACTORFLAGS 4 nullop
           else
           {
            state monsterstealjustbeforeplayer
            setvarvar fta fta_normal setvar ftq 185
            palfrom 4 0 32
           }
           state activationflag killit
ends

state medikitmonster_ratio
             ifvarvarl ITEMSEEKC tempb ifvarg ACTORPICKUPAMOUNT 0
             {
              ifactor COLA addvar ITEMSEEKC 100
              ifactor SWMEDIKIT addvar ITEMSEEKC 200
              ifactor SIXPAK addvar ITEMSEEKC 300
              ifactor SWBIGMEDIKIT addvar ITEMSEEKC 500
              ifactor MEDPACK addvar ITEMSEEKC 750
              ifactor SURGERYKIT addvar ITEMSEEKC 1000
              subvar ACTORPICKUPAMOUNT 1
              addvar tempe 1
             }
ends

state medikitmonster
            state checkenemypickuphealth
            getactorvar[ITEMSEEK].ENEMYMAXHP ITEMENEMYMAXHP

            ifvarg ITEMSEEKB 0 ifvarvarl ITEMSEEKB ITEMENEMYMAXHP
            {
             state checkexplodeflag

             // TEMP4 = Maximum HP % to reach
             // tempb = becomes the % of health needed to heal to reach TEMP4 [tempb - TEMPARMOR = tempb]
             setvar tempb 1000
             setvar TEMP4 1000
	       setvarvar TEMPARMOR ITEMSEEKB
             mulvar TEMPARMOR 1000
             divvarvar TEMPARMOR ITEMENEMYMAXHP
             subvarvar tempb TEMPARMOR
             // addlogvar tempb
             // addlogvar TEMP4

             setvar ITEMSEEKC 0
             setvar ACTORPICKUPAMOUNT 1
             state checkpickupamountflags
             setvar tempe 0

             setvar TEMPVAR5 10
             whilevarn TEMPVAR5 0
             {
              state medikitmonster_ratio
              subvar TEMPVAR5 1
             }

             mulvarvar ITEMSEEKC ITEMENEMYMAXHP
             divvar ITEMSEEKC 1000
             addvarvar ITEMSEEKB ITEMSEEKC
             ifvarvarg ITEMSEEKB ITEMENEMYMAXHP setvarvar ITEMSEEKB ITEMENEMYMAXHP
             setactorvar[ITEMSEEK].ENEMYHP ITEMSEEKB
             state showhealing_actorhp

             state resetitemtarget
             state getitemseekerspecies

             ifvarg ACTORPICKUPAMOUNT 7
             {
              ifactor COLA { espawn COLA setactorvar[RETURN].ACTORFLAGS 384 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWMEDIKIT { espawn SWMEDIKIT setactorvar[RETURN].ACTORFLAGS 384 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SIXPAK { espawn SIXPAK setactorvar[RETURN].ACTORFLAGS 384 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWBIGMEDIKIT { espawn SWBIGMEDIKIT setactorvar[RETURN].ACTORFLAGS 384 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor MEDPACK { espawn MEDPACK setactorvar[RETURN].ACTORFLAGS 384 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SURGERYKIT { espawn SURGERYKIT setactorvar[RETURN].ACTORFLAGS 384 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              subvar ACTORPICKUPAMOUNT 8
             }
             ifvarg ACTORPICKUPAMOUNT 3
             {
              ifactor COLA { espawn COLA setactorvar[RETURN].ACTORFLAGS 256 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWMEDIKIT { espawn SWMEDIKIT setactorvar[RETURN].ACTORFLAGS 256 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SIXPAK { espawn SIXPAK setactorvar[RETURN].ACTORFLAGS 256 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWBIGMEDIKIT { espawn SWBIGMEDIKIT setactorvar[RETURN].ACTORFLAGS 256 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor MEDPACK { espawn MEDPACK setactorvar[RETURN].ACTORFLAGS 256 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SURGERYKIT { espawn SURGERYKIT setactorvar[RETURN].ACTORFLAGS 256 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              subvar ACTORPICKUPAMOUNT 4
             }
             ifvarg ACTORPICKUPAMOUNT 1
             {
              ifactor COLA { espawn COLA setactorvar[RETURN].ACTORFLAGS 128 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWMEDIKIT { espawn SWMEDIKIT setactorvar[RETURN].ACTORFLAGS 128 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SIXPAK { espawn SIXPAK setactorvar[RETURN].ACTORFLAGS 128 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWBIGMEDIKIT { espawn SWBIGMEDIKIT setactorvar[RETURN].ACTORFLAGS 128 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor MEDPACK { espawn MEDPACK setactorvar[RETURN].ACTORFLAGS 128 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SURGERYKIT { espawn SURGERYKIT setactorvar[RETURN].ACTORFLAGS 128 setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              subvar ACTORPICKUPAMOUNT 2
             }
             ifvare ACTORPICKUPAMOUNT 1
             {
              ifactor COLA { espawn COLA setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWMEDIKIT { espawn SWMEDIKIT setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SIXPAK { espawn SIXPAK setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SWBIGMEDIKIT { espawn SWBIGMEDIKIT setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor MEDPACK { espawn MEDPACK setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              ifactor SURGERYKIT { espawn SURGERYKIT setactorvar[RETURN].FLAGSSET? 1 state scatterdrops }
              subvar ACTORPICKUPAMOUNT 1
             }

             ifvarand ACTORFLAGS 4 nullop
             else
             {
              ifactor COLA 
              {
               ifvarg tempe 1
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT %d SMALL MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT %d SMALL MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT %d SMALL MEDIKITS!
                qsprintf 185 185 tempe
               }
               else
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT A SMALL MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A SMALL MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT A SMALL MEDIKIT!
               }
              }
              ifactor SWMEDIKIT 
              {
               ifvarg tempe 1
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT %d MEDIUM MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT %d MEDIUM MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT %d MEDIUM MEDIKITS!
                qsprintf 185 185 tempe
               }
               else
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT A MEDIUM MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A MEDIUM MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT A MEDIUM MEDIKIT!
               }
              }
              ifactor SIXPAK 
              {
               ifvarg tempe 1
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT %d LARGE MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT %d LARGE MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT %d LARGE MEDIKITS!
                qsprintf 185 185 tempe
               }
               else
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT A LARGE MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A LARGE MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT A LARGE MEDIKIT!
               }
              }
              ifactor SWBIGMEDIKIT
              {
               ifvarg tempe 1
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT %d EXTRA-LARGE MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT %d EXTRA-LARGE MEDIKITS!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT %d EXTRA-LARGE MEDIKITS!
                qsprintf 185 185 tempe
               }
               else
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT AN EXTRA-LARGE MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A EXTRA-LARGE MEDIKIT!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT A EXTRA-LARGE MEDIKIT!
               }
              }
              ifactor MEDPACK 
              {
               ifvarg tempe 1
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT %d MED PACKS!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT %d MED PACKS!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT %d MED PACKS!
                qsprintf 185 185 tempe
               }
               else
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT A MED PACK!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A MED PACK!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT A MED PACK!
               }
              }
              ifactor SURGERYKIT 
              {
               ifvarg tempe 1
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT %d SURGERY KITS!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT %d SURGERY KITS!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT %d SURGERY KITS!
                qsprintf 185 185 tempe
               }
               else
               {
                ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT A SURGERY KIT!
                ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A SURGERY KIT!
                ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 185 ^15A VEHICLE GOT A SURGERY KIT!
               }
              }

              setactorvar[ITEMSEEK].ENEMYHPDAMAGED? -1
              globalsound DUKE_GET
              globalsound USE_MEDIKITITEM
             }
             state enemygrabitemflash
             setvar WORLDTILESHUFFLES 0
             state getworldtile
            }
ends

state accquireenemystats
 setvarvar ENEMYMAXHPATOMIC ENEMYMAXHP
 mulvar ENEMYMAXHPATOMIC 2
 setvarvar ENEMYMAXAPATOMIC ENEMYMAXAP
 mulvar ENEMYMAXAPATOMIC 2
 setvarvar ENEMYCURRENTFIRSTAID ENEMYFIRSTAID
ends

state espawnskillitems
   ifvare SKILLLEVEL 0 { ifrnd 1 { espawnvar SPAWNID state scatterdrops } }
   ifvare SKILLLEVEL 1 { ifrnd 2 { ifrnd 85 { espawnvar SPAWNID state scatterdrops } } }
   ifvare SKILLLEVEL 2 { ifrnd 2 { ifrnd 170 { espawnvar SPAWNID state scatterdrops } } }
   ifvare SKILLLEVEL 3 { ifrnd 2 { espawnvar SPAWNID state scatterdrops } }
   ifvare SKILLLEVEL 4 { ifrnd 3 { ifrnd 128 { espawnvar SPAWNID state scatterdrops } } }
   ifvare SKILLLEVEL 5 { ifrnd 4 { espawnvar SPAWNID state scatterdrops } }
   ifvare SKILLLEVEL 6 { ifrnd 6 { espawnvar SPAWNID state scatterdrops } }
   ifvare SKILLLEVEL 7 { ifrnd 9 { espawnvar SPAWNID state scatterdrops } }
   ifvare SKILLLEVEL 8 { ifrnd 16 { espawnvar SPAWNID state scatterdrops } }
   ifvare SKILLLEVEL 9 { ifrnd 25 { espawnvar SPAWNID state scatterdrops } }
ends

state drop_artifacts  // For making monsters drop artifacts (Boots, Scuba, Quad, Invuln, Regen, etc) when killed
 ifvarg ENEMYBOOTSAMOUNT 0
 {
  espawn BOOTS state scatterdrops
  setvarvar TEMPVAR ENEMYBOOTSAMOUNT
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actor's Scuba Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYBOOTSAMOUNT 0
 }
 else
 {
  ifrnd 16
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    setvar SPAWNID BOOTS
    state espawnskillitems
   }
  }
 }

 ifvarg ENEMYAIRTANKAMOUNT 0
 {
  espawn AIRTANK state scatterdrops
  setvarvar TEMPVAR ENEMYAIRTANKAMOUNT
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actor's Scuba Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYAIRTANKAMOUNT 0
 }
 else
 {
  ifrnd 16
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    setvar SPAWNID AIRTANK
    state espawnskillitems
   }
  }
 }

 ifvarg ENEMYQUADTIME 0
 {
  espawn QUADDAMAGE setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops
  setvarvar TEMPVAR ENEMYQUADTIME
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actorr's Quad Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYQUADTIME 0
 }
 else
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   setvar SPAWNID QUADDAMAGE
   state espawnskillitems
  }
 }

 ifvarg ENEMYINVULNTIME 0
 {
  espawn ICONOFTHEDEFENDER setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops
  setvarvar TEMPVAR ENEMYINVULNTIME
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actor's Invuln Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYINVULNTIME 0
 }
 else
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   setvar SPAWNID ICONOFTHEDEFENDER
   state espawnskillitems
  }
 }

 ifvarg ENEMYREGENTIME 0
 {
  espawn REGENITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops
  setvarvar TEMPVAR ENEMYREGENTIME
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actor's Regen Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYREGENTIME 0
 }
 else
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   setvar SPAWNID REGENITEM
   state espawnskillitems
  }
 }

 ifvarg ENEMYAPREGENTIME 0
 {
  espawn APREGENITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops
  setvarvar TEMPVAR ENEMYAPREGENTIME
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actor's AP Regen Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYAPREGENTIME 0
 }
 else
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   setvar SPAWNID APREGENITEM
   state espawnskillitems
  }
 }

 ifvarg ENEMYVAMPIRETIME 0
 {
  espawn VAMPIREITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops
  setvarvar TEMPVAR ENEMYVAMPIRETIME
  setactorvar[RETURN].POWERUPBENEFIT TEMPVAR // Transfers the actor's Vampire Time into the dropped powerup so the next user gets what was left of it
  setactorvar[THISACTOR].ENEMYVAMPIRETIME 0
 }
 else
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   setvar SPAWNID VAMPIREITEM
   state espawnskillitems
  }
 }
ends

state invulnicon-nonplayers
 ifvare oldskoolmode 0
 {
  getactor[THISACTOR].x TESTX 
  getactor[THISACTOR].y TESTY
  getactor[THISACTOR].z TESTZ
  getactor[THISACTOR].picnum TEMP
  setactor[THISACTOR].x TESTX
  setactor[THISACTOR].y TESTY 
  setactor[THISACTOR].z TESTZ
  getactor[THISACTOR].xrepeat TESTXREPEAT1 
  getactor[THISACTOR].yrepeat TESTYREPEAT1 
  getactorvar[THISACTOR].ACTORSHEIGHT INVULNAURARANGEZ
  mulvarvar INVULNAURARANGEZ TESTYREPEAT1
  mulvar INVULNAURARANGEZ 4
  setvar INVULNAURARANGEXY 844
  addvarvar INVULNAURARANGEXY TESTXREPEAT1
  addvar INVULNAURARANGEZ 1688
  addvarvar INVULNAURARANGEZ TESTYREPEAT1
  addvarvar INVULNAURARANGEZ TESTYREPEAT1

    getactor[THISACTOR].picnum TEMP
    ifvare TEMP ROTATEGUN state invulntarget_monsters
    ifvare TEMP SHARK state invulntarget_monsters
    ifvare TEMP LIZTROOP state invulntarget_monsters
    ifvare TEMP PIGCOP state invulntarget_monsters
    ifvare TEMP RECON state invulntarget_monsters
    ifvare TEMP LIZMAN state invulntarget_monsters
    ifvare TEMP OCTABRAIN state invulntarget_monsters
    ifvare TEMP DRONE state invulntarget_monsters
    ifvare TEMP NEWBEAST state invulntarget_monsters
    ifvare TEMP COMMANDER state invulntarget_monsters
    ifvare TEMP TANK state invulntarget_monsters
    ifvare TEMP SCORPIONTANK state invulntarget_monsters
    ifvare TEMP BOSS1 state invulntarget_monsters
    ifvare TEMP BOSS2 state invulntarget_monsters
    ifvare TEMP BOSS3 state invulntarget_monsters
    ifvare TEMP BOSS4 state invulntarget_monsters
    ifvare TEMP PRESIDENTCLINTON state invulntarget_civilians
    ifvare TEMP ROBOTDOG state invulntarget_civilians
    ifvare TEMP ROBOTDOG2 state invulntarget_civilians
    ifvare TEMP PODFEM1 state invulntarget_civilians
    ifvare TEMP NAKED1 state invulntarget_civilians
    ifvare TEMP FEM1 state invulntarget_civilians
    ifvare TEMP FEM2 state invulntarget_civilians
    ifvare TEMP FEM3 state invulntarget_civilians
    ifvare TEMP FEM4 state invulntarget_civilians
    ifvare TEMP FEM5 state invulntarget_civilians
    ifvare TEMP FEM6 state invulntarget_civilians
    ifvare TEMP FEM7 state invulntarget_civilians
    ifvare TEMP FEM9 state invulntarget_civilians
    ifvare TEMP FEM10 state invulntarget_civilians
    ifvare TEMP TOUGHGAL state invulntarget_civilians
    ifvare TEMP WOMAN state invulntarget_civilians
    ifvare TEMP DANCE1 state invulntarget_civilians
    ifvare TEMP DANCE2 state invulntarget_civilians
    ifvare TEMP DANCE3 state invulntarget_civilians
    ifvare TEMP DANCE5 state invulntarget_civilians
    ifvare TEMP DANCE6 state invulntarget_civilians
    ifvare TEMP DANCE7 state invulntarget_civilians
    ifvare TEMP DANCE9 state invulntarget_civilians
    ifvare TEMP STAND1 state invulntarget_civilians
    ifvare TEMP DEALER state invulntarget_civilians
    ifvare TEMP STAND3 state invulntarget_civilians
    ifvare TEMP STAND4 state invulntarget_civilians
    ifvare TEMP WOLFDUDE state invulntarget_civilians
    ifvare TEMP COP1 state invulntarget_civilians
    ifvare TEMP PUNKDUDE state invulntarget_civilians
    ifvare TEMP COP2 state invulntarget_civilians
    ifvare TEMP SITTINGDUDE state invulntarget_civilians
    ifvare TEMP ANIMEGIRL1 state invulntarget_civilians
    ifvare TEMP ANIMEGIRL2 state invulntarget_civilians
    ifvare TEMP ANIMEGIRL3 state invulntarget_civilians
    ifvare TEMP ANIMEGIRL4 state invulntarget_civilians
 }
ends

state enemyquaddamage
    ifvare mainmenu 0 ifvarn FROZEN? 1 subvar ENEMYQUADTIME 1
    state itemfullbright
    ifvare ENEMYQUADTIME 104 sound QUADDAMAGE2
    ifvare ENEMYQUADTIME 1
    {
      state getitemseekerspeciesquote
      ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 301 ^10AN ENEMY'S QUAD DAMAGE JUST WORE OFF! :D
      ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 301 ^15A CIVILIAN'S QUAD DAMAGE JUST WORE OFF! -_-
      ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 301 ^15A VEHICLE'S QUAD DAMAGE JUST WORE OFF! :(
      setvarvar fta fta_normal setvar ftq 301 
    }
ends

state enemyvampireitem
    ifvare mainmenu 0 ifvarn FROZEN? 1 subvar ENEMYVAMPIRETIME 1
    state itemfullbright
//    ifvare ENEMYVAMPIRETIME 104 sound QUADDAMAGE2
    ifvare ENEMYVAMPIRETIME 1
    {
      state getitemseekerspeciesquote
      ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 301 ^10AN ENEMY'S VAMPIRE MASK JUST WORE OFF! XD
      ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 301 ^15A CIVILIAN'S VAMPIRE MASK JUST WORE OFF! @_@
      ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 301 ^15A VEHICLE'S VAMPIRE MASK JUST WORE OFF! :(
      setvarvar fta fta_normal setvar ftq 301 
    }
ends

state enemyinvulnitem
    ifvare mainmenu 0
    { 
     ifvarn FROZEN? 1 
     {
      addvar ENEMYINVULNCOUNTER 1
      subvar ENEMYINVULNTIME 1 
     } 
    }
    ifvarand ACTORSTATUS? 4 // Remove Slow
    {
     subvar ACTORSTATUS? 4
     setvar ACTORPOISONTIMER 0
    }
    ifvarand ACTORSTATUS? 8 // Remove Poison
    {
     subvar ACTORSTATUS? 8
     setvar ACTORPOISONTIMER 0
    }
    ifvarand ACTORSTATUS? 16 // Remove Dimness
    {
     subvar ACTORSTATUS? 16
     setvar ACTORPOISONTIMER 0
    }
    ifvarand ACTORSTATUS? 128 // Remove Confusion
    {
     subvar ACTORSTATUS? 128
     setvar ACTORPOISONTIMER 0
    }
    state itemfullbright
    state invulnicon-nonplayers
    ifvarg ENEMYINVULNCOUNTER 38 { sound INVULN_PULSE setvar ENEMYINVULNCOUNTER 0 }
    ifvare ENEMYINVULNTIME 104 sound INVULNITEM2
    ifvare ENEMYINVULNTIME 1
    {
      state getitemseekerspeciesquote
      ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 301 ^10AN ENEMY'S INVULN ITEM JUST WORE OFF! :D
      ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 301 ^15A CIVILIAN'S INVULN ITEM JUST WORE OFF! -_-
      ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 301 ^15A VEHICLE'S INVULN ITEM JUST WORE OFF! ;_;
      setvarvar fta fta_normal setvar ftq 301 
    }
ends

state enemyarmortype

 ifvarl ENEMYAP 1
 { 
  setvar ENEMYARMORPERCENT 0 
 }
 else
 {
  ifvarl ENEMYARMORPERCENT 100 setvar ENEMYARMORPERCENT 100
  ifvarg ENEMYARMORPERCENT 1000 setvar ENEMYARMORPERCENT 1000
 }

 // Enemy Natural Regeneration / Poison Damage Degeneration
 ifvare mainmenu 0
 {
  ifvare CLOAKED? 1 nullop 
  else ifvare FROZEN? 1 nullop
  else ifvare SHRUNK? 1 nullop
  else addvar ACTORREGENTIMER 1
  // addlogvar ACTORREGENTIMER

  ifvare PUBLICBETA? 0 { ifvarand ACTORSTATUS? 8 setvar ACTORREGENINTERVAL 39 else setvar ACTORREGENINTERVAL 78 } else { setvar ACTORREGENINTERVAL 26 }
  ifvarvarg ACTORREGENTIMER ACTORREGENINTERVAL
  {
   ifvarand ACTORSTATUS? 8 // Has Poison
   { 
    setvarvar TEMPVAR ENEMYMAXHP
    randvar TEMPVAR2 10
    setvar TEMPVAR3 20
    ifrnd 128 addvarvar TEMPVAR3 TEMPVAR2 else subvarvar TEMPVAR3 TEMPVAR2
    mulvarvar TEMPVAR TEMPVAR3
    divvar TEMPVAR 1000
    mulvar TEMPVAR -1
 
    ifvarl TEMPVAR 0
    {
     ifvarl TEMPVAR3 11 { ifrnd 40 state monsterpainsounds2 }
     ifvare TEMPVAR3 11 { ifrnd 48 state monsterpainsounds2 }
     ifvare TEMPVAR3 12 { ifrnd 56 state monsterpainsounds2 }
     ifvare TEMPVAR3 13 { ifrnd 64 state monsterpainsounds2 }
     ifvare TEMPVAR3 14 { ifrnd 72 state monsterpainsounds2 }
     ifvare TEMPVAR3 15 { ifrnd 80 state monsterpainsounds2 }
     ifvare TEMPVAR3 16 { ifrnd 88 state monsterpainsounds2 }
     ifvare TEMPVAR3 17 { ifrnd 96 state monsterpainsounds2 }
     ifvare TEMPVAR3 18 { ifrnd 112 state monsterpainsounds2 }
     ifvare TEMPVAR3 19 { ifrnd 120 state monsterpainsounds2 }
     ifvare TEMPVAR3 20 { ifrnd 128 state monsterpainsounds2 }
     ifvare TEMPVAR3 21 { ifrnd 136 state monsterpainsounds2 }
     ifvare TEMPVAR3 22 { ifrnd 144 state monsterpainsounds2 }
     ifvare TEMPVAR3 23 { ifrnd 152 state monsterpainsounds2 }
     ifvare TEMPVAR3 24 { ifrnd 160 state monsterpainsounds2 }
     ifvare TEMPVAR3 25 { ifrnd 168 state monsterpainsounds2 }
     ifvare TEMPVAR3 26 { ifrnd 176 state monsterpainsounds2 }
     ifvare TEMPVAR3 27 { ifrnd 184 state monsterpainsounds2 }
     ifvare TEMPVAR3 28 { ifrnd 192 state monsterpainsounds2 }
     ifvare TEMPVAR3 29 { ifrnd 200 state monsterpainsounds2 }
     ifvarg TEMPVAR3 29 { ifrnd 208 state monsterpainsounds2 }
     addvarvar ENEMYHP TEMPVAR

     setvarvar ITEMSEEKC TEMPVAR
     mulvar ITEMSEEKC -1
     ifvarg ITEMSEEKC 0
     {
      setvarvar SHOWDAMAGE ITEMSEEKC
      // addlogvar ITEMSEEKC
      setvar SHOWDAMAGETYPE 0
      setvarvar SHOWDAMAGEACTORID THISACTOR
      state showdamage
     }
 
     setvar ENEMYHPDAMAGED? 1
    }
    setvar ACTORREGENTIMER 0
   }
   else
   {
    ifvarl ENEMYREGENTIME 1 ifvarg ENEMYHP 0 ifvarvarl ENEMYHP ENEMYMAXHP
    {
     setvarvar TEMPVAR ENEMYMAXHP
     mulvarvar TEMPVAR ENEMYLEVEL
     divvar TEMPVAR 10000
     ifvarl TEMPVAR 1 setvar TEMPVAR 1
 
     randvar RANDOMIZER 120
     addvar RANDOMIZER 1
     ifvarg RANDOMIZER 0 ifvarl RANDOMIZER 2 mulvar TEMPVAR 5 // 1
     else ifvarg RANDOMIZER 1 ifvarl RANDOMIZER 5 mulvar TEMPVAR 4 // 2-4 +3
     else ifvarg RANDOMIZER 4 ifvarl RANDOMIZER 14 mulvar TEMPVAR 3 // 5-13 +9
     else ifvarg RANDOMIZER 13 ifvarl RANDOMIZER 41 mulvar TEMPVAR 2 // 14-40 +27
     else ifvarg RANDOMIZER 40 ifvarl RANDOMIZER 122 mulvar TEMPVAR 1 // 41-121 +81 
     // addlogvar TEMPVAR
     // addlogvar RANDOMIZER

     ifvarand ACTORFLAGS 512 
     {
      mulvar TEMPVAR 5
      divvar TEMPVAR 2
     }
 
     ifvare PUBLICBETA? 0 divvar TEMPVAR 9 else divvar TEMPVAR 3
  
     ifvarl TEMPVAR 1 setvar TEMPVAR 1
     ifvarg TEMPVAR 2049152 setvar TEMPVAR 2049152
 
     setvar ENEMYHPDAMAGED? -1
     addvarvar ENEMYHP TEMPVAR
     ifvarvarg ENEMYHP ENEMYMAXHP setvarvar ENEMYHP ENEMYMAXHP
     // addlogvar TEMPVAR

     setvarvar ITEMSEEKC TEMPVAR
     ifvarg ITEMSEEKC 0
     {
      setvarvar SHOWDAMAGE ITEMSEEKC
      // addlogvar ITEMSEEKC
      setvar SHOWDAMAGETYPE 3
      setvarvar SHOWDAMAGEACTORID THISACTOR
      state showdamage
     }

     // Reset the interval timer
     setvarvar TEMPVAR4 ENEMYLEVEL divvar TEMPVAR4 20
     setvar ACTORREGENTIMER 0
     addvarvar ACTORREGENTIMER TEMPVAR4

     // Elites Regenerate 4-9 tics faster depending on level range
     ifvarand ACTORFLAGS 512 
     {
      randvar TEMPVAR4 2
      addvar TEMPVAR4 4
      ifvarg ENEMYLEVEL 33 addvar TEMPVAR4 1
      ifvarg ENEMYLEVEL 66 addvar TEMPVAR4 1
      ifvarg ENEMYLEVEL 99 addvar TEMPVAR4 1
      addvarvar ACTORREGENTIMER TEMPVAR4
     }
    } 
   } 
  }

 }

 // Sets up how enemies use their Quad Damage
 ifvarg ENEMYQUADTIME 0
 {
  ifvarand ENEMYPOWERUPBITFIELD 1 nullop else addvar ENEMYPOWERUPBITFIELD 1
  ifvare CLOAKED? 1 nullop else state enemyquaddamage
 }
 else
 {
  ifvarand ENEMYPOWERUPBITFIELD 1 subvar ENEMYPOWERUPBITFIELD 1
 }

 // Sets up how enemies use their Icon of the Defender
 ifvarg ENEMYINVULNTIME 0
 {
  ifvarand ENEMYPOWERUPBITFIELD 2 nullop else addvar ENEMYPOWERUPBITFIELD 2
  ifvare CLOAKED? 1 nullop else state enemyinvulnitem
 }
 else
 {
  ifvarand ENEMYPOWERUPBITFIELD 2 subvar ENEMYPOWERUPBITFIELD 2
 }

 ifvarg ENEMYVAMPIRETIME 0
 {
  ifvarand ENEMYPOWERUPBITFIELD 16 nullop else addvar ENEMYPOWERUPBITFIELD 16
  ifvare CLOAKED? 1 nullop else state enemyvampireitem
 }
 else
 {
  ifvarand ENEMYPOWERUPBITFIELD 16 subvar ENEMYPOWERUPBITFIELD 16
 }

 // Check all statuses and make sure to decrement any timers they have.
 ifvarand ACTORSTATUS? 2 // Haste
 {
  ifvarg ACTORHASTETIMER 0
  {
   ifvare CLOAKED? 1 nullop 
   else ifvare FROZEN? 1 nullop
   else ifvare SHRUNK? 1 nullop
   else subvar ACTORHASTETIMER 1
  }
  else
  {
   redefinequote 335 ^33AN ENEMY'S HASTINESS HAS WORN OFF! :D
   subvar ACTORSTATUS? 2
   setvar ACTORHASTETIMER 0
   setvarvar fta fta_normal setvar ftq 335
  }
 }
 ifvarand ACTORSTATUS? 4 // Slow
 {
  ifvarg ACTORSLOWTIMER 0
  {
   ifvare CLOAKED? 1 nullop 
   else ifvare FROZEN? 1 nullop
   else ifvare SHRUNK? 1 nullop
   else subvar ACTORSLOWTIMER 1
  }
  else
  {
   redefinequote 335 ^10AN ENEMY'S SLOWNESS HAS WORN OFF! D:
   subvar ACTORSTATUS? 4
   setvar ACTORSLOWTIMER 0
   setvarvar fta fta_normal setvar ftq 335
  }
 }

 ifvarand ACTORSTATUS? 8 // Poison
 {
  ifactor ROTATEGUN // Machines Cannot be Poisoned [they have no "blood"]
  {
   subvar ACTORSTATUS? 8
   setvar ACTORPOISONTIMER 0
  }
  else
  ifactor DRONE // Machines Cannot be Poisoned [they have no "blood"]
  {
   subvar ACTORSTATUS? 8
   setvar ACTORPOISONTIMER 0
  }
  else
  ifactor TANK // Machines Cannot be Poisoned [they have no "blood"]
  {
   subvar ACTORSTATUS? 8
   setvar ACTORPOISONTIMER 0
  }
  else
  ifactor SCORPIONTANK // Machines Cannot be Poisoned [they have no "blood"]
  {
   subvar ACTORSTATUS? 8
   setvar ACTORPOISONTIMER 0
  }
  else
  {
   ifvarg ACTORPOISONTIMER 0
   {
    ifvare CLOAKED? 1 nullop 
    else ifvare FROZEN? 1 nullop
    else ifvare SHRUNK? 1 nullop
    else subvar ACTORPOISONTIMER 1
   }
   else
   {
    redefinequote 335 ^10AN ENEMY'S POISON HAS WORN OFF! :(
    subvar ACTORSTATUS? 8
    setvar ACTORPOISONTIMER 0
    setvarvar fta fta_normal setvar ftq 335
   }
  }
 }
 ifvarand ACTORSTATUS? 16 // Dimness
 {
  ifactor TANK // Tanks Cannot Be Dimmed [they have no "eyes"]
  {
   subvar ACTORSTATUS? 16
   setvar ACTORDIMNESSTIMER 0
  }
  else
  ifactor SCORPIONTANK // Tanks Cannot be Dimmed [they have no "eyes"]
  {
   subvar ACTORSTATUS? 16
   setvar ACTORDIMNESSTIMER 0
  }
  else
  {
   ifvare mainmenu 0 // only mess with the view angles when the menu isn't open
   {
    getactor[THISACTOR].ang ACTORANGLE 
    randvar TEMPVAR4 10 // 7
    ifrnd 128 mulvar TEMPVAR4 -1
    addvar TEMPVAR4 40 // 25
 
    addvar DIMNESSSWITCHTIMER 1
    ifvarvarg DIMNESSSWITCHTIMER TEMPVAR4 // Will randomly set the direction of spinning while dimmed every second
    {
     randvar DIMNESSDIRECTION 1
     setvar DIMNESSSWITCHTIMER 0
    } 
 
    ifvare DIMNESSDIRECTION 0
    { 
     randvar TEMPVAR 4
     randvar TEMPVAR2 2 addvar TEMPVAR2 1
     mulvarvar TEMPVAR TEMPVAR2
     ifrnd 128 mulvar TEMPVAR -1
     addvar ACTORANGLE 24
     addvarvar ACTORANGLE TEMPVAR
    }
    else
    {
     randvar TEMPVAR 4
     randvar TEMPVAR2 2 addvar TEMPVAR2 1
     mulvarvar TEMPVAR TEMPVAR2
     ifrnd 128 mulvar TEMPVAR -1
     subvar ACTORANGLE 24
     subvarvar ACTORANGLE TEMPVAR
    }
    setactor[THISACTOR].ang ACTORANGLE 
   }

   ifvarg ACTORDIMNESSTIMER 0
   {
    ifvare CLOAKED? 1 nullop 
    else ifvare FROZEN? 1 nullop
    else ifvare SHRUNK? 1 nullop
    else subvar ACTORDIMNESSTIMER 1
   }
   else
   {
    redefinequote 335 ^10AN ENEMY'S DIMNESS HAS WORN OFF! :(
    subvar ACTORSTATUS? 16
    setvar ACTORDIMNESSTIMER 0
    setvarvar fta fta_normal setvar ftq 335
   }
  }
 }
 ifvarand ACTORSTATUS? 128 // Confusion
 {
  ifactor TANK // Tanks Cannot Be Confused [they're driven by enemies who cannot be currently confused due to the tank's protective armor]
  {
   subvar ACTORSTATUS? 128
   setvar ACTORCONFUSIONTIMER 0
  }
  else
  ifactor SCORPIONTANK // Tanks Cannot Be Confused [they're driven by enemies who cannot be currently confused due to the tank's protective armor]
  {
   subvar ACTORSTATUS? 128
   setvar ACTORCONFUSIONTIMER 0
  }
  else
  {
   ifvare mainmenu 0 // only mess with the view angles when the menu isn't open
   {
    getactor[THISACTOR].ang ACTORANGLE 
    randvar TEMPVAR4 5 // 7
    ifrnd 128 mulvar TEMPVAR4 -1
    addvar TEMPVAR4 20 // 25

    addvar CONFUSESWITCHTIMER 1
    ifvarvarg CONFUSESWITCHTIMER TEMPVAR4 // Will randomly set the direction of spinning while confused every second
    {
     randvar CONFUSEDIRECTION 1
     setvar CONFUSESWITCHTIMER 0
    }

    ifvare CONFUSEDIRECTION 0
    { 
     randvar TEMPVAR 16
     randvar TEMPVAR2 2 addvar TEMPVAR2 1
     mulvarvar TEMPVAR TEMPVAR2
     ifrnd 128 mulvar TEMPVAR -1
     ifrnd 85 addvar ACTORANGLE 32 else ifrnd 128 addvar ACTORANGLE 64 else addvar ACTORANGLE 96
     addvarvar ACTORANGLE TEMPVAR
    }
    else
    {
     randvar TEMPVAR 16
     randvar TEMPVAR2 2 addvar TEMPVAR2 1
     mulvarvar TEMPVAR TEMPVAR2
     ifrnd 128 mulvar TEMPVAR -1
     ifrnd 85 subvar ACTORANGLE 32 else ifrnd 128 subvar ACTORANGLE 64 else subvar ACTORANGLE 96
     subvarvar ACTORANGLE TEMPVAR
    }
    setactor[THISACTOR].ang ACTORANGLE 
   } 

   ifvarg ACTORCONFUSIONTIMER 0
   {
    ifvare CLOAKED? 1 nullop 
    else ifvare FROZEN? 1 nullop
    else ifvare SHRUNK? 1 nullop
    else subvar ACTORCONFUSIONTIMER 1
   }
   else
   {
    redefinequote 335 ^10AN ENEMY'S CONFUSION HAS WORN OFF! :(
    subvar ACTORSTATUS? 128
    setvar ACTORCONFUSIONTIMER 0
    setvarvar fta fta_normal setvar ftq 335
   }
  }
 }
 ifvarand ACTORSTATUS? 512 // Damage Shell
 {
  ifvarg ACTORSHELLTIMER 0
  {
   ifvare CLOAKED? 1 nullop 
   else ifvare FROZEN? 1 nullop
   else ifvare SHRUNK? 1 nullop
   else subvar ACTORSHELLTIMER 1
  }
  else
  {
   redefinequote 335 ^22AN ENEMY'S DAMAGE-SHELL HAS WORN OFF! :)
   subvar ACTORSTATUS? 512
   setvar ACTORSHELLTIMER 0
   setvarvar fta fta_normal setvar ftq 335
  }
 }
 ifvarand ACTORSTATUS? 1024 // Psychic Shield
 {
  ifvarg ACTORPSISHIELDTIMER 0
  {
   ifvare CLOAKED? 1 nullop 
   else ifvare FROZEN? 1 nullop
   else ifvare SHRUNK? 1 nullop
   else subvar ACTORPSISHIELDTIMER 1
  }
  else
  {
   redefinequote 335 ^22AN ENEMY'S PSYCHIC-SHIELD HAS WORN OFF! :)
   subvar ACTORSTATUS? 1024
   setvar ACTORPSISHIELDTIMER 0
   setvarvar fta fta_normal setvar ftq 335
  }
 }

 // Makes the enemy use their First Aid Kit if they have one everytime they lose health until it runs out
 setvarvar ENEMYCURRENTFIRSTAID ENEMYFIRSTAID
 ifvarg ENEMYHP 0 ifvarg ENEMYCURRENTFIRSTAID 0
 {
  ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
  else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)

  ifvarand ACTORSTATUS? 128 // If confused, make chances less
  {
   ifvare SKILLLEVEL 0 setvar RNDMIZERLIMIT 255 // ifrnd 1
   ifvare SKILLLEVEL 1 setvar RNDMIZERLIMIT 255 // ifrnd 1
   ifvare SKILLLEVEL 2 setvar RNDMIZERLIMIT 254 // ifrnd 2
   ifvare SKILLLEVEL 3 setvar RNDMIZERLIMIT 253 // ifrnd 3
   ifvare SKILLLEVEL 4 setvar RNDMIZERLIMIT 249 // ifrnd 7
   ifvare SKILLLEVEL 5 setvar RNDMIZERLIMIT 244 // ifrnd 12
   ifvare SKILLLEVEL 6 setvar RNDMIZERLIMIT 234 // ifrnd 22
   ifvare SKILLLEVEL 7 setvar RNDMIZERLIMIT 218 // ifrnd 38
   ifvare SKILLLEVEL 8 setvar RNDMIZERLIMIT 198 // ifrnd 58
   ifvare SKILLLEVEL 9 setvar RNDMIZERLIMIT 192 // ifrnd 64
  }
  else
  {
   ifvare SKILLLEVEL 0 setvar RNDMIZERLIMIT 255 // ifrnd 1
   ifvare SKILLLEVEL 1 setvar RNDMIZERLIMIT 253 // ifrnd 3
   ifvare SKILLLEVEL 2 setvar RNDMIZERLIMIT 249 // ifrnd 7
   ifvare SKILLLEVEL 3 setvar RNDMIZERLIMIT 241 // ifrnd 15
   ifvare SKILLLEVEL 4 setvar RNDMIZERLIMIT 229 // ifrnd 27
   ifvare SKILLLEVEL 5 setvar RNDMIZERLIMIT 208 // ifrnd 48
   ifvare SKILLLEVEL 6 setvar RNDMIZERLIMIT 170 // ifrnd 86
   ifvare SKILLLEVEL 7 setvar RNDMIZERLIMIT 105 // ifrnd 151
   ifvare SKILLLEVEL 8 setvar RNDMIZERLIMIT 27 // ifrnd 229
   ifvare SKILLLEVEL 9 setvar RNDMIZERLIMIT 1 // ifrnd 255
  }
  state rndmizer256

  ifvarvarg RNDMIZER RNDMIZERLIMIT // Makes Enemy use their Medikit at a specfic frequency depending on Difficulty Level
  {
   ifvarg ENEMYHP 0
    ifvarvarl ENEMYHP ENEMYMAXHP
   {
    setvarvar TEMPVAR ENEMYMAXHP
    subvarvar TEMPVAR ENEMYHP
    ifvarvarl TEMPVAR ENEMYFIRSTAID
    {
     addvarvar ENEMYHP TEMPVAR
     subvarvar ENEMYFIRSTAID TEMPVAR

     setvarvar ITEMSEEK THISACTOR
     setvarvar ITEMSEEKC TEMPVAR
     state showhealing_actorhp

     setvar TEMPVAR 0
     sound USE_MEDIKITITEM
    }
    else
    {
     addvarvar ENEMYHP ENEMYFIRSTAID
     setvarvar TEMPVAR ENEMYFIRSTAID
     setvar ENEMYFIRSTAID 0

     setvarvar ITEMSEEK THISACTOR
     setvarvar ITEMSEEKC TEMPVAR
     state showhealing_actorhp

     setvar TEMPVAR 0
     sound USE_MEDIKITITEM
    }

    ifvare DRIVERID -1
    {
     setvar EDISPLAYFAFLASHTIMER 28
     setvar ENEMYHPDAMAGED? -1
    }
    else ifvarvare DRIVERID PLAYERID
    {
     setvar VDISPLAYFAFLASHTIMER 28
     setvar VEHICLEHPDAMAGED? -1
    }
   }
  }
 }

  // Do a final check to make sure timers for ailments that aren't active are reset to 0
  ifvarand ACTORSTATUS? 2 nullop else setvar ACTORHASTETIMER 0
  ifvarand ACTORSTATUS? 4 nullop else setvar ACTORSLOWTIMER 0
  ifvarand ACTORSTATUS? 8 nullop else setvar ACTORPOISONTIMER 0
  ifvarand ACTORSTATUS? 16 nullop else setvar ACTORDIMNESSTIMER 0
  ifvarand ACTORSTATUS? 128 nullop else setvar ACTORCONFUSIONTIMER 0
  ifvarand ACTORSTATUS? 512 nullop else setvar ACTORSHELLTIMER 0
  ifvarand ACTORSTATUS? 1024 nullop else setvar ACTORPSISHIELDTIMER 0
ends

state enemyrecover5perhealth
      addvarvar ENEMYHP ENEMYREGENAMOUNT2
      ifvarg ENEMYREGENAMOUNT2 0
      {
       setvarvar SHOWDAMAGE ENEMYREGENAMOUNT2
       // addlogvar ENEMYREGENAMOUNT2
       setvar SHOWDAMAGETYPE 3
       setvarvar SHOWDAMAGEACTORID THISACTOR
       state showdamage
      }
      ifvarvarg ENEMYHP STATLIMITATOMIC setvarvar ENEMYHP STATLIMITATOMIC
      ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
      ifvarvarl ENEMYHP STATLIMITATOMIC
      {
       sound REGEN_HEALTH5 
       ifvare DRIVERID -1 setvar ENEMYHPDAMAGED? -1 else ifvarvare DRIVERID PLAYERID setvar VEHICLEHPDAMAGED? -1
      }
ends

state enemyregenitem
  ifvarg ENEMYREGENTIME 0
  {
   ifvarand ENEMYPOWERUPBITFIELD 4 nullop else addvar ENEMYPOWERUPBITFIELD 4
   state itemfullbright
   ifvare mainmenu 0 ifvarn FROZEN? 1 addvar ENEMYREGENCOUNTER 1
   ifvarand ACTORSTATUS? 8 // Remove Poison
   {
    subvar ACTORSTATUS? 8
    setvar ACTORPOISONTIMER 0
   }
   ifvarg ENEMYREGENCOUNTER 25
   {
    setvarvar ENEMYREGENAMOUNT1 ENEMYMAXHP
    ifvare PUBLICBETA? 1 mulvar ENEMYREGENAMOUNT1 150 else mulvar ENEMYREGENAMOUNT1 50
    divvar ENEMYREGENAMOUNT1 1000
    setvarvar ENEMYREGENAMOUNT2 ENEMYMAXHP
    ifvare PUBLICBETA? 1 mulvar ENEMYREGENAMOUNT2 50 else mulvar ENEMYREGENAMOUNT2 16
    divvar ENEMYREGENAMOUNT2 1000

    ifvarvarl ENEMYHP ENEMYMAXHPATOMIC ifvarvarg ENEMYHP ENEMYMAXHP state enemyrecover5perhealth
    else ifvarvare ENEMYHP ENEMYMAXHP state enemyrecover5perhealth
    else ifvarvarl ENEMYHP ENEMYMAXHP ifvarg ENEMYHP -1
    {
     addvarvar ENEMYHP ENEMYREGENAMOUNT1
     ifvarg ENEMYREGENAMOUNT1 0
     {
      setvarvar SHOWDAMAGE ENEMYREGENAMOUNT1
      // addlogvar ENEMYREGENAMOUNT1
      setvar SHOWDAMAGETYPE 3
      setvarvar SHOWDAMAGEACTORID THISACTOR
      state showdamage
     }
     ifvarvarg ENEMYHP STATLIMITATOMIC setvarvar ENEMYHP STATLIMITATOMIC
     ifvarvarg ENEMYHP ENEMYMAXHPATOMIC setvarvar ENEMYHP ENEMYMAXHPATOMIC
     ifvarvarl ENEMYHP STATLIMITATOMIC
     {
      sound REGEN_HEALTH15 
      ifvare DRIVERID -1 setvar ENEMYHPDAMAGED? -1 else ifvarvare DRIVERID PLAYERID setvar VEHICLEHPDAMAGED? -1
     }
    }
    setvar ENEMYREGENCOUNTER 0
   }
   ifvare mainmenu 0 ifvarn FROZEN? 1 subvar ENEMYREGENTIME 1
   ifvare ENEMYREGENTIME 1
   {
    setvar ENEMYREGENCOUNTER 0

    state getitemseekerspeciesquote
    ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 301 ^10AN ENEMY'S REGENERATION ANKH JUST WORE OFF! :D
    ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 301 ^15A CIVILIAN'S REGENERATION ANKH JUST WORE OFF! -_-
    ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 301 ^15A VEHICLE'S REGENERATION ANKH JUST WORE OFF! :(
    setvarvar fta fta_normal setvar ftq 301 
   }
  } 
  else
  {
   ifvarand ENEMYPOWERUPBITFIELD 4 subvar ENEMYPOWERUPBITFIELD 4
  }
ends

state enemyrecover5perarmor
       addvarvar ENEMYAP ENEMYAPREGENAMOUNT2
       ifvarg ENEMYAPREGENAMOUNT2 0
       {
        setvarvar SHOWDAMAGE ENEMYAPREGENAMOUNT2
        // addlogvar ENEMYAPREGENAMOUNT2
        setvar SHOWDAMAGETYPE 4
        setvarvar SHOWDAMAGEACTORID THISACTOR
        state showdamage
       }
       ifvarvarg ENEMYAP STATLIMITATOMIC setvarvar ENEMYAP STATLIMITATOMIC
       ifvarvarg ENEMYAP ENEMYMAXAPATOMIC setvarvar ENEMYAP ENEMYMAXAPATOMIC
       ifvarvarl ENEMYAP STATLIMITATOMIC
       {
        sound REGEN_ARMOR5
        ifvare DRIVERID -1 setvar ENEMYAPDAMAGED? -1 else ifvarvare DRIVERID PLAYERID setvar VEHICLEAPDAMAGED? -1
       }
ends

state enemyapregenitem
   ifvarg ENEMYAPREGENTIME 0
   {
    ifvarand ENEMYPOWERUPBITFIELD 8 nullop else addvar ENEMYPOWERUPBITFIELD 8
    state itemfullbright
    setvar ENEMYARMORPERCENT 1000
    ifvare mainmenu 0 ifvarn FROZEN? 1 addvar ENEMYAPREGENCOUNTER 1 
    ifvarg ENEMYAPREGENCOUNTER 25
    {
     setvarvar ENEMYAPREGENAMOUNT1 ENEMYMAXAP
     ifvare PUBLICBETA? 1 mulvar ENEMYAPREGENAMOUNT1 150 else mulvar ENEMYAPREGENAMOUNT1 50
     divvar ENEMYAPREGENAMOUNT1 1000
     setvarvar ENEMYAPREGENAMOUNT2 ENEMYMAXAP
     ifvare PUBLICBETA? 1 mulvar ENEMYAPREGENAMOUNT2 50 else mulvar ENEMYAPREGENAMOUNT2 16
     divvar ENEMYAPREGENAMOUNT2 1000

     ifvarvarl ENEMYAP ENEMYMAXAPATOMIC ifvarvarg ENEMYAP ENEMYMAXAP state enemyrecover5perarmor
     else ifvarvare ENEMYAP ENEMYMAXAP state enemyrecover5perarmor
     else ifvarvarl ENEMYAP ENEMYMAXAP ifvarg ENEMYAP -1
     {
      addvarvar ENEMYAP ENEMYAPREGENAMOUNT1
      ifvarg ENEMYAPREGENAMOUNT1 0
      {
       setvarvar SHOWDAMAGE ENEMYAPREGENAMOUNT1
       // addlogvar ENEMYAPREGENAMOUNT1
       setvar SHOWDAMAGETYPE 4
       setvarvar SHOWDAMAGEACTORID THISACTOR
       state showdamage
      }
      ifvarvarg ENEMYAP STATLIMITATOMIC setvarvar ENEMYAP STATLIMITATOMIC
      ifvarvarg ENEMYAP ENEMYMAXAPATOMIC setvarvar ENEMYAP ENEMYMAXAPATOMIC
      ifvarvarl ENEMYAP STATLIMITATOMIC
      {
       sound REGEN_ARMOR15
       ifvare DRIVERID -1 setvar ENEMYAPDAMAGED? -1 else ifvarvare DRIVERID PLAYERID setvar VEHICLEAPDAMAGED? -1
      }
     }
     setvar ENEMYAPREGENCOUNTER 0
    }
    ifvare mainmenu 0 ifvarn FROZEN? 1 subvar ENEMYAPREGENTIME 1
    ifvare ENEMYAPREGENTIME 1
    {
     setvar ENEMYAPREGENCOUNTER 0
     state getitemseekerspeciesquote
     ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 301 ^10AN ENEMY'S SHIELD EMBLEM JUST WORE OFF! :D
     ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 301 ^15A CIVILIAN'S SHIELD EMBLEM JUST WORE OFF! -_-
     ifvare ITEMSEEKSPECIESTYPE 2 redefinequote 301 ^15A VEHICLE'S SHIELD EMBLEM JUST WORE OFF! :(
     setvarvar fta fta_normal setvar ftq 301 
    }

   } 
   else
   {
    ifvarand ENEMYPOWERUPBITFIELD 8 subvar ENEMYPOWERUPBITFIELD 8
   }
ends

state hpcheckfor0hp
 setvarvar ENEMYMAXHPATOMIC ENEMYMAXHP
 mulvar ENEMYMAXHPATOMIC 2

 // Forces the enemy to die if they have exactly 0 HP and they are not frozen over [or choking in the case of the LIZTROOP] [normally a monster will only die if it receives hittype damage when <=-1 HP]
 ifvarn SKILLSET? 0
 {
  ifvarl ENEMYHP 1 
  {
   ifvarn FROZEN? 1 
   { 
    ifvarn CHOKING? 1
    {
     ifvarn EXPANDING? 1
     {
      ifvarl ZEROHITS 6
      {
       // addlogvar ZEROHITS
       setvar ZEROHP 1 
       setactor[THISACTOR].extra 0
       setactor[THISACTOR].htpicnum SHOTSPARK1 
       setactor[THISACTOR].htextra ZEROHP
       addvar ZEROHITS 1
      } 
     }
    }
   }
  }
 }
ends

state enemymaxhpcountdown

// Check if actor's taken HP Damage of any kind [ >0 ]
 ifvarl ENEMYHPDAMAGED? 0 { ifvarn ATTACHEDOBJECTS? 0 { ifvarn HPBARCHILD -1 { setactorvar[HPBARCHILD].HPBARFLASHTIMER -28 } } addvar EDISPLAYHPFLASHTIMER -28 setvar ENEMYHPDAMAGED? 0 }
 ifvarg ENEMYHPDAMAGED? 0 { ifvarn ATTACHEDOBJECTS? 0 { ifvarn HPBARCHILD -1 { setactorvar[HPBARCHILD].HPBARFLASHTIMER 28 } } addvar EDISPLAYHPFLASHTIMER 28 setvar ENEMYHPDAMAGED? 0 }
 ifvarl EDISPLAYHPFLASHTIMER 0 { addvar EDISPLAYHPFLASHTIMER 1 } else ifvarg EDISPLAYHPFLASHTIMER 0 { subvar EDISPLAYHPFLASHTIMER 1 }

 ifvarl EDISPLAYFAFLASHTIMER 0 { addvar EDISPLAYFAFLASHTIMER 1 } else ifvarg EDISPLAYFAFLASHTIMER 0 { subvar EDISPLAYFAFLASHTIMER 1 }

// Check if actor's taken AP Damage of any kind [ >0 ]
 ifvarl ENEMYAPDAMAGED? 0 { ifvarn ATTACHEDOBJECTS? 0 { ifvarn APBARCHILD -1 { setactorvar[APBARCHILD].APBARFLASHTIMER -28 } } addvar EDISPLAYAPFLASHTIMER -28 setvar ENEMYAPDAMAGED? 0 }
 ifvarg ENEMYAPDAMAGED? 0 { ifvarn ATTACHEDOBJECTS? 0 { ifvarn APBARCHILD -1 { setactorvar[APBARCHILD].APBARFLASHTIMER 28 } } addvar EDISPLAYAPFLASHTIMER 28 setvar ENEMYAPDAMAGED? 0 }
 ifvarl EDISPLAYAPFLASHTIMER 0 { addvar EDISPLAYAPFLASHTIMER 1 } else ifvarg EDISPLAYAPFLASHTIMER 0 { subvar EDISPLAYAPFLASHTIMER 1 }

// Check water or not
 ifonwater { setvar WATER? 1 } else ifinwater { setvar WATER? 2 } else { setvar WATER? 0 }

// Sets up how enemies use their Regeneration Ankh
 state hpcheckfor0hp

// Enemy Regen Powerup
 ifvare CLOAKED? 1 nullop else state enemyregenitem

// Sets up how enemies use their Shield Emblem
 ifvare CLOAKED? 1 nullop else state enemyapregenitem

 // Force Limit Checks on Non-Player Actor Stats
 ifvarvarg ENEMYMAXHP STATLIMIT setvarvar ENEMYMAXHP STATLIMIT
 ifvarvarg ENEMYMAXAP STATLIMIT setvarvar ENEMYMAXAP STATLIMIT
 ifvarvarg ENEMYHP STATLIMITATOMIC setvarvar ENEMYHP STATLIMITATOMIC
 ifvarvarg ENEMYAP STATLIMITATOMIC setvarvar ENEMYAP STATLIMITATOMIC
 ifvarvarg ENEMYFIRSTAID STATLIMITATOMIC setvarvar ENEMYFIRSTAID STATLIMITATOMIC
 ifvarvarg ACTORATTACK STATLIMIT setvarvar ACTORATTACK STATLIMIT
 ifvarvarg ACTORDEFENSE STATLIMIT setvarvar ACTORDEFENSE STATLIMIT

 getactor[THISACTOR].cstat TEMP
 ifvarand TEMP 1024 nullop else addvar TEMP 1024
 setactor[THISACTOR].cstat TEMP

ends

state difficulty
 getuserdef[THISACTOR].player_skill SKILLLEVEL
 getuserdef[THISACTOR].volume_number DISPLAYEPISODE
 getuserdef[THISACTOR].level_number DISPLAYLEVEL
 addvar DISPLAYEPISODE 1
 addvar DISPLAYLEVEL 1
ends

// State for calcing enemy health on skills above four and by Episode/Level

state assessskillflags
 ifvare SKILLLEVELFLAGS 0 { setvar SKILLLEVELFLAGS 1023 } // All Skills
 ifvare SKILLLEVEL 0 { ifvarand SKILLLEVELFLAGS 1 nullop else killit }
 ifvare SKILLLEVEL 1 { ifvarand SKILLLEVELFLAGS 2 nullop else killit }
 ifvare SKILLLEVEL 2 { ifvarand SKILLLEVELFLAGS 4 nullop else killit }
 ifvare SKILLLEVEL 3 { ifvarand SKILLLEVELFLAGS 8 nullop else killit }
 ifvare SKILLLEVEL 4 { ifvarand SKILLLEVELFLAGS 16 nullop else killit }
 ifvare SKILLLEVEL 5 { ifvarand SKILLLEVELFLAGS 32 nullop else killit }
 ifvare SKILLLEVEL 6 { ifvarand SKILLLEVELFLAGS 64 nullop else killit }
 ifvare SKILLLEVEL 7 { ifvarand SKILLLEVELFLAGS 128 nullop else killit }
 ifvare SKILLLEVEL 8 { ifvarand SKILLLEVELFLAGS 256 nullop else killit }
 ifvare SKILLLEVEL 9 { ifvarand SKILLLEVELFLAGS 512 nullop else killit }
ends

state getenemylevel2
// OFF-LIMITS
 getactor[THISACTOR].extra ENEMYLEVEL
 setactor[THISACTOR].extra -1
 getactor[THISACTOR].xvel ENEMYLEVELMINSPAWN
 setactor[THISACTOR].xvel 0
 getactor[THISACTOR].yvel ENEMYLEVELMAXSPAWN
 setactor[THISACTOR].yvel 0
 getactor[THISACTOR].zvel ACTORFLAGS
 setactor[THISACTOR].zvel 0
 setactor[THISACTOR].htowner -1
 setactorvar[THISACTOR].ENEMYMAXHP 1 // Prevents instanteous monster death on activation
// END OFF LIMITS

// state assessskillflags

 ifvarn ATTACHEDOBJECTS? 0
 {
  ifvare RADARARROWSET? 0
  {
   espawn POINTERARROW // POINTERARROW is for when the actor can be seen on the Mercury Computer's Radar
   setactorvar[THISACTOR].POINTERICONCHILD RETURN
   setactorvar[RETURN].POINTERICONPARENT THISACTOR
   setvar RADARARROWSET? 1
  }
 }

 ifvarn ENEMYLEVEL -1 setvar ENEMYLEVELPRESET? 1 // Sets a flag to keep a preset enemy's levels intact despite recalcuations at player levelups
 ifvarl ENEMYLEVEL 0 
 {
  setvar ENEMYLEVEL 0
  ifvarg ENEMYLEVELMINSPAWN 0
  {
   ifvarvarl ENEMYLEVELMINSPAWN ENEMYLEVELMAXSPAWN
   {
    setvarvar tempc ENEMYLEVELMAXSPAWN
    subvarvar tempc ENEMYLEVELMINSPAWN    
    randvarvar ENEMYLEVEL tempc
    addvarvar ENEMYLEVEL ENEMYLEVELMINSPAWN
   }
   else
   {
    setvarvar ENEMYLEVEL ENEMYLEVELMINSPAWN
   }
  }
 }

 ifvarg ENEMYLEVEL 100 setvar ENEMYLEVEL 100
ends

state capmaxhpenemy
 ifvarvarg ENEMYHP STATLIMITATOMIC setvarvar ENEMYHP STATLIMITATOMIC
ends

state newenemystatcalc
 getactor[THISACTOR].picnum STATCALCPICNUM
 getactor[THISACTOR].pal STATCALCPAL

// ************************************
// *Calculates Hit Points for Monsters*
// ************************************

 ifvare ENEMYLEVEL 0 state getenemylevel

 // Gets Base HP levels
 ifvare SKILLLEVEL 0 setvar TEMPVAR2 1000
 ifvare SKILLLEVEL 1 setvar TEMPVAR2 1333
 ifvare SKILLLEVEL 2 setvar TEMPVAR2 1667
 ifvare SKILLLEVEL 3 setvar TEMPVAR2 2000
 ifvare SKILLLEVEL 4 setvar TEMPVAR2 2333
 ifvare SKILLLEVEL 5 setvar TEMPVAR2 2667
 ifvare SKILLLEVEL 6 setvar TEMPVAR2 3000
 ifvare SKILLLEVEL 7 setvar TEMPVAR2 3333
 ifvare SKILLLEVEL 8 setvar TEMPVAR2 3667
 ifvare SKILLLEVEL 9 setvar TEMPVAR2 4000
 mulvarvar ENEMYHP TEMPVAR2
 divvar ENEMYHP 1000

 setvar TEMPVAR2 750
 setvar TEMPVAR3 250
 mulvarvar TEMPVAR3 DISPLAYEPISODE
 addvarvar TEMPVAR2 TEMPVAR3
 mulvarvar ENEMYHP TEMPVAR2
 divvar ENEMYHP 1000

 setvar TEMPVAR2 975
 setvar TEMPVAR3 25
 mulvarvar TEMPVAR3 DISPLAYLEVEL
 addvarvar TEMPVAR2 TEMPVAR3
 mulvarvar ENEMYHP TEMPVAR2
 divvar ENEMYHP 1000
 // Ends Get Base HP levels

 setvarvar ENEMYMAXAP ENEMYHP

 setvarvar SKILLHEALTHCALC ENEMYHP
 mulvar SKILLHEALTHCALC 100
 divvar SKILLHEALTHCALC 1000 // Determines 10% of the base HP value to use for the varience
 randvarvar TEMPVAR SKILLHEALTHCALC

 ifrnd 128 addvarvar ENEMYHP TEMPVAR else subvarvar ENEMYHP TEMPVAR

//****************
//*Level Ups here*
//****************
 ifvarg ENEMYLEVEL 1
 {
  setvar ENEMYTEMPLEVEL 1
  whilevarvarn ENEMYTEMPLEVEL ENEMYLEVEL state calcleveluphp
 }
//********************
//*End Level Ups here*
//********************

 state capmaxhpenemy
 setvarvar ENEMYMAXHP ENEMYHP
 setactor[THISACTOR].extra 16384

// Atomic Health?

 ifvare SKILLLEVEL 0 { ifrnd 4 { ifrnd 16 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 1 { ifrnd 8 { ifrnd 20 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 2 { ifrnd 12 { ifrnd 24 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 3 { ifrnd 16 { ifrnd 32 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 4 { ifrnd 20 { ifrnd 40 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 5 { ifrnd 24 { ifrnd 52 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 6 { ifrnd 32 { ifrnd 64 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 7 { ifrnd 40 { ifrnd 80 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 8 { ifrnd 48 { ifrnd 96 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 ifvare SKILLLEVEL 9 { ifrnd 64 { ifrnd 128 mulvar ENEMYHP 200 else mulvar ENEMYHP 150 } else mulvar ENEMYHP 100 }
 divvar ENEMYHP 100

 state capmaxhpenemy

// **************************************
// *Calculates Armor Points for Monsters*
// **************************************

 setvarvar SKILLARMORCALC ENEMYMAXAP
 mulvar SKILLARMORCALC 100
 divvar SKILLARMORCALC 1000 // Determines 10% of the base HP value to use for the varience
 randvarvar TEMPVAR SKILLARMORCALC

 ifrnd 128 addvarvar ENEMYMAXAP TEMPVAR else subvarvar ENEMYMAXAP TEMPVAR

//****************
//*Level Ups here*
//****************
 ifvarg ENEMYLEVEL 1
 {
  setvar ENEMYTEMPLEVEL 1
  whilevarvarn ENEMYTEMPLEVEL ENEMYLEVEL state calclevelupap
 }
//********************
//*End Level Ups here*
//********************

 ifvarvarg ENEMYMAXAP STATLIMIT setvarvar ENEMYMAXAP STATLIMIT
 setvarvar ENEMYAP ENEMYMAXAP

 setvarvar tempd SKILLLEVEL
 ifvarg SKILLLEVEL 4 subvar tempd 1
 mulvarvar ENEMYAP tempd

 divvar ENEMYAP 4 

 ifvarvarg ENEMYAP STATLIMITATOMIC setvarvar ENEMYAP STATLIMITATOMIC

ifvarg ENEMYAP 0
{
 ifvarl SKILLLEVEL 5
 {
   ifrnd 64 setvar ENEMYARMORPERCENT 333
   else ifrnd 85 setvar ENEMYARMORPERCENT 500
   else ifrnd 128 setvar ENEMYARMORPERCENT 667
   else setvar ENEMYARMORPERCENT 900
 }
 else
 {
   randvar ENEMYARMORPERCENT 100
   addvar ENEMYARMORPERCENT 900
 }
}

// ********************************
// *Calculates Attack for Monsters*
// ********************************

  setvarvar ENEMYSTAT ACTORATTACK
  state calcatkdef
  setvarvar ACTORATTACK ENEMYSTAT

  setvarvar SKILLATTACKCALC ACTORATTACK
  mulvar SKILLATTACKCALC 25
  divvar SKILLATTACKCALC 100 // Determines 100% of the base Def value to use for the varience
  randvarvar TEMPVAR SKILLATTACKCALC

  ifrnd 128 addvarvar ACTORATTACK TEMPVAR else subvarvar ACTORATTACK TEMPVAR

//****************
//*Level Ups here*
//****************
 ifvarg ENEMYLEVEL 1
 {
  setvar ENEMYTEMPLEVEL 1
  whilevarvarn ENEMYTEMPLEVEL ENEMYLEVEL state calclevelupatk
 }
//********************
//*End Level Ups here*
//********************

  ifvare STATCALCPAL 9 setvar ACTORATTACK 0

  ifvarvarg ACTORATTACK STATLIMIT setvarvar ACTORATTACK STATLIMIT

// *********************************
// *Calculates Defense for Monsters*
// *********************************

  setvarvar ENEMYSTAT ACTORDEFENSE
  state calcatkdef
  setvarvar ACTORDEFENSE ENEMYSTAT

  setvarvar SKILLDEFENSECALC ACTORDEFENSE
  mulvar SKILLDEFENSECALC 25
  divvar SKILLDEFENSECALC 100 // Determines 100% of the base Def value to use for the varience
  randvarvar TEMPVAR SKILLDEFENSECALC

  ifrnd 128 addvarvar ACTORDEFENSE TEMPVAR else subvarvar ACTORDEFENSE TEMPVAR

//****************
//*Level Ups here*
//****************
 ifvarg ENEMYLEVEL 1
 {
  setvar ENEMYTEMPLEVEL 1
  whilevarvarn ENEMYTEMPLEVEL ENEMYLEVEL state calclevelupdef
 }
//********************
//*End Level Ups here*
//********************

  ifvare STATCALCPAL 9 setvar ACTORDEFENSE 0

  ifvarvarg ACTORDEFENSE STATLIMIT setvarvar ACTORDEFENSE STATLIMIT

// ***************************************************
// *Setting Up Possible First Aid Amount for Monsters*
// ***************************************************

  ifvare SKILLLEVEL 0 ifrnd 4 { state setenemyfirstaid1 ifrnd 8 state setenemyfirstaid2 }
  ifvare SKILLLEVEL 1 ifrnd 8 { state setenemyfirstaid1 ifrnd 16 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 2 ifrnd 16 { state setenemyfirstaid1 ifrnd 16 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 3 ifrnd 32 { state setenemyfirstaid1 ifrnd 32 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 4 ifrnd 64 { state setenemyfirstaid1 ifrnd 32 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 5 ifrnd 96 { state setenemyfirstaid1 ifrnd 64 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 6 ifrnd 128 { state setenemyfirstaid1 ifrnd 64 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 7 ifrnd 192 { state setenemyfirstaid1 ifrnd 128 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 8 ifrnd 224 { state setenemyfirstaid1 ifrnd 192 state setenemyfirstaid2 }  
  ifvare SKILLLEVEL 9 ifrnd 240 { state setenemyfirstaid1 ifrnd 224 state setenemyfirstaid2 }  

// ****************************************
// *Setting Up Possible Boots for Monsters*
// ****************************************

  setvar INITBENEFIT BOOT_AMOUNT
  state calciteminits
  setvarvar ENEMYBOOTSAMOUNT INITTYPE

// *********************************************
// *Setting Up Possible Scuba Gear for Monsters*
// *********************************************

  setvar INITBENEFIT SCUBA_AMOUNT
  state calciteminits
  setvarvar ENEMYAIRTANKAMOUNT INITTYPE

// **********************************************
// *Setting Up Possible Quad Damage for Monsters*
// **********************************************

  setvar INITBENEFIT 780
  state calciteminits
  setvarvar ENEMYQUADTIME INITTYPE

// *******************************************************
// *Setting Up Possible Icon of the Defender for monsters*
// *******************************************************

  setvar INITBENEFIT 780
  state calciteminits
  setvarvar ENEMYINVULNTIME INITTYPE

// ****************************************************
// *Setting Up Possible Regeneration Ankh for monsters*
// ****************************************************

  setvar INITBENEFIT 780
  state calciteminits
  setvarvar ENEMYREGENTIME INITTYPE

// ************************************************
// *Setting Up Possible Shield Emblem for monsters*
// ************************************************

  setvar INITBENEFIT 780
  state calciteminits
  setvarvar ENEMYAPREGENTIME INITTYPE

// ***************************************************
// *Setting Up Possible Vampire Artifact for monsters*
// ***************************************************

  setvar INITBENEFIT 780
  state calciteminits
  setvarvar ENEMYVAMPIRETIME INITTYPE

// ****************************************
// ****************************************
// ** END OF INITIALIZATION CALCULATIONS **
// ****************************************
// ****************************************

  ifvarand ACTORFLAGS 512 // 512 = Elite Monster
  {
   mulvar ENEMYMAXHP 4
   ifvarvarg ENEMYMAXHP STATLIMIT setvarvar ENEMYMAXHP STATLIMIT
   mulvar ENEMYHP 4
   mulvar ENEMYMAXAP 4
   ifvarvarg ENEMYMAXAP STATLIMIT setvarvar ENEMYMAXAP STATLIMIT
   mulvar ENEMYAP 4
   mulvar ENEMYARMORPERCENT 2
   ifvarg ENEMYARMORPERCENT 1000 setvar ENEMYARMORPERCENT 1000
   mulvar ENEMYFIRSTAID 4
   mulvar ENEMYMAXAIRTIME 4
   mulvar ENEMYAIRTIME 4
   mulvar ACTORATTACK 4
   mulvar ACTORDEFENSE 4
   mulvar ENEMYBOOTSAMOUNT 4
   mulvar ENEMYAIRTANKAMOUNT 4
   mulvar ENEMYQUADTIME 4
   mulvar ENEMYINVULNTIME 4
   mulvar ENEMYREGENTIME 4
   mulvar ENEMYAPREGENTIME 4
   mulvar ENEMYVAMPIRETIME 4
   addvar ACTORMAXFALLRESIST 8
   addvar ACTORFALLRESIST 8
  }

  ifvarand ACTORFLAGS 4096 // Special Flag #1
  {
   ifactor LIZTROOP setvar ENEMYBOMBER? 1 else subvar ACTORFLAGS 4096
  }

  setactor[THISACTOR].htowner -1

ends

// SAVES

state spawnmoneyrescue
     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 240 addvar TEMP2 10 // ifrnd 240 { espawn TENDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 224 addvar TEMP2 10 // ifrnd 224 { espawn TENDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 224 addvar TEMP2 20 // ifrnd 224 { spawn TWENTYDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 112 addvar TEMP2 20 // ifrnd 112 { spawn TWENTYDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 112 addvar TEMP2 50 // ifrnd 112 { spawn FIFTYDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 112 addvar TEMP2 50 // ifrnd 56 { spawn FIFTYDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 56 addvar TEMP2 100 // ifrnd 56 { spawn ONEHUNDREDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 28 addvar TEMP2 100 // ifrnd 28 { spawn ONEHUNDREDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 28 addvar TEMP2 500 // ifrnd 28 { spawn FIVEHUNDREDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 14 addvar TEMP2 500 // ifrnd 14 { spawn FIVEHUNDREDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 14 addvar TEMP2 1000 // ifrnd 14 { spawn ONETHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 7 addvar TEMP2 1000 // ifrnd 7 { spawn ONETHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 7 addvar TEMP2 5000 // ifrnd 7 { spawn FIVETHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 3 ifrnd 128 addvar TEMP2 5000 // ifrnd 3 ifrnd 128 { spawn FIVETHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 3 ifrnd 128 addvar TEMP2 10000 // ifrnd 3 ifrnd 128 { spawn TENTHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 1 ifrnd 192 addvar TEMP2 10000 // ifrnd 1 ifrnd 192 { spawn TENTHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 1 ifrnd 192 addvar TEMP2 100000 // ifrnd 1 ifrnd 192 { spawn ONEHUNDREDTHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 1 ifrnd 96 addvar TEMP2 100000 // ifrnd 1 ifrnd 96 { spawn ONEHUNDREDTHOUSANDDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 1 ifrnd 24 addvar TEMP2 1000000 // ifrnd 1 ifrnd 24 { spawn ONEMILLIONDOLLARS state setdroppedmoneyowner }
     }

     state 96outof256rnd
     ifvarvarg RNDMIZER RNDMIZERLIMIT
     {
      ifrnd 1 ifrnd 6 addvar TEMP2 1000000 // ifrnd 1 ifrnd 6 { spawn ONEMILLIONDOLLARS state setdroppedmoneyowner }
     }
ends

state ryansitems
     state stopsearchsounds
     ifrnd 192 // Rewards
     {
      ifrnd 128
      {
       ifvare CHARACTERSELECTED? 8 globalsound LISA_SAVEREWARD
       ifvare CHARACTERSELECTED? 15 globalsound MAKEN_SAVEREWARD
      }
      espawn MONEYBAG state setdroppedmoneyowner
      getactorvar[RETURN].MONEYBAGDOLLARS TEMP2
      getactorvar[RETURN].MONEYBAGCENTS zvelsav
      state spawnmoneyrescue
      ifvare CHARACTERSELECTED? 8
      { 
       ifvarg LISAMONEYTURNS2 1 state spawnmoneyrescue
       ifvarg LISAMONEYTURNS2 2 state spawnmoneyrescue
       ifvarg LISAMONEYTURNS2 3 state spawnmoneyrescue
       ifvare LISAMONEYMAXLEVEL 1 state spawnmoneyrescue
       ifvare LISAMONEYMAXLEVEL 1 state spawnmoneyrescue
      }
      setactorvar[RETURN].MONEYBAGDOLLARS TEMP2
      setactorvar[RETURN].MONEYBAGCENTS zvelsav

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 86 { espawn EYEDROP state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 43 { espawn EYEDROP state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 86 { espawn ANTIDOTE state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 43 { espawn ANTIDOTE state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 86 { espawn FOGHORN state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 43 { espawn FOGHORN state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 32 state celldrops
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 8 state celldrops
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 2 state celldrops
      }
      
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 16 { espawn RESURRECTIONCHALICE state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 8 { espawn RESURRECTIONCHALICE state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 8 { espawn COILS state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 4 { espawn COILS state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 96 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 48 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
      }

      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 32
       {
        ifrnd 32 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 16
       {
        ifrnd 32 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 32
       {
        ifrnd 64 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else ifrnd 85 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else ifrnd 128 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 16
       {
        ifrnd 64 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else ifrnd 85 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else ifrnd 128 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 32
       {
        ifrnd 85 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else ifrnd 128 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 16
       {
        ifrnd 85 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else ifrnd 128 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 32
       {
        ifrnd 128 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 16
       {
        ifrnd 128 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
        else { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 1
       {
        ifrnd 64 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 1
       {
        ifrnd 4 { espawn AFAS_DROP state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 16
       {
        ifrnd 53 { espawn QUADDAMAGE setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else ifrnd 64 { espawn ICONOFTHEDEFENDER setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else ifrnd 85 { espawn REGENITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else ifrnd 128 { espawn APREGENITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else { espawn VAMPIREITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
       }
      }
      state 16outof256rnd
      ifvarvarg RNDMIZER RNDMIZERLIMIT
      {
       ifrnd 8
       {
        ifrnd 53 { espawn QUADDAMAGE setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else ifrnd 64 { espawn ICONOFTHEDEFENDER setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else ifrnd 85 { espawn REGENITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else ifrnd 128 { espawn APREGENITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
        else { espawn VAMPIREITEM setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops }
       }
      }
     }
     else // Trap or Enemy
     {
      ifrnd 192 // Trap
      {
       ifrnd 224 
       {
        ifvare CHARACTERSELECTED? 8 globalsound LISA_SAVETRAP
        ifvare CHARACTERSELECTED? 15 globalsound MAKEN_SAVETRAP
       }
       eshoot MORTER 
       ifvarn RETURN -1
       {
        setactor[RETURN].owner THISACTOR
        getactor[RETURN].extra TEMP
        mulvar TEMP 10
        ifvarg TEMP 32767 setvar TEMP 32767
        setactor[RETURN].extra TEMP
       }
       sound TELEPORTER
       spawn TRANSPORTERSTAR
      }
      else // Enemy
      {
       ifrnd 252 
       {
        ifvare CHARACTERSELECTED? 8 globalsound LISA_SAVEENEMY
        ifvare CHARACTERSELECTED? 15 globalsound MAKEN_SAVEENEMY
       }
       ifrnd 85
       {
        espawn LIZTROOPJETPACK
        ifrnd 128 setactor[RETURN].pal 22 else setactor[RETURN].pal 21
       }
       else
       ifrnd 128
       {
        espawn PIGCOPDIVE
        ifrnd 128 setactor[RETURN].pal 0 else setactor[RETURN].pal 21
       }
       else
       {
        espawn LIZMANJUMP
        ifrnd 128 setactor[RETURN].pal 0 else setactor[RETURN].pal 19
       }
      }
     }

      subvar TELEPORTERCOILS 1
      // ifvare MONEYGAIN 1 { setvar DISPLAYDOLLARS 0 setvar DISPLAYCENTS 0 }
      subvar DISPLAYDOLLARS 100
      subvar DOLLARS 100
      // setvar MONEYGAIN -1
      state displaymoney
ends

state saverank
      ifactor FEM10
      {
       addvar CIVILIANSSAVED_LEVEL 2
       addvar CIVILIANSSAVED_GAME 2
      }
      else
      {
       addvar CIVILIANSSAVED_LEVEL 1
       addvar CIVILIANSSAVED_GAME 1
      }

      ifvarg MAX_CIVILIANSSAVED_LEVEL 0
      {
       ifvarvare CIVILIANSSAVED_LEVEL MAX_CIVILIANSSAVED_LEVEL
       {
        globalsound FOUND_ALLSECRETS
        redefinequote 130 ^23 YOU RESCUED ALL RESCUABLE CIVILIANS, ANIMALS AND INNOCENTS!
        setvarvar fta fta_normal setvar ftq 130
       }
      }

      addvarvar RANKPOINTS RANKPOINTSTEMP
      setvar RANKPOINTSTEMP 0
      sound TELEPORTER
	spawn TRANSPORTERSTAR
      ifactor FEM2
      {
       espawn POLEFEM2
       getactor[THISACTOR].xrepeat TEMP
       setactor[RETURN].xrepeat TEMP
       getactor[THISACTOR].yrepeat TEMP
       setactor[RETURN].yrepeat TEMP
       getactor[THISACTOR].cstat TEMP
       ifvarand TEMP 1024 subvar TEMP 1024
       setactor[RETURN].cstat TEMP
       getactor[THISACTOR].pal TEMP
       setactor[RETURN].pal TEMP
      }
      ifactor PODFEM1
      {
       espawn PODFEM1POD
       getactor[THISACTOR].xrepeat TEMP
       setactor[RETURN].xrepeat TEMP
       getactor[THISACTOR].yrepeat TEMP
       setactor[RETURN].yrepeat TEMP
       getactor[THISACTOR].cstat TEMP
       ifvarand TEMP 1024 subvar TEMP 1024
       setactor[RETURN].cstat TEMP
       getactor[THISACTOR].pal TEMP
       setactor[RETURN].pal TEMP
      }
      tip
      // OFF-LIMITS
      setactor[THISACTOR].extra -1 // attempt to remove NPC's lifebars from the map
      // END OFF-LIMITS
      killit
ends

state dogsave
  state useswitchcheckwall
  ifp pfacing 
  {
   ifpdistl 1280 ifvare TEMP2 1 
   {
    ifhitspace 
    {
     ifvarg TELEPORTERCOILS 0
     {
      ifvarg DOLLARS 99
      {
       sound BARKING_DOG 
       state ryansitems

       randvar RANKPOINTSTEMP DOGSAVERANKPOINTSRAND 
       addvar RANKPOINTSTEMP DOGSAVERANKPOINTSSOLID 
       setvar TEMPVAR 1
       state expmulti
       state saverank
       redefinequote 130 ^20YOU RESCUED THE LITTLE DOG! 
       setvarvar fta fta_normal setvar ftq 130
      }
      else 
      { 
       redefinequote 130 ^10NOT ENOUGH MONEY, MAN! 
       setvarvar fta fta_normal setvar ftq 130
      }
     }
     else
     {
      redefinequote 130 ^10YOU HAVE NO TELEPORTER COILS! 
      setvarvar fta fta_normal setvar ftq 130
     }
    }
   }
  }
ends

state femsave
  state useswitchcheckwall
  ifp pfacing 
  {
   ifpdistl 1280 ifvare TEMP2 1
   {
    ifhitspace 
    {
     ifvarg TELEPORTERCOILS 0
     {
      ifvarg DOLLARS 99
      {
       state ryansitems

       randvar RANKPOINTSTEMP FEMSAVERANKPOINTSRAND 
       addvar RANKPOINTSTEMP FEMSAVERANKPOINTSSOLID 
       setvar TEMPVAR 1
       state expmulti
       state saverank
       ifactor FEM10 redefinequote 130 ^20YOU RESCUED 2 WOMEN! 
       else redefinequote 130 ^20YOU RESCUED THE WOMAN! 

       setvarvar fta fta_normal setvar ftq 130
      }
      else 
      { 
       redefinequote 130 ^10NOT ENOUGH MONEY, MAN! 
       setvarvar fta fta_normal setvar ftq 130
      }
     }
     else
     {
      redefinequote 130 ^10YOU HAVE NO TELEPORTER COILS! 
      setvarvar fta fta_normal setvar ftq 130
     }
    }
   }
  }
ends

state civsave
  state useswitchcheckwall
  ifp pfacing 
  {
   ifpdistl 1280 ifvare TEMP2 1
   {
    ifhitspace 
    {
     ifvarg TELEPORTERCOILS 0
     {
      ifvarg DOLLARS 99
      {
       state ryansitems
 
       state displaymoney
       randvar RANKPOINTSTEMP CIVILIANSAVERANKPOINTSRAND 
       addvar RANKPOINTSTEMP CIVILIANSAVERANKPOINTSSOLID 
       setvar TEMPVAR 1
       state expmulti
       state saverank
       redefinequote 130 ^20YOU RESCUED THE CIVILIAN! 
       setvarvar fta fta_normal setvar ftq 130
      }
      else 
      { 
       redefinequote 130 ^10NOT ENOUGH MONEY, MAN! 
       setvarvar fta fta_normal setvar ftq 130
      }
     }
     else
     {
      redefinequote 130 ^10YOU HAVE NO TELEPORTER COILS! 
      setvarvar fta fta_normal setvar ftq 130
     }
    }
   }
  }
ends

state frosty
   ifrnd 64 
   {
    globalsound FROSTY
    setvar FORDENTIMER 19
    randvar FORDENTYPE 1
    redefinequote 340 ^1FROSTY!!
    userquote 340
   }
ends

state jib_sounds

 // Random Mortal-Kombat related jib sounds
 ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 224 else setvar RNDMIZERLIMIT 192 state rndmizer256
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  ifvare oldskoolmode 0
  {
   ifrnd 64
   {
    ifrnd 53
    {
     globalsound KAHNFATALITY
     redefinequote 340 ^10FATALITY!!
     userquote 340
    }
    else
    ifrnd 64
    {
     globalsound KAHNEXCELLENT
     redefinequote 340 ^22EXCELLENT!!
     userquote 340
    }
    else
    ifrnd 85 
    {
     globalsound MORTALYELL 
     redefinequote 340 ^20MORTAL KOMBAT!!!!
     userquote 340
    }
    else 
    ifrnd 128 
    {
     globalsound TOASTY
     setvar FORDENTIMER 19
     randvar FORDENTYPE 1
     redefinequote 340 ^2TOASTY!!
     userquote 340
    }
    else 
    {
     globalsound CRISPY
     setvar FORDENTIMER 19 
     randvar FORDENTYPE 1
     redefinequote 340 ^10CRISPY!!
     userquote 340
    }
   }
  }
 }

ifvare PUBLICBETA? 0 setvar RNDMIZERLIMIT 224 else setvar RNDMIZERLIMIT 192 state rndmizer256
ifvarvarg RNDMIZER RNDMIZERLIMIT
{
 getactor[THISACTOR].htowner temp
 ifvarg CURRENTHITPOINTS 0 // ifp palive
 ifvarvare temp PLAYERID
 {
  ifvare ONELINERINPLAY? 0 // If there is no one-liner playing, continue
  ifrnd SWEARFREQUENCY
  {
   ifvare CHARACTERSELECTED? 1 // If Duke is selected use his sounds and userquotes
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0
    {
     globalsound JIBBED_ACTOR1 
     redefinequote 340 ^17DUKE: HEHEHE... WHAT A MESS!
    }
    ifvare RANDOMIZER 1 
    {
     globalsound JIBBED_ACTOR2
     redefinequote 340 ^17DUKE: BITCHIN'!
    }
    ifvare RANDOMIZER 2
    {
     globalsound JIBBED_ACTOR3
     redefinequote 340 ^17DUKE: HOLY COW!
    }
    ifvare RANDOMIZER 3
    {
     globalsound JIBBED_ACTOR4
     redefinequote 340 ^17DUKE: HOLY SHIT!
    }
    ifvare RANDOMIZER 4
    {
     globalsound JIBBED_ACTOR5
     redefinequote 340 ^17DUKE: DAMN I'M GOOD!
    }
    ifvare RANDOMIZER 5 
    {
     globalsound JIBBED_ACTOR6
     redefinequote 340 ^17DUKE: YEAH, PIECE OF CAKE!
    }
    ifvare RANDOMIZER 6 
    {
     globalsound JIBBED_ACTOR7
     redefinequote 340 ^17DUKE: OOOH... THAT'S GOTTA HURT!
    }
    ifvare RANDOMIZER 7
    {
     globalsound JIBBED_ACTOR8
     redefinequote 340 ^17DUKE: BLOW IT OUT YOUR ASS!
    }
    ifvare RANDOMIZER 8
    {
     globalsound JIBBED_ACTOR9
     redefinequote 340 ^17DUKE: EAT SHIT AND DIE!
    }
    ifvare RANDOMIZER 9
    {
     globalsound JIBBED_ACTOR10
     redefinequote 340 ^17DUKE: YOUR FACE, YOUR ASS, WHAT'S THE DIFFERENCE?!
    }
    ifvare RANDOMIZER 10
    {
     globalsound JIBBED_ACTOR11
     redefinequote 340 ^17DUKE: SEE YOU IN HELL!
    }
    ifvare RANDOMIZER 11
    {
     globalsound JIBBED_ACTOR12
     redefinequote 340 ^17DUKE: SUCK IT DOWN!
    }
    ifvare RANDOMIZER 12
    {
     globalsound JIBBED_ACTOR13
     redefinequote 340 ^17DUKE: LET GOD SORT 'EM OUT!
    }
    ifvare RANDOMIZER 13
    {
     globalsound JIBBED_ACTOR14
     redefinequote 340 ^17DUKE: GET THAT CRAP OUTTA HERE!
    }
    ifvare RANDOMIZER 14
    {
     globalsound JIBBED_ACTOR15
     redefinequote 340 ^17DUKE: YOU GUYS SUCK!
    }
    ifvare RANDOMIZER 15
    {
     globalsound MDEVSPEECH
     redefinequote 340 ^17DUKE: I'M GONNA GET MEDIEVAL ON YOUR ASSES!
    }
    ifvare RANDOMIZER 16
    {
     globalsound SMACKED
     redefinequote 340 ^17DUKE: I'M GONNA PUT THE SMACK DAB ON YOUR ASS!
    }
    ifvare RANDOMIZER 17
    {
     globalsound BONUS_SPEECH3
     redefinequote 340 ^17DUKE: GONNA RIP 'EM A NEW ONE!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 2
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
     globalsound JACK_ONELINER01
     redefinequote 340 ^17JACK: STILL THINK I'M JUST A 'LITTLE KID'?!
    }
    ifvare RANDOMIZER 1
    {
     globalsound JACK_ONELINER02
     redefinequote 340 ^17JACK: THIS PLANET BELONG TO HUMANS, NOT YOU!
    }
    ifvare RANDOMIZER 2
    {
     globalsound JACK_ONELINER03
     redefinequote 340 ^17JACK: A YEAR OF DEFEATS, AND YOU STILL DON'T GET IT?!
    }
    ifvare RANDOMIZER 3
    {
     globalsound JACK_ONELINER04
     redefinequote 340 ^17JACK: YOU GUYS ARE REALLY STARTING TO PISS ME OFF!
    }
    ifvare RANDOMIZER 4
    {
     globalsound JACK_ONELINER05
     redefinequote 340 ^17JACK: DON'T TOUCH ME, I'M DEADLY!
    }
    ifvare RANDOMIZER 5
    {
     globalsound JACK_ONELINER06
     redefinequote 340 ^17JACK: GET OFF OUR PLANET, ALIEN SCUM!!
    }
    ifvare RANDOMIZER 6
    {
     globalsound JACK_ONELINER07
     redefinequote 340 ^17JACK: OH I'M NO "BOY WONDER", BUDDY!
    }
    ifvare RANDOMIZER 7
    {
     globalsound JACK_ONELINER08
     redefinequote 340 ^17JACK: FUNNY, NO BRAIN IN THAT MASS OF PARTS! WHY AM I NOT SURPRISED?!
    }
    ifvare RANDOMIZER 8
    {
     globalsound JACK_ONELINER09
     redefinequote 340 ^17JACK: WOW YOU BREAK FASTER THAN MY GAMING SYSTEMS!
    }
    ifvare RANDOMIZER 9
    {
     globalsound JACK_ONELINER10
     redefinequote 340 ^17JACK: I *DON'T* NEED DUKE TO KICK YOUR SORRY ALIEN ASSES!
    }
    ifvare RANDOMIZER 10
    {
     globalsound JACK_ONELINER11
     redefinequote 340 ^17JACK: LOOKS LIKE YOU WEREN'T A BAD ENOUGH DUDE TO KILL ME!
    }
    ifvare RANDOMIZER 11
    {
     globalsound JACK_ONELINER12
     redefinequote 340 ^17JACK: WOW YOU GUYS... REALLY SUCK!
    }
    ifvare RANDOMIZER 12
    {
     globalsound JACK_ONELINER13
     redefinequote 340 ^17JACK: YEAH, GO SUCK THAT ONE DOWN!
    }
    ifvare RANDOMIZER 13
    {
     globalsound JACK_ONELINER14
     redefinequote 340 ^17JACK: YOU GUYS ARE VERY POOR JUDGES OF APPEARANCE, AREN'T YOU?!
    }
    ifvare RANDOMIZER 14
    {
     globalsound JACK_ONELINER15
     redefinequote 340 ^17JACK: GOOD RULES AND EVIL DROOLS!!
    }
    ifvare RANDOMIZER 15
    {
     globalsound JACK_ONELINER16
     redefinequote 340 ^17JACK: HOW *NOT* MIGHTY AN OPPONENT YOU WERE!
    }
    ifvare RANDOMIZER 16
    {
     globalsound JACK_ONELINER17
     redefinequote 340 ^17JACK: YOU SHOULD'VE STAYED IN SCHOOL, FELLA!
    }
    ifvare RANDOMIZER 17
    {
     globalsound JACK_ONELINER18
     redefinequote 340 ^17JACK: MAN, SAVING THE WORLD IS SO MUCH FUN!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 3
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
     globalsound BUBSY_ONELINER01
     redefinequote 340 ^23BUBSY: LOOKS LIKE YOU FAILED THE SCREEN TEST!
    }
    ifvare RANDOMIZER 1
    {
     globalsound BUBSY_ONELINER02
     redefinequote 340 ^23BUBSY: YOU JERKS ARE NOTHING COMPARED TO HAMM'S MINIONS!
    }
    ifvare RANDOMIZER 2
    {
     globalsound BUBSY_ONELINER03
     redefinequote 340 ^23BUBSY: YOU'RE SUCH A WASTE OF TALENT!
    }
    ifvare RANDOMIZER 3
    {
     globalsound BUBSY_ONELINER04
     redefinequote 340 ^23BUBSY: LOOKS LIKE YOUR WILL TO LIVE JUST WENT ON STRIKE!
    }
    ifvare RANDOMIZER 4
    {
     globalsound BUBSY_ONELINER05
     redefinequote 340 ^23BUBSY: HAH, YOU GUYS EVEN MORE AMATEUR THAN THE WOOLIES WERE!
    }
    ifvare RANDOMIZER 5
    {
     globalsound BUBSY_ONELINER06
     redefinequote 340 ^23BUBSY: BANG! OH YOU MUST'VE BLINKED! TOO BAD!
    }
    ifvare RANDOMIZER 6
    {
     globalsound BUBSY_ONELINER07
     redefinequote 340 ^23BUBSY: YOU DIDN'T DIE THE RIGHT WAY! YOU GOTTA DO A RETAKE!
    }
    ifvare RANDOMIZER 7
    {
     globalsound BUBSY_ONELINER08
     redefinequote 340 ^23BUBSY: I WILL CRUSH YOU ALL WITH MY AWESOME STAR POWA'!
    }
    ifvare RANDOMIZER 8
    {
     globalsound BUBSY_ONELINER09
     redefinequote 340 ^23BUBSY: YOU'RE SUPPOSED TO FALL DOWN... NOT EXPLODE!!
    }
    ifvare RANDOMIZER 9
    {
     globalsound BUBSY_ONELINER10
     redefinequote 340 ^23BUBSY: YOU'RE LUCKY! YOU'D BE EATEN ALIVE IN REAL SHOW BUSINESS!
    }
    ifvare RANDOMIZER 10
    {
     globalsound BUBSY_ONELINER11
     redefinequote 340 ^23BUBSY: DEAR ME, IT SEEMS YOU'VE BEEN CANCELLED!
    }
    ifvare RANDOMIZER 11
    {
     globalsound BUBSY_ONELINER12
     redefinequote 340 ^23BUBSY: MY FUR BRISTLES WITH ANGER! I HATE IT WHEN MY FUR BRISTLES!
    }
    ifvare RANDOMIZER 12
    {
     globalsound BUBSY_ONELINER13
     redefinequote 340 ^23BUBSY: GO AHEAD, MAKE ME LAUGH!
    }
    ifvare RANDOMIZER 13
    {
     globalsound BUBSY_ONELINER14
     redefinequote 340 ^23BUBSY: LOOKS LIKE YOUR WARDROBE DIDN'T HELP YOU MUCH!
    }
    ifvare RANDOMIZER 14
    {
     globalsound BUBSY_ONELINER15
     redefinequote 340 ^23BUBSY: DON'T WORRY, I'LL GIVE YOU A CAMEO IN MY NEXT MOVIE!
    }
    ifvare RANDOMIZER 15
    {
     globalsound BUBSY_ONELINER16
     redefinequote 340 ^23BUBSY: I'M ALLY TO GOOD, AND I'M EVIL'S WORST NIGHTMARE!
    }
    ifvare RANDOMIZER 16
    {
     globalsound BUBSY_ONELINER17
     redefinequote 340 ^23BUBSY: IT'S CALLED BAD END... HAHAHAHA!!
    }
    ifvare RANDOMIZER 17
    {
     globalsound BUBSY_ONELINER18
     redefinequote 340 ^23BUBSY: LIGHTS OUT, BUBSY RADIO!!!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 4
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
// SOUND HERE
     redefinequote 340 ^0AMI: A GOOD MIND IS EXTREMELY DANGEROUS FOR YOU CRETINS TO IGNORE!
    }
    ifvare RANDOMIZER 1
    {
// SOUND HERE
     redefinequote 340 ^0AMI: YOU MUST'VE FAILED THE CLASS ABOUT "UNDERESTIMATING THE ENEMY"!
    }
    ifvare RANDOMIZER 2
    {
// SOUND HERE
     redefinequote 340 ^0AMI: I GUESS REPENTANCE BY WATER ISN'T YOUR STYLE!
    }
    ifvare RANDOMIZER 3
    {
// SOUND HERE
     redefinequote 340 ^0AMI: WHY ARE SO MANY ALIEN RACES SO WAR-HAPPY?!
    }
    ifvare RANDOMIZER 4
    {
// SOUND HERE
     redefinequote 340 ^0AMI: I HATE TO JUDGE, BUT THAT PERFORMANCE WAS DISAPPOINTING!
    }
    ifvare RANDOMIZER 5
    {
// SOUND HERE
     redefinequote 340 ^0AMI: MAYBE YOU'LL COME BACK AS A BETTER PERSON SOMEDAY!
    }
    ifvare RANDOMIZER 6
    {
// SOUND HERE
     redefinequote 340 ^0AMI: SADLY THERE'S THINGS EVEN THE BEST DOCTOR CAN'T HEAL!
    }
    ifvare RANDOMIZER 7
    {
// SOUND HERE
     redefinequote 340 ^0AMI: ARE ALL THE MEMBERS OF YOUR RACE THIS SCATTERBRAINED?!
    }
    ifvare RANDOMIZER 8
    {
// SOUND HERE
     redefinequote 340 ^0AMI: DUNK WHAT'S LEFT OF YOURSELF IN THE WATER AND THINK ABOUT THIS!
    }
    ifvare RANDOMIZER 9
    {
// SOUND HERE
     redefinequote 340 ^0AMI: QUIT THROWING YOUR LIVES AWAY FOR SOMETHING YOU CAN'T WIN!
    }
    ifvare RANDOMIZER 10
    {
// SOUND HERE
     redefinequote 340 ^0AMI: I WILL PROTECT THIS PLANET FROM YOU ALIEN-CREEPS TO MY LAST BREATH!
    }
    ifvare RANDOMIZER 11
    {
// SOUND HERE
     redefinequote 340 ^0AMI: YOU ARE NOTHING BUT A STREAM, WHILE I AM THE OCEAN ITSELF!!
    }
    ifvare RANDOMIZER 12
    {
// SOUND HERE
     redefinequote 340 ^0AMI: LOOKS LIKE YOU WERE DROWNED BY YOUR SHEER EVIL!
    }
    ifvare RANDOMIZER 13
    {
// SOUND HERE
     redefinequote 340 ^0AMI: A PITY TO EXTINGUISH POTENTIAL LIKE YOURS, BUT THERE WAS NO CHOICE!
    }
    ifvare RANDOMIZER 14
    {
// SOUND HERE
     redefinequote 340 ^0AMI: NOW YOU CAN NEVER TAKE ANOTHER LIFE OR HURT ANOTHER ONE EVER AGAIN!
    }
    ifvare RANDOMIZER 15
    {
// SOUND HERE
     redefinequote 340 ^0AMI: MY CALM SURGES OVER THE RAGE BURNING IN YOUR HEART!
    }
    ifvare RANDOMIZER 16
    {
// SOUND HERE
     redefinequote 340 ^0AMI: WHY!? WHY CAN'T OUR RACES JUST... GET ALONG FOR ONCE?!
    }
    ifvare RANDOMIZER 17
    {
// SOUND HERE
     redefinequote 340 ^0AMI: I AM GETTING SICK... SICK AND TIRED OF KILLING YOU GUYS!!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 5 // If Lo Wang is selected, use his sounds and userquotes
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
     globalsound WANG_ONELINER01 
     redefinequote 340 ^15HIGA: YOU VERY BAD MAN!
    }
    ifvare RANDOMIZER 1
    {
     globalsound WANG_ONELINER02 
     redefinequote 340 ^15HIGA: I STICK A FIRECRACKER UP YOUR ASS! HAHAHA!!
    }
    ifvare RANDOMIZER 2
    {
     globalsound WANG_ONELINER03 
     redefinequote 340 ^15HIGA: I HOPE YOU WERE PAYING ATTENTION!
    }
    ifvare RANDOMIZER 3
    {
     globalsound WANG_ONELINER04
     redefinequote 340 ^15HIGA: I KILL YOU!!
    }
    ifvare RANDOMIZER 4
    {
     globalsound WANG_ONELINER05
     redefinequote 340 ^15HIGA: HAHAH! YOU NO MESS WITH LO WANG!
    }
    ifvare RANDOMIZER 5
    {
     globalsound WANG_ONELINER06
     redefinequote 340 ^15HIGA: YOU HAVE NO HONOR!
    }
    ifvare RANDOMIZER 6
    {
     globalsound WANG_ONELINER07
     redefinequote 340 ^15HIGA: IT'S ALL IN THE REFLEXES!
    }
    ifvare RANDOMIZER 7
    {
     globalsound WANG_ONELINER08
     redefinequote 340 ^15HIGA: SAYANORA, SCUMBAG!
    }
    ifvare RANDOMIZER 8
    {
     globalsound WANG_ONELINER09
     redefinequote 340 ^15HIGA: SNATCH PEBBLE FROM HAND!
    }
    ifvare RANDOMIZER 9
    {
     globalsound WANG_ONELINER10
     redefinequote 340 ^15HIGA: YOU LOOK LIKE STUPID!
    }
    ifvare RANDOMIZER 10
    {
     globalsound WANG_ONELINER11
     redefinequote 340 ^15HIGA: TAKSAN BALLS, SCORE SHITPEANUTS!
    }
    ifvare RANDOMIZER 11
    {
     globalsound WANG_ONELINER12
     redefinequote 340 ^15HIGA: OH YOU LITTLE TINY DICK!
    }
    ifvare RANDOMIZER 12
    {
     globalsound WANG_ONELINER13
     redefinequote 340 ^15HIGA: THIS NO TOURNAMENT, THIS IS FOR REAL!
    }
    ifvare RANDOMIZER 13
    {
     globalsound WANG_ONELINER14
     redefinequote 340 ^15HIGA: YOU MOVE LIKE A PREGEANT YAK!
    }
    ifvare RANDOMIZER 14
    {
     globalsound WANG_ONELINER15
     redefinequote 340 ^15HIGA: WHO WANTS SOME WANG?!
    }
    ifvare RANDOMIZER 15
    {
     globalsound WANG_ONELINER16
     redefinequote 340 ^15HIGA: REVENGE IS DISH BEST SERVED RAW!
    }
    ifvare RANDOMIZER 16
    {
     globalsound WANG_ONELINER17
     redefinequote 340 ^15HIGA: YOU ARE TINY GRASSHOPPA!
    }
    ifvare RANDOMIZER 17
    {
     globalsound WANG_ONELINER18
     redefinequote 340 ^15HIGA: HOLY SHIT!!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 6 // ESSence
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
     globalsound ESSENCE_ONELINER01
     redefinequote 340 ^12ESSENCE: OH COME ON, YOU CLOWNS CAN DO BETTER THAN THIS!
    }
    ifvare RANDOMIZER 1
    {
     globalsound ESSENCE_ONELINER02
     redefinequote 340 ^12ESSENCE: YOU GUYS ARE LITERALLY FALLING APART SINCE I SWITCHED SIDES!
    }
    ifvare RANDOMIZER 2
    {
     globalsound ESSENCE_ONELINER03
     redefinequote 340 ^12ESSENCE: ALL THAT POTENTIAL GONE TO WASTE, DUE TO YOUR BLIND LOYALITY!
    }
    ifvare RANDOMIZER 3
    {
     globalsound ESSENCE_ONELINER04
     redefinequote 340 ^12ESSENCE: I MIGHT BE A TRAITOR, BUT I'M STILL ALIVE UNLIKE YOUR PATHETIC CARCASS!
    }
    ifvare RANDOMIZER 4
    {
     globalsound ESSENCE_ONELINER05
     redefinequote 340 ^12ESSENCE: YOUR SUPERIOR MUST'VE BEEN A BIG SLACKER!
    }
    ifvare RANDOMIZER 5
    {
     globalsound ESSENCE_ONELINER06
     redefinequote 340 ^12ESSENCE: DAMMIT! CAN'T ANY OF YOU FOOLS BE A CHALLENGE?!
    }
    ifvare RANDOMIZER 6
    {
     globalsound ESSENCE_ONELINER07
     redefinequote 340 ^12ESSENCE: I'M BEGINNING TO SEE WHY NUKEM CAN DEFEAT YOU POOR SAPS SO OFTEN!
    }
    ifvare RANDOMIZER 7
    {
     globalsound ESSENCE_ONELINER08
     redefinequote 340 ^12ESSENCE: FOR MY FATHER'S HONOR, YOU BASTARDS!
    }
    ifvare RANDOMIZER 8
    {
     globalsound ESSENCE_ONELINER09
     redefinequote 340 ^12ESSENCE: YOUNG, BRASH, INEXPERIENCED, DEAD!
    }
    ifvare RANDOMIZER 9
    {
     globalsound ESSENCE_ONELINER10
     redefinequote 340 ^12ESSENCE: HOLY SHIT, THIS IS SO MUCH FUN, HAHAHA!!
    }
    ifvare RANDOMIZER 10
    {
     globalsound ESSENCE_ONELINER11
     redefinequote 340 ^12ESSENCE: REST IN PIECES, CHUMP!
    }
    ifvare RANDOMIZER 11
    {
     globalsound ESSENCE_ONELINER12
     redefinequote 340 ^12ESSENCE: HOPE THEY APPRICATE THE NEW RED PAINT JOB!
    }
    ifvare RANDOMIZER 12
    {
     globalsound ESSENCE_ONELINER13
     redefinequote 340 ^12ESSENCE: SUCK IT DOWN, BITCHES!!
    }
    ifvare RANDOMIZER 13
    {
     globalsound ESSENCE_ONELINER14
     redefinequote 340 ^12ESSENCE: YOU JUST GOT OWNED, SUCKA!
    }
    ifvare RANDOMIZER 14
    {
     globalsound ESSENCE_ONELINER15
     redefinequote 340 ^12ESSENCE: HEY, AT LEAST I'M SOLVING OUR OVERPOPULATION PROBLEMS THIS WAY!
    }
    ifvare RANDOMIZER 15
    {
     globalsound ESSENCE_ONELINER16
     redefinequote 340 ^12ESSENCE: INDEED THE STUPID DO DIE YOUNG!
    }
    ifvare RANDOMIZER 16
    {
     globalsound ESSENCE_ONELINER17
     redefinequote 340 ^12ESSENCE: MAYBE YOU WON'T BE SUCH A DISAPPOINTMENT DOWN IN HELL!
    }
    ifvare RANDOMIZER 17
    {
     globalsound ESSENCE_ONELINER18
     redefinequote 340 ^12ESSENCE: LOOKS LIKE YOU WOKE UP ON THE WRONG SIDE OF THE MISSILE TODAY!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 7
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
// SOUND HERE
     redefinequote 340 ^17TED: HAHAHA... YOU GUYS ARE THE BIGGEST CHUMPS I'VE EVER MET!
    }
    ifvare RANDOMIZER 1
    {
// SOUND HERE
     redefinequote 340 ^17TED: YOU'RE NOT JUST DEALING WITH ANY EXPLOSIVES' USER!
    }
    ifvare RANDOMIZER 2
    {
// SOUND HERE
     redefinequote 340 ^17TED: YOUR STYLE IS SLOPPY, AND FATAL TO YOURSELF!
    }
    ifvare RANDOMIZER 3
    {
// SOUND HERE
     redefinequote 340 ^17TED: NOW THAT'S HOW YOU MAKE SOMETHING EXPLODE IN STYLE!!
    }
    ifvare RANDOMIZER 4
    {
// SOUND HERE
     redefinequote 340 ^17TED: HAHAHA!! "GRENADIER TED" STRIKES AGAIN!!
    }
    ifvare RANDOMIZER 5
    {
// SOUND HERE
     redefinequote 340 ^17TED: LOOKS LIKE I GAVE YOU A 'SPECIAL' IMAGE ENHANCEMENT!
    }
    ifvare RANDOMIZER 6
    {
// SOUND HERE
     redefinequote 340 ^17TED: I SERIOUSLY HOPE THE REST OF YOUR KIND FARES BETTER THAN YOU!
    }
    ifvare RANDOMIZER 7
    {
// SOUND HERE
     redefinequote 340 ^17TED: I'M NO LONGER AMUSED BY YOUR USELESS PERSISTANCE!
    }
    ifvare RANDOMIZER 8
    {
// SOUND HERE
     redefinequote 340 ^17TED: LOOKS LIKE YOU CRACKED UNDER ALL THE PRESSURE!
    }
    ifvare RANDOMIZER 9
    {
// SOUND HERE
     redefinequote 340 ^17TED: MY NAME WILL BE INFAMOUS AMONG YOUR KIND SOON ENOUGH!
    }
    ifvare RANDOMIZER 10
    {
// SOUND HERE
     redefinequote 340 ^17TED: LISA, THIS ONE'S FOR YOU MY FRIEND!
    }
    ifvare RANDOMIZER 11
    {
// SOUND HERE
     redefinequote 340 ^17TED: STUBBORNNESS IS NOT ALWAYS A GOOD THING, YOU LEARNED THAT THE HARD WAY!
    }
    ifvare RANDOMIZER 12
    {
// SOUND HERE
     redefinequote 340 ^17TED: LOOKS LIKE MY GUN WAS BETTER THAN YOURS!
    }
    ifvare RANDOMIZER 13
    {
// SOUND HERE
     redefinequote 340 ^17TED: I GUESS YOUR 'TRAINING' ISN'T WHAT MANY THINK IT WAS!
    }
    ifvare RANDOMIZER 14
    {
// SOUND HERE
     redefinequote 340 ^17TED: NOT EXPECTING A 'KID' TO KICK YOUR ASS, DID YOU?!
    }
    ifvare RANDOMIZER 15
    {
// SOUND HERE
     redefinequote 340 ^17TED: EVEN IN OLD AGE, I'LL STILL KICK YOUR ASSES IF I HAVE TO!
    }
    ifvare RANDOMIZER 16
    {
// SOUND HERE
     redefinequote 340 ^17TED: DON'T FALL TO PIECES ON ME! I'M JUST GETTING STARTED!
    }
    ifvare RANDOMIZER 17
    {
// SOUND HERE
     redefinequote 340 ^17TED: YOU GUYS ARE NOTHING BUT AN ENDLESS SOURCE OF HUMOR!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 8
   {
    getactorvar[PLAYERID].VEHICLEID TEMPVAR5
    ifvarn TEMPVAR5 -1
    {
     randvar RANDOMIZER 3
     ifvare RANDOMIZER 0 
     {
      globalsound LISA_ONELINERTANK01
      redefinequote 340 ^7LISA: LOOKS LIKE YOU UNDERESTIMATED MY UNDERSTANDING OF THIS RIOT TANK!
     }
     ifvare RANDOMIZER 1
     {
      globalsound LISA_ONELINERTANK02
      redefinequote 340 ^7LISA: THIS DAMN THING'S TOO SLOW, SO YOU'LL HAVE TO SUFFICE WITH DYING BY TANK FIRE!
     }
     ifvare RANDOMIZER 2
     {
      globalsound LISA_ONELINERTANK03
      redefinequote 340 ^7LISA: IT'S YOUR FAULT FOR TRYING TO ATTACK ME WHILE I'M INSIDE THIS GOLIATH!
     }
     ifvare RANDOMIZER 3
     {
      globalsound LISA_ONELINERTANK04
      redefinequote 340 ^7LISA: YOU'RE LUCKY I CAN'T *THROW* THIS THING AT YOU INSTEAD, OR I WOULD!
     }
    }
    else
    {
     randvar RANDOMIZER 17
     ifvare RANDOMIZER 0 
     {
      globalsound LISA_ONELINER01
      redefinequote 340 ^7LISA: LOOKS LIKE THE SUN JUST SET ON YOUR LIFE!
     }
     ifvare RANDOMIZER 1
     {
      globalsound LISA_ONELINER02
      redefinequote 340 ^7LISA: HEHEHE... BEHOLD THE CHAOS OF "SUNSET LISA"!!
     }
     ifvare RANDOMIZER 2
     {
      globalsound LISA_ONELINER03
      redefinequote 340 ^7LISA: YOU GAVE NO QUARTER, SO YOU GET NONE, SCUMBAG!
     }
     ifvare RANDOMIZER 3
     {
      globalsound LISA_ONELINER04
      redefinequote 340 ^7LISA: IT'S CALLED "BRAINS *&* BEAUTY", YOU PRIDE-DRIVEN IDIOT!
     }
     ifvare RANDOMIZER 4
     {
      globalsound LISA_ONELINER05
      redefinequote 340 ^7LISA: ARE ALL OF YOU ALIENS THIS BRASH AND UNFOCUSED?!
     }
     ifvare RANDOMIZER 5
     {
      globalsound LISA_ONELINER06
      redefinequote 340 ^7LISA: YOU KNOW, YOU LOOKED LESS UGLY WHEN YOU WERE IN ONE PIECE!
     }
     ifvare RANDOMIZER 6
     {
      globalsound LISA_ONELINER07
      redefinequote 340 ^7LISA: WHY DO YOU ALIEN TURDS KEEP FIGHTING WHEN YOU CAN'T WIN?!
     }
     ifvare RANDOMIZER 7
     {
      globalsound LISA_ONELINER08
      redefinequote 340 ^7LISA: SIGNED TO YOU WITH DISGUST, LISA BATES!
     }
     ifvare RANDOMIZER 8
     {
      globalsound LISA_ONELINER09
      redefinequote 340 ^7LISA: OOPS, DID MY APPEARANCE DISTRACT YOU TOO MUCH!?
     }
     ifvare RANDOMIZER 9
     {
      globalsound LISA_ONELINER10
      redefinequote 340 ^7LISA: THAT WAS FOR GAWKING AT ME & MY PICTURES, YOU PERVERT!
     }
     ifvare RANDOMIZER 10
     {
      globalsound LISA_ONELINER11
      redefinequote 340 ^7LISA: THAT ONE'S FOR MY BEST FRIEND TED, DIRTBAG!
     }
     ifvare RANDOMIZER 11
     {
      globalsound LISA_ONELINER12
      redefinequote 340 ^7LISA: I AM THE SUNLIGHT, YOU ARE THE DARKNESS THAT WITHERS AROUND ME!
     }
     ifvare RANDOMIZER 12
     {
      globalsound LISA_ONELINER13
      redefinequote 340 ^7LISA: NOT THE 'EASY LITTLE GIRL' YOU THOUGHT OF ME, AM I?!
     }
     ifvare RANDOMIZER 13
     {
      globalsound LISA_ONELINER14
      redefinequote 340 ^7LISA: HEY CRETIN, I DON'T PLAY WITH DOLLS ANYMORE, MORE LIKE GUNS!
     }
     ifvare RANDOMIZER 14
     {
      globalsound LISA_ONELINER15
      redefinequote 340 ^7LISA: OUR TECH'S NOT AS OUTDATED AS YOU THOUGHT, IS IT?!
     }
     ifvare RANDOMIZER 15
     {
      globalsound LISA_ONELINER16
      redefinequote 340 ^7LISA: YOU'RE NOT WORTHY OF EVEN THINKING OF OGLING ME, ALIEN SCUM!
     }
     ifvare RANDOMIZER 16
     {
      globalsound LISA_ONELINER17
      redefinequote 340 ^7LISA: I LOVE THE WAYS MY TECHNOLOGY KICKS YOUR ALIEN BUTTS!
     }
     ifvare RANDOMIZER 17
     {
      globalsound LISA_ONELINER18
      redefinequote 340 ^7LISA: DON'T YOU SEE THE COSMIC JOKE YOU'VE BEEN MADE OUT AS?!
     }
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 9 // Cybanis
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0 
    {
     globalsound CYBANIS_ONELINER01
     redefinequote 340 ^12CYBANIS: I'M THE HURRICANE, YOU'RE MERELY STRAW IN THE WIND!
    }
    ifvare RANDOMIZER 1
    {
     globalsound CYBANIS_ONELINER02
     redefinequote 340 ^12CYBANIS: HA HA HA, CRUSHED LIKE A BUG ON A WINDOW!
    }
    ifvare RANDOMIZER 2
    {
     globalsound CYBANIS_ONELINER03
     redefinequote 340 ^12CYBANIS: KEEP YOURSELF TOGETHER, YOU'RE ALL OVER THE PLACE!
    }
    ifvare RANDOMIZER 3
    {
     globalsound CYBANIS_ONELINER04
     redefinequote 340 ^12CYBANIS: FEEL LUCKY, YOUR DEATH WAS QUICK, AND PAINFUL!
    }
    ifvare RANDOMIZER 4
    {
     globalsound CYBANIS_ONELINER05
     redefinequote 340 ^12CYBANIS: HMPH! I NEVER DID LIKE YOUR LITTLE 'KISS-ASS'...
    }
    ifvare RANDOMIZER 5
    {
     globalsound CYBANIS_ONELINER06
     redefinequote 340 ^12CYBANIS: THE WRATH OF A CYCLOIDIAN LEAVES NO SURVIVORS!!
    }
    ifvare RANDOMIZER 6
    {
     globalsound CYBANIS_ONELINER07
     redefinequote 340 ^12CYBANIS: GOOD ALIEN?! BAD ALIEN?! WHO GIVES A SHIT?!
    }
    ifvare RANDOMIZER 7
    {
     globalsound CYBANIS_ONELINER08
     redefinequote 340 ^12CYBANIS: AHHH, THE INVIGORATING SMELL OF BURNT PIECES OF FLESH!
    }
    ifvare RANDOMIZER 8
    {
     globalsound CYBANIS_ONELINER09
     redefinequote 340 ^12CYBANIS: YOU JUST GOT, AS THE HUMANS CALL IT, "OWNED!"
    }
    ifvare RANDOMIZER 9
    {
     globalsound CYBANIS_ONELINER10
     redefinequote 340 ^12CYBANIS: ANYONE ELSE WANT WANT SOME?!
    }
    ifvare RANDOMIZER 10
    {
     globalsound CYBANIS_ONELINER11
     redefinequote 340 ^12CYBANIS: MWAHAHA!! I HAVE ENOUGH HERE FOR ALL OF YOU BITCHES!!
    }
    ifvare RANDOMIZER 11
    {
     globalsound CYBANIS_ONELINER12
     redefinequote 340 ^12CYBANIS: *SIGH* NETHRA, FORGIVE MY RASH ACTIONS ON THIS DAY...
    }
    ifvare RANDOMIZER 12
    {
     globalsound CYBANIS_ONELINER13
     redefinequote 340 ^12CYBANIS: IF YOU HADN'T BEEN A SUCK-UP, YOU MIGHT'VE ACTUALLY LIVED!
    }
    ifvare RANDOMIZER 13
    {
     globalsound CYBANIS_ONELINER14
     redefinequote 340 ^12CYBANIS: YOU CAN THANK ME FOR YOUR IMAGE IMPROVEMENT IN HELL!
    }
    ifvare RANDOMIZER 14
    {
     globalsound CYBANIS_ONELINER15
     redefinequote 340 ^12CYBANIS: THE STRONG SURVIVE, AND THE WEAK... DON'T EXIST ANYMORE!
    }
    ifvare RANDOMIZER 15
    {
     globalsound CYBANIS_ONELINER16
     redefinequote 340 ^12CYBANIS: HMPH, MAYBE YOU'LL REINCARNATE AS SOMETHING USEFUL FOR ONCE!
    }
    ifvare RANDOMIZER 16
    {
     globalsound CYBANIS_ONELINER17
     redefinequote 340 ^12CYBANIS: YOU BASTARDS TURN YOUR BACKS ON ME, I KILL YOU! IT'S NATURE!
    }
    ifvare RANDOMIZER 17
    {
     globalsound CYBANIS_ONELINER18
     redefinequote 340 ^12CYBANIS: I WILL GIVE YOU A REASON TO FEAR THE WRATH OF CYBANIS MORGANDOS!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 10
   {
    ifvare NETHRAFORM? 0 // Alien Form
    {
     randvar RANDOMIZER 17
     ifvare RANDOMIZER 0
     {
      globalsound NETHRA_ONELINER01
      redefinequote 340 ^0NETHRA: WHY MUST YOU FORCE ME TO DO THIS TO YOU?!
     }
     ifvare RANDOMIZER 1
     {
      globalsound NETHRA_ONELINER02
      redefinequote 340 ^0NETHRA: MOTHER, WHAT ARE YOU FEEDING THESE GUYS?!
     }
     ifvare RANDOMIZER 2
     {
      globalsound NETHRA_ONELINER03
      redefinequote 340 ^0NETHRA: THAT EXPERIENCE WAS RATHER... SHOCKING!
     }
     ifvare RANDOMIZER 3
     {
      globalsound NETHRA_ONELINER04
      redefinequote 340 ^0NETHRA: YOU GUYS JUST WON'T LISTEN TO REASON WILL YOU?!
     }
     ifvare RANDOMIZER 4
     {
      globalsound NETHRA_ONELINER05
      redefinequote 340 ^0NETHRA: DAMMIT, STOP WITH THIS SENSELESS WARMONGERING!
     }
     ifvare RANDOMIZER 5
     {
      globalsound NETHRA_ONELINER06
      redefinequote 340 ^0NETHRA: MOTHER, YOU MUST STOP THIS SENSELESS WAR! TOO MANY ARE DYING!
     }
     ifvare RANDOMIZER 6
     {
      globalsound NETHRA_ONELINER07
      redefinequote 340 ^0NETHRA: ALL YOUR POTENTIAL DOWN THE DRAIN... MAN THIS REALLY SUCKS!
     }
     ifvare RANDOMIZER 7
     {
      globalsound NETHRA_ONELINER08
      redefinequote 340 ^0NETHRA: I'VE GOT TO SNAP SOME SENSE INTO MOTHER BEFORE WE ALL DIE!
     }
     ifvare RANDOMIZER 8
     {
      globalsound NETHRA_ONELINER09
      redefinequote 340 ^0NETHRA: ARE ALL OF YOU BLINDLY LOYAL TO MOTHER?!
     }
     ifvare RANDOMIZER 9
     {
      globalsound NETHRA_ONELINER10
      redefinequote 340 ^0NETHRA: I HATE TO SAY IT, BUT THIS IS SOLVING OUR POPULATION PROBLEMS!
     }
     ifvare RANDOMIZER 10
     {
      globalsound NETHRA_ONELINER11
      redefinequote 340 ^0NETHRA: THIS IS NOT WHAT I WANTED TO DO WITH YOU GUYS!
     }
     ifvare RANDOMIZER 11
     {
      globalsound NETHRA_ONELINER12
      redefinequote 340 ^0NETHRA: I'M GETTING SICK OF THIS BULLHEADEDNESS!
     }
     ifvare RANDOMIZER 12
     {
      globalsound NETHRA_ONELINER13
      redefinequote 340 ^0NETHRA: I'M GETTING TO THE POINT I DON'T CARE IF YOU GUYS DIE OR NOT!
     }
     ifvare RANDOMIZER 13
     {
      globalsound NETHRA_ONELINER14
      redefinequote 340 ^0NETHRA: I JUST WANT PEACE FOR OUR KIND FOR ONCE!
     }
     ifvare RANDOMIZER 14
     {
      globalsound NETHRA_ONELINER15
      redefinequote 340 ^0NETHRA: CAN'T YOU GUYS SEE YOU CAN'T DEFEAT THE EARTH'S PEOPLE?!
     }
     ifvare RANDOMIZER 15
     {
      globalsound NETHRA_ONELINER16
      redefinequote 340 ^0NETHRA: ALL WE'RE DOING IS KILLING OURSELVES IN THIS SENSELESS WAR!
     }
     ifvare RANDOMIZER 16
     {
      globalsound NETHRA_ONELINER17
      redefinequote 340 ^0NETHRA: I AM YOUR PRINCESS, I WISH YOU WOULD LISTEN TO ME FOR ONCE!
     }
     ifvare RANDOMIZER 17
     {
      globalsound NETHRA_ONELINER18
      redefinequote 340 ^0NETHRA: THAT'S IT! I'VE HAD ABOUT ALL I CAN STAND FROM YOU IDIOTS!
     }
     ifvare oldskoolmode 0 userquote 340
    }
    ifvare NETHRAFORM? 1 // Human Form
    {
     randvar RANDOMIZER 17
     ifvare RANDOMIZER 0
     {
      globalsound CHRISTINA_ONELINER01
      redefinequote 340 ^0CHRISTINA: YOU'RE NOT MUCH OF A GENTLEMAN, ARE YOU?!
     }
     ifvare RANDOMIZER 1
     {
      globalsound CHRISTINA_ONELINER02
      redefinequote 340 ^0CHRISTINA: YOUR PUNISHMENT WAS SWIFT, AND HOPEFULLY JUST!
     }
     ifvare RANDOMIZER 2
     {
      globalsound CHRISTINA_ONELINER03
      redefinequote 340 ^0CHRISTINA: REALLY KNOW HOW TO SWEEP A GIRL OFF HER FEET, DON'T YOU?!
     }
     ifvare RANDOMIZER 3
     {
      globalsound CHRISTINA_ONELINER04
      redefinequote 340 ^0CHRISTINA: YOU GUYS SHOULD KNOW BETTER NOT TO UNDERESTIMATE LITTLE OL' ME!
     }
     ifvare RANDOMIZER 4
     {
      globalsound CHRISTINA_ONELINER05
      redefinequote 340 ^0CHRISTINA: HEHEHE, I GUESS YOU STARED AT ME TOO LONG!
     }
     ifvare RANDOMIZER 5
     {
      globalsound CHRISTINA_ONELINER06
      redefinequote 340 ^0CHRISTINA: LOOK AT IT THIS WAY, AT LEAST YOU WENT OUT WITH A GOOD VIEW!
     }
     ifvare RANDOMIZER 6
     {
      globalsound CHRISTINA_ONELINER07
      redefinequote 340 ^0CHRISTINA: AM I TOO HOT FOR YOU TO HANDLE!?
     }
     ifvare RANDOMIZER 7
     {
      globalsound CHRISTINA_ONELINER08
      redefinequote 340 ^0CHRISTINA: YOU GUYS ARE GETTING SO PREDICTABLE!
     }
     ifvare RANDOMIZER 8
     {
      globalsound CHRISTINA_ONELINER09
      redefinequote 340 ^0CHRISTINA: THIS IS GETTING REALLY TEDIOUS AND BORING!
     }
     ifvare RANDOMIZER 9
     {
      globalsound CHRISTINA_ONELINER10
      redefinequote 340 ^0CHRISTINA: I HOPE ONE OF YOU WILL GIVE ME A REAL CHALLENGE SOON!
     }
     ifvare RANDOMIZER 10
     {
      globalsound CHRISTINA_ONELINER11
      redefinequote 340 ^0CHRISTINA: YOU GOT YOUR ASS KICKED BY A GIRL! NAH-NAH-NAH!
     }
     ifvare RANDOMIZER 11
     {
      globalsound CHRISTINA_ONELINER12
      redefinequote 340 ^0CHRISTINA: YOUR TESTOSTERONE IS BIGGER THAN YOU CAN HANDLE!
     }
     ifvare RANDOMIZER 12
     {
      globalsound CHRISTINA_ONELINER13
      redefinequote 340 ^0CHRISTINA: APPEARANTLY YOU GUYS DON'T KNOW THE CONCEPT OF DISCRETION!
     }
     ifvare RANDOMIZER 13
     {
      globalsound CHRISTINA_ONELINER14
      redefinequote 340 ^0CHRISTINA: DID YOU SERIOUSLY THINK YOU COULD KILL ME WITH THAT?!
     }
     ifvare RANDOMIZER 14
     {
      globalsound CHRISTINA_ONELINER15
      redefinequote 340 ^0CHRISTINA: IF YOU LEFT THIS PLANET, I WOULDN'T HAVE TO KILL YOU GUYS!
     }
     ifvare RANDOMIZER 15
     {
      globalsound CHRISTINA_ONELINER16
      redefinequote 340 ^0CHRISTINA: IS IT TOO MUCH FOR YOU GUYS TO USE REAL TACT!?
     }
     ifvare RANDOMIZER 16
     {
      globalsound CHRISTINA_ONELINER17
      redefinequote 340 ^0CHRISTINA: COME ON! I CAN KEEP THIS UP ALL DAY IF I MUST!
     }
     ifvare RANDOMIZER 17
     {
      globalsound CHRISTINA_ONELINER18
      redefinequote 340 ^0CHRISTINA: I'M SURE THAT WAS WORSE THAN JUST A KICK TO THE NUTS!
     }
     ifvare oldskoolmode 0 userquote 340
    }
   }
   else
   ifvare CHARACTERSELECTED? 11
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: YOU SHOW NO MERCY, YOU GET NO MERCY!
    }
    ifvare RANDOMIZER 1
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: NOBODY, AND I MEAN NOBODY THREATENS MY FRIENDS WHEN I'M AROUND!!
    }
    ifvare RANDOMIZER 2
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: YOU GUYS REALLY ARE ABSENTMINDED, AREN'T YOU?!
    }
    ifvare RANDOMIZER 3
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: I HATE ENDING LIVES, BUT YOU'RE A SPECIAL CASE!
    }
    ifvare RANDOMIZER 4
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: I JUST KICKED YOUR ALIEN BUTT BLACK AND BLUE!
    }
    ifvare RANDOMIZER 5
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: I'M SORRY, DID I GIVE YOU A MIRGRAINE?!
    }
    ifvare RANDOMIZER 6
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: UGH, YOU GUYS ARE NOTHING BUT BRUTES!
    }
    ifvare RANDOMIZER 7
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: TELL ME YOU GUYS DON'T HAVE A HIVEMIND MENTALITY...!
    }
    ifvare RANDOMIZER 8
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: ICK, I WOULDN'T WANT TO BE YOU RIGHT NOW!
    }
    ifvare RANDOMIZER 9
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: I'D MOURN FOR YOU, BUT I DIDN'T SEE A BRAIN IN THERE!
    }
    ifvare RANDOMIZER 10
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: HEY, SHOVE OFF! I'M GETTING SICK OF YOUR PERSISTANCE!
    }
    ifvare RANDOMIZER 11
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: SORRY ABOUT THAT, BUT YOU REALLY TICKED ME OFF!
    }
    ifvare RANDOMIZER 12
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: I HOPE YOUR PRIDE'S NOT TOO SORE FOR LOSING TO ME!
    }
    ifvare RANDOMIZER 13
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: YOU KNOW WHAT, I'VE FOUGHT STRONGER ALIEN RACES THAN YOU!
    }
    ifvare RANDOMIZER 14
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: YOU GUYS JUST WON'T LEARN YOUR LESSON WILL YOU?!
    }
    ifvare RANDOMIZER 15
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: THIS IS GETTING EXTREMELY BORING! AT LEAST TRY TO THINK BETTER!
    }
    ifvare RANDOMIZER 16
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: I MIGHT LOOK WEAK, BUT I'M ACTUALLY VERY DEADLY WHEN THREATENED!
    }
    ifvare RANDOMIZER 17
    {
// SOUND HERE
     redefinequote 340 ^20PAULA: IT DOESN'T TAKE A PSYCHIC TO SEE HOW PATHETIC YOU DID!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 12
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0
    {
// SOUND HERE
     redefinequote 340 ^15LORI: YOU DESERVE NOTHING LESS FOR WHAT YOU'VE DONE TO US!
    }
    ifvare RANDOMIZER 1
    {
// SOUND HERE
     redefinequote 340 ^15LORI: WOW, YOU GUYS ARE SURE AGRESSIVE! BIG MISTAKE!
    }
    ifvare RANDOMIZER 2
    {
// SOUND HERE
     redefinequote 340 ^15LORI: JUST LEAVE US AND OUR WORLD ALONE BEFORE I REALLY GET MAD!
    }
    ifvare RANDOMIZER 3
    {
// SOUND HERE
     redefinequote 340 ^15LORI: YOU GUYS SHOULD'VE MADE ABSOLUTELY SURE I WAS DEAD BACK THERE!
    }
    ifvare RANDOMIZER 4
    {
// SOUND HERE
     redefinequote 340 ^15LORI: I HOPE I DIDN'T DISAPPOINT YOU! OH WAIT, YOU DISAPPOINTED *ME*!
    }
    ifvare RANDOMIZER 5
    {
// SOUND HERE
     redefinequote 340 ^15LORI: ALRIGHT THAT'S IT! NO MORE MISS NICE GIRL!
    }
    ifvare RANDOMIZER 6
    {
// SOUND HERE
     redefinequote 340 ^15LORI: UUGH... YOU GUYS MAKE A BIG MESS OUT OF THINGS!
    }
    ifvare RANDOMIZER 7
    {
// SOUND HERE
     redefinequote 340 ^15LORI: I MIGHT SPEAK SOFT, BUT I CARRY A VERY BIG STICK!
    }
    ifvare RANDOMIZER 8
    {
// SOUND HERE
     redefinequote 340 ^15LORI: WHAT IS THE PROBLEM WITH YOU GUYS?!
    }
    ifvare RANDOMIZER 9
    {
// SOUND HERE
     redefinequote 340 ^15LORI: JUST ANOTHER PRIDE-DRIVEN ALIEN GONE TO PIECES!
    }
    ifvare RANDOMIZER 10
    {
// SOUND HERE
     redefinequote 340 ^15LORI: WHAT'S LEFT OF YOU WON'T FILL A LUNCHBOX!
    }
    ifvare RANDOMIZER 11
    {
// SOUND HERE
     redefinequote 340 ^15LORI: FOR MASS-MURDERING ALIENS, YOU SURE DON'T TAKE A HIT WELL!
    }
    ifvare RANDOMIZER 12
    {
// SOUND HERE
     redefinequote 340 ^15LORI: I'LL LET GOD SORT YOU GUYS OUT!
    }
    ifvare RANDOMIZER 13
    {
// SOUND HERE
     redefinequote 340 ^15LORI: GET OUT OF MY WAY, ALIEN SCUM!
    }
    ifvare RANDOMIZER 14
    {
// SOUND HERE
     redefinequote 340 ^15LORI: I WILL NEVER FORGIVE WHAT YOU'VE ALL DONE!
    }
    ifvare RANDOMIZER 15
    {
// SOUND HERE
     redefinequote 340 ^15LORI: YOU LEARNED THE HARD WHY WHAT HAPPENS WHEN I GET PISSED OFF!
    }
    ifvare RANDOMIZER 16
    {
// SOUND HERE
     redefinequote 340 ^15LORI: NOW YOU'RE NOT SUCH A SORE SIGHT TO MY EYES!
    }
    ifvare RANDOMIZER 17
    {
// SOUND HERE
     redefinequote 340 ^15LORI: FOR THOSE WHO DIED AT YOUR HANDS ON FLIGHT DNF-9235!!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 13
   {
    randvar RANDOMIZER 17
    ifvare RANDOMIZER 0
    {
     globalsound MINAKO_ONELINER01
     redefinequote 340 ^23MINAKO: V IS FOR VICTORY, ALIEN-CREEP!
    }
    ifvare RANDOMIZER 1
    {
     globalsound MINAKO_ONELINER02
     redefinequote 340 ^23MINAKO: I'M NOT JUST ANOTHER HELPLESS AND PRETTY BLONDE, AM I!?
    }
    ifvare RANDOMIZER 2
    {
     globalsound MINAKO_ONELINER03
     redefinequote 340 ^23MINAKO: GUESS YOU DIDN'T BELIEVE IN YOURSELF WELL ENOUGH!
    }
    ifvare RANDOMIZER 3
    {
     globalsound MINAKO_ONELINER04
     redefinequote 340 ^23MINAKO: MY PUNISHMENT OF YOU COMES FROM THE HEAVENS THEMSELVES!
    }
    ifvare RANDOMIZER 4
    {
     globalsound MINAKO_ONELINER05
     redefinequote 340 ^23MINAKO: MY LOVE OUTSHINES THE DARKNESS OF YOUR HATRED!
    }
    ifvare RANDOMIZER 5
    {
     globalsound MINAKO_ONELINER06
     redefinequote 340 ^23MINAKO: FEMALE OR NOT, I DEAL SWIFT JUSTICE TO THE WICKED, HUMAN OR ALIEN!
    }
    ifvare RANDOMIZER 6
    {
     globalsound MINAKO_ONELINER07
     redefinequote 340 ^23MINAKO: NOW YOU KNOW WHY I'M THE GODDESS OF LOVE!
    }
    ifvare RANDOMIZER 7
    {
     globalsound MINAKO_ONELINER08
     redefinequote 340 ^23MINAKO: STOP OGLING ME AND FIGHT FOR REAL IF YOU GUYS WANT TO LIVE!
    }
    ifvare RANDOMIZER 8
    {
     globalsound MINAKO_ONELINER09
     redefinequote 340 ^23MINAKO: YOU GUYS ARE GONNA PAY FOR HURTING MY FRIENDS!
    }
    ifvare RANDOMIZER 9
    {
     globalsound MINAKO_ONELINER10
     redefinequote 340 ^23MINAKO: SORRY, BUT I DON'T ACCEPT RITUAL SACRIFICES!
    }
    ifvare RANDOMIZER 10
    {
     globalsound MINAKO_ONELINER11
     redefinequote 340 ^23MINAKO: SHOT THROUGH THE HEART, AND I'M TO BLAME!
    }
    ifvare RANDOMIZER 11
    {
     globalsound MINAKO_ONELINER12
     redefinequote 340 ^23MINAKO: WOW, YOU ACTUALLY LOOK BETTER NOW THAN BEFORE!
    }
    ifvare RANDOMIZER 12
    {
     globalsound MINAKO_ONELINER13
     redefinequote 340 ^23MINAKO: BOW DOWN TO THE GODDESS OF LOVE!
    }
    ifvare RANDOMIZER 13
    {
     globalsound MINAKO_ONELINER14
     redefinequote 340 ^23MINAKO: I'M NOT SINGING ANY OF MY SONGS FOR YOU!
    }
    ifvare RANDOMIZER 14
    {
     globalsound MINAKO_ONELINER15
     redefinequote 340 ^23MINAKO: WOW, YOU REALLY KNOW HOW TO CHARM A GIRL, DON'T YOU?!
    }
    ifvare RANDOMIZER 15
    {
     globalsound MINAKO_ONELINER16
     redefinequote 340 ^23MINAKO: THAT ONE'S FOR MY FRIENDS: USAGI, REI AND MAKOTO!
    }
    ifvare RANDOMIZER 16
    {
     globalsound MINAKO_ONELINER17
     redefinequote 340 ^23MINAKO: AM I STILL JUST ANOTHER PRETTY FACE TO YOU NOW?!
    }
    ifvare RANDOMIZER 17
    {
     globalsound MINAKO_ONELINER18
     redefinequote 340 ^23MINAKO: JUST ANOTHER ALIEN WHO CAN'T PERFORM UNDER PRESSURE!
    }
    ifvare oldskoolmode 0 userquote 340
   }
   else
   ifvare CHARACTERSELECTED? 14
   {
    ifvare debugtoggle 1 
    {
     randvar RANDOMIZER 17
     ifvare RANDOMIZER 0
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: POOR LITTLE FOOL CAUGHT LIKE A RAT! HAHAHAHA!!
     }
     ifvare RANDOMIZER 1
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: MY ANGER BOILS! AND NO ONE SURVIVES MY ANGER!!
     }
     ifvare RANDOMIZER 2
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: EVERYONE LEARNS THEIR PLACE IN LIFE... OR DEATH... AT SOME POINT!!
     }
     ifvare RANDOMIZER 3
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: I AM THE ALMIGHTY, AND YOU ARE NOT!!
     }
     ifvare RANDOMIZER 4
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: SORRY, I GUESS I OVERUSED MY POWER A BIT TOO MUCH! HAHAHAHA!!
     }
     ifvare RANDOMIZER 5
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: PITIFUL WEAKLING, THAT'LL TEACH YOU A LESSON IN TRUE POWER!!
     }
     ifvare RANDOMIZER 6
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: A MERE ANT CANNOT DEFEAT AN IMMORTAL GIANT LIKE ME!
     }
     ifvare RANDOMIZER 7
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: I DEARLY HOPED YOUR ARROGANCE, NOT YOUR LACK OF POWER, GOT YOU KILLED!
     }
     ifvare RANDOMIZER 8
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: CARNAGE IS SUCH AN INVIGORATING SMELL... OH WAIT, THAT'S JUST YOUR CARCASS!
     }
     ifvare RANDOMIZER 9
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: NO ONE WILL MISS YOUR PATHETIC ASS!
     }
     ifvare RANDOMIZER 10
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: COWARDS DIE HORRIBLE DEATHS, AND I CAN SEE YOU'RE A QUITE THE COWARD!
     }
     ifvare RANDOMIZER 11
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: I COMMEND YOUR BRAVERY, BUT BRAVERY CAN ALSO BE A SIGN OF STUPIDITY!
     }
     ifvare RANDOMIZER 12
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: YOU SHOULD'VE GROVELED AT MY FEET! AT LEAST YOU WOULD'VE LIVED!
     }
     ifvare RANDOMIZER 13
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: LOOKS LIKE I JUST LAID THE ROYAL SMACKDOWN ON YOUR ASS!
     }
     ifvare RANDOMIZER 14
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: WHAT'S WRONG, NOT WHAT YOU WERE EXPECTING ME TO BE?!
     }
     ifvare RANDOMIZER 15
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: DON'T FEEL BAD, AT LEAST YOU WERE KILLED BY A SURPREME BEING!
     }
     ifvare RANDOMIZER 16
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: YOUR END, COMES BEYOND MY CHAOS!
     }
     ifvare RANDOMIZER 17
     {
// SOUND HERE
      redefinequote 340 ^0HINOTORI: THE SUN *DOESN'T* SHINE OUT OF YOUR ASS, NOW DOES IT?!
     }
     ifvare oldskoolmode 0 userquote 340
    }
   }
   else
   ifvare CHARACTERSELECTED? 15
   {
    getactorvar[PLAYERID].VEHICLEID TEMPVAR5
    ifvarn TEMPVAR5 -1
    {
     randvar RANDOMIZER 3
     ifvare RANDOMIZER 0 
     {
      globalsound MAKEN_ONELINERTANK01
      redefinequote 340 ^10MAKEN: SO HOW'S IT FEEL TO HAVE YOUR OWN WEAPONS USED AGAINST YOU!?
     }
     ifvare RANDOMIZER 1
     {
      globalsound MAKEN_ONELINERTANK02
      redefinequote 340 ^10MAKEN: YOU'RE AS FUTILE AS ANTS TRYING TO KILL A GIANT!
     }
     ifvare RANDOMIZER 2
     {
      globalsound MAKEN_ONELINERTANK03
      redefinequote 340 ^10MAKEN: A PITY I DIDN'T NEED TO HACK THIS TO KILL YOU WITH IT!
     }
     ifvare RANDOMIZER 3
     {
      globalsound MAKEN_ONELINERTANK04
      redefinequote 340 10MAKEN: VROOM VROOM VROOM, YOU GO SQUISHIE, ASSHOLE!
     }
    }
    else
    {
     randvar RANDOMIZER 17
     ifvare RANDOMIZER 0
     {
      globalsound MAKEN_ONELINER01
      redefinequote 340 ^10MAKEN: JUSTICE CAN BE SUCH A BITCH, CAN'T IT?!
     }
     ifvare RANDOMIZER 1
     {
      globalsound MAKEN_ONELINER02
      redefinequote 340 ^10MAKEN: THE SIGHT OF YOU ALMOST MAKES ME PUKE!
     }
     ifvare RANDOMIZER 2
     {
      globalsound MAKEN_ONELINER03
      redefinequote 340 ^10MAKEN: KASEY, THAT ONE WAS FOR YOU!
     }
     ifvare RANDOMIZER 3
     {
      globalsound MAKEN_ONELINER04
      redefinequote 340 ^10MAKEN: YOU CAN'T DEFEAT ONE WHO KNOWS EVERYTHING ABOUT YOU!
     }
     ifvare RANDOMIZER 4
     {
      globalsound MAKEN_ONELINER05
      redefinequote 340 ^10MAKEN: THE LESS OF YOU SCUMBAG BASTARDS LEFT, THE BETTER I FEEL!
     }
     ifvare RANDOMIZER 5
     {
      globalsound MAKEN_ONELINER06
      redefinequote 340 ^10MAKEN: NOW YOU CAN TELL YOUR BUDDIES IN HELL OF THE WRATH OF MAKEN SHINKARA!
     }
     ifvare RANDOMIZER 6
     {
      globalsound MAKEN_ONELINER07
      redefinequote 340 ^10MAKEN: AT LEAST YOU DIED PAINLESSLY, A DEATH UNFITTING OF SCUM LIKE YOU!
     }
     ifvare RANDOMIZER 7
     {
      globalsound MAKEN_ONELINER08
      redefinequote 340 ^10MAKEN: LIKE THROWING SALT ON A SLUG... A HIDEOUS SLUG THAT IS!
     }
     ifvare RANDOMIZER 8
     {
      globalsound MAKEN_ONELINER09
      redefinequote 340 ^10MAKEN: IN MY BROTHER'S NAME, ALIEN BASTARDS!
     }
     ifvare RANDOMIZER 9
     {
      globalsound MAKEN_ONELINER10
      redefinequote 340 ^10MAKEN: THIS ONE'S FOR YOU LORI!
     }
     ifvare RANDOMIZER 10
     {
      globalsound MAKEN_ONELINER11
      redefinequote 340 ^10MAKEN: I AM DARKNESS BEYOND YOUR WORST NIGHTMARKES, ALIEN SCUM!
     }
     ifvare RANDOMIZER 11
     {
      globalsound MAKEN_ONELINER12
      redefinequote 340 ^10MAKEN: HOW DOES IT FEEL TO BE THE ONES GETTING INVADED BY US?!
     }
     ifvare RANDOMIZER 12
     {
      globalsound MAKEN_ONELINER13
      redefinequote 340 ^10MAKEN: DIE YOU UGLY SON OF A BITCH!
     }
     ifvare RANDOMIZER 13
     {
      globalsound MAKEN_ONELINER14
      redefinequote 340 ^10MAKEN: YOU JUST FAILED SURPREMELY AT LIFE!
     }
     ifvare RANDOMIZER 14
     {
      globalsound MAKEN_ONELINER15
      redefinequote 340 ^10MAKEN: YEAH, TASTE MY VENGENACE AS I SHOVE A ROCKET UP YOUR ASS!
     }
     ifvare RANDOMIZER 15
     {
      globalsound MAKEN_ONELINER16
      redefinequote 340 ^10MAKEN: I CAN'T BELIEVE I EVER PRETENDED TO WORK FOR YOU ASSHOLES!
     }
     ifvare RANDOMIZER 16
     {
      globalsound MAKEN_ONELINER17
      redefinequote 340 ^10MAKEN: YOU GOT WHAT WAS COMING TO YOU, NO QUESTIONS ASKED!
     }
     ifvare RANDOMIZER 17
     {
      globalsound MAKEN_ONELINER18
      redefinequote 340 ^10MAKEN: ALL YOUR LIVES ARE BELONG TO ME NOW!
     }
     ifvare oldskoolmode 0 userquote 340
    }
   }
  }
 }
}
ends


state boss_jibs
  guts JIBS2 2
  guts JIBS3 4
  guts JIBS4 6
  guts JIBS5 4
  guts JIBS6 6
  ifrnd 6 { guts JIBS1 2 { espawn NEWBLOODPOOL setactor[RETURN].pal 2 setactor[RETURN].cstat 34 } } // a badly drawn spine
ends

state standard_jibs
  guts JIBS2 1
  guts JIBS3 2
  guts JIBS4 3
  guts JIBS5 2
  guts JIBS6 3
  ifrnd 6 { guts JIBS1 1 { espawn NEWBLOODPOOL setactor[RETURN].pal 2 setactor[RETURN].cstat 34 } } // a badly drawn spine
  ifactor EGG state jib_sounds
  ifactor LIZTROOP state jib_sounds
  ifactor LIZTROOPSTAYPUT state jib_sounds
  ifactor LIZTROOPSHOOT state jib_sounds
  ifactor LIZTROOPJETPACK state jib_sounds
  ifactor LIZTROOPRUNNING state jib_sounds
  ifactor LIZTROOPDUCKING state jib_sounds
  ifactor LIZTROOPONTOILET state jib_sounds
  ifactor LIZTROOPJUSTSIT state jib_sounds
  ifactor LIZMAN state jib_sounds
  ifactor LIZMANSTAYPUT state jib_sounds
  ifactor LIZMANSPITTING state jib_sounds
  ifactor LIZMANJUMP state jib_sounds
  ifactor OCTABRAIN state jib_sounds
  ifactor OCTABRAINSTAYPUT state jib_sounds
  ifactor PIGCOP state jib_sounds
  ifactor PIGCOPSTAYPUT state jib_sounds
  ifactor PIGCOPDIVE state jib_sounds
  ifactor BOSS1 state jib_sounds
  ifactor BOSS1STAYPUT state jib_sounds
  ifactor BOSS1SHOOT state jib_sounds
  ifactor BOSS1LOB state jib_sounds
  ifactor BOSS2 state jib_sounds
  ifactor BOSS2STAYPUT state jib_sounds
  ifactor BOSS2SHOOT state jib_sounds
  ifactor BOSS2BREATH state jib_sounds
  ifactor BOSS3 state jib_sounds
  ifactor BOSS3STAYPUT state jib_sounds
  ifactor BOSS3LOB state jib_sounds
  ifactor COMMANDER state jib_sounds
  ifactor COMMANDERSTAYPUT state jib_sounds
  ifactor BOSS4 state jib_sounds
  ifactor BOSS4STAYPUT state jib_sounds
  ifactor NEWBEAST state jib_sounds
  ifactor NEWBEASTSTAYPUT state jib_sounds
  ifactor NEWBEASTJUMP state jib_sounds
  ifactor NEWBEASTHANG state jib_sounds
ends

state genericshrunkcode
  ifcount 32
  {
    ifpdistl SQUISHABLEDISTANCE 
    {
     // OFF-LIMITS
     setactor[THISACTOR].extra -1 
     // END OFF-LIMITS
     pstomp
     ifvare STOMPTIMER 3
     {
      state addtokillamounts
      state check_a_characters_kills
      redefinequote 340 ^21SQUISH!!
      userquote 340
      ifactor SHARK state sharkawards
      ifactor LIZTROOP state liztroopawards
      ifactor PIGCOP state pigcopawards
      ifactor LIZMAN state lizmanawards
      ifactor OCTABRAIN state octabrainawards
      ifactor COMMANDER state commanderawards
      ifactor NEWBEAST state newbeastawards
      ifactor BOSS1 state boss1awards
      ifactor BOSS2 state boss2awards
      ifactor BOSS3 state boss3awards
      ifactor BOSS4 state boss4awards
      setvar TEMPVAR 0
      state expmulti
      state exp_given      
     }
    }
  }
  else
  {
    sizeto MINXSTRETCH MINYSTRETCH
    spawn FRAMEEFFECT1
  }
ends

state genericgrowcode
  ifcount 32
  {
    guts JIBS4 24
    guts JIBS6 28
    addkills 1
    sound SQUISHED
    sound PIPEBOMB_EXPLODE
    hitradius 2048 60 70 80 90
    { espawn NEWBLOODPOOL setactor[RETURN].pal 2 setactor[RETURN].cstat 34 }
    spawn EXPLOSION2
    setactor[THISACTOR].extra -1
    setvar EXPANDING? 0
    killit
  }
  else
  {
    ifactor COMMANDER
      sizeto 100 100
    else
      ifactor SHARK
        sizeto 84 84
    else
      sizeto MAXXSTRETCH MAXYSTRETCH
    break
  }
ends

// APLAYER = 85h
// SHARK - 44h
// LIZTROOP = 88h
// OCTABRAIN = 95h
// SCORPIONTANK = 90h
// DRONE = 40h
// COMMANDER = 83h
// RECON = 60h
// TANK = 74h
// PIGCOP = 87h
// LIZMAN = 87h
// ROTATEGUN = 19h
// BOSS1 = 134h
// BOSS2 = 140h
// BOSS3 = 132h
// NEWBEAST = 117h
// BOSS4 = 164h

state playercheckboots
           ifvare VEHICLEID -1
           {
            ifvarl BOOTSTIME 1
            {
             debris SCRAP1 1
             debris SCRAP2 1
             debris SCRAP3 1
             setvar BOOTSTIME 0
            }
           }
           else
           {
            ifvarl TEMPVAR2 1
            {
             debris SCRAP1 1
             debris SCRAP2 1
             debris SCRAP3 1
             setvar TEMPVAR2 0
             setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
            }
           }
ends

state getplayerhealthondmgflr
 ifvare VEHICLEID -1 setvarvar temp CURRENTHITPOINTS else getactorvar[VEHICLEID].ENEMYHP temp
ends

state setplayerhealthondmgflr
 setactor[THISACTOR].htpicnum -1
 ifvare VEHICLEID -1 setvarvar CURRENTHITPOINTS temp else setactorvar[VEHICLEID].ENEMYHP temp
ends

state pythagoras_reactor
// next code gets distance between actortarget (x,y) and lightning (x,y), puts result in REACTORDISTANCE
getactor[THISACTOR].x temp
getactor[REACTORACTORDMGID].x tempb

subvarvar temp tempb
mulvarvar temp temp
	
getactor[THISACTOR].y tempc
getactor[REACTORACTORDMGID].y tempd

subvarvar tempc tempd
mulvarvar tempc tempc
	
addvarvar temp tempc
sqrt temp temp
setvarvar REACTORDISTANCE temp
ends

state reactordetectifdead
 ifvarn REACTORACTORDMGID -1
 { 
  getactorvar[REACTORACTORDMGID].DRIVERID temp
  ifvarn temp -1 { setvar REACTORACTORDMGID -1 break } // Vehicles only
  getactorvar[REACTORACTORDMGID].ENEMYHP temp
  ifvarl temp 1 { setvar REACTORACTORDMGID -1 break } // Makes it that if the current "target" is dead, set to -1 to search for a living one
  getactorvar[REACTORACTORDMGID].SHRUNK? temp
  ifvare temp 1 { setvar REACTORACTORDMGID -1 break } // Makes it that if the current "target" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[REACTORACTORDMGID].FROZEN? temp
  ifvare temp 1 { setvar REACTORACTORDMGID -1 break } // Makes it that if the current "target" is frozen, set to -1 to search for a non-frozen one
  getactorvar[REACTORACTORDMGID].CLOAKED? temp
  ifvare temp 1 { setvar REACTORACTORDMGID -1 break } // Makes it that if the current "target" is cloaked, set to -1 to search for a non-cloaked one
  state pythagoras_reactor
  ifvarg REACTORDISTANCE 4096 { setvar REACTORACTORDMGID -1 break }
 }
ends

state pythagoras_lightning
// next code gets distance between actortarget (x,y) and lightning (x,y), puts result in LIGHTNINGDISTANCE
getactor[THISACTOR].x temp
getactor[LIGHTNINGACTORDMGID].x tempb

subvarvar temp tempb
mulvarvar temp temp
	
getactor[THISACTOR].y tempc
getactor[LIGHTNINGACTORDMGID].y tempd

subvarvar tempc tempd
mulvarvar tempc tempc
	
addvarvar temp tempc
sqrt temp temp
setvarvar LIGHTNINGDISTANCE temp
ends

state lightningdetectifdead
 ifvarn LIGHTNINGACTORDMGID -1
 { 
  getactorvar[LIGHTNINGACTORDMGID].DRIVERID temp
  ifvarn temp -1 { setvar LIGHTNINGACTORDMGID -1 break } // Vehicles only
  getactorvar[LIGHTNINGACTORDMGID].ENEMYHP temp
  ifvarl temp 1 { setvar LIGHTNINGACTORDMGID -1 break } // Makes it that if the current "target" is dead, set to -1 to search for a living one
  getactorvar[LIGHTNINGACTORDMGID].SHRUNK? temp
  ifvare temp 1 { setvar LIGHTNINGACTORDMGID -1 break } // Makes it that if the current "target" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[LIGHTNINGACTORDMGID].FROZEN? temp
  ifvare temp 1 { setvar LIGHTNINGACTORDMGID -1 break } // Makes it that if the current "target" is frozen, set to -1 to search for a non-frozen one
  getactorvar[LIGHTNINGACTORDMGID].CLOAKED? temp
  ifvare temp 1 { setvar LIGHTNINGACTORDMGID -1 break } // Makes it that if the current "target" is cloaked, set to -1 to search for a non-cloaked one
  state pythagoras_lightning
  ifvarg LIGHTNINGDISTANCE 1536 { setvar LIGHTNINGACTORDMGID -1 break }
 }
ends

state monsterdamagesounds
 state monsterpainsounds1
ends

state lightning_damagesounds
ifvarg TEMPVAR2 0
{
 getactor[LIGHTNINGACTORDMGID].picnum temp
 setvarvar TEMP5 LIGHTNINGACTORDMGID
 state monsterdamagesounds
}
ends

state reactor_damagesounds
ifvarg TEMPVAR2 0
{
 getactor[REACTORACTORDMGID].picnum temp
 setvarvar TEMP5 REACTORACTORDMGID
 state monsterdamagesounds
}
ends

state calcrankitems
            state stopsearchsounds
            addvar RANKITEMSFOUND_LEVEL 1
            addvar RANKITEMSFOUND_GAME 1
            ifvare PUBLICBETA? 1 nullop else divvar RANKPOINTSTEMP 4
            setvar WORLDTILESHUFFLES 0
            state getworldtile
            globalsound DUKE_GET

            ifvarg MAX_RANKITEMSFOUND_LEVEL 0
            {
             ifvarvare RANKITEMSFOUND_LEVEL MAX_RANKITEMSFOUND_LEVEL
             {
              globalsound FOUND_ALLSECRETS
              redefinequote 335 ^23 YOU HAVE FOUND ALL OF THE MEMORBILIA!
             }
            }

            setvar TEMPVAR 1
            state expmulti
            setvarvar fta fta_normal setvar ftq 335
            addvarvar RANKPOINTS RANKPOINTSTEMP
            killit
ends

state setrankitemmax
  ifvare TALLYSET? 0
  {
   getactor[THISACTOR].cstat TEMP ifvarand TEMP 1024 nullop else { addvar TEMP 1024 setactor[THISACTOR].cstat TEMP }
   addvar MAX_RANKITEMSFOUND_LEVEL 1
   addvar MAX_RANKITEMSFOUND_GAME 1
   setvar ISMEMORBILIA? 1
   setvar TALLYSET? 1
  }
ends

// Collectables [Posters, Etc. RANK-heavy items! :P]

state grabspecialfigurine
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {       
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A RARE FIGURINE!
            setvar RANKPOINTSTEMP 400
            state calcrankitems
           }
      }
     }
ends

state grabspecialposter5
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A ^10EXTREMELY^23 SPECIAL POSTER!
            randvar RANKPOINTSTEMP 512
            addvar RANKPOINTSTEMP 512
            state calcrankitems
           }
      }
     }
ends

state grabspecialposter4
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A ^10VERY^23 SPECIAL POSTER!
            setvar RANKPOINTSTEMP 384
            state calcrankitems
           }
      }
     }
ends

state grabspecialposter3
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A ^21VERY^23 SPECIAL POSTER!
            setvar RANKPOINTSTEMP 256
            state calcrankitems
           }
      }
     }
ends


state grabspecialposter2
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A VERY SPECIAL POSTER!
            setvar RANKPOINTSTEMP 128
            state calcrankitems
           }
      }
     }
ends

state grabspecialposter
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A SPECIAL POSTER!
            setvar RANKPOINTSTEMP 64
            state calcrankitems
           }
      }
     }
ends

state grabposter
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A POSTER!
            setvar RANKPOINTSTEMP 32
            state calcrankitems
           }
      }
     }
ends

state grabspecialmagazine2
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A VERY SPECIAL MAGAZINE!
            setvar RANKPOINTSTEMP 144
            state calcrankitems
           }
      }
     }
ends

state grabspecialmagazine
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
        ifpdistl RETRIEVEDISTANCE
          ifp pfacing
           ifhitspace
           {
            redefinequote 335 ^23 GRABBED A SPECIAL MAGAZINE!
            setvar RANKPOINTSTEMP 48
            state calcrankitems
           }
      }
     }
ends

state grabmagazine
     ifvare oldskoolmode 0
     {
      state setrankitemmax
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
       ifpdistl RETRIEVEDISTANCE
       {
        ifp pfacing
        {
         ifhitspace
         {
          redefinequote 335 ^23 GRABBED A MAGAZINE!
          setvar RANKPOINTSTEMP 24
          state calcrankitems
         }
        }
       }
      }
     }
ends

state expanding
        ifactor APLAYER nullop else { setactor[THISACTOR].extra 0 setvar ENEMYHP 0 }
        setvar EXPANDING? 1
ends

state freezeup
        sound SOMETHINGFROZE
        
        ifactor APLAYER setactor[THISACTOR].extra 0 else { setactor[THISACTOR].extra 0 setvar ENEMYHP 0 }
        setvar FROZEN? 1
ends

state unfreeze
      setvar FROZEN? 0

      ifactor APLAYER setvarvar TEMP MAXHITPOINTS
      else setvarvar TEMP ENEMYMAXHP

      divvar TEMP 100
      ifvarl TEMP 1 setvar TEMP 1
      ifactor APLAYER { setactor[THISACTOR].extra 16384 ifvare oldskoolmode 1 addvar TEMP 2 setvarvar CURRENTHITPOINTS TEMP }
      else { setactor[THISACTOR].extra 16384 setvarvar ENEMYHP TEMP }
      setactor[THISACTOR].htpicnum -1
      getlastpal
ends

state headhitstate
// wackplayer
ends

state pythagoras_fire
// next code gets distance between actortarget (x,y) and lightning (x,y), puts result in FIREDISTANCE
getactor[THISACTOR].x temp
getactor[FIREACTORDMGID].x tempb

subvarvar temp tempb
mulvarvar temp temp
	
getactor[THISACTOR].y tempc
getactor[FIREACTORDMGID].y tempd

subvarvar tempc tempd
mulvarvar tempc tempc
	
addvarvar temp tempc
sqrt temp temp
setvarvar FIREDISTANCE temp
ends

state firedetectifdead
 ifvarn FIREACTORDMGID -1
 { 
  getactorvar[FIREACTORDMGID].DRIVERID temp
  ifvarn temp -1 { setvar FIREACTORDMGID -1 break } // Vehicles only
  getactorvar[FIREACTORDMGID].ENEMYHP temp
  ifvarl temp 1 { setvar FIREACTORDMGID -1 break } // Makes it that if the current "target" is dead, set to -1 to search for a living one
  getactorvar[FIREACTORDMGID].SHRUNK? temp
  ifvare temp 1 { setvar FIREACTORDMGID -1 break } // Makes it that if the current "target" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[FIREACTORDMGID].FROZEN? temp
  ifvare temp 1 { setvar FIREACTORDMGID -1 break } // Makes it that if the current "target" is frozen, set to -1 to search for a non-frozen one
  getactorvar[FIREACTORDMGID].CLOAKED? temp
  ifvare temp 1 { setvar FIREACTORDMGID -1 break } // Makes it that if the current "target" is cloaked, set to -1 to search for a non-cloaked one
  state pythagoras_fire
  ifactor FIREBARREL
  {
   ifvarg FIREDISTANCE 1480 { setvar FIREACTORDMGID -1 break }
  }
  else
  ifactor FIREVASE
  {
   ifvarg FIREDISTANCE 1480 { setvar FIREACTORDMGID -1 break }
  }
  else
  ifactor FIRE
  {
   ifvarg FIREDISTANCE 844 { setvar FIREACTORDMGID -1 break }
  }
  else
  ifactor FIRE2
  {
   ifvarg FIREDISTANCE 844 { setvar FIREACTORDMGID -1 break }
  }
  else
  ifactor BURNING
  {
   ifvarg FIREDISTANCE 844 { setvar FIREACTORDMGID -1 break }
  }
  else
  ifactor BURNING2
  {
   ifvarg FIREDISTANCE 844 { setvar FIREACTORDMGID -1 break }
  }
  else
  {
   ifvarg FIREDISTANCE 844 { setvar FIREACTORDMGID -1 break }
  }
 }
ends

state fire_damagesounds
ifvarg TEMPVAR2 0
{
 getactor[FIREACTORDMGID].picnum temp
 setvarvar TEMP5 FIREACTORDMGID
 state monsterdamagesounds
}
ends

state firebarreldmgactors
  ifrnd 32
  {
   addvar FINDNEAR_INTERVAL 1
   ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
   {
    findnearactor3d FEM1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM2 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM3 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM4 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM5 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM6 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM7 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM9 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM10 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d WOMAN 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ROBOTDOG 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ROBOTDOG2 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d TOUGHGAL 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NAKED1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PODFEM1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d WOLFDUDE 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE2 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE3 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE5 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE6 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE7 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE9 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d STAND1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DEALER 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d STAND3 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d STAND4 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PUNKDUDE 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COP1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COP2 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d SITTINGDUDE 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL2 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL3 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL4 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PRESIDENTCLINTON 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ROTATEGUN 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d SHARK 1480 FIREACTORDMGID state firedetectifdead 
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOP 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPSTAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPSHOOT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPDUCKING 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPJETPACK 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPRUNNING 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPJUSTSIT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPONTOILET 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PIGCOP 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PIGCOPDIVE 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PIGCOPSTAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMAN 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMANSTAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMANJUMP 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMANSPITTING 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DRONE 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d OCTABRAIN 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d OCTABRAINSTAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEAST 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEASTSTAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEASTJUMP 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEASTHANG 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COMMANDER 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COMMANDERSTAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d TANK 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d EMPTYTANK 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d SCORPIONTANK 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1STAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1SHOOT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1LOB 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2STAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2SHOOT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2BREATH 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS3 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS3STAYPUT 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS3LOB 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS4 1480 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS4STAYPUT 1480 FIREACTORDMGID state firedetectifdead
    setvar FINDNEAR_INTERVAL 0
   }   

   ifvarn FIREACTORDMGID -1
   {

     ifvare mainmenu 0
     {
      getactorvar[FIREACTORDMGID].ENEMYINVULNTIME TEMP3
      ifvarl TEMP3 1
      {
       getactorvar[FIREACTORDMGID].ENEMYHP TEMPVAR2
       ifvarg TEMPVAR2 0
       {
        setactor[FIREACTORDMGID].extra 16384
        randvar tempe 2
        addvar tempe 5
        ifactor FIREBARREL
        {
         ifvarl FIREDISTANCE 1481
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum FIREBARREL
         }
        }
        else
        ifactor FIREVASE
        {
         ifvarl FIREDISTANCE 1481
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum FIREVASE
         }
        }
        else
        ifactor FIRE
        {
         ifvarl FIREDISTANCE 845
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum FIRE
         }
        }
        else
        ifactor FIRE2
        {
         ifvarl FIREDISTANCE 845
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum FIRE2
         }
        }
        else
        ifactor BURNING
        {
         ifvarl FIREDISTANCE 845
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum BURNING
         }
        }
        else
        ifactor BURNING2
        {
         ifvarl FIREDISTANCE 845
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum BURNING2
         }
        }
        else
        {
         ifvarl FIREDISTANCE 845 
         {
          setactor[FIREACTORDMGID].htextra tempe
          setactor[FIREACTORDMGID].htowner THISACTOR
          setactor[FIREACTORDMGID].htpicnum STEAM
         }
        }
       }
      }
      else sound INVULNITEM3
     }

   }
  }
ends

state firedmgactors
  ifrnd 32
  {
   addvar FINDNEAR_INTERVAL 1
   ifvarvarg FINDNEAR_INTERVAL FINDNEAR_INTERVAL_MAX
   {
    findnearactor3d FEM1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM2 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM3 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM4 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM5 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM6 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM7 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM9 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d FEM10 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d WOMAN 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ROBOTDOG 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ROBOTDOG2 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d TOUGHGAL 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NAKED1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PODFEM1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d WOLFDUDE 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE2 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE3 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE5 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE6 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE7 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DANCE9 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d STAND1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DEALER 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d STAND3 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d STAND4 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PUNKDUDE 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COP1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COP2 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d SITTINGDUDE 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL2 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL3 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ANIMEGIRL4 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PRESIDENTCLINTON 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d ROTATEGUN 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d SHARK 844 FIREACTORDMGID state firedetectifdead 
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOP 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPSTAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPSHOOT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPDUCKING 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPJETPACK 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPRUNNING 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPJUSTSIT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZTROOPONTOILET 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PIGCOP 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PIGCOPDIVE 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d PIGCOPSTAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMAN 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMANSTAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMANJUMP 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d LIZMANSPITTING 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d DRONE 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d OCTABRAIN 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d OCTABRAINSTAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEAST 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEASTSTAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEASTJUMP 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d NEWBEASTHANG 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COMMANDER 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d COMMANDERSTAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d TANK 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d EMPTYTANK 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d SCORPIONTANK 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1STAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1SHOOT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS1LOB 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2STAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2SHOOT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS2BREATH 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS3 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS3STAYPUT 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS3LOB 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS4 844 FIREACTORDMGID state firedetectifdead
    ifvare FIREACTORDMGID -1 findnearactor3d BOSS4STAYPUT 844 FIREACTORDMGID state firedetectifdead
    setvar FINDNEAR_INTERVAL 0
   }   

   ifvarn FIREACTORDMGID -1
   {

     ifvare mainmenu 0
     {
      getactorvar[FIREACTORDMGID].ENEMYINVULNTIME TEMP3
      ifvarl TEMP3 1
      {
       getactorvar[FIREACTORDMGID].ENEMYHP TEMPVAR2
       ifvarg TEMPVAR2 0
       {
        setactor[FIREACTORDMGID].extra 16384
        randvar tempe 2
        addvar tempe 5
        ifvarl FIREDISTANCE 845 
        {
         setactor[FIREACTORDMGID].htextra tempe
         setactor[FIREACTORDMGID].htowner THISACTOR
         setactor[FIREACTORDMGID].htpicnum FIRE
        }
       }
      }
      else sound INVULNITEM3
     }

   }
  }
ends

state pythagoras_steam
// next code gets distance between actortarget (x,y) and lightning (x,y), puts result in STEAMDISTANCE
getactor[THISACTOR].x temp
getactor[STEAMACTORDMGID].x tempb

subvarvar temp tempb
mulvarvar temp temp
	
getactor[THISACTOR].y tempc
getactor[STEAMACTORDMGID].y tempd

subvarvar tempc tempd
mulvarvar tempc tempc
	
addvarvar temp tempc
sqrt temp temp
setvarvar STEAMDISTANCE temp
ends

state steamdetectifdead
 ifvarn STEAMACTORDMGID -1
 { 
  getactorvar[STEAMACTORDMGID].DRIVERID temp
  ifvarn temp -1 { setvar STEAMACTORDMGID -1 break } // Vehicles only
  getactorvar[STEAMACTORDMGID].ENEMYHP temp
  ifvarl temp 1 { setvar STEAMACTORDMGID -1 break } // Makes it that if the current "target" is dead, set to -1 to search for a living one
  getactorvar[STEAMACTORDMGID].SHRUNK? temp
  ifvare temp 1 { setvar STEAMACTORDMGID -1 break } // Makes it that if the current "target" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[STEAMACTORDMGID].FROZEN? temp
  ifvare temp 1 { setvar STEAMACTORDMGID -1 break } // Makes it that if the current "target" is frozen, set to -1 to search for a non-frozen one
  getactorvar[STEAMACTORDMGID].CLOAKED? temp
  ifvare temp 1 { setvar STEAMACTORDMGID -1 break } // Makes it that if the current "target" is cloaked, set to -1 to search for a non-cloaked one
  state pythagoras_steam
  ifvarg STEAMDISTANCE 1024 { setvar STEAMACTORDMGID -1 break }
 }
ends

state steam_damagesounds
ifvarg TEMPVAR2 0
{
 getactor[STEAMACTORDMGID].picnum temp
 setvarvar TEMP5 STEAMACTORDMGID
 state monsterdamagesounds
}
ends

state playerarmorshrapnelspecial
    setvarvar ARMORDAMAGEFACTOR tempd
    mulvar ARMORDAMAGEFACTOR 1000
    ifvarn MAXARMORPOINTS 0 divvarvar ARMORDAMAGEFACTOR MAXARMORPOINTS

    ifvarg tempd 0 { sound ARMOR_HIT state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 125 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 250 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 375 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 500 { state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 625 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 750 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 875 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1000 { state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 1125 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1250 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1375 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1500 { state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 1625 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1750 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1875 state randomshrapnel
    ifvare ARMORDAMAGEFACTOR 2000 { state sparkstate state randomshrapnel }
ends

state player_specialarmor // for dealing armor-damage outside of the main damage formula
   getactorvar[PLAYERID].VEHICLEID TEMPVAR2
   ifvare TEMPVAR2 -1
   {
    setvarvar ARMORLIMIT tempe
    mulvarvar ARMORLIMIT ARMORPERCENT // 50
    divvar ARMORLIMIT 1000
    subvar ARMORLIMIT 1
   }
   else
   {
    setvarvar ARMORLIMIT tempe
    getactorvar[TEMPVAR2].ENEMYARMORPERCENT TEMPVAR4
    mulvarvar ARMORLIMIT TEMPVAR4 // 50
    divvar ARMORLIMIT 1000
    subvar ARMORLIMIT 1
   }

   ifvarg tempe 0
   {
    getactorvar[PLAYERID].VEHICLEID TEMPVAR2
    ifvare TEMPVAR2 -1
    {
     ifvarvarg CURRENTARMORPOINTS ARMORLIMIT
     {
      setvarvar tempd tempe
      mulvarvar tempd ARMORPERCENT // 50
      divvar tempd 1000

      mulvarvar tempe DAMAGEPERCENT // 50
      divvar tempe 1000
      subvarvar CURRENTARMORPOINTS tempd
     }
     else
     {
      subvarvar tempe CURRENTARMORPOINTS
      setvarvar tempd CURRENTARMORPOINTS
      setvar CURRENTARMORPOINTS 0
     }
    }
    else
    {
     getactorvar[TEMPVAR2].ENEMYAP TEMPVAR3
     getactorvar[TEMPVAR2].ENEMYARMORPERCENT TEMPVAR4
     ifvarvarg TEMPVAR3 ARMORLIMIT
     {
      setvarvar tempd tempe
      mulvarvar tempd TEMPVAR4 // 50
      divvar tempd 1000

      setvar TEMPVAR5 1000
      subvarvar TEMPVAR5 TEMPVAR4
      mulvarvar tempe TEMPVAR5 // 50
      divvar tempe 1000

      subvarvar TEMPVAR3 tempd
      setactorvar[TEMPVAR2].ENEMYAP TEMPVAR3
     }
     else
     {
      subvarvar tempe TEMPVAR3
      setvarvar tempd TEMPVAR3
      setvar TEMPVAR3 0
      setactorvar[TEMPVAR2].ENEMYAP TEMPVAR3
     }
    }
   }
   else setvar tempd 0

   ifvarg tempd 0 { state playerarmorshrapnelspecial setvar VEHICLEAPDAMAGED? 1 }
ends

state enemyarmorshrapnelspecial
    setvarvar ARMORDAMAGEFACTOR tempd
    mulvar ARMORDAMAGEFACTOR 1000
    ifvarn TEMP2 0 divvarvar ARMORDAMAGEFACTOR TEMP2

    ifvarg tempd 0 { sound ARMOR_HIT state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 125 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 250 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 375 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 500 { state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 625 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 750 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 875 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1000 { state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 1125 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1250 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1375 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1500 { state sparkstate state randomshrapnel }
    ifvarg ARMORDAMAGEFACTOR 1625 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1750 state randomshrapnel
    ifvarg ARMORDAMAGEFACTOR 1875 state randomshrapnel
    ifvare ARMORDAMAGEFACTOR 2000 { state sparkstate state randomshrapnel }
ends

state enemy_specialarmor
       setvarvar TEMPENEMYAP TEMPVAR3
       setvarvar ENEMYARMORLIMIT tempe
       mulvarvar ENEMYARMORLIMIT TEMP3 // 50
       divvar ENEMYARMORLIMIT 1000
       subvar ENEMYARMORLIMIT 1
       ifvarl ENEMYARMORLIMIT 1 { ifrnd 128 setvar ENEMYARMORLIMIT 1 else setvar ENEMYARMORLIMIT 0 }

       ifvarg tempe 0
       {
        ifvarvarg TEMPENEMYAP ENEMYARMORLIMIT
        {
         setvarvar tempd tempe
         mulvarvar tempd TEMP3 // 50
         divvar tempd 1000
         ifvarl tempd 1 { ifrnd 128 { setvar tempd 1 setvar tempe 0 } else { setvar tempd 0 setvar tempe 1 } }

         setvar ENEMYDAMAGEPERCENT 1000
         subvarvar ENEMYDAMAGEPERCENT TEMP3
         mulvarvar tempe ENEMYDAMAGEPERCENT // 50
         divvar tempe 1000
         ifvarl tempe 0 setvar tempe 0 

         subvarvar TEMPENEMYAP tempd
         setvarvar TEMPVAR3 TEMPENEMYAP
        }
        else
        {
         subvarvar tempe TEMPENEMYAP
         setvarvar tempd TEMPENEMYAP
         setvar TEMPENEMYAP 0
         setvarvar TEMPVAR3 TEMPENEMYAP
        }
       }
       else setvar tempd 0
       ifvarg tempd 0 { state enemyarmorshrapnelspecial setactorvar[FLOORFLAMEACTORDMGID].ENEMYAPDAMAGED? 1 }
ends

state pythagoras_floorflame
// next code gets distance between actortarget (x,y) and lightning (x,y), puts result in FLOORFLAMEDISTANCE
getactor[THISACTOR].x temp
getactor[FLOORFLAMEACTORDMGID].x tempb

subvarvar temp tempb
mulvarvar temp temp
	
getactor[THISACTOR].y tempc
getactor[FLOORFLAMEACTORDMGID].y tempd

subvarvar tempc tempd
mulvarvar tempc tempc
	
addvarvar temp tempc
sqrt temp temp
setvarvar FLOORFLAMEDISTANCE temp
ends

state floorflamedmgdisplays
          getactorvar[PLAYERID].VEHICLEID TEMPVAR2
          ifvare TEMPVAR2 -1 setvarvar TEMPVAR3 CURRENTARMORPOINTS else getactorvar[TEMPVAR2].ENEMYAP TEMPVAR3

          ifvarg TEMPVAR3 0
          {
           ifvarn SHOWDAMAGEPLAYER 0
           {
            ifvarg tempd 0
            {
             setvarvar SHOWDAMAGE tempd
             // addlogvar tempd
             setvar SHOWDAMAGETYPE 1
             setvarvar SHOWDAMAGEACTORID PLAYERID
             state showdamage
            }
           }
           ifvarg tempd 0
           {
            setvar ATTACKINGACTORPICNUM 2333
            getactor[THISACTOR].pal TEMP
            setvarvar ATTACKINGACTORPAL TEMP
            setvarvar PLAYERARMORDAMAGETEMP tempd
            setactor[THISACTOR].htpicnum -1
            ifvare TEMPVAR2 -1 setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
            setvar ATTACKERDISPLAYTIMER 0 setvar ARMORNULLDAMAGE 0
            setvar ARMORDAMAGETIMER 0
           }
           else
           {
            ifvarl tempe 1 sound NODAMAGE
            setvar ATTACKINGACTORPICNUM 2333
            getactor[THISACTOR].pal TEMP
            setvarvar ATTACKINGACTORPAL TEMP
            setvarvar PLAYERARMORDAMAGETEMP tempd
            setactor[THISACTOR].htpicnum -1
            ifvare TEMPVAR2 -1 setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
            setvar ATTACKERDISPLAYTIMER 0 setvar ARMORNULLDAMAGE 1
            setvar ARMORDAMAGETIMER 0
           }
          }

          ifvarn SHOWDAMAGEPLAYER 0
          {
           ifvarg tempe 0
           {
            setvarvar SHOWDAMAGE tempe
            // addlogvar tempe
            setvar SHOWDAMAGETYPE 0
            setvarvar SHOWDAMAGEACTORID PLAYERID
            state showdamage
           }
          }

          ifvarg tempe 0
          {
           setvarvar PAINSOUNDFACTOR tempe
           state checkpainfactor

           getactorvar[PLAYERID].VEHICLEID TEMPVAR2
           ifvare TEMPVAR2 -1
           {
            state characterpainsounds
            setvarvar DAMAGEHUEFACTOR TEMPVAR2
            state playerdamagehues-firetype
           }
           else palfrom 32 0 16
   
           setvar ATTACKINGACTORPICNUM 2333
           getactor[THISACTOR].pal TEMP
           setvarvar ATTACKINGACTORPAL TEMP
           setvarvar PLAYERDAMAGETEMP tempe
           setactor[THISACTOR].htpicnum -1
           ifvare TEMPVAR2 -1 setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
           setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 0
           setvar HEALTHDAMAGETIMER 0
          }
          else
          {
           sound NODAMAGE
           setvar ATTACKINGACTORPICNUM 2333
           getactor[THISACTOR].pal TEMP
           setvarvar ATTACKINGACTORPAL TEMP
           setvarvar PLAYERDAMAGETEMP tempe
           setactor[THISACTOR].htpicnum -1
           ifvare TEMPVAR2 -1 setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
           setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 1
           setvar HEALTHDAMAGETIMER 0
          }
ends

state floorflamedetectifdead
 ifvarn FLOORFLAMEACTORDMGID -1
 { 
  getactorvar[FLOORFLAMEACTORDMGID].DRIVERID temp
  ifvarn temp -1 { setvar FLOORFLAMEACTORDMGID -1 break } // Vehicles only
  getactorvar[FLOORFLAMEACTORDMGID].ENEMYHP temp
  ifvarl temp 1 { setvar FLOORFLAMEACTORDMGID -1 break } // Makes it that if the current "target" is dead, set to -1 to search for a living one
  getactorvar[FLOORFLAMEACTORDMGID].SHRUNK? temp
  ifvare temp 1 { setvar FLOORFLAMEACTORDMGID -1 break } // Makes it that if the current "target" is shrunken, set to -1 to search for a non-shrunken one
  getactorvar[FLOORFLAMEACTORDMGID].FROZEN? temp
  ifvare temp 1 { setvar FLOORFLAMEACTORDMGID -1 break } // Makes it that if the current "target" is frozen, set to -1 to search for a non-frozen one
  getactorvar[FLOORFLAMEACTORDMGID].CLOAKED? temp
  ifvare temp 1 { setvar FLOORFLAMEACTORDMGID -1 break } // Makes it that if the current "target" is cloaked, set to -1 to search for a non-cloaked one
  state pythagoras_floorflame
  ifvarg FLOORFLAMEDISTANCE 1024 { setvar FLOORFLAMEACTORDMGID -1 break }
 }
ends

state floorflame_damagesounds
ifvarg TEMPVAR2 0
{
 getactor[FLOORFLAMEACTORDMGID].picnum temp
 setvarvar TEMP5 FLOORFLAMEACTORDMGID
 state monsterdamagesounds
}
ends

state toughgalspeech
  ifrnd 64 { ifnosounds soundonce TOUGHGALSND1 }
  else ifrnd 64 { ifnosounds soundonce TOUGHGALSND2 }
  else ifrnd 64 { ifnosounds soundonce TOUGHGALSND3 }
  else ifnosounds soundonce TOUGHGALSND4
ends

move MOUSEVELS 32

state scrap1
	  debris SCRAP3 4
	  debris SCRAP1 3
	  debris SCRAP4 2
	  debris SCRAP2 2
	  debris SCRAP5 1
ends

state piratebreak1
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
ends

state dcflaskbreak
        ifrnd 85 lotsofglass 4 else ifrnd 128 lotsofglass 5 else lotsofglass 6
        ifrnd 128 sound GLASS_BREAKING else sound GLASS_HEAVYBREAK
ends

state breakobject
  ifaction 0
  {
    action ANULLACTION
    cstator 257
    ifactor ROBOTMOUSE
      clipdist 64
  }
  else
    ifactor ROBOTMOUSE
  {
      ifdead
      {
        ifcount 32
        {
          globalsound MOUSEANNOY
          killit
        }
        break
      }
      ifcount 64 ifrnd 6
      {
        ifrnd 128
          move MOUSEVELS randomangle geth
        else
        {
          ifrnd 64
            soundonce HAPPYMOUSESND1
          else
            ifrnd 64
              soundonce HAPPYMOUSESND2
          else
            ifrnd 64
              soundonce HAPPYMOUSESND3
          else
            soundonce HAPPYMOUSESND4
        }
        resetcount
      }
  }

  ifhitweapon
  {
    ifdead
    {
      ifactor FOODOBJECT6 state jibfood
      else ifactor FOODOBJECT11 state jibfood
      else ifactor FOODOBJECT12 state jibfood
      else ifactor FOODOBJECT13 state jibfood
      else ifactor FOODOBJECT14 state jibfood
      else ifactor FOODOBJECT15 state jibfood
      else ifactor FOODOBJECT16 state jibfood
      else ifactor FOODOBJECT17 state jibfood
      else ifactor SKINNEDCHICKEN state jibfood
      else ifactor BARSTOOL sound VENT_BUST
      else
	ifactor TABLE
	{
	 sound GLASS_HEAVYBREAK  
	 debris SCRAP1 5
	 debris SCRAP2 5
	 debris SCRAP3 5
	 ifrnd 128 cactor BARBROKE
	}
      else
      ifactor SHOPPINGCART
      {
       debris SCRAP1 5
       debris SCRAP2 5
       debris SCRAP3 5
       sound GLASS_HEAVYBREAK
       killit
      }
      else
      ifactor ROBOTDOG
      {
       soundonce DEAD_DOG
       guts JIBS2 1
       guts JIBS3 2
       guts JIBS6 3
       randvar RANKPOINTSTEMP DOGKILLRANKPOINTSRAND 
       addvar RANKPOINTSTEMP DOGKILLRANKPOINTSSOLID 
       setvar TEMPVAR 1
       state drop_artifacts
       state checkkillerofciv
       state expmulti
       state exp_given
       killit
      }
      else
      ifactor ROBOTDOG2
      {
       soundonce DEAD_DOG
       guts JIBS2 1
       guts JIBS3 2
       guts JIBS6 3
       randvar RANKPOINTSTEMP DOGKILLRANKPOINTSRAND 
       addvar RANKPOINTSTEMP DOGKILLRANKPOINTSSOLID 
       setvar TEMPVAR 1
       state drop_artifacts
       state checkkillerofciv
       state expmulti
       state exp_given
       killit
      }
      else
      ifactor PRESIDENTCLINTON // Kills the player if they Clinton is killed [since he is supposed to be saved, not killed]
      {
       guts JIBS2 1
       guts JIBS3 2
       guts JIBS6 3
       soundonce MALENPC_DEATH1
       state drop_artifacts
       setvar INSTANTDEATH 1
       killit
      }
      else
        ifactor FEATHEREDCHICKEN
          state jibfood
      else
      ifactor DOLPHIN1
      {
        state civjibs
        state jibfood
      }
      else
        ifactor DOLPHIN2
      {
        state civjibs
        state jibfood
      }
      else
        ifactor SNAKEP
      {
        state civjibs
        state jibfood
      }
      else 
       ifactor DONUTS
	{
        debris SCRAP1 1
        spritepal 7
        guts JIBS6 2
        ifvarand ACTORFLAGS 4096 state pickupexplosion
        ifvarand ACTORFLAGS 8192 state pickupexplosion
        killit
	}
      else 
       ifactor DONUTS2
	{
        spritepal 7
        guts JIBS6 2
        ifvarand ACTORFLAGS 4096 state pickupexplosion
        ifvarand ACTORFLAGS 8192 state pickupexplosion
        killit
	}
      else 
       ifactor VIDEO1
	{
  	  debris SCRAP3 3
	  debris SCRAP4 2
	  lotsofglass 30
	}
      else 
       ifactor VIDEO3
	{
	  debris SCRAP3 3
	  debris SCRAP4 2
	  lotsofglass 30
	}
	else
       ifactor VIDEO2
	{
	  debris SCRAP3 3
	  debris SCRAP4 2
	  lotsofglass 30
	}
      else
       ifactor E-GLASS
	{
	  state scrap1
	  sound GLASS_HEAVYBREAK
	  lotsofglass 30
	}
      else
       ifactor HERMIT
	{
	  state scrap1
	  lotsofglass 10
	}
      else
       ifactor WOLFDUDE
      {
 	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
       ifactor COP1
      {
 	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
       ifactor COP2
      {
 	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
       ifactor PUNKDUDE
      {
 	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
       ifactor SITTINGDUDE
      {
 	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DANCE1
      {
 	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DANCE2
      {
  	  soundonce LADY_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DANCE3
      {
	  soundonce LADY_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DANCE5
      {
	  soundonce LADY_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DANCE6
      {
	  soundonce LADY_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DANCE7
      {
	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor OTTO
      {
        soundonce DOLPHINSND
        state drop_artifacts
        state civjibs
	  state scrap1
	  state jibfood
      }
      else
      ifactor DANCE9
      {
	  soundonce LADY_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor BODY1
      {
	  soundonce MALENPC_DEATH1
	  sound SQUISHED
        state civjibs
	  state jibfood
      }
      else
      ifactor BODY2
      {
	  sound SQUISHED
        state civjibs
	  state jibfood
      }
      else
      ifactor BODY3
      {
	  sound SQUISHED
        state civjibs
	  state jibfood
      }
      else
      ifactor STAND1
      {
	  soundonce MALENPC_DEATH1
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor DEALER
      {
	  soundonce MALENPC_DEATH1    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor STAND3
      {
	  soundonce MALENPC_DEATH1    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor STAND4
      {
	  soundonce MALENPC_DEATH1    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor ANIMEGIRL1
      {
	  soundonce ANIMEGIRL_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor ANIMEGIRL2
      {
	  soundonce ANIMEGIRL_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor ANIMEGIRL3
      {
	  soundonce ANIMEGIRL_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
      ifactor ANIMEGIRL4
      {
	  soundonce ANIMEGIRL_SCREAM    
        state drop_artifacts
        state civiliankilled
      }
      else
        ifactor MAILBAG
        {
          mail 30
          debris SCRAP3 5
          debris SCRAP4 3
          killit
        }
      else
        ifactor TEDDYBEAR
      {
        debris SCRAP3 5
        spritepal 1
        debris SCRAP3 6
      }
      else
      {
        ifrnd 128
          sound GLASS_BREAKING
        else
          sound GLASS_HEAVYBREAK
      }

      ifactor CLOCK
      {
        cactor BROKENCLOCK
        break
      }
      else
        ifactor JOLLYMEAL
      {
        spawn ATOMICHEALTH
        debris SCRAP3 1
        debris SCRAP4 2
      }
      else
        ifactor GUMBALLMACHINE
      {
        cactor GUMBALLMACHINEBROKE
        strength 1
        debris SCRAP4 2
        lotsofglass 10
        break
      }
      else
        ifactor GUMBALLMACHINEBROKE
      {
        debris SCRAP3 3
        debris SCRAP4 2
        lotsofglass 10
      }
      else
        ifactor DUKEBURGER
      {
        debris SCRAP3 14
        debris SCRAP1 13
        debris SCRAP4 12
        debris SCRAP2 12
        debris SCRAP5 11
      }
      else
        ifactor POLICELIGHTPOLE state scrap1
      else
        ifactor TOPSECRET
          paper 10
      else
        ifactor GUNPOWDERBARREL
      {
        spawn EXPLOSION2
        sound PIPEBOMB_EXPLODE
        hitradius 2048 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
        ifpdistl 2048
          wackplayer
        debris SCRAP1 10
        debris SCRAP2 13
        debris SCRAP3 4
        debris SCRAP4 17
        debris SCRAP5 6
      }
      else
        ifactor FLOORBASKET
      {
        spawn PUKE
        debris SCRAP1 2
        debris SCRAP3 3
        debris SCRAP4 2
      }
      else
        ifactor CHESTOFGOLD
      {
        debris SCRAP1 2
        debris SCRAP3 3
        debris SCRAP4 2
      }
      else
        ifactor ROBOTMOUSE
      {
        debris SCRAP2 10
        spritepal 1
        debris SCRAP3 4
        resetcount
        cstat 32768
        break
      }
      else
      ifactor ROBOTPIRATE
        state piratebreak1
      else
      ifactor PIRATE1A
        state piratebreak1
      else
      ifactor MAN
        state piratebreak1
      else
      ifactor MAN2
        state piratebreak1
      else
      ifactor PIRATE2A
        state piratebreak1
      else
      ifactor PIRATE3A
        state piratebreak1
      else
      ifactor PIRATE4A
        state piratebreak1
      else
      ifactor PIRATE4A
        state piratebreak1
      else
      ifactor PIRATE5A
        state piratebreak1
      else
      ifactor PIRATE6A
        state piratebreak1
      else
      ifactor DCFLASK1EMPTY
        state dcflaskbreak
      else
      ifactor DCFLASK1FILLED
        state dcflaskbreak
      else
      ifactor DCFLASK2EMPTY
        state dcflaskbreak
      else
      ifactor DCFLASK2FILLED
        state dcflaskbreak
      else
      ifactor DCFLASK3EMPTY
        state dcflaskbreak
      else
      ifactor DCFLASK3FILLED
        state dcflaskbreak
      else
      ifactor DCVIALS1
        state dcflaskbreak
      else
      ifactor DCTUBES1
        state dcflaskbreak
      else
      ifactor DCFLASK4FILLED
        state dcflaskbreak
      else
      ifactor DCFLASK5FILLED
      {
        ifrnd 85 lotsofglass 5 else ifrnd 128 lotsofglass 6 else lotsofglass 7
        ifrnd 128 sound GLASS_BREAKING else sound GLASS_HEAVYBREAK
      }
      else
      ifactor DCFLASK6FILLED
      {
        ifrnd 85 lotsofglass 3 else ifrnd 128 lotsofglass 4 else lotsofglass 5
        ifrnd 128 sound GLASS_BREAKING else sound GLASS_HEAVYBREAK
      }
      else
      ifactor DCTUBES2
        state dcflaskbreak
      else
      ifactor DCTUBES3
      {
        state dcflaskbreak
        state dcflaskbreak
      }
      else
      {
        lotsofglass 10
        debris SCRAP4 3
      }
      killit
    }
    else
      ifactor DOLPHIN1
    {
      guts JIBS6 1
      soundonce DOLPHINSND
      ifstrength TOUGH
      {
        cactor DOLPHIN2
        sound SQUISHED
      }
    }
    else
      ifactor DOLPHIN2
    {
      guts JIBS6 1
      soundonce DOLPHINSND
    }
    else
      ifactor ROBOTDOG
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       guts JIBS6 1
       soundonce WHINING_DOG
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor ROBOTDOG2
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       guts JIBS6 1
       soundonce WHINING_DOG
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE1
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE2
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce LADY_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE3
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce LADY_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE5
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce LADY_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE6
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce LADY_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE7
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DANCE9
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce LADY_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor STAND1
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor STAND3
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor STAND4
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor DEALER
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor WOLFDUDE
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor PUNKDUDE
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor SITTINGDUDE
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor COP1
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor COP2
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor PRESIDENTCLINTON
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       ifrnd 85 soundonce MALENPC_PAIN1
       else ifrnd 128 soundonce MALENPC_PAIN2
       else soundonce MALENPC_PAIN3
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor ANIMEGIRL1
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce ANIMEGIRL_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor ANIMEGIRL2
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce ANIMEGIRL_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor ANIMEGIRL3
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce ANIMEGIRL_SCREAM
      }
      else sound NODAMAGE
     }
    }
    else
      ifactor ANIMEGIRL4
    {
     ifvarl ENEMYINVULNTIME 1
     {
      ifvarg ENEMYLASTDAMAGE 0
      {
       spawn BLOOD
       soundonce ANIMEGIRL_SCREAM
      }
      else sound NODAMAGE
     }
    }
  }
  else
  {
    ifactor CLOCK
      nullop
    else
      ifactor TOPSECRET
	nullop
    else
      ifactor SKINNEDCHICKEN
	nullop
    else
      ifactor FEATHEREDCHICKEN
	nullop
    else
      ifactor FOODOBJECT2
	nullop
    else
      ifactor FOODOBJECT6
	nullop
    else
      ifactor DOLPHIN1
	nullop
    else
      ifactor DOLPHIN2
	nullop
     else
     ifactor HERMIT
	 nullop
     else
      ifactor VIDEO1
	  nullop
     else
      ifactor VIDEO2
	  nullop
     else
     ifactor VIDEO3
	nullop
     else
     ifactor BODY1
	nullop
     else
     ifactor BODY2
	nullop
     else
     ifactor BODY3
	nullop
     else
     ifactor E-GLASS
      nullop
     else
     ifactor ANIMEGIRL4
      nullop
     else
      ifvare mainmenu 0 fall
  }
ends

move RESPAWN_ACTOR_FLAG

state getcode
 ifvarand ACTORFLAGS 2 nullop
 else
 {
  ifactor SATCHEL_LARGE state bonusgrab
  else ifactor SATCHEL_SMALL state bonusgrab
  else ifactor MAXHPUP state bonusgrab
  else ifactor MAXAPUP state bonusgrab
  else ifactor MAXEPUP state bonusgrab
  else ifactor MAXHPAPUP state bonusgrab
  else ifactor ATKUP state bonusgrab
  else ifactor DEFUP state bonusgrab
  else ifactor ATKDEFUP state bonusgrab
  else ifactor SPDUP state bonusgrab
  else ifactor AIRTIMEBONUS state bonusgrab
  else ifactor AIRJUMPBONUS state bonusgrab
  else ifactor MANTLEBONUS state bonusgrab
  else ifactor FORTUNECOOKIE globalsound FORTUNECOOKIE1
  else ifactor ATOMICHEALTH globalsound GETATOMICHEALTH
  else ifactor SUPERATOM globalsound GETATOMICHEALTH
  else globalsound DUKE_GET
  palfrom 16 0 32
 }

  ifvare PUBLICBETA? 1
  {
   randvar CHARACTERARRAY 14
   addvar CHARACTERARRAY 1
   ifvarvare CHARACTERARRAY CHARACTERSELECTED? addvar SHRINKINGRESISTPLAYER 1
   else
   {
    getactorvar[CHARACTERARRAY].CHARACTERSHRINKINGRESIST tempd
    addvar tempd 1
    setactorvar[CHARACTERARRAY].CHARACTERSHRINKINGRESIST tempd
   }
  }
  setvar WORLDTILESHUFFLES 0
  state getworldtile
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
  {
   state activationflag killit
  }
ends

state randgetweapsnds
ifvarand ACTORFLAGS 2 nullop
else
{
 ifvare CHARACTERSELECTED? 1
 {
  randvar RNDVOICE 4
  ifvare RNDVOICE 0 globalsound DUKE_GETWEAPON1
  ifvare RNDVOICE 1 globalsound DUKE_GETWEAPON2
  ifvare RNDVOICE 2 globalsound DUKE_GETWEAPON3
  ifvare RNDVOICE 3 globalsound DUKE_GETWEAPON4
  ifvare RNDVOICE 4 globalsound DUKE_GETWEAPON6
 }
 else
 ifvare CHARACTERSELECTED? 5
 {
  randvar RNDVOICE 4
  ifvare RNDVOICE 0 globalsound WANG_GETWEAPON1
  ifvare RNDVOICE 1 globalsound WANG_GETWEAPON2
  ifvare RNDVOICE 2 globalsound WANG_GETWEAPON3
  ifvare RNDVOICE 3 globalsound WANG_GETWEAPON4
  ifvare RNDVOICE 4 globalsound WANG_GETWEAPON5
 }
 else
 ifvare CHARACTERSELECTED? 8
 {
  randvar RNDVOICE 4
  ifvare RNDVOICE 0 globalsound LISA_GETWEAPON1
  ifvare RNDVOICE 1 globalsound LISA_GETWEAPON2
  ifvare RNDVOICE 2 globalsound LISA_GETWEAPON3
  ifvare RNDVOICE 3 globalsound LISA_GETWEAPON4
  ifvare RNDVOICE 4 globalsound LISA_GETWEAPON5
 }
 else
 ifvare CHARACTERSELECTED? 15
 {
  randvar RNDVOICE 4
  ifvare RNDVOICE 0 globalsound MAKEN_GETWEAPON1
  ifvare RNDVOICE 1 globalsound MAKEN_GETWEAPON2
  ifvare RNDVOICE 2 globalsound MAKEN_GETWEAPON3
  ifvare RNDVOICE 3 globalsound MAKEN_GETWEAPON4
  ifvare RNDVOICE 4 globalsound MAKEN_GETWEAPON5
 }
 globalsound DUKE_GET
}
setvar WORLDTILESHUFFLES 0
state getworldtile

ends

state getweaponcode

  state randgetweapsnds
  ifvarand ACTORFLAGS 2 nullop else palfrom 32 0 32
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
  {
   state activationflag killit
  }
ends

state respawnit
  ifcount RESPAWNITEMTIME
  {
    spawn TRANSPORTERSTAR
    move 0
    cstat 0
    sound TELEPORTER
  }
ends

state quikget
 ifvarand ACTORFLAGS 2 nullop
 else
 {
  ifactor SATCHEL_LARGE state bonusgrab
  else ifactor SATCHEL_SMALL state bonusgrab
  else ifactor MAXHPUP state bonusgrab
  else ifactor MAXAPUP state bonusgrab
  else ifactor MAXEPUP state bonusgrab
  else ifactor MAXHPAPUP state bonusgrab
  else ifactor ATKUP state bonusgrab
  else ifactor DEFUP state bonusgrab
  else ifactor ATKDEFUP state bonusgrab
  else ifactor SPDUP state bonusgrab
  else ifactor AIRTIMEBONUS state bonusgrab
  else ifactor AIRJUMPBONUS state bonusgrab
  else ifactor MANTLEBONUS state bonusgrab
  else ifactor FORTUNECOOKIE globalsound FORTUNECOOKIE1
  else ifactor ATOMICHEALTH globalsound GETATOMICHEALTH
  else ifactor SUPERATOM globalsound GETATOMICHEALTH
  else globalsound DUKE_GET
  palfrom 16 0 32
 }

 ifvare PUBLICBETA? 1
 {
  randvar CHARACTERARRAY 14
  addvar CHARACTERARRAY 1
  ifvarvare CHARACTERARRAY CHARACTERSELECTED? addvar SHRINKINGRESISTPLAYER 1
  else
  {
   getactorvar[CHARACTERARRAY].CHARACTERSHRINKINGRESIST tempd
   addvar tempd 1
   setactorvar[CHARACTERARRAY].CHARACTERSHRINKINGRESIST tempd
  }
 }
 setvar WORLDTILESHUFFLES 0
 state getworldtile
 state activationflag killit
ends

state quikweaponget
  state randgetweapsnds
  ifvarand ACTORFLAGS 2 nullop else palfrom 32 0 32
  state activationflag killit
ends

state checkartifacttimes
 ifvare FLAGSSET? 0
 {
  ifvarl POWERUPBENEFIT 1 setvar POWERUPBENEFIT 780
  setvarvar ACTORPICKUPAMOUNT POWERUPBENEFIT
  state checkpickupamountflags
  setvarvar POWERUPBENEFIT ACTORPICKUPAMOUNT

  setvar FLAGSSET? 1
 }
ends

state grabheatsensoritem
           state checkexplodeflag
  
           setvarvar NIGHTVISIONTIME HEAT_AMOUNT
           setplayer[THISACTOR].heat_amount NIGHTVISIONTIME 

           setvar ACTORPICKUPAMOUNT 1
           state checkpickupamountflags
           subvar ACTORPICKUPAMOUNT 1
           addvarvar HEATSENSORS ACTORPICKUPAMOUNT
           
 	     ifvarand ACTORFLAGS 2 nullop
           else
           {
            ifvarg ACTORPICKUPAMOUNT 0
            {
             globalsound FOUND_INVENTORY
             redefinequote 836 ^20NIGHT VISION GOGGLES ^14[+%d ADDED TO INVENTORY!]
             qsprintf 836 836 ACTORPICKUPAMOUNT
             setvarvar fta fta_normal setvar ftq 836
            }
            else
            {
             setvarvar fta fta_normal setvar ftq 101
            }
           }
	     ifspawnedby HEATSENSOR
	       state getcode
	     else
	       state quikget
ends

state grabheatsensorinventory
        ifvarn oldskoolmode 1
        {
         setvarvar ACTORPICKUPAMOUNT 1
         state checkpickupamountflags
         addvarvar HEATSENSORS ACTORPICKUPAMOUNT
         ifvarand ACTORFLAGS 2 nullop
         else
         {
          ifvare ACTORPICKUPAMOUNT 1
          {
           redefinequote 836 ^14 STORED A PAIR OF NV GOGGLES INTO INVENTORY!
          }
          else
          {
           redefinequote 836 ^14 STORED %ld PAIRS OF NV GOGGLES INTO INVENTORY!
           qsprintf 836 836 ACTORPICKUPAMOUNT
          }
          setvarvar fta fta_normal setvar ftq 836
         }
         globalsound FOUND_INVENTORY
         ifspawnedby HEATSENSOR
          state getcode
         else
          state quikget
        }
ends

state dropfiveclips
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn AMMO state scatterdrops
  espawn AMMO state scatterdrops
  espawn AMMO state scatterdrops
  espawn AMMO state scatterdrops
  espawn AMMO state scatterdrops
 }
ends

state dropfiveshotgunboxes
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn SHOTGUNAMMO state scatterdrops
  espawn SHOTGUNAMMO state scatterdrops
  espawn SHOTGUNAMMO state scatterdrops
  espawn SHOTGUNAMMO state scatterdrops
  espawn SHOTGUNAMMO state scatterdrops
 }
ends

state dropfivebatteries
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn BATTERYAMMO state scatterdrops
  espawn BATTERYAMMO state scatterdrops
  espawn BATTERYAMMO state scatterdrops
  espawn BATTERYAMMO state scatterdrops
  espawn BATTERYAMMO state scatterdrops
 }
ends

state dropfiverocketboxes
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn RPGAMMO state scatterdrops
  espawn RPGAMMO state scatterdrops
  espawn RPGAMMO state scatterdrops
  espawn RPGAMMO state scatterdrops
  espawn RPGAMMO state scatterdrops
 }
ends

state dropfivepipeboxes
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn HBOMBAMMO state scatterdrops
  espawn HBOMBAMMO state scatterdrops
  espawn HBOMBAMMO state scatterdrops
  espawn HBOMBAMMO state scatterdrops
  espawn HBOMBAMMO state scatterdrops
 }
ends

state dropfiveshrinkcrystals
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn CRYSTALAMMO state scatterdrops
  espawn CRYSTALAMMO state scatterdrops
  espawn CRYSTALAMMO state scatterdrops
  espawn CRYSTALAMMO state scatterdrops
  espawn CRYSTALAMMO state scatterdrops
 }
ends

state dropfiveexpandermics
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn GROWAMMO state scatterdrops
  espawn GROWAMMO state scatterdrops
  espawn GROWAMMO state scatterdrops
  espawn GROWAMMO state scatterdrops
  espawn GROWAMMO state scatterdrops
 }
ends

state dropfivestingerboxes
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn DEVISTATORAMMO state scatterdrops
  espawn DEVISTATORAMMO state scatterdrops
  espawn DEVISTATORAMMO state scatterdrops
  espawn DEVISTATORAMMO state scatterdrops
  espawn DEVISTATORAMMO state scatterdrops
 }
ends

state dropfivefreezemodules
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
  espawn FREEZEAMMO state scatterdrops
  espawn FREEZEAMMO state scatterdrops
  espawn FREEZEAMMO state scatterdrops
  espawn FREEZEAMMO state scatterdrops
  espawn FREEZEAMMO state scatterdrops
 }
ends

state droprandomshrinkerstuff
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
        ifrnd 85 { espawn CRYSTALAMMO state scatterdrops }
        else ifrnd 128 { espawn GROWAMMO state scatterdrops }
        else { { espawn CRYSTALAMMO state scatterdrops } { espawn GROWAMMO state scatterdrops } }
 }
ends

state droptripbombs
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
        ifrnd 24 { espawn TRIPBOMBSPRITE state scatterdrops }
        ifrnd 24 { espawn TRIPBOMBSPRITE state scatterdrops }
        ifrnd 24 { espawn TRIPBOMBSPRITE state scatterdrops }
 }
ends

state droprandomexplosivestuff
 state 16outof256rnd
 ifvarvarg RNDMIZER RNDMIZERLIMIT
 {
        ifrnd 64 { espawn RPGAMMO state scatterdrops }
        else ifrnd 85 { espawn DEVISTATORAMMO state scatterdrops }
        else ifrnd 128 { espawn HBOMBAMMO state scatterdrops }
        else { espawn RPGAMMO state scatterdrops espawn DEVISTATORAMMO state scatterdrops espawn HBOMBAMMO state scatterdrops }
 }
ends

state drop_ammo
  ifrnd SPAWNAMMOODDS
  {
   ifspritepal 19 
   { 
    ifrnd 16 { espawn RPGSPRITE state scatterdrops }
    ifrnd 16 { espawn DEVISTATORSPRITE state scatterdrops }
    state droptripbombs
    state droptripbombs
    state droprandomexplosivestuff
    state droprandomexplosivestuff
   }
   ifspritepal 14 
   { 
    ifrnd 16 { espawn SHRINKERSPRITE state scatterdrops }
    state droprandomshrinkerstuff
    state droprandomshrinkerstuff
   }
   ifspritepal 17 
   { 
    ifrnd 26 state dropfiveclips
    else ifrnd 28 state dropfiveshotgunboxes
    else ifrnd 32 state dropfivebatteries
    else ifrnd 36 state dropfiverocketboxes
    else ifrnd 42 state dropfivepipeboxes
    else ifrnd 53 state dropfiveshrinkcrystals
    else ifrnd 64 state dropfiveexpandermics
    else ifrnd 85 state dropfivestingerboxes
    else ifrnd 128 state dropfivefreezemodules
    else { state dropfiveclips state dropfiveshotgunboxes state dropfivebatteries state dropfiverocketboxes state dropfivepipeboxes state dropfiveshrinkcrystals state dropfiveexpandermics state dropfivestingerboxes state dropfivefreezemodules }
   }
   else 
   { 
    ifvare oldskoolmode 0 
    { 
     ifrnd 240 { espawn AMMO state scatterdrops } else { espawn FIRSTGUNSPRITE state scatterdrops } 
    }
    else { espawn AMMO state scatterdrops }    
   }
   ifvare oldskoolmode 0 { ifrnd 1 { ifrnd 64 { espawn JETPACK state scatterdrops } } }
  }
ends

state drop_battery
  ifrnd SPAWNAMMOODDS { espawn BATTERYAMMO state scatterdrops }
ends

state drop_sgshells
  ifrnd SPAWNAMMOODDS { espawn SHOTGUNAMMO state scatterdrops }
ends

state drop_armor
  ifrnd SPAWNAMMOODDS
   {
    ifvare oldskoolmode 0
    {
     ifrnd 112
     {
      espawn SHIELD
      setactorvar[RETURN].ARMORISUSED? 1
      state scatterdrops
     }
     else
     ifrnd 224
     {
      espawn COLORSHIELD
      setactorvar[RETURN].ARMORISUSED? 1
      state scatterdrops
     }
     else
     {
      espawn SUPERSHIELD
      setactorvar[RETURN].ARMORISUSED? 1
      state scatterdrops
     } 
    }
    else
    {
     espawn SHIELD state scatterdrops
    }    
   }
ends

state drop_shotgun
  ifrnd SPAWNAMMOODDS
   {
    ifvare oldskoolmode 0
    {
     ifrnd 128 { espawn SHOTGUNSPRITE state scatterdrops } else { espawn SHOTGUNAMMO state scatterdrops } 
    }
    else
    {
     espawn SHOTGUNSPRITE state scatterdrops
    }    
   }
ends

state drop_chaingun
  ifrnd SPAWNAMMOODDS
  {
   ifrnd 64 { espawn CHAINGUNSPRITE state scatterdrops } else { espawn BATTERYAMMO state scatterdrops }    
  }
ends

//*********************************
//* Dropped into Money Bag States *
//*********************************
state mbag_rndcoinlesser2
   randvar RANDOMVARIABLE 1
   addvar RANDOMVARIABLE 1
   ifvare CHARACTERSELECTED? 8 { ifvarg LISAMONEYTURNS2 2 { addvar RANDOMVARIABLE 1 ifvarg RANDOMVARIABLE 3 setvar RANDOMVARIABLE 3 } }
   ifvare CHARACTERSELECTED? 8 { ifvare LISAMONEYMAXLEVEL 1 { addvar RANDOMVARIABLE 2 ifvarg RANDOMVARIABLE 5 setvar RANDOMVARIABLE 5 } }

   ifvare RANDOMVARIABLE 1 addvar zvelsav 1
   else ifvare RANDOMVARIABLE 2 addvar zvelsav 5
   else ifvare RANDOMVARIABLE 3 addvar zvelsav 10 
   else ifvare RANDOMVARIABLE 4 addvar zvelsav 25
   else ifvare RANDOMVARIABLE 5 addvar zvelsav 50 
ends

state mbag_rndcoinlesser
   setvar LISAMONEYTURNS 0

   state mbag_rndcoinlesser2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1

    ifvare LISAMONEYTURNS 1
    {
     state mbag_rndcoinlesser2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 2
    {
     state mbag_rndcoinlesser2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 3
    {
     state mbag_rndcoinlesser2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rndcoingreater2
   randvar RANDOMVARIABLE 1
   addvar RANDOMVARIABLE 1
   ifvare CHARACTERSELECTED? 8 { ifvarg LISAMONEYTURNS2 2 { addvar RANDOMVARIABLE 1 ifvarg RANDOMVARIABLE 3 setvar RANDOMVARIABLE 3 } }
   ifvare CHARACTERSELECTED? 8 { ifvare LISAMONEYMAXLEVEL 1 { addvar RANDOMVARIABLE 2 ifvarg RANDOMVARIABLE 5 setvar RANDOMVARIABLE 5 } }

   ifvare RANDOMVARIABLE 1 addvar zvelsav 10 
   else ifvare RANDOMVARIABLE 2 addvar zvelsav 25 
   else ifvare RANDOMVARIABLE 3 addvar zvelsav 50 
   else ifvare RANDOMVARIABLE 4 addvar TEMP2 1 
   else ifvare RANDOMVARIABLE 5 addvar TEMP2 1
ends

state mbag_rndcoingreater
   setvar LISAMONEYTURNS 0

   state mbag_rndcoingreater2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1

    ifvare LISAMONEYTURNS 1
    {
     state mbag_rndcoingreater2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 2
    {
     state mbag_rndcoingreater2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 3
    {
     state mbag_rndcoingreater2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rndcoingreatest2
   randvar RANDOMVARIABLE 1
   addvar RANDOMVARIABLE 1
   ifvare CHARACTERSELECTED? 8 { ifvarg LISAMONEYTURNS2 2 { addvar RANDOMVARIABLE 1 ifvarg RANDOMVARIABLE 3 setvar RANDOMVARIABLE 3 } }
   ifvare CHARACTERSELECTED? 8 { ifvare LISAMONEYMAXLEVEL 1 { addvar RANDOMVARIABLE 2 ifvarg RANDOMVARIABLE 5 setvar RANDOMVARIABLE 5 } }

   ifvare RANDOMVARIABLE 1 addvar zvelsav 50 
   else ifvare RANDOMVARIABLE 2 addvar TEMP2 1 
   else ifvare RANDOMVARIABLE 3 addvar TEMP2 1 
   else ifvare RANDOMVARIABLE 4 addvar TEMP2 2
   else ifvare RANDOMVARIABLE 5 addvar TEMP2 5 
ends

state mbag_rndcoingreatest
   setvar LISAMONEYTURNS 0

   state mbag_rndcoingreatest2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1

    ifvare LISAMONEYTURNS 1
    {
     state mbag_rndcoingreatest2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 2
    {
     state mbag_rndcoingreatest2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 3
    {
     state mbag_rndcoingreatest2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rnddollarlesser2
   randvar RANDOMVARIABLE 8
   addvar RANDOMVARIABLE 1
   ifvare CHARACTERSELECTED? 8 { ifvarg LISAMONEYTURNS2 2 { addvar RANDOMVARIABLE 1 ifvarg RANDOMVARIABLE 10 setvar RANDOMVARIABLE 10 } }
   ifvare CHARACTERSELECTED? 8 { ifvare LISAMONEYMAXLEVEL 1 { addvar RANDOMVARIABLE 2 ifvarg RANDOMVARIABLE 12 setvar RANDOMVARIABLE 12 } }

   ifvare RANDOMVARIABLE 1 addvar TEMP2 1 
   else ifvare RANDOMVARIABLE 2 addvar TEMP2 2
   else ifvare RANDOMVARIABLE 3 addvar TEMP2 2
   else ifvare RANDOMVARIABLE 4 addvar TEMP2 5
   else ifvare RANDOMVARIABLE 5 addvar TEMP2 5
   else ifvare RANDOMVARIABLE 6 addvar TEMP2 9
   else ifvare RANDOMVARIABLE 7 addvar TEMP2 10
   else ifvare RANDOMVARIABLE 8 addvar TEMP2 10
   else ifvare RANDOMVARIABLE 9 addvar TEMP2 20
   else ifvare RANDOMVARIABLE 10 addvar TEMP2 50
   else ifvare RANDOMVARIABLE 11 addvar TEMP2 80
   else ifvare RANDOMVARIABLE 12 addvar TEMP2 100
ends

state mbag_rnddollarlesser
   setvar LISAMONEYTURNS 0

   state mbag_rnddollarlesser2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1

    ifvare LISAMONEYTURNS 1
    {
     state mbag_rnddollarlesser2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 2
    {
     state mbag_rnddollarlesser2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 3
    {
     state mbag_rnddollarlesser2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rnddollargreater2
   randvar RANDOMVARIABLE 3
   addvar RANDOMVARIABLE 1
   ifvare CHARACTERSELECTED? 8 { ifvarg LISAMONEYTURNS2 2 { addvar RANDOMVARIABLE 1 ifvarg RANDOMVARIABLE 5 setvar RANDOMVARIABLE 5 } }
   ifvare CHARACTERSELECTED? 8 { ifvare LISAMONEYMAXLEVEL 1 { addvar RANDOMVARIABLE 2 ifvarg RANDOMVARIABLE 7 setvar RANDOMVARIABLE 7 } }

   ifvare RANDOMVARIABLE 1 addvar TEMP2 50
   else ifvare RANDOMVARIABLE 2 addvar TEMP2 80
   else ifvare RANDOMVARIABLE 3 addvar TEMP2 100
   else ifvare RANDOMVARIABLE 4 addvar TEMP2 500
   else ifvarg RANDOMVARIABLE 4 ifvarl RANDOMVARIABLE 7 addvar TEMP2 1000
   else ifvare RANDOMVARIABLE 7 addvar TEMP2 5000
ends

state mbag_rnddollargreater
   setvar LISAMONEYTURNS 0

   state mbag_rnddollargreater2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1

    ifvare LISAMONEYTURNS 1
    {
     state mbag_rnddollargreater2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 2
    {
     state mbag_rnddollargreater2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 3
    {
     state mbag_rnddollargreater2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rnddollargreatest2
   randvar RANDOMVARIABLE 34
   addvar RANDOMVARIABLE 1
   ifvare CHARACTERSELECTED? 8 { ifvarg LISAMONEYTURNS2 2 { addvar RANDOMVARIABLE 1 ifvarg RANDOMVARIABLE 35 setvar RANDOMVARIABLE 35 } }
   ifvare CHARACTERSELECTED? 8 { ifvare LISAMONEYMAXLEVEL 1 { addvar RANDOMVARIABLE 2 ifvarg RANDOMVARIABLE 35 setvar RANDOMVARIABLE 35 } }

   ifvarg RANDOMVARIABLE 0 ifvarl RANDOMVARIABLE 9 addvar TEMP2 1000
   else ifvarg RANDOMVARIABLE 8 ifvarl RANDOMVARIABLE 17 addvar TEMP2 5000
   else ifvarg RANDOMVARIABLE 16 ifvarl RANDOMVARIABLE 25 addvar TEMP2 10000
   else ifvarg RANDOMVARIABLE 24 ifvarl RANDOMVARIABLE 33 addvar TEMP2 100000
   else ifvarg RANDOMVARIABLE 32 ifvarl RANDOMVARIABLE 35 addvar TEMP2 1000000
   else ifvare RANDOMVARIABLE 35 addvar TEMP2 1000000000
ends

state mbag_rnddollargreatest
   setvar LISAMONEYTURNS 0

   state mbag_rnddollargreatest2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1

    ifvare LISAMONEYTURNS 1
    {
     state mbag_rnddollargreatest2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 2
    {
     state mbag_rnddollargreatest2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
    ifvare LISAMONEYTURNS 3
    {
     state mbag_rnddollargreatest2
     ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rndmoneylesser2
 ifvare CHARACTERSELECTED? 8
 {
  ifvare LISAMONEYMAXLEVEL 1
  {
   ifrnd 64 state mbag_rndcoinlesser else state mbag_rnddollarlesser
  }
  else
  {
   ifrnd 128 state mbag_rndcoinlesser else state mbag_rnddollarlesser
  }
 }
 else
 {
  ifrnd 128 state mbag_rndcoinlesser else state mbag_rnddollarlesser
 }
ends

state mbag_rndmoneylesser
   setvar LISAMONEYTURNS0 0

   state mbag_rndmoneylesser2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1

    ifvare LISAMONEYTURNS0 1
    {
     state mbag_rndmoneylesser2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
    ifvare LISAMONEYTURNS0 2
    {
     state mbag_rndmoneylesser2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
    ifvare LISAMONEYTURNS0 3
    {
     state mbag_rndmoneylesser2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rndmoneygreater2
 ifvare CHARACTERSELECTED? 8
 {
  ifvare LISAMONEYMAXLEVEL 1
  {
   ifrnd 64 state mbag_rndcoingreater else state mbag_rnddollargreater
  }
  else
  {
   ifrnd 128 state mbag_rndcoingreater else state mbag_rnddollargreater
  }
 }
 else
 {
  ifrnd 128 state mbag_rndcoingreater else state mbag_rnddollargreater
 }
ends

state mbag_rndmoneygreater
   setvar LISAMONEYTURNS0 0

   state mbag_rndmoneygreater2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1

    ifvare LISAMONEYTURNS0 1
    {
     state mbag_rndmoneygreater2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
    ifvare LISAMONEYTURNS0 2
    {
     state mbag_rndmoneygreater2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
    ifvare LISAMONEYTURNS0 3
    {
     state mbag_rndmoneygreater2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

state mbag_rndmoneygreatest2
 ifvare CHARACTERSELECTED? 8
 {
  ifvare LISAMONEYMAXLEVEL 1
  {
   ifrnd 64 state mbag_rndcoingreatest else state mbag_rnddollargreatest
  }
  else
  {
   ifrnd 128 state mbag_rndcoingreatest else state mbag_rnddollargreatest
  }
 }
 else
 {
  ifrnd 128 state mbag_rndcoingreatest else state mbag_rnddollargreatest
 }
ends

state mbag_rndmoneygreatest
   setvar LISAMONEYTURNS0 0

   state mbag_rndmoneygreatest2

   ifvare CHARACTERSELECTED? 8
   {
    ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1

    ifvare LISAMONEYTURNS0 1
    {
     state mbag_rndmoneygreatest2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
    ifvare LISAMONEYTURNS0 2
    {
     state mbag_rndmoneygreatest2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
    ifvare LISAMONEYTURNS0 3
    {
     state mbag_rndmoneygreatest2
     ifvarvarl LISAMONEYTURNS0 LISAMONEYTURNS2 addvar LISAMONEYTURNS0 1
    }
   }
//   addlogvar TEMP2
//   addlogvar zvelsav
ends

//****************************************
//* End of Dropped into Money Bag States *
//****************************************

state boss_dropmoneybag
  ifspritepal 24
  {
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 240 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 160 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 80 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 40 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rndcoingreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rndcoingreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rndcoingreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rnddollargreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rnddollargreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rnddollargreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rndmoneygreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rndmoneygreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 20 state mbag_rndmoneygreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rndcoingreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rndcoingreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rndcoingreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rnddollargreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rnddollargreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rnddollargreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rndmoneygreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rndmoneygreatest }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 10 state mbag_rndmoneygreatest }
  }
  else
  {
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 224 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 224 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 224 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 56 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 56 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 56 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 28 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 28 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 28 state mbag_rndmoneygreater }
  }
ends

state actor_dropmoneybag
  espawn MONEYBAG state setdroppedmoneyowner
  getactorvar[RETURN].MONEYBAGDOLLARS TEMP2
  getactorvar[RETURN].MONEYBAGCENTS zvelsav
  
  ifactor PIGCOP
  {
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 224 state mbag_rndcoinlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 224 state mbag_rnddollarlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 224 state mbag_rndmoneylesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rndcoinlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rnddollarlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rndmoneylesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 112 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 56 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 56 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 56 state mbag_rndmoneygreater }
  }
  else // Not a Pigcop
  {
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 168 state mbag_rndcoinlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 168 state mbag_rnddollarlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 168 state mbag_rndmoneylesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 96 state mbag_rndcoinlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 96 state mbag_rnddollarlesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 96 state mbag_rndmoneylesser }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 96 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 96 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 96 state mbag_rndmoneygreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 21 state mbag_rndcoingreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 21 state mbag_rnddollargreater }
   state 96outof256rnd ifvarvarg RNDMIZER RNDMIZERLIMIT { ifrnd 21 state mbag_rndmoneygreater }
  }

  ifactor PIGCOP
  {
   ifspritepal 24 state boss_dropmoneybag
   ifspritepal 24 ifrnd 64 state boss_dropmoneybag
   ifspritepal 24 ifrnd 16 state boss_dropmoneybag
  }
  else
  ifactor BOSS1
  {
   state boss_dropmoneybag
   ifspritepal 24 state boss_dropmoneybag
   ifspritepal 24 ifrnd 64 state boss_dropmoneybag
   ifspritepal 24 ifrnd 16 state boss_dropmoneybag
  }
  else
  ifactor BOSS2
  {
   state boss_dropmoneybag
   ifspritepal 24 state boss_dropmoneybag
   ifspritepal 24 ifrnd 64 state boss_dropmoneybag
   ifspritepal 24 ifrnd 16 state boss_dropmoneybag
  }
  else
  ifactor BOSS3
  {
   state boss_dropmoneybag
   ifspritepal 24 state boss_dropmoneybag
   ifspritepal 24 ifrnd 64 state boss_dropmoneybag
   ifspritepal 24 ifrnd 16 state boss_dropmoneybag
  }
  else
  ifactor BOSS4
  {
   state boss_dropmoneybag
   ifspritepal 24 state boss_dropmoneybag
   ifspritepal 24 ifrnd 64 state boss_dropmoneybag
   ifspritepal 24 ifrnd 16 state boss_dropmoneybag
  }
  else
  ifactor LIZTROOP
  {
   ifspritepal 17 state boss_dropmoneybag
   ifspritepal 17 ifrnd 64 state boss_dropmoneybag
   ifspritepal 17 ifrnd 16 state boss_dropmoneybag
  }
  ifactor LIZMAN
  {
   ifspritepal 17 state boss_dropmoneybag
   ifspritepal 17 ifrnd 64 state boss_dropmoneybag
   ifspritepal 17 ifrnd 16 state boss_dropmoneybag
  }
  ifactor COMMANDER
  {
  ifspritepal 24 state boss_dropmoneybag
  ifspritepal 24 ifrnd 64 state boss_dropmoneybag
  ifspritepal 24 ifrnd 16 state boss_dropmoneybag
  }
  setactorvar[RETURN].MONEYBAGDOLLARS TEMP2
  setactorvar[RETURN].MONEYBAGCENTS zvelsav
//  addlogvar TEMP2
//  addlogvar zvelsav
ends

state monster_drop_bonus2
  ifvare SKILLLEVEL 9
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 4 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 32 { espawn AFAS_DROP state scatterdrops } } }
    ifrnd 1 { ifrnd 1 { ifrnd 1 { espawn FAUXLEVELUP state scatterdrops } } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 32 state celldrops
  }
  else
  ifvarl SKILLLEVEL 9
  ifvarg SKILLLEVEL 4
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 2 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 16 { espawn AFAS_DROP state scatterdrops } } }
    ifrnd 1 { ifrnd 1 { ifrnd 1 { ifrnd 128 { espawn FAUXLEVELUP state scatterdrops } } } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 2 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 16 state celldrops
  }
  else
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } } }
    ifrnd 1 { ifrnd 1 { ifrnd 1 { ifrnd 64 { espawn FAUXLEVELUP state scatterdrops } } } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 2 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 8 state celldrops
  }
ends

state monster_drop_bonus1
  ifvare SKILLLEVEL 9
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 3 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 24 { espawn AFAS_DROP state scatterdrops } } }
    ifrnd 1 { ifrnd 1 { ifrnd 1 { ifrnd 96 { espawn FAUXLEVELUP state scatterdrops } } } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 9 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 9 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 9 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 24 state celldrops
  }
  ifvarl SKILLLEVEL 9
  ifvarg SKILLLEVEL 4
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 128 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 4 { espawn AFAS_DROP state scatterdrops } } }
    ifrnd 1 { ifrnd 1 { ifrnd 1 { ifrnd 16 { espawn FAUXLEVELUP state scatterdrops } } } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 128 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 6 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 12 state celldrops
  }
  else
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 64 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 1 { ifrnd 2 { espawn AFAS_DROP state scatterdrops } } }
    ifrnd 1 { ifrnd 1 { ifrnd 1 { ifrnd 8 { espawn FAUXLEVELUP state scatterdrops } } } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 64 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { ifrnd 128 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 2 { ifrnd 128 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 2 { ifrnd 128 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 3 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 2 { ifrnd 128 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }

   ifrnd 6 state celldrops
  }
ends

state boss_drops
  ifspritepal 24
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 256 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { espawn RESURRECTIONCHALICE state scatterdrops }
   }
  }
  else // ifspritepal not= 24
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn RESURRECTIONCHALICE state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 1 { espawn RESURRECTIONCHALICE state scatterdrops }
   }
  }

  ifvare SKILLLEVEL 9
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { ifrnd 16 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { ifrnd 128 { espawn AFAS_DROP state scatterdrops } }
    ifrnd 8 { ifrnd 16 { espawn FAUXLEVELUP state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 48 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 48 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 64 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 48 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 96 state celldrops
  }
  ifvarl SKILLLEVEL 9
  ifvarg SKILLLEVEL 4
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { ifrnd 8 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { ifrnd 64 { espawn AFAS_DROP state scatterdrops } }
    ifrnd 4 { ifrnd 16 { espawn FAUXLEVELUP state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 24 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 24 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 32 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 24 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }
   ifrnd 64 state celldrops
  }
  else
  {
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { ifrnd 4 { espawn AIRJUMPBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops } }
   }
   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 2 { ifrnd 32 { espawn AFAS_DROP state scatterdrops } }
    ifrnd 2 { ifrnd 8 { espawn FAUXLEVELUP state scatterdrops } }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 4 { espawn SATCHEL_LARGE setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 8 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn MANTLEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn AIRTIMEBONUS setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn SATCHEL_SMALL setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXHPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXHPAPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn MAXEPUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn ATKUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn DEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 16 { espawn ATKDEFUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   state 16outof256rnd
   ifvarvarg RNDMIZER RNDMIZERLIMIT
   {
    ifrnd 12 { espawn SPDUP setactorvar[RETURN].ITEMWASDROPPED? 1 state determinebonussizes state scatterdrops }
   }

   ifrnd 32 state celldrops
  }
ends

state drop_health
 ifactor COMMANDER
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   ifrnd 224 { espawn COILS state scatterdrops }
  }
  state monster_drop_bonus2
 }
 else
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   ifrnd 16 { espawn COILS state scatterdrops }
  }
  state monster_drop_bonus2
 }

 ifactor PIGCOP
 {
  state monster_drop_bonus1
  ifspritepal 24 state boss_drops
  ifspritepal 24 ifrnd 64 state boss_drops
  ifspritepal 24 ifrnd 16 state boss_drops
  ifspritepal 24 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
  ifspritepal 24 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
  ifspritepal 24 { ifrnd 4 { espawn RIOTSHIELD state scatterdrops } else { ifrnd 1 { espawn RIOTSHIELD state scatterdrops } } }
 }
 else
 ifactor BOSS1
 {
  state boss_drops
  ifspritepal 24 ifrnd 64 state boss_drops
  ifspritepal 24 ifrnd 16 state boss_drops
  ifspritepal 24 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
  ifspritepal 24 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
 }
 else
 ifactor BOSS2
 {
  state boss_drops
  ifspritepal 24 ifrnd 64 state boss_drops
  ifspritepal 24 ifrnd 16 state boss_drops
  ifspritepal 24 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
  ifspritepal 24 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
 }
 else
 ifactor BOSS3
 {
  state boss_drops
  ifspritepal 24 ifrnd 64 state boss_drops
  ifspritepal 24 ifrnd 16 state boss_drops
  ifspritepal 24 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
  ifspritepal 24 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
 }
 else
 ifactor BOSS4
 {
  state boss_drops
  ifspritepal 24 ifrnd 64 state boss_drops
  ifspritepal 24 ifrnd 16 state boss_drops
  ifspritepal 24 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
  ifspritepal 24 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
 }
 else
 {
  state monster_drop_bonus1
  ifactor LIZTROOP
  {
   ifspritepal 17 state boss_drops
   ifspritepal 17 ifrnd 64 state boss_drops
   ifspritepal 17 ifrnd 16 state boss_drops
   ifspritepal 17 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
   ifspritepal 17 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
  }
  ifactor LIZMAN
  {
   ifspritepal 17 state boss_drops
   ifspritepal 17 ifrnd 64 state boss_drops
   ifspritepal 17 ifrnd 16 state boss_drops
   ifspritepal 17 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
   ifspritepal 17 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
  }
  ifactor COMMANDER
  {
   ifspritepal 24 state boss_drops
   ifspritepal 24 ifrnd 64 state boss_drops
   ifspritepal 24 ifrnd 16 state boss_drops
   ifspritepal 24 { ifrnd 8 { espawn AFAS_DROP state scatterdrops } }
   ifspritepal 24 { ifrnd 2 { espawn FAUXLEVELUP state scatterdrops } }
  }
 }

 ifrnd HEALTHDROPODDS
 {
  state 16outof256rnd
  ifvarvarg RNDMIZER RNDMIZERLIMIT
  {
   getcurraddress TEMP6
   ifrnd 192 randvar RANDOMIZER 242
   else randvar RANDOMIZER 291
   addvar RANDOMIZER 1

   ifvarg RANDOMIZER 0 ifvarl RANDOMIZER 25 { espawn COLA state scatterdrops } // 1-24 [24]
   else ifvarg RANDOMIZER 24 ifvarl RANDOMIZER 47 { espawn SWMEDIKIT state scatterdrops } // 25-46 [22]
   else ifvarg RANDOMIZER 46 ifvarl RANDOMIZER 66 { espawn SIXPAK state scatterdrops } // 47-65 [19]
   else ifvarg RANDOMIZER 65 ifvarl RANDOMIZER 82 { espawn SWBIGMEDIKIT state scatterdrops } // 66-81 [16]
   else ifvarg RANDOMIZER 81 ifvarl RANDOMIZER 94 { espawn MEDPACK state scatterdrops } // 82-93 [12]
   else ifvarg RANDOMIZER 93 ifvarl RANDOMIZER 101 { espawn SURGERYKIT state scatterdrops } // 94-100 [7]
   else ifvarg RANDOMIZER 100 ifvarl RANDOMIZER 111 { espawn EYEDROP state scatterdrops } // 101-110 [10]
   else ifvarg RANDOMIZER 110 ifvarl RANDOMIZER 121 { espawn ANTIDOTE state scatterdrops } // 111-120 [10]
   else ifvarg RANDOMIZER 120 ifvarl RANDOMIZER 131 { espawn FOGHORN state scatterdrops } // 121-130 [10]
   else ifvarg RANDOMIZER 130 ifvarl RANDOMIZER 136 { espawn RESURRECTIONCHALICE state scatterdrops } // 131-135 [5]
   else ifvarg RANDOMIZER 135 ifvarl RANDOMIZER 146 { espawn FIRSTAID state scatterdrops } // 136-145 [10]
   else ifvarg RANDOMIZER 145 ifvarl RANDOMIZER 166 { espawn SHIELD ifrnd 160 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } // 146-165 [20]
   else ifvarg RANDOMIZER 165 ifvarl RANDOMIZER 174 { espawn SUPERSHIELD ifrnd 224 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } // 166-173 [8]
   else ifvarg RANDOMIZER 173 ifvarl RANDOMIZER 179 { ifrnd 128 { espawn ATOMICHEALTH state scatterdrops } else { espawn FORTUNECOOKIE state scatterdrops } } // 174-178 [5]
   else ifvarg RANDOMIZER 178 ifvarl RANDOMIZER 181 { espawn SUPERATOM state scatterdrops } // 179-180 [2]
   else ifvarg RANDOMIZER 180 ifvarl RANDOMIZER 186 { espawn ENERGYSHELL state scatterdrops } // 181-185 [5]
   else ifvarg RANDOMIZER 185 ifvarl RANDOMIZER 191 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 15 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 186-190 [5]
   else ifvarg RANDOMIZER 190 ifvarl RANDOMIZER 194 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 14 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 191-193 [3]
   else ifvarg RANDOMIZER 193 ifvarl RANDOMIZER 197 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 16 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 194-196 [3]
   else ifvarg RANDOMIZER 196 ifvarl RANDOMIZER 200 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 23 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 197-199 [3]
   else ifvarg RANDOMIZER 199 ifvarl RANDOMIZER 202 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 10 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 200-201 [2]
   else ifvarg RANDOMIZER 201 ifvarl RANDOMIZER 204 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 13 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 202-203 [2]
   else ifvarg RANDOMIZER 203 ifvarl RANDOMIZER 206 { espawn COLORSHIELD { setactorvar[RETURN].ACTORNATURALPAL 20 ifrnd 128 { setactorvar[RETURN].ARMORISUSED? 1 } state scatterdrops } } // 204-205 [2]
   else ifvarg RANDOMIZER 205 ifvarl RANDOMIZER 211 { espawn ONELIFETSHIRT state scatterdrops } // 206-210 [5]
   else ifvarg RANDOMIZER 210 ifvarl RANDOMIZER 215 { espawn TWOLIFETSHIRT state scatterdrops } // 211-214 [4]
   else ifvarg RANDOMIZER 214 ifvarl RANDOMIZER 218 { espawn CONTINUEITEM state scatterdrops } // 215-217 [3]
   else ifvarg RANDOMIZER 217 ifvarl RANDOMIZER 226 { espawn TELEBEACON state scatterdrops } // 218-225 [8]
   else ifvare RANDOMIZER 226 { espawn JETPACK state scatterdrops } // 226 [1]
   else ifvare RANDOMIZER 227 { espawn STEROIDS state scatterdrops } // 227 [1]
   else ifvare RANDOMIZER 228 { espawn AIRTANK state scatterdrops } // 228 [1]
   else ifvare RANDOMIZER 229 { espawn BOOTS state scatterdrops } // 229 [1]
   else ifvare RANDOMIZER 230 { espawn HOLODUKE state scatterdrops } // 230 [1]
   else ifvare RANDOMIZER 231 { espawn HEATSENSOR state scatterdrops } // 231 [1]
   else ifvare RANDOMIZER 232 { espawn RANDOMPOWERUP state scatterdrops } // 232 [1]
   else ifvare RANDOMIZER 233 { espawn COILS state scatterdrops } // 233 [1]
   else ifvare RANDOMIZER 234 { espawn ENERGYCELL_LARGE state scatterdrops } // 234 [1]
   else ifvarg RANDOMIZER 234 ifvarl RANDOMIZER 240 { espawn SMALLENERGYDRINK state scatterdrops } // 235-239 [5]
   else ifvarg RANDOMIZER 239 ifvarl RANDOMIZER 243 { espawn LARGEENERGYDRINK state scatterdrops } // 240-242 [3]
   else ifvare RANDOMIZER 243 { espawn HYPERENERGYDRINK state scatterdrops } // 243 [1]
   // Rare Items { 25% chance of attempting to select these }
   else ifvare RANDOMIZER 244 { espawn HACKERVISION state scatterdrops } // 244 [1]
   else ifvarg RANDOMIZER 244 ifvarl RANDOMIZER 247 { espawn SUNRING state scatterdrops } // 245-246 [2]
   else ifvarg RANDOMIZER 246 ifvarl RANDOMIZER 249 { espawn AQUARING state scatterdrops } // 247-248 [2]
   else ifvarg RANDOMIZER 248 ifvarl RANDOMIZER 251 { espawn PLASMARING state scatterdrops } // 249-250 [2]
   else ifvarg RANDOMIZER 250 ifvarl RANDOMIZER 253 { espawn SPIRITRING state scatterdrops } // 251-252 [2]
   else ifvarg RANDOMIZER 252 ifvarl RANDOMIZER 255 { espawn CHARMANKH state scatterdrops } // 253-254 [2]
   else ifvarg RANDOMIZER 254 ifvarl RANDOMIZER 257 { espawn MIRRORSHIELD state scatterdrops } // 255-256 [2]
   else ifvarg RANDOMIZER 256 ifvarl RANDOMIZER 259 { espawn EXPBADGE state scatterdrops } // 257-258 [2]
   else ifvarg RANDOMIZER 258 ifvarl RANDOMIZER 261 { espawn RANKBADGE state scatterdrops } // 259-260 [2]
   else ifvarg RANDOMIZER 260 ifvarl RANDOMIZER 263 { espawn MONEYBADGE state scatterdrops } // 261-262 [2]
   else ifvarg RANDOMIZER 262 ifvarl RANDOMIZER 265 { espawn RIOTSHIELD state scatterdrops } // 263-264 [2]
   else ifvarg RANDOMIZER 264 ifvarl RANDOMIZER 267 { espawn NYXGLOVEPAIR state scatterdrops } // 265-266 [2]
   else ifvarg RANDOMIZER 266 ifvarl RANDOMIZER 269 { espawn RABBITSFOOT state scatterdrops } // 267-268 [2]
   else ifvarg RANDOMIZER 268 ifvarl RANDOMIZER 271 { espawn JUMPBOOTPAIR state scatterdrops } // 269-270 [2]
   else ifvarg RANDOMIZER 270 ifvarl RANDOMIZER 273 { espawn SHOCKABBOOTPAIR state scatterdrops } // 271-272 [2]
   else ifvarg RANDOMIZER 272 ifvarl RANDOMIZER 275 { espawn HAPPYSHOEPAIR state scatterdrops } // 273-274 [2]
   else ifvarg RANDOMIZER 274 ifvarl RANDOMIZER 277 { espawn STYLESHOEPAIR state scatterdrops } // 275-276 [2]
   else ifvarg RANDOMIZER 276 ifvarl RANDOMIZER 279 { espawn CHARMSHOEPAIR state scatterdrops } // 277-278 [2]
   else ifvarg RANDOMIZER 278 ifvarl RANDOMIZER 281 { espawn POWERWRIST state scatterdrops } // 279-280 [2]
   else ifvare RANDOMIZER 281 { espawn AFAS_DROP state scatterdrops } // 281 [1]
   else ifvare RANDOMIZER 282 { espawn FAUXLEVELUP state scatterdrops } // 282 [1]
   else ifvare RANDOMIZER 283 { espawn ENERGYSHELL_UPGRADED state scatterdrops } // 283 [1]
   else ifvare RANDOMIZER 284 { ifrnd 192 { espawn SILKCARNATION  setactorvar[RETURN].ACTORNATURALPAL 10 state scatterdrops } else jump TEMP6 } // 284 [1] 
   else ifvare RANDOMIZER 285 { ifrnd 192 { espawn RAREPIRATEDOUBLOON state scatterdrops } else jump TEMP6 } // 285 [1] 
   else ifvare RANDOMIZER 286 { ifrnd 192 { espawn FIXEDDICEPAIR state scatterdrops } else jump TEMP6 } // 286 [1] 
   else ifvare RANDOMIZER 287 { ifrnd 192 { espawn MALAKIANGEM setactorvar[RETURN].ACTORNATURALPAL 17 state scatterdrops } else jump TEMP6 } // 287 [1] 
   else ifvare RANDOMIZER 288 { ifrnd 192 { espawn SAFELOCKBOX state scatterdrops } else jump TEMP6 } // 288 [1] 
   else ifvare RANDOMIZER 289 { ifrnd 192 { espawn SECRETRECIPE state scatterdrops } else jump TEMP6 } // 289 [1] 
   else ifvare RANDOMIZER 290 { ifrnd 192 { espawn SLURPEEMACHINE state scatterdrops } else jump TEMP6 } // 290 [1] 
   else ifvare RANDOMIZER 291 { ifrnd 192 { espawn STOCKOWNERSHIP state scatterdrops } else jump TEMP6 } // 291 [1] 
   else ifvare RANDOMIZER 292 { ifrnd 192 { espawn TRANSDIMENSIONALSAFE state scatterdrops } else jump TEMP6 } // 292 [1] 
  }
 }

 state actor_dropmoneybag

 ifvare SKILLLEVEL 0 ifrnd 1 state drop_health
 ifvare SKILLLEVEL 1 ifrnd 2 state drop_health
 ifvare SKILLLEVEL 2 ifrnd 3 state drop_health
 ifvare SKILLLEVEL 3 ifrnd 4 state drop_health
 ifvare SKILLLEVEL 4 ifrnd 6 state drop_health
 ifvare SKILLLEVEL 5 ifrnd 8 state drop_health
 ifvare SKILLLEVEL 6 ifrnd 12 state drop_health
 ifvare SKILLLEVEL 7 ifrnd 16 state drop_health
 ifvare SKILLLEVEL 8 ifrnd 24 state drop_health
 ifvare SKILLLEVEL 9 ifrnd 32 state drop_health
ends

//

// Mantling?

define MANTDIST 384 // 480-384=96

state pythagoras
// next code gets distance between (x,y) and (hitx,hity), puts result in xydist

setvarvar temp x
setvarvar tempb hitx

subvarvar temp tempb
mulvarvar temp temp
	
setvarvar tempc y
setvarvar tempd hity

subvarvar tempc tempd
mulvarvar tempc tempc
	
addvarvar temp tempc
sqrt temp temp
setvarvar xydist temp
ends

state checkmantlesprite

ifvarn hitsprite -1
{
	getactor[hitsprite].picnum picnum
	ifvare picnum 3699 // special mantling sprite
	ifvarl xydist MANTDIST
		setvar EDGEGRAPPLING 1
}
ends

state checkwall

	setvar EDGEGRAPPLING 0

	// we start by checking for the dreaded slope at feet problem

	getactor[THISACTOR].z z
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].sectnum mysector
	getactor[THISACTOR].ang angvar
	setvar zdist 0
	cos mycos angvar
	sin mysin angvar
	
	hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
	state pythagoras
	setvarvar xydist2 xydist // saves the distance
	subvar z 1536
	hitscan x y z mysector mycos mysin zdist hitsector hitwall2 hitsprite hitx hity hitz clipmask
	state pythagoras
/*
      ifvarn hitsprite -1
      {
	 getactor[hitsprite].picnum picnum
	 ifvare picnum CRATE2 ifvarl xydist 844
	 {
		setvar EDGEGRAPPLING 1 break 
	 }	
      }
*/

	ifvarn hitwall -1
	ifvarvare hitwall hitwall2 ifvarvarg xydist xydist2 break // it's one of those slopes...
	
// Character Reach Z (the value determines how far the character can 'reach up' to grapple/mantle on an edge
      setvarvar TEMPVAR PLAYERHEIGHT
      divvar TEMPVAR 3
      	subvarvar z TEMPVAR
      	// subvar z 3072 // 1536 // now we do the first "real" hitscan
// End Character Reach Z

	hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
	state pythagoras
	
	ifvarg xydist MANTDIST
	{
		subvar z 3072
		hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
		addvar z 3072
		state checkmantlesprite
		ifvare EDGEGRAPPLING 1 break
  		ifvarg xydist MANTDIST break
	}
	ifvarn hitsprite -1
	{
		state checkmantlesprite
		ifvare EDGEGRAPPLING 1 break
		getactor[hitsprite].cstat temp
		ifvarand temp 1 nullop else break // a non-blocking sprite will prevent mantling
	}
	
	//ifvare hitwall -1 ifvarn hitsprite -1 setvarvar hitwall hitsprite // treats sprite as wall
	
	// now a second hitscan to see whether the upper body is above the wall

	subvar z 7168
	hitscan x y z mysector mycos mysin zdist hitsector hitwall2 hitsprite hitx hity hitz clipmask

	//ifvare hitwall2 -1 ifvarn hitsprite2 -1 setvarvar hitwall2 hitsprite2 // treats sprite as wall

	state pythagoras
	state checkmantlesprite
	ifvare INTHEAIR? 0 setvar tempb MANTDIST else setvar tempb 256
	ifvarvarg xydist tempb 
       ifvarvarn hitwall hitwall2
	 {
        setvar EDGEGRAPPLING 1
	 }
	 else
	 {
		subvar z 3072
		hitscan x y z mysector mycos mysin zdist hitsector hitwall2 hitsprite hitx hity hitz clipmask

		ifvarvare hitwall hitwall2 break
		state pythagoras
  		state checkmantlesprite
		ifvare EDGEGRAPPLING 1 break
		ifvarl xydist MANTDIST 
		{
			// there's still the possibility it could be a duct...
			ifvarn hitsprite -1
			{
				getactor[hitsprite].picnum picnum
				ifvare picnum BGRATE1 setvar EDGEGRAPPLING 1
				ifvare picnum FANSPRITEBROKE setvar EDGEGRAPPLING 1
			}
			break
		}
	 }

	setvar EDGEGRAPPLING 1

ends

state edgegrabbing

ifp ponground ifvare INTHEAIR? 1 setvar INTHEAIR? 0
ifvarl EDGEGRAPPLING 0 addvar EDGEGRAPPLING 1
ifvare EDGEGRAPPLING 1 addvar EDGEGRAPPLEDELAY 1 else setvar EDGEGRAPPLEDELAY 0
ifvarn ONAWALL? 0 break
ifvarn VEHICLEID -1 break

ifvare EDGEGRAPPLING 0
{
      ifvare PLAYERPULLUPSOUND? 1 setvar PLAYERPULLUPSOUND? 0
	getplayer[THISACTOR].posx x
	getplayer[THISACTOR].posy y
	getactor[THISACTOR].z z
	getplayer[THISACTOR].cursectnum mysector
	getflorzofslope mysector x y mz // mz is the return var
	subvarvar mz z // mz is now the distance to the ground
	setvar temp 0
	ifvarl mz 6144 nullop else    
	{
		getplayer[THISACTOR].poszv temp
		ifvare INTHEAIR? 1 setvar tempb 0 else setvar tempb 1536
		ifvarvarg temp tempb
		{
			state checkwall
			ifvare EDGEGRAPPLING 1 
			{
				getplayer[THISACTOR].posz EDGEGRAPPLEZ
				ifvare CHARACTERSELECTED? 1 { stopsound DUKE_GRUNT sound DUKE_GRUNT }
				ifvare CHARACTERSELECTED? 8 { stopsound LISA_WALLGRAB sound LISA_WALLGRAB }
				ifvare CHARACTERSELECTED? 15 { stopsound MAKEN_WALLGRAB sound MAKEN_WALLGRAB }
				wackplayer
				getplayer[THISACTOR].posz z
				subvar z 512
				setplayer[THISACTOR].posz z
				shiftvarr temp 7
				addvar temp 3
				setvarvar EDGEWAITTIME temp
				ifvarg EDGEWAITTIME 40 setvar EDGEWAITTIME 40
			}
			
		}
	}

}

ifvarg EDGEGRAPPLING 0
{
	ifvare mainmenu 0
      {
       ifvarl INVULNTIME 1
       {
        ifvarn CHARACTERSELECTED? 9 // Cybanis has unlimited mantle-strength
        {
         ifvare DEATHSWITCHDELAY 0
         {
          ifvare EDGEGRAPPLING 1 // Drain at normal rate
          {
           ifp ponsteroids // Triple your Mantling time if using steroids
           {
            setvar TEMPVAR5 33
            // Check for Power Wrist [equippable item]
            setvar DAMAGEMODIFIER 1000
            ifvare PLAYEREQUIPSLOTITEM1 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM2 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM3 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM4 18 subvar DAMAGEMODIFIER 125
            mulvarvar TEMPVAR5 DAMAGEMODIFIER
            divvar TEMPVAR5 1000

            subvarvar MANTLINGTIMEREXTRA TEMPVAR5
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1 
             addvar MANTLINGTIMEREXTRA 100
            }
            // addlogvar MANTLINGTIMEREXTRA
            ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
           }
           else
           {
            setvar TEMPVAR5 100
            // Check for Power Wrist [equippable item]
            setvar DAMAGEMODIFIER 1000
            ifvare PLAYEREQUIPSLOTITEM1 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM2 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM3 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM4 18 subvar DAMAGEMODIFIER 125
            mulvarvar TEMPVAR5 DAMAGEMODIFIER
            divvar TEMPVAR5 1000

            subvarvar MANTLINGTIMEREXTRA TEMPVAR5
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1 
             addvar MANTLINGTIMEREXTRA 100
            }
            // addlogvar MANTLINGTIMEREXTRA
            ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
           }
          }
          else // Drain at double rate when pulling up
          {
           ifvare PLAYERPULLUPSOUND? 0
           {
            ifvare CHARACTERSELECTED? 8 { stopsound LISA_WALLGRAB stopsound LISA_WALLPULLUP sound LISA_WALLPULLUP }
            ifvare CHARACTERSELECTED? 15 { stopsound MAKEN_WALLGRAB stopsound MAKEN_WALLPULLUP sound MAKEN_WALLPULLUP }
            setvar PLAYERPULLUPSOUND? 1
           }
           ifp ponsteroids // Triple your Mantling time if using steroids
           {
            setvar TEMPVAR5 50
            // Check for Power Wrist [equippable item]
            setvar DAMAGEMODIFIER 1000
            ifvare PLAYEREQUIPSLOTITEM1 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM2 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM3 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM4 18 subvar DAMAGEMODIFIER 125
            mulvarvar TEMPVAR5 DAMAGEMODIFIER
            divvar TEMPVAR5 1000

            subvarvar MANTLINGTIMEREXTRA TEMPVAR5
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1
             addvar MANTLINGTIMEREXTRA 100
            }
            // addlogvar MANTLINGTIMEREXTRA
            ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
           }
           else
           {
            setvar TEMPVAR5 150
            // Check for Power Wrist [equippable item]
            setvar DAMAGEMODIFIER 1000
            ifvare PLAYEREQUIPSLOTITEM1 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM2 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM3 18 subvar DAMAGEMODIFIER 125
            ifvare PLAYEREQUIPSLOTITEM4 18 subvar DAMAGEMODIFIER 125
            mulvarvar TEMPVAR5 DAMAGEMODIFIER
            divvar TEMPVAR5 1000

            subvarvar MANTLINGTIMEREXTRA TEMPVAR5
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1
             addvar MANTLINGTIMEREXTRA 100
            }
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1
             addvar MANTLINGTIMEREXTRA 100
            }
            // addlogvar MANTLINGTIMEREXTRA
            ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
           }
          }
         } 
        }
        else
        {
         setvarvar tempc MANTLINGTIMERMAX
         subvarvar tempc 1
         setvarvar MANTLINGTIMER tempc
        }
       }
       else
       {
        ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
        {
         setvarvar tempc MANTLINGTIMERMAX
         subvarvar tempc 1
         setvarvar MANTLINGTIMER tempc
        }
       }
      }

	ifvare EDGEGRAPPLING 1 // hanging there, possibly strafing
	{
		setplayer[THISACTOR].falling_counter 0

		getplayer[THISACTOR].posxv xvel
		ifvare CHARACTERSELECTED? 1 mulvar xvel 75
		ifvare CHARACTERSELECTED? 2 mulvar xvel 63
		ifvare CHARACTERSELECTED? 3 mulvar xvel 88
		ifvare CHARACTERSELECTED? 4 mulvar xvel 38
		ifvare CHARACTERSELECTED? 5 mulvar xvel 91
		ifvare CHARACTERSELECTED? 6 mulvar xvel 69
		ifvare CHARACTERSELECTED? 7 mulvar xvel 66
		ifvare CHARACTERSELECTED? 8 mulvar xvel 58 // 40
		ifvare CHARACTERSELECTED? 9 mulvar xvel 81
		ifvare CHARACTERSELECTED? 10 mulvar xvel 53
		ifvare CHARACTERSELECTED? 11 mulvar xvel 47
		ifvare CHARACTERSELECTED? 12 mulvar xvel 71
		ifvare CHARACTERSELECTED? 13 mulvar xvel 78
		ifvare CHARACTERSELECTED? 14 mulvar xvel 94
		ifvare CHARACTERSELECTED? 15 mulvar xvel 44
             divvar xvel 100
		setplayer[THISACTOR].posxv xvel

		getplayer[THISACTOR].posyv yvel
		ifvare CHARACTERSELECTED? 1 mulvar yvel 75
		ifvare CHARACTERSELECTED? 2 mulvar yvel 63
		ifvare CHARACTERSELECTED? 3 mulvar yvel 88
		ifvare CHARACTERSELECTED? 4 mulvar yvel 38
		ifvare CHARACTERSELECTED? 5 mulvar yvel 91
		ifvare CHARACTERSELECTED? 6 mulvar yvel 69
		ifvare CHARACTERSELECTED? 7 mulvar yvel 66
		ifvare CHARACTERSELECTED? 8 mulvar yvel 58 // 40
		ifvare CHARACTERSELECTED? 9 mulvar yvel 81
		ifvare CHARACTERSELECTED? 10 mulvar yvel 53
		ifvare CHARACTERSELECTED? 11 mulvar yvel 47
		ifvare CHARACTERSELECTED? 12 mulvar yvel 71
		ifvare CHARACTERSELECTED? 13 mulvar yvel 78
		ifvare CHARACTERSELECTED? 14 mulvar yvel 94
		ifvare CHARACTERSELECTED? 15 mulvar yvel 44
             divvar yvel 100
		setplayer[THISACTOR].posyv yvel

		setplayer[THISACTOR].posz EDGEGRAPPLEZ
		setplayer[THISACTOR].poszv 0
		state checkwall	
	}
	else
	{
		ifvare CHARACTERSELECTED? 1 setplayer[THISACTOR].poszv -1536
		else ifvare CHARACTERSELECTED? 2 setplayer[THISACTOR].poszv -1280
		else ifvare CHARACTERSELECTED? 3 setplayer[THISACTOR].poszv -1792
		else ifvare CHARACTERSELECTED? 4 setplayer[THISACTOR].poszv -768
		else ifvare CHARACTERSELECTED? 5 setplayer[THISACTOR].poszv -1856
		else ifvare CHARACTERSELECTED? 6 setplayer[THISACTOR].poszv -1408
		else ifvare CHARACTERSELECTED? 7 setplayer[THISACTOR].poszv -1344
		else ifvare CHARACTERSELECTED? 8 setplayer[THISACTOR].poszv -1212 // -832
		else ifvare CHARACTERSELECTED? 9 setplayer[THISACTOR].poszv -1664
		else ifvare CHARACTERSELECTED? 10 setplayer[THISACTOR].poszv -1088
		else ifvare CHARACTERSELECTED? 11 setplayer[THISACTOR].poszv -960
		else ifvare CHARACTERSELECTED? 12 setplayer[THISACTOR].poszv -1472
		else ifvare CHARACTERSELECTED? 13 setplayer[THISACTOR].poszv -1600
		else ifvare CHARACTERSELECTED? 14 setplayer[THISACTOR].poszv -1920
		else ifvare CHARACTERSELECTED? 15 setplayer[THISACTOR].poszv -896
		getplayer[THISACTOR].ang angvar
		cos xvel angvar
		sin yvel angvar
		mulvar xvel 64 
		mulvar yvel 64
		setplayer[THISACTOR].posxv xvel
		setplayer[THISACTOR].posyv yvel
		getactor[THISACTOR].z z
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].sectnum mysector
		getactor[THISACTOR].ang angvar
		setvar zdist 0
		cos mycos angvar
		sin mysin angvar
		hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
		state pythagoras
		ifvarg xydist 384 setvar EDGEGRAPPLING -10
		addvar EDGEGRAPPLING 1
		ifvarg EDGEGRAPPLING 20 setvar EDGEGRAPPLING -10
	}
	
}

ends

state checkhitscan
 getplayer[THISACTOR].posx x
 getplayer[THISACTOR].posy y
 getplayer[THISACTOR].posz z
 getplayer[THISACTOR].cursectnum mysector
 getplayer[THISACTOR].ang angvar
 getplayer[THISACTOR].horiz zdist2
 subvar zdist2 100
 mulvar zdist2 -2048
 cos mycos angvar
 sin mysin angvar
 hitscan x y z mysector mycos mysin zdist2 hitsector hitwall hitsprite hitx hity hitz clipmask
 updatesector hitx hity hitsector
ends

state falling
// getplayer[THISACTOR].falling_counter fallcounter
 ifvarg fallcounter -1 ifvarl fallcounter 47 state stopfallscreams

 ifvare fallcounter 47 
 { 
  ifvare oldskoolmode 0
  {
   redefinequote 241 ^21YOU'RE FALLING WAY TOO FAR!!
   setvarvar fta fta_normal setvar ftq 241
  }
  ifvarg CURRENTHITPOINTS 0 // ifp palive 
  { 
   ifvare CHARACTERSELECTED? 1 globalsound DUKE_SCREAM2
   else ifvare CHARACTERSELECTED? 2 globalsound JACK_FALLSCREAM
   else ifvare CHARACTERSELECTED? 5 globalsound WANG_SCREAM
   else ifvare CHARACTERSELECTED? 6 globalsound ESSENCE_FALLSCREAM
   else ifvare CHARACTERSELECTED? 8 globalsound LISA_FALLSCREAM
   else ifvare CHARACTERSELECTED? 9 globalsound CYBANIS_FALLSCREAM
   else ifvare CHARACTERSELECTED? 15 globalsound MAKEN_FALLSCREAM
   else globalsound DUKE_SCREAM2
  }
  else ifp pdead state stopfallscreams
 }

 ifvarg fallcounter 60
 { 
  setvar FALLSOUND? 1
  ifvarl fallcounter2 63 addvar fallcounter2 1
  setvar fallcounter 60
  setplayer[THISACTOR].falling_counter fallcounter
 }
 ifvarg fallcounter 8
 {
  setvar FALLSOUND? 1
  setvarvar totalfallcounter fallcounter
  addvarvar totalfallcounter fallcounter2
  ifp ponground nullop else setvarvar rfallcounter fallcounter
 }

 ifvarl fallcounts 0 // each count shaves off 2 fallcounter tics
  ifvarg fallcounter 0
   { 
     setplayer[THISACTOR].falling_counter 0
     addvar fallcounts 1 
     resetcount
   }
ends

state lockplayerhealthfloors
    state stoppainsounds
ends

state playerregen5percenthp
      addvarvar CURRENTHITPOINTS PLAYERREGENAMOUNT2
      ifvarn SHOWDAMAGEPLAYER 0
      {
       ifvarg PLAYERREGENAMOUNT2 0
       {
        setvarvar SHOWDAMAGE PLAYERREGENAMOUNT2
        // addlogvar PLAYERREGENAMOUNT2
        setvar SHOWDAMAGETYPE 3
        setvarvar SHOWDAMAGEACTORID THISACTOR
        state showdamage
       }
      }
      ifvarvarg CURRENTHITPOINTS STATLIMITATOMIC setvarvar CURRENTHITPOINTS STATLIMITATOMIC
      ifvarvarg CURRENTHITPOINTS MAXHITPOINTSATOMIC setvarvar CURRENTHITPOINTS MAXHITPOINTSATOMIC
      ifvarvarl CURRENTHITPOINTS STATLIMITATOMIC sound REGEN_HEALTH5 setvar PLAYERHPDAMAGED? -1
ends

state playerregen5percentap
      addvarvar PLAYERAPREGENAMOUNT PLAYERAPREGENAMOUNT2
      ifvarn SHOWDAMAGEPLAYER 0
      {
       ifvarg PLAYERAPREGENAMOUNT2 0
       {
        setvarvar SHOWDAMAGE PLAYERAPREGENAMOUNT2
        // addlogvar PLAYERAPREGENAMOUNT2
        setvar SHOWDAMAGETYPE 4
        setvarvar SHOWDAMAGEACTORID THISACTOR
        state showdamage
       }
      }
      ifvarvarg PLAYERAPREGENAMOUNT STATLIMITATOMIC setvarvar PLAYERAPREGENAMOUNT STATLIMITATOMIC
      ifvarvarg PLAYERAPREGENAMOUNT MAXARMORPOINTSATOMIC setvarvar PLAYERAPREGENAMOUNT MAXARMORPOINTSATOMIC
      ifvarvarl PLAYERAPREGENAMOUNT STATLIMITATOMIC sound REGEN_ARMOR5 setvar PLAYERAPDAMAGED? -1
      setvarvar CURRENTARMORPOINTS PLAYERAPREGENAMOUNT
ends

state playerregenhealthnormal
   ifvarand PLAYERSTATUS? 8 { setvarvar TEMP STATLIMITATOMIC addvar TEMP 1 } else { setvarvar TEMP MAXHITPOINTS } // If player is poisoned, their health will go down even if above 100%
   ifvarvarl CURRENTHITPOINTS TEMP // TEMP or MAXHITPOINTS
   {
    ifvarg CURRENTHITPOINTS 0 // ifp palive
    {
     ifvare mainmenu 0 
     {
      ifvarvarl CURRENTHITPOINTS MAXHITPOINTS 
      { 
       ifp ponsteroids addvar HITPOINTREGENTICS 4 else addvar HITPOINTREGENTICS 1
      } 
      else
      {
       ifvarand PLAYERSTATUS? 8
       { 
        ifp ponsteroids addvar HITPOINTREGENTICS 4 else addvar HITPOINTREGENTICS 1
       }
       else
       {
        setvar HITPOINTREGENTICS 0
       }
      }
     }
      ifvare PUBLICBETA? 0 { ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENINTERVAL 39 else setvar HITPOINTREGENINTERVAL 78 } else { setvar HITPOINTREGENINTERVAL 26 }
      ifvarvarg HITPOINTREGENTICS HITPOINTREGENINTERVAL
      { 
       ifvarl REGENTIME 1 // Only Regenerate at the usual rate when NOT using Regen Powerup
       {
        setvarvar TEMPVAR MAXHITPOINTS
        mulvarvar TEMPVAR PLAYERLEVEL
        ifp ponsteroids divvar TEMPVAR 6667 else divvar TEMPVAR 10000
        ifvarl TEMPVAR 1 setvar TEMPVAR 1
 
        randvar RANDOMIZER 120
        addvar RANDOMIZER 1
        ifvarg RANDOMIZER 0 ifvarl RANDOMIZER 2 mulvar TEMPVAR 5 // 1
        ifvarg RANDOMIZER 1 ifvarl RANDOMIZER 5 mulvar TEMPVAR 4 // 2-4 +3
        ifvarg RANDOMIZER 4 ifvarl RANDOMIZER 14 mulvar TEMPVAR 3 // 5-13 +9
        ifvarg RANDOMIZER 13 ifvarl RANDOMIZER 41 mulvar TEMPVAR 2 // 14-40 +27
        ifvarg RANDOMIZER 40 ifvarl RANDOMIZER 122 mulvar TEMPVAR 1 // 41-121 +81

        ifvarand PLAYERSTATUS? 8 // If the player is 'Poisoned', turn the gain into a loss and flash the screen a sickly green
        {
         setvarvar TEMPVAR MAXHITPOINTS
         randvar TEMPVAR2 10
         setvar TEMPVAR3 20
         ifrnd 128 addvarvar TEMPVAR3 TEMPVAR2 else subvarvar TEMPVAR3 TEMPVAR2
         mulvarvar TEMPVAR TEMPVAR3
         divvar TEMPVAR 1000

         ifvare CHARACTERSELECTED? 2 mulvar TEMPVAR 2 // Jack Inverts Poison Damage to 2x Healing         
         else ifvare CHARACTERSELECTED? 4 { ifvare SECTORLOTAG 1 { mulvar TEMPVAR -4 divvar TEMPVAR 5 } else ifvare SECTORLOTAG 2 { mulvar TEMPVAR -2 divvar TEMPVAR 5 } else { mulvar TEMPVAR -1 } } // Ami loses less HP in or under water when poisoned
         else ifvare CHARACTERSELECTED? 12 divvar TEMPVAR 2 // Lori only suffers 1/2 damage from Poison
         else mulvar TEMPVAR -1 // All others

         ifp ponsteroids { mulvar TEMPVAR 9 divvar TEMPVAR 2 }

//         ifvare PUBLICBETA? 0 divvar TEMPVAR 9 else divvar TEMPVAR 3

         ifvare CHARACTERSELECTED? 2
         {
          setvar TEMPMOD 0
          ifvare PLAYEREQUIPSLOTITEM1 5 addvar TEMPMOD 3
          ifvare PLAYEREQUIPSLOTITEM2 5 addvar TEMPMOD 3
          ifvare PLAYEREQUIPSLOTITEM3 5 addvar TEMPMOD 3
          ifvare PLAYEREQUIPSLOTITEM4 5 addvar TEMPMOD 3
          ifvarl TEMPMOD 1 setvar TEMPMOD 1
          mulvarvar TEMPVAR TEMPMOD
         }

         // Check Slurpee Machine [Permenant Boost Item]
         ifvarvarg PARTYSIZE SLURPEEMACHINES setvarvar TEMP6 SLURPEEMACHINES else setvarvar TEMP6 PARTYSIZE
         ifvare CHARACTERSELECTED? 2 mulvar TEMP6 2 else mulvar TEMP6 -2 // 2% per item
         addvar TEMP6 100
         mulvarvar TEMPVAR TEMP6
         divvar TEMPVAR 100

         ifvare DEFENSECHEAT 1 { divvar TEMPVAR 1000 ifvarg TEMPVAR -1 setvar TEMPVAR -1 state cheatersound }
         ifvarn CHARACTERSELECTED? 2 ifvarg TEMPVAR -1 setvar TEMPVAR -1
         palfrom 32 0 32 

         ifvarl TEMPVAR 0
         {
          setvarvar PAINSOUNDFACTOR TEMPVAR
          mulvar PAINSOUNDFACTOR -1
          state checkpainfactor

          setvarvar DAMAGEHUEFACTOR TEMPVAR
          mulvar DAMAGEHUEFACTOR -1
          state playerdamagehues-acidtype

          ifvarl TEMPVAR3 11 { ifrnd 40 state characterpainsounds }
          ifvare TEMPVAR3 11 { ifrnd 48 state characterpainsounds }
          ifvare TEMPVAR3 12 { ifrnd 56 state characterpainsounds }
          ifvare TEMPVAR3 13 { ifrnd 64 state characterpainsounds }
          ifvare TEMPVAR3 14 { ifrnd 72 state characterpainsounds }
          ifvare TEMPVAR3 15 { ifrnd 80 state characterpainsounds }
          ifvare TEMPVAR3 16 { ifrnd 88 state characterpainsounds }
          ifvare TEMPVAR3 17 { ifrnd 96 state characterpainsounds }
          ifvare TEMPVAR3 18 { ifrnd 112 state characterpainsounds }
          ifvare TEMPVAR3 19 { ifrnd 120 state characterpainsounds }
          ifvare TEMPVAR3 20 { ifrnd 128 state characterpainsounds }
          ifvare TEMPVAR3 21 { ifrnd 136 state characterpainsounds }
          ifvare TEMPVAR3 22 { ifrnd 144 state characterpainsounds }
          ifvare TEMPVAR3 23 { ifrnd 152 state characterpainsounds }
          ifvare TEMPVAR3 24 { ifrnd 160 state characterpainsounds }
          ifvare TEMPVAR3 25 { ifrnd 168 state characterpainsounds }
          ifvare TEMPVAR3 26 { ifrnd 176 state characterpainsounds }
          ifvare TEMPVAR3 27 { ifrnd 184 state characterpainsounds }
          ifvare TEMPVAR3 28 { ifrnd 192 state characterpainsounds }
          ifvare TEMPVAR3 29 { ifrnd 200 state characterpainsounds }
          ifvarg TEMPVAR3 29 { ifrnd 208 state characterpainsounds }
          setvarvar tempe TEMPVAR
          mulvar tempe -1
          setvar ATTACKINGACTORPICNUM 5216
          getactor[THISACTOR].pal TEMP
          setvarvar ATTACKINGACTORPAL TEMP
          setvarvar PLAYERDAMAGETEMP tempe

          ifvarn SHOWDAMAGEPLAYER 0
          {
           ifvarg tempe 0
           {
            setvarvar SHOWDAMAGE tempe
            setvar SHOWDAMAGETYPE 0
            setvarvar SHOWDAMAGEACTORID THISACTOR
            state showdamage
           }
          }

          setactor[THISACTOR].htpicnum -1
          setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
          setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 0
          ifvarg tempe 0 setvar HEALTHDAMAGETIMER 0
         }
        } 
        else 
        { 
         ifvare CHARACTERSELECTED? 1 mulvar TEMPVAR 3 // Duke always recovers 3x the normal HP
         else ifvare CHARACTERSELECTED? 4 { ifvare SECTORLOTAG 1 { mulvar TEMPVAR 2 } else ifvare SECTORLOTAG 2 { mulvar TEMPVAR 5 } else { mulvar TEMPVAR 1 } } // Ami Recovers more HP in or under water
         else ifvare CHARACTERSELECTED? 5 mulvar TEMPVAR 2 // Higa always recovers 2x the normal HP
         else ifvare CHARACTERSELECTED? 7 { mulvar TEMPVAR 9 divvar TEMPVAR 4 } // Ted always recovers 2.25x the normal HP
         else ifvare CHARACTERSELECTED? 8 { mulvar TEMPVAR 3 divvar TEMPVAR 2 } // Lisa always recovers 1.5x the normal HP
         else ifvare CHARACTERSELECTED? 10 mulvar TEMPVAR 2 // Christina/Nethra always recovers 2x the normal HP 
         else ifvare CHARACTERSELECTED? 12 { mulvar TEMPVAR 7 divvar TEMPVAR 4 } // Lori always recovers 1.75x the normal HP
         else ifvare CHARACTERSELECTED? 14 mulvar TEMPVAR 4 // 'Mystery Lady' always recovers 4x the normal HP 
         else ifvare CHARACTERSELECTED? 15 { mulvar TEMPVAR 5 divvar TEMPVAR 4 } // Maken always recovers 1.25x the normal HP
         else mulvar TEMPVAR 1 // All others recover HP at a normal rate

         setvar DAMAGEMODIFIER 1000
         state support-hpregen
         ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
         mulvarvar TEMPVAR DAMAGEMODIFIER
         divvar TEMPVAR 1000

         ifvare PUBLICBETA? 0 divvar TEMPVAR 9 else divvar TEMPVAR 3

         ifvarl TEMPVAR 1 setvar TEMPVAR 1
         ifvarg TEMPVAR 2049152 setvar TEMPVAR 2049152

         setvar TEMPMOD 0
         ifvare PLAYEREQUIPSLOTITEM1 5 addvar TEMPMOD 3
         ifvare PLAYEREQUIPSLOTITEM2 5 addvar TEMPMOD 3
         ifvare PLAYEREQUIPSLOTITEM3 5 addvar TEMPMOD 3
         ifvare PLAYEREQUIPSLOTITEM4 5 addvar TEMPMOD 3
         ifvarl TEMPMOD 1 setvar TEMPMOD 1
         ifvarg TEMPVAR 2049152 setvar TEMPVAR 2049152
         mulvarvar TEMPVAR TEMPMOD

         ifvarl TEMPVAR 1 setvar TEMPVAR 1
         // Check Slurpee Machine [Permenant Boost Item]
         ifvarvarg PARTYSIZE SLURPEEMACHINES setvarvar TEMP6 SLURPEEMACHINES else setvarvar TEMP6 PARTYSIZE
         mulvar TEMP6 2 // 2% per item
         addvar TEMP6 100
         mulvarvar TEMPVAR TEMP6
         divvar TEMPVAR 100

         ifvarl TEMPVAR 1 setvar TEMPVAR 1
         ifvarg TEMPVAR 2049152 setvar TEMPVAR 2049152
        }

        ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
        else ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
        addvarvar CURRENTHITPOINTS TEMPVAR
        ifvarvarg CURRENTHITPOINTS STATLIMITATOMIC setvarvar CURRENTHITPOINTS STATLIMITATOMIC
        ifvarand PLAYERSTATUS? 8 nullop else { ifvarvarg CURRENTHITPOINTS MAXHITPOINTS setvarvar CURRENTHITPOINTS MAXHITPOINTS } // Prevents Poison ailment from setting above 100% HP to 100% :P

        ifvarn SHOWDAMAGEPLAYER 0
        {
         ifvarg TEMPVAR 0
         {
          setvarvar SHOWDAMAGE TEMPVAR
          // addlogvar TEMPVAR
          setvar SHOWDAMAGETYPE 3
          setvarvar SHOWDAMAGEACTORID THISACTOR
          state showdamage
         }
        }
        setvar TEMPVAR 0

        // Reset the interval timer
        setvarvar TEMPVAR4 PLAYERLEVEL divvar TEMPVAR4 20

        ifvare CHARACTERSELECTED? 1 // Duke Nukem
        { 
         ifvarand PLAYERSTATUS? 8 { setvar HITPOINTREGENTICS -2 randvar TEMPVAR5 2 subvarvar HITPOINTREGENTICS TEMPVAR5 } // - 2 to 4 tics of Poison Damage
         else { setvar HITPOINTREGENTICS 4 randvar TEMPVAR5 4 addvarvar HITPOINTREGENTICS TEMPVAR5 } // + 4 to 8 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 4 // Ami Mizuno 
        { 
         ifvarand PLAYERSTATUS? 8
         {
          // Ami suffers poison damage in slower intervals in and under the water
          ifvare SECTORLOTAG 1 setvar HITPOINTREGENTICS -4
          else ifvare SECTORLOTAG 2 setvar HITPOINTREGENTICS -7
          else setvar HITPOINTREGENTICS -1
         }
         else
         {
          // Ami recovers in quicker intervals in and under the water
          ifvare SECTORLOTAG 1 setvar HITPOINTREGENTICS 8
          else ifvare SECTORLOTAG 2 setvar HITPOINTREGENTICS 14
          else { setvar HITPOINTREGENTICS 1 randvar TEMPVAR5 1 addvarvar HITPOINTREGENTICS TEMPVAR5 }
         }
        } 
        ifvare CHARACTERSELECTED? 5 // Lo Wang
        { 
         ifvarand PLAYERSTATUS? 8 { setvar HITPOINTREGENTICS -1 randvar TEMPVAR5 2 subvarvar HITPOINTREGENTICS TEMPVAR5 } // - 1 to 3 tics of Poison Damage
         else { setvar HITPOINTREGENTICS 2 randvar TEMPVAR5 4 addvarvar HITPOINTREGENTICS TEMPVAR5 } // + 2 to 6 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 6 // ESSence Margalan
        { 
         ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -4 // - 4 tics of Poison Damage
         else setvar HITPOINTREGENTICS 8 // + 8 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 7 // Ted Maldoras
        { 
         ifvarand PLAYERSTATUS? 8 { setvar HITPOINTREGENTICS -3 randvar TEMPVAR5 1 subvarvar HITPOINTREGENTICS TEMPVAR5 } // - 3 to 4 tics of Poison Damage
         else { setvar HITPOINTREGENTICS 6 randvar TEMPVAR5 2 addvarvar HITPOINTREGENTICS TEMPVAR5 } // + 6 to 8 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 8 // Lisa Bates
        { 
         ifvarand PLAYERSTATUS? 8 { setvar HITPOINTREGENTICS -6 randvar TEMPVAR5 2 subvarvar HITPOINTREGENTICS TEMPVAR5 } // - 6 to 8 tics of Poison Damage
         else { setvar HITPOINTREGENTICS 12 randvar TEMPVAR5 4 addvarvar HITPOINTREGENTICS TEMPVAR5 } // + 12 to 16 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 9 // Cybanis Morgandos
        { 
         ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -4 // - 4 tics of Poison Damage
         else setvar HITPOINTREGENTICS 8 // + 8 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 10 // Nethra Maboroshi / Christina Mitchell
        { 
         ifvare NETHRAFORM? 0 // Nethra heals 8 times faster than Christina
         {
          ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -8 // - 8 tics of Poison Damage
          else setvar HITPOINTREGENTICS 16 // + 16 tics of Healing
         }
         else
         {
          ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -1 // - 1 tic of Poison Damage
          else setvar HITPOINTREGENTICS 2 // + 2 tics of Healing
         }
        }
        else
        ifvare CHARACTERSELECTED? 12 // Lori Stephens
        { 
         ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -3 // - 3 tics of Poison Damage
         else setvar HITPOINTREGENTICS 6 // + 6 tics of Healing
        }
        else
        ifvare CHARACTERSELECTED? 13 // Minako Aino
        { 
         ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -5 // - 5 tics of Poison Damage
         else setvar HITPOINTREGENTICS 10 // + 10 tics of Healing
        } 
        else
        ifvare CHARACTERSELECTED? 15 // Maken Shinkara
        { 
         ifvarand PLAYERSTATUS? 8 setvar HITPOINTREGENTICS -3 // - 3 tics of Poison Damage
         else setvar HITPOINTREGENTICS 6 // + 6 tics of Healing
        }
        else setvar HITPOINTREGENTICS 0 // Jack, Bubsy, Paula & Mystery Lady

        // Add Speed from Character Levels
        ifvarand PLAYERSTATUS? 8 subvarvar HITPOINTREGENTICS TEMPVAR4
        else addvarvar HITPOINTREGENTICS TEMPVAR4

        // Add Speed from Equipped Charm Ankhs
        setvar TEMPMOD 0
        ifvare PLAYEREQUIPSLOTITEM1 5 addvar TEMPMOD 1
        ifvare PLAYEREQUIPSLOTITEM2 5 addvar TEMPMOD 1
        ifvare PLAYEREQUIPSLOTITEM3 5 addvar TEMPMOD 1
        ifvare PLAYEREQUIPSLOTITEM4 5 addvar TEMPMOD 1
        divvar TEMPMOD 2
        ifvarand PLAYERSTATUS? 8 subvarvar HITPOINTREGENTICS TEMPMOD
        else addvarvar HITPOINTREGENTICS TEMPMOD
        
       }
      }
    }
   }
ends

state playerregenenergynormal
   ifvarvarl CURRENTENERGYPOINTS MAXENERGYPOINTS // TEMP or MAXHITPOINTS
   {
    ifvarg CURRENTHITPOINTS 0 // ifp palive
    {
      ifvare mainmenu 0 
      {
       ifvarvarl CURRENTENERGYPOINTS MAXENERGYPOINTS 
       { 
        ifp ponsteroids addvar ENERGYPOINTREGENTICS 4 else addvar ENERGYPOINTREGENTICS 1
       } 
      }
      ifvare PUBLICBETA? 0 setvar ENERGYPOINTREGENINTERVAL 624 else setvar ENERGYPOINTREGENINTERVAL 208
      ifvarvarg ENERGYPOINTREGENTICS ENERGYPOINTREGENINTERVAL
      { 
        setvarvar TEMPVAR MAXENERGYPOINTS
        mulvarvar TEMPVAR PLAYERLEVEL
        ifp ponsteroids divvar TEMPVAR 6667 else divvar TEMPVAR 10000
        ifvarl TEMPVAR 1 setvar TEMPVAR 1
 
        randvar RANDOMIZER 120
        addvar RANDOMIZER 1
        ifvarg RANDOMIZER 0 ifvarl RANDOMIZER 2 mulvar TEMPVAR 5 // 1
        ifvarg RANDOMIZER 1 ifvarl RANDOMIZER 5 mulvar TEMPVAR 4 // 2-4 +3
        ifvarg RANDOMIZER 4 ifvarl RANDOMIZER 14 mulvar TEMPVAR 3 // 5-13 +9
        ifvarg RANDOMIZER 13 ifvarl RANDOMIZER 41 mulvar TEMPVAR 2 // 14-40 +27
        ifvarg RANDOMIZER 40 ifvarl RANDOMIZER 122 mulvar TEMPVAR 1 // 41-121 +81

        // Character Specfic Multipliers/Dividors
        ifvare CHARACTERSELECTED? 11 { ifrnd 64 mulvar TEMPVAR 2 } // Paula has 25% chance of recovering 2x EP
        else ifvare CHARACTERSELECTED? 14 { ifrnd 85 mulvar TEMPVAR 2 } // Mystery Lady has 33% chance of recovering 2x EP

        ifvare PUBLICBETA? 0 divvar TEMPVAR 9 else divvar TEMPVAR 3

        ifvarl TEMPVAR 1 setvar TEMPVAR 1
        // Check Slurpee Machine [Permenant Boost Item]
        ifvarvarg PARTYSIZE SLURPEEMACHINES setvarvar TEMP6 SLURPEEMACHINES else setvarvar TEMP6 PARTYSIZE
        mulvar TEMP6 2 // 2% per item
        addvar TEMP6 100
        mulvarvar TEMPVAR TEMP6
        divvar TEMPVAR 100

        ifvarl TEMPVAR 1 setvar TEMPVAR 1
        ifvarg TEMPVAR 2049152 setvar TEMPVAR 2049152

        addvarvar CURRENTENERGYPOINTS TEMPVAR
        ifvarvarg CURRENTENERGYPOINTS STATLIMITATOMIC setvarvar CURRENTENERGYPOINTS STATLIMITATOMIC
        ifvarvarg CURRENTENERGYPOINTS MAXENERGYPOINTS setvarvar CURRENTENERGYPOINTS MAXENERGYPOINTS
        setvar TEMPVAR 0

        // Reset the interval timer
        setvarvar TEMPVAR4 PLAYERLEVEL divvar TEMPVAR4 5

        // Character Specfic Timer Alterations
        ifvare CHARACTERSELECTED? 10 setvar ENERGYPOINTREGENTICS 26 // Christina has 1 second less regen wait
        else ifvare CHARACTERSELECTED? 12 setvar ENERGYPOINTREGENTICS 13 // Lori has 1/2 second less regen wait
        else ifvare CHARACTERSELECTED? 14 setvar ENERGYPOINTREGENTICS 65 // Mystery Lady 2 1/2 seconds less regen wait
        else ifvare CHARACTERSELECTED? 15 setvar ENERGYPOINTREGENTICS 13 // Maken has 1/2 second less regen wait
        else setvar ENERGYPOINTREGENTICS 0

        // Add Speed from Character Levels
        addvarvar ENERGYPOINTREGENTICS TEMPVAR4        

      }
    }
   }
ends

state pressoncolamachine
 ifvare oldskoolmode 0
 {
  ifvarg wallxdist -845
  {
   ifvarl wallxdist 845
   {
    ifvarg wallydist -845
    {
     ifvarl wallydist 845
     {
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
       ifhitspace
       { 
        state stopsearchsounds
        ifvare com_pause 0
        {
         getactorvar[hitwall].VENDINGQUANITY tempe
         ifvarg tempe 0
         {
          ifvarg DOLLARS 49
          {
           ifvare CHARACTERSELECTED? 4 setvarvar tempg MAXHITPOINTSATOMIC
           else setvarvar tempg MAXHITPOINTS
           ifvarvarl CURRENTHITPOINTS tempg
           {
            state gotmedsyoureallyneeded
            subvar DOLLARS 50
            subvar DISPLAYDOLLARS 50
            // setvar MONEYGAIN -1 
            state displaymoney
            setvarvar temp MAXHITPOINTS

            ifvare CHARACTERSELECTED? 4 setvar TEMP7 150 else setvar TEMP7 100 
            state checksecretrecipes
            mulvarvar temp TEMP7
            divvar temp 1000

            addvarvar CURRENTHITPOINTS temp
            ifvarvarg CURRENTHITPOINTS tempg setvarvar CURRENTHITPOINTS tempg

            ifvarn SHOWDAMAGEPLAYER 0
            {
             ifvarg temp 0
             {
              setvarvar SHOWDAMAGE temp
              // addlogvar temp
              setvar SHOWDAMAGETYPE 3
              setvarvar SHOWDAMAGEACTORID THISACTOR
              state showdamage
             }
            }

            sound COLA_DISPENSE1
            ifrnd 168
            {
             ifvare CHARACTERSELECTED? 1 globalsound DUKE_EATFOOD1
             ifvare CHARACTERSELECTED? 5 globalsound WANG_EATFOOD1
             ifvare CHARACTERSELECTED? 8 globalsound LISA_EATFOOD1
             ifvare CHARACTERSELECTED? 15 globalsound MAKEN_EATFOOD1
            }
            subvar tempe 1
            setactorvar[hitwall].VENDINGQUANITY tempe

            ifvare CHARACTERSELECTED? 4 setvar TEMP7 150 else setvar TEMP7 100
            state checksecretrecipes_text
            ifvarg SECRETRECIPES 0
            {
             setvarvar TEMP4 TEMP7
             divvar TEMP4 10
             setvarvar TEMP5 TEMP7
             modvar TEMP5 10
             redefinequote 321 ^20YOU DRANK A COLA FROM THE MACHINE! +%d.%d% HP!
             qsprintf 321 321 TEMP4 TEMP5
            }
            else
            {
             ifvare CHARACTERSELECTED? 4 redefinequote 321 ^20YOU DRANK A COLA FROM THE MACHINE! +15% HP!
             else redefinequote 321 ^20YOU DRANK A COLA FROM THE MACHINE! +10% HP!
            }
            setvar PLAYERHPDAMAGED? -1
           }
           else redefinequote 321 ^23YOU DO NOT NEED TO DRINK ANYTHING!
          }
          else redefinequote 321 ^21YOU DO NOT HAVE ENOUGH MONEY ($50)!
         }
         else redefinequote 321 ^21THE COLA MACHINE IS OUT OF ORDER!

         setvarvar fta fta_normal setvar ftq 321
         state stopsearchsounds
         setvar com_pause 39
        }
       }
      }
     }
    }
   }
  }
 }
ends

state pressonsnackmachine
 ifvare oldskoolmode 0
 {
  ifvarg wallxdist -845
  {
   ifvarl wallxdist 845
   {
    ifvarg wallydist -845
    {
     ifvarl wallydist 845
     {
      ifvarg CURRENTHITPOINTS 0 // ifp palive
      {
       ifhitspace
       { 
        state stopsearchsounds
        ifvare com_pause 0
        {
         getactorvar[hitwall].VENDINGQUANITY tempe
         ifvarg tempe 0
         {
          ifvarg DOLLARS 24
          {          
           ifvarvarl CURRENTHITPOINTS MAXHITPOINTS
           {
            state gotmedsyoureallyneeded
            subvar DOLLARS 25
            subvar DISPLAYDOLLARS 25
            state displaymoney
            setvarvar temp MAXHITPOINTS

            setvar TEMP7 50 
            state checksecretrecipes
            mulvarvar temp TEMP7
            divvar temp 1000

            addvarvar CURRENTHITPOINTS temp
            ifvarvarg CURRENTHITPOINTS MAXHITPOINTS setvarvar CURRENTHITPOINTS MAXHITPOINTS

            ifvarn SHOWDAMAGEPLAYER 0
            {
             ifvarg temp 0
             {
              setvarvar SHOWDAMAGE temp
              // addlogvar temp
              setvar SHOWDAMAGETYPE 3
              setvarvar SHOWDAMAGEACTORID THISACTOR
              state showdamage
             }
            }

            sound SNACK_DISPENSE1
            ifrnd 136
            {
             ifvare CHARACTERSELECTED? 1 globalsound DUKE_EATFOOD1
             ifvare CHARACTERSELECTED? 5 globalsound WANG_EATFOOD1
             ifvare CHARACTERSELECTED? 8 globalsound LISA_EATFOOD1
             ifvare CHARACTERSELECTED? 15 globalsound MAKEN_EATFOOD1
            }
            subvar tempe 1
            setactorvar[hitwall].VENDINGQUANITY tempe

            setvar TEMP7 50
            state checksecretrecipes_text
            ifvarg SECRETRECIPES 0
            {
             setvarvar TEMP4 TEMP7
             divvar TEMP4 10
             setvarvar TEMP5 TEMP7
             modvar TEMP5 10
             redefinequote 321 ^20YOU ATE A SNACK FROM THE MACHINE! +%d.%d% HP!
             qsprintf 321 321 TEMP4 TEMP5
            }
            else
            {
             redefinequote 321 ^20YOU ATE A SNACK FROM THE MACHINE! +5% HP!
            }      
            setvar PLAYERHPDAMAGED? -1
           }
           else redefinequote 321 ^23YOU DO NOT NEED TO EAT ANYTHING!
          }
          else redefinequote 321 ^21YOU DO NOT HAVE ENOUGH MONEY ($25)!
         }
         else redefinequote 321 ^21THE SNACK MACHINE IS OUT OF ORDER!

         setvarvar fta fta_normal setvar ftq 321
         state stopsearchsounds
         setvar com_pause 39
        }
       }
      }
     }
    }
   }
  }
 }
ends

state gameover
  setuserdef[THISACTOR].eog 1 
  endofgame 1
  startlevel 0 0
ends

state invulnicon-player
 ifvare oldskoolmode 0
 {
  getactor[THISACTOR].x TESTX 
  getactor[THISACTOR].y TESTY
  getactor[THISACTOR].z TESTZ
  setactor[THISACTOR].x TESTX
  setactor[THISACTOR].y TESTY 
  setactor[THISACTOR].z TESTZ
  getactor[THISACTOR].xrepeat TESTXREPEAT1 
  getactor[THISACTOR].yrepeat TESTYREPEAT1 
  getactorvar[THISACTOR].ACTORSHEIGHT INVULNAURARANGEZ
  mulvarvar INVULNAURARANGEZ TESTYREPEAT1
  mulvar INVULNAURARANGEZ 4
  setvar INVULNAURARANGEXY 844
  addvarvar INVULNAURARANGEXY TESTXREPEAT1
  addvar INVULNAURARANGEZ 1688
  addvarvar INVULNAURARANGEZ TESTYREPEAT1
  addvarvar INVULNAURARANGEZ TESTYREPEAT1
  ifvare VEHICLEID -1
  {
   ifvarg INVULNTIME 0 state invulntarget_player
  }
  else
  {
   getactorvar[VEHICLEID].ENEMYINVULNTIME tempb
   ifvarg tempb 0 { state invulntarget_player }
  }
 }
ends

state globaltimer
   ifvare mainmenu 0 { ifvarl TIMERRAWFORMAT 21474836 addvar TIMERRAWFORMAT 1 }
   ifvare mainmenu 0 { ifvarl TIMERRAWFORMAT 21474836 { ifvarl TIMERRAWFORMAT_LEVEL 21474836 addvar TIMERRAWFORMAT_LEVEL 1 } }
ends

state playergetcorrectz // For getting z ranges for damage floors and walking sounds
          getactor[THISACTOR].x x
          getactor[THISACTOR].y y
          updatesector x y TEMP
          getflorzofslope TEMP x y tempb
          setvarvar tempe tempb
          addvar tempb -513
          getactor[THISACTOR].z PLAYERDMGFLRZ
          ifp pducking addvar PLAYERDMGFLRZ -5280
          addvar PLAYERDMGFLRZ 32
          setvar tempd 82
          getactor[THISACTOR].xrepeat temp
          mulvarvar tempd temp
          mulvar tempd 4
          addvar tempd 4096
          ifvare temp 0 { addvar tempd 512 addvar tempb -512 }
          addvarvar tempe tempd
          ifvare SHRUNK? 1 { addvar tempe 16128 addvar tempb 16128 }
ends

state refreshhealth2
 getactorvar[CHARACTERARRAY].CHARACTERMAXHP TEMP
 mulvar TEMP 2
 getactorvar[CHARACTERARRAY].CHARACTERHP temp
 ifvarvarg temp TEMP setvarvar temp TEMP
 setactorvar[CHARACTERARRAY].CHARACTERHP temp

 getactorvar[CHARACTERARRAY].CHARACTERMAXAP TEMP
 mulvar TEMP 2
 getactorvar[CHARACTERARRAY].CHARACTERAP temp
 ifvarvarg temp TEMP setvarvar temp TEMP
 setactorvar[CHARACTERARRAY].CHARACTERAP temp

 getactorvar[CHARACTERARRAY].CHARACTERMAXHP TEMP
 mulvar TEMP 2
 getactorvar[CHARACTERARRAY].CHARACTERFA temp
 ifvarvarg temp TEMP setvarvar temp TEMP
 setactorvar[CHARACTERARRAY].CHARACTERFA temp

 getactorvar[CHARACTERARRAY].CHARACTERAPABSORB TEMP
 ifvarg TEMP 1000 setvar TEMP 1000
 setactorvar[CHARACTERARRAY].CHARACTERAPABSORB TEMP

ends

state refreshhealthvalues
ifvarn CHARACTERSELECTED? 1
{
 setvar CHARACTERARRAY 1
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 2
{
 setvar CHARACTERARRAY 2
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 3
{
 setvar CHARACTERARRAY 3
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 4
{
 setvar CHARACTERARRAY 4
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 5
{
 setvar CHARACTERARRAY 5
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 6
{
 setvar CHARACTERARRAY 6
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 7
{
 setvar CHARACTERARRAY 7
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 8
{
 setvar CHARACTERARRAY 8
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 9
{
 setvar CHARACTERARRAY 9
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 10
{
 setvar CHARACTERARRAY 10
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 11
{
 setvar CHARACTERARRAY 11
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 12
{
 setvar CHARACTERARRAY 12
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 13
{
 setvar CHARACTERARRAY 13
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 14
{
 setvar CHARACTERARRAY 14
 state refreshhealth2
}
ifvarn CHARACTERSELECTED? 15
{
 setvar CHARACTERARRAY 15
 state refreshhealth2
}

 ifvarl PLAYERHPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0 
  {
   ifvarn HPBARCHILD -1 
   {
    ifvare VEHICLEID -1 setactorvar[HPBARCHILD].HPBARFLASHTIMER -28
   }
  }
  setvar DISPLAYHPFLASHTIMER -28
  setvar PLAYERHPDAMAGED? 0
 }

 ifvarg PLAYERHPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn HPBARCHILD -1
   {
    ifvare VEHICLEID -1 setactorvar[HPBARCHILD].HPBARFLASHTIMER 28
   }
  }
  setvar DISPLAYHPFLASHTIMER 28
  setvar PLAYERHPDAMAGED? 0 
 }
 ifvarl DISPLAYHPFLASHTIMER 0 addvar DISPLAYHPFLASHTIMER 1 else ifvarg DISPLAYHPFLASHTIMER 0 subvar DISPLAYHPFLASHTIMER 1
 ifvarl DISPLAYFAFLASHTIMER 0 addvar DISPLAYFAFLASHTIMER 1 else ifvarg DISPLAYFAFLASHTIMER 0 subvar DISPLAYFAFLASHTIMER 1
 ifvarl PLAYERAPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn APBARCHILD -1
   {
    ifvare VEHICLEID -1 setactorvar[APBARCHILD].APBARFLASHTIMER -28
   }
  }
  setvar DISPLAYAPFLASHTIMER -28
  setvar PLAYERAPDAMAGED? 0
 }

 ifvarg PLAYERAPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn APBARCHILD -1
   {
    ifvare VEHICLEID -1 setactorvar[APBARCHILD].APBARFLASHTIMER 28
   }
  }
  setvar DISPLAYAPFLASHTIMER 28
  setvar PLAYERAPDAMAGED? 0
 }
 ifvarl DISPLAYAPFLASHTIMER 0 addvar DISPLAYAPFLASHTIMER 1 else ifvarg DISPLAYAPFLASHTIMER 0 subvar DISPLAYAPFLASHTIMER 1



 ifvarl VEHICLEHPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0 
  {
   ifvarn HPBARCHILD -1 
   {
    ifvarn VEHICLEID -1 setactorvar[HPBARCHILD].HPBARFLASHTIMER -28
   }
  }
  setvar VDISPLAYHPFLASHTIMER -28
  setvar VEHICLEHPDAMAGED? 0
 }

 ifvarg VEHICLEHPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn HPBARCHILD -1
   {
    ifvarn VEHICLEID -1 setactorvar[HPBARCHILD].HPBARFLASHTIMER 28
   }
  }
  setvar VDISPLAYHPFLASHTIMER 28
  setvar VEHICLEHPDAMAGED? 0 
 }
 ifvarl VDISPLAYHPFLASHTIMER 0 addvar VDISPLAYHPFLASHTIMER 1 else ifvarg VDISPLAYHPFLASHTIMER 0 subvar VDISPLAYHPFLASHTIMER 1
 ifvarl VDISPLAYFAFLASHTIMER 0 addvar VDISPLAYFAFLASHTIMER 1 else ifvarg VDISPLAYFAFLASHTIMER 0 subvar VDISPLAYFAFLASHTIMER 1


 ifvarl VEHICLEAPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn APBARCHILD -1
   {
    ifvarn VEHICLEID -1 setactorvar[APBARCHILD].APBARFLASHTIMER -28
   }
  }
  setvar VDISPLAYAPFLASHTIMER -28
  setvar VEHICLEAPDAMAGED? 0
 }

 ifvarg VEHICLEAPDAMAGED? 0
 {
  ifvarn ATTACHEDOBJECTS? 0
  {
   ifvarn APBARCHILD -1
   {
    ifvarn VEHICLEID -1 setactorvar[APBARCHILD].APBARFLASHTIMER 28
   }
  }
  setvar VDISPLAYAPFLASHTIMER 28
  setvar VEHICLEAPDAMAGED? 0
 }
 ifvarl VDISPLAYAPFLASHTIMER 0 addvar VDISPLAYAPFLASHTIMER 1 else ifvarg VDISPLAYAPFLASHTIMER 0 subvar VDISPLAYAPFLASHTIMER 1
ends

//

//**********************************
//*DamageHazard Formulas and States*
//**********************************

state dmgflr-defensecheat
 ifvare DEFENSECHEAT 1 { divvar TEMPVAR 1000 ifvarl TEMPVAR 1 setvar TEMPVAR 1 state cheatersound }
ends

state checkplayerstatus_dmgfloor
              ifvarand PLAYERSTATUS? 512
              {
               randvar CALCVAR2 33
               setvar CALCVAR1 333               
               ifrnd 128 addvarvar CALCVAR1 CALCVAR2 else addvarvar CALCVAR1 CALCVAR2
               ifvarg CALCVAR1 1000 setvar CALCVAR1 1000
               setvar CALCVAR3 1000
               subvarvar CALCVAR3 CALCVAR1

               mulvarvar TEMPVAR CALCVAR3
               divvar TEMPVAR 1000
              }
              ifvarand PLAYERSTATUS? 4096
              {
               randvar CALCVAR2 25
               setvar CALCVAR1 250               
               ifrnd 128 addvarvar CALCVAR1 CALCVAR2 else addvarvar CALCVAR1 CALCVAR2
               ifvarg CALCVAR1 1000 setvar CALCVAR1 1000
               setvar CALCVAR3 1000
               subvarvar CALCVAR3 CALCVAR1

               mulvarvar TEMPVAR CALCVAR3
               divvar TEMPVAR 1000
              }
ends

state damagemod-tempvar
      ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
      mulvarvar tempe DAMAGEMODIFIER
      divvar tempe 1000
      ifvarl tempe 1 setvar tempe 1
      ifvarg tempe 2049152 setvar tempe 2049152
ends

state damagemod-dmgflr-general
      ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
      mulvarvar TEMPVAR DAMAGEMODIFIER
      divvar TEMPVAR 1000
      ifvarl TEMPVAR 1 setvar TEMPVAR 1
      ifvarg TEMPVAR 2049152 setvar TEMPVAR 2049152
ends

state dmgflr-steroids
   ifp ponsteroids
   {
    ifvare SKILLLEVEL 0 setvar TEMP3 99
    else
    {
     setvar TEMP3 10
     mulvarvar TEMP3 SKILLLEVEL
     mulvarvar TEMPVAR TEMP3
    }
    divvar TEMPVAR 100
    ifvarl TEMPVAR 1 setvar TEMPVAR 1
   }
ends

state check-heatratio-player2
  getactorvar[temph].FLOORHEATRATIO tempg
  mulvarvar TEMPVAR tempg
  divvar TEMPVAR 100
ends

state check-heatratio-player
  getactor[THISACTOR].sectnum temph
  getsector[temph].floorpicnum tempf
  ifvare tempf NEWFLOORPLASMA state check-heatratio-player2
  else ifvare tempf HOTLAVA state check-heatratio-player2
  else ifvare tempf MEGALAVA state check-heatratio-player2
  else ifvare tempf ULTRALAVA state check-heatratio-player2
  else ifvare tempf HYPERMAGMA state check-heatratio-player2
ends

state dmgfloor-pnulldamage
               ifvare CHARACTERSELECTED? 11
               {
                ifrnd 56
                {
                 redefinequote 321 ^20NULLED THE DAMAGE!!
                 ifrnd 128 { setvar TEMPVAR 0 sound NODAMAGE setvarvar fta fta_normal setvar ftq 321 } else { setvar TEMPVAR 1 }
                }
               }
ends

state dmgfloor-vehicleusage
              ifvarn VEHICLEID -1
              {
               ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3
               {
                divvar TEMPVAR 5
                ifvarg TEMPVAR 0
                {
                 getactor[VEHICLEID].extra TEMPVAR2
                 subvar TEMPVAR2 1 
                 ifvarl TEMPVAR2 0 setvar TEMPVAR2 0
                 setactor[VEHICLEID].extra TEMPVAR2
                 ifvarl TEMPVAR2 1 setactor[VEHICLEID].htextra 10
                }
               }
              }
ends

state player-newfloorslime_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          subvar BOOTSTIME 1
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 4
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          subvar TEMPVAR2 1
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-newfloorslime_dmg   // NEWFLOORSLIME [Atomic / Poison Elemental]
        ifvare VEHICLEID -1 // Not in a Vehicle...
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 1 mulvar TEMPVAR 1 addvar TEMPVAR 0 } // 1 dmg per tic (0.78125% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 3 mulvar TEMPVAR 1 addvar TEMPVAR 1 } // 1 to 4 dmg per tic (6.25% chance) [all other Characters]
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 setvar tempd 0
               ifvare SKILLLEVEL 3 setvar tempd 0
               ifvare SKILLLEVEL 4 setvar tempd 0
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 8 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
              }
              else setvar tempd 1
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************
              ifvare CHARACTERSELECTED? 2 subvar TEMPVAR 2
              else ifvare CHARACTERSELECTED? 3
              {
               ifvare BUBSYFORM? 1 divvar TEMPVAR 4
              }
              else
              ifvare CHARACTERSELECTED? 4
              {
               ifvare SECTORLOTAG 2 ifvare WATER? 2 divvar TEMPVAR 6
               ifvare SECTORLOTAG 1 ifvare WATER? 1 { mulvar TEMPVAR 2 divvar TEMPVAR 7 }

               ifvare AMIFORM? 0 { mulvar TEMPVAR 4 divvar TEMPVAR 3 } // 133% Damage
               else ifvare AMIFORM? 1 divvar TEMPVAR 2 // 50% Damage
               else ifvare AMIFORM? 2 divvar TEMPVAR 3 // 33% Damage
               ifvarand PLAYERSTATUS? 256
               {
                ifp pducking divvar TEMPVAR 25 else divvar TEMPVAR 5
               }
              }
              else ifvare CHARACTERSELECTED? 12 subvar TEMPVAR 1
              else ifvare CHARACTERSELECTED? 14 divvar TEMPVAR 10
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Atomic Support / Duke**
               state support-atomicresist

               //**Poison Support / Jack**
               state support-poisonresist

               state damagemod-dmgflr-general
              }

              //**********************************
              //*Support System [ESSence Support]*
              //**********************************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //**Overall Support / ESSence**
               state support-overallresist
               state damagemod-dmgflr-general         
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              ifvarg TEMPVAR 0 
              {
               ifvare CHARACTERSELECTED? 2 nullop
               else
               ifvare CHARACTERSELECTED? 3
               {
                ifvare BUBSYFORM? 1
                {
                 ifrnd 1 state addpoison
                }
               }
               else
               ifvare CHARACTERSELECTED? 8
               {
                ifvare HAVEENERGYSHIELD? 1
                {
	           ifvare ENERGYSHIELDMODE 1 
                 {
                  ifvarg DAMAGEINCELL 0 nullop
                  else
                  {
                   ifrnd 4 state addpoison
                  }
                 }
                 else
                 {
                  ifrnd 4 state addpoison
                 }
                }
                else
                {
                 ifrnd 4 state addpoison
                }
               }
               else
               ifvare CHARACTERSELECTED? 12
               {
                ifrnd 1 { ifrnd 128 state addpoison }
               }
               else
               ifvare CHARACTERSELECTED? 14
               {
                ifrnd 2 state addpoison
               }
               else
               ifvare CHARACTERSELECTED? 15
               {
                ifrnd 2 state addpoison
               }
               else
               {
                ifrnd 4 state addpoison
               }

              }
              state dmgfloor-pnulldamage
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr
              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-acidtype
              }              
         }
        }
        else // In a Vehicle...
        {
         ifrnd 4
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 2
              addvar TEMPVAR 1
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 setvar tempd 0
               ifvare SKILLLEVEL 3 setvar tempd 0
               ifvare SKILLLEVEL 4 setvar tempd 0
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 8 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
              }
              else setvar tempd 1
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // 1 to 3 dmg per tic (1.5625% chance)
              state dmgflr-defensecheat
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 16 0 8 0
         }
        }
ends

state player-newhurtrail_boots-nethra
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          subvar BOOTSTIME 1
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 8
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          subvar TEMPVAR2 1
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-newhurtrail_dmg-nethra
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          state getplayerhealthondmgflr
          randvar TEMPVAR 3
          mulvar TEMPVAR 1
          addvar TEMPVAR 1
          mulvar TEMPVAR -11
          divvar TEMPVAR 2
          subvarvar temp TEMPVAR
          ifvarvarg temp MAXHITPOINTSATOMIC setvarvar temp MAXHITPOINTSATOMIC
          ifvarvarg temp STATLIMITATOMIC setvarvar temp STATLIMITATOMIC
          state setplayerhealthondmgflr
          ifvarg TEMPVAR 0 palfrom 32 64 64 64
          setvar PLAYERHPDAMAGED? -1

          setvarvar TEMPHEALTH TEMPVAR
          mulvar TEMPHEALTH -1
          state showhealing_playerhp

          sound ABSORB_DAMAGE
          sound SHORT_CIRCUIT
         }
        }
        else
        {
         ifrnd 8
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          subvar TEMPVAR2 1
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-newhurtrail_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          subvar BOOTSTIME 1
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 8
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          subvar TEMPVAR2 1
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-newhurtrail_dmg   // NEWHURTRAIL [Atomic / Electric Elemental]
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 1 mulvar TEMPVAR 1 addvar TEMPVAR 0 } // 1 dmg per tic (1.5625% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 3 mulvar TEMPVAR 1 addvar TEMPVAR 1 } // 1 to 4 dmg per tic (12.5% chance) [all other Characters]
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 setvar tempd 0
               ifvare SKILLLEVEL 3 setvar tempd 0
               ifvare SKILLLEVEL 4 setvar tempd 0
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 8 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
              }
              else setvar tempd 1
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Character Modifiers*
              //*********************
              // 1 to 4 dmg per tic (12.5% chance)
              ifvare CHARACTERSELECTED? 10 
              { 
               ifvare NETHRAFORM? 0 // Nethra in Protector Drone form will absorb Electricity and heal :P
               {
                mulvar TEMPVAR -11
                divvar TEMPVAR 2
                subvarvar temp TEMPVAR
                ifvarvarg temp MAXHITPOINTSATOMIC setvarvar temp MAXHITPOINTSATOMIC
                ifvarvarg temp STATLIMITATOMIC setvarvar temp STATLIMITATOMIC

                setvarvar TEMPHEALTH TEMPVAR
                mulvar TEMPHEALTH -1
                state showhealing_playerhp

                setvar PLAYERHPDAMAGED? -1
                sound ABSORB_DAMAGE
                sound SHORT_CIRCUIT
               } 
               else // This is specfically for Nethra in Human form [Christina]. This code does not affect other characters or Nethra in Alien Form.
               {
                setvarvar TEMPDAMAGEVAR TEMPVAR
                state char_elecdamage_misc
                setvarvar TEMPVAR TEMPDAMAGEVAR
                ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

                //*********************
                //*Check Malakian Gems*
                //*********************
                setvarvar TEMP7 TEMPVAR
                state checkformalakiangem 
                setvarvar TEMPVAR TEMP7

                //********
                //*Others*
                //********
                state checkplayerstatus_dmgfloor
                ifvare SHRUNK? 1
                {
                 ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
                }
 
                //****************
                //*Support System*
                //****************
                ifvarg TEMPVAR 0
                {
                 setvar DAMAGEMODIFIER 1000
 
                 //**Atomic Support / Duke**
                 state support-atomicresist
 
                 //**Electric Support / Nethra**
                 state support-electricresist
 
                 state damagemod-dmgflr-general
                }
 
                //**********************************
                //*Support System [ESSence Support]*
                //**********************************
                ifvarg TEMPVAR 0
                {
                 setvar DAMAGEMODIFIER 1000
                 //**Overall Support / ESSence**
                 state support-overallresist
                 state damagemod-dmgflr-general         
                }

                //******************
                //*Equipment System*
                //******************
                ifvarg TEMPVAR 0
                {
                 setvar DAMAGEMODIFIER 1000
                 // Equipment Slot #1
                 ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                 // Equipment Slot #2
                 ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                 // Equipment Slot #3
                 ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                 // Equipment Slot #4
                 ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                 state damagemod-dmgflr-general
                }
 
                state dmgflr-defensecheat
                state dmgflr-steroids

                setvarvar TEMPDAMAGEVAR TEMPVAR
                state lisashield_misc
                setvarvar TEMPVAR TEMPDAMAGEVAR

                subvarvar temp TEMPVAR
               } 
              } 
              else // This is for damage to anyone who's not Nethra in her Human form [Christina]. This code will not affect Christina or Nethra
              {
               setvarvar TEMPDAMAGEVAR TEMPVAR
               state char_elecdamage_misc
               setvarvar TEMPVAR TEMPDAMAGEVAR

               //*********************
               //*Check Malakian Gems*
               //*********************
               setvarvar TEMP7 TEMPVAR
               state checkformalakiangem 
               setvarvar TEMPVAR TEMP7

               ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

               //********
               //*Others*
               //********
               state checkplayerstatus_dmgfloor
               ifvare SHRUNK? 1
               {
                ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
               }

               //****************
               //*Support System*
               //****************
               ifvarg TEMPVAR 0
               {
                setvar DAMAGEMODIFIER 1000

                //**Atomic Support / Duke**
                state support-atomicresist

                //**Electric Support / Nethra**
                state support-electricresist

                state damagemod-dmgflr-general
               }

               //******************
               //*Equipment System*
               //******************
               ifvarg TEMPVAR 0
               {
                setvar DAMAGEMODIFIER 1000
                // Equipment Slot #1
                ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                // Equipment Slot #2
                ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                // Equipment Slot #3
                ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                // Equipment Slot #4
                ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
                state damagemod-dmgflr-general
               }

               state dmgflr-defensecheat
               state dmgflr-steroids

               setvarvar TEMPDAMAGEVAR TEMPVAR
               state lisashield_misc
               setvarvar TEMPVAR TEMPDAMAGEVAR

               state dmgfloor-pnulldamage
               subvarvar temp TEMPVAR
              }

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               ifvare CHARACTERSELECTED? 10
               {
                ifvare NETHRAFORM? 0
                {
                 palfrom 32 64 64 64
                 sound ABSORB_DAMAGE
                }
                else
                {
                 setvarvar DAMAGEHUEFACTOR TEMPVAR
                 state playerdamagehues-electrictype
                }
               }
               else
               {
                setvarvar DAMAGEHUEFACTOR TEMPVAR
                state playerdamagehues-electrictype
               }
               sound SHORT_CIRCUIT
              }
         }
        }
        else
        {
         ifrnd 8
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 2
              addvar TEMPVAR 1
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 setvar tempd 0
               ifvare SKILLLEVEL 3 setvar tempd 0
               ifvare SKILLLEVEL 4 setvar tempd 0
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 8 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
              }
              else setvar tempd 1
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // 1 to 3 dmg per tic (1.5625% chance)
              state dmgflr-defensecheat
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               sound SHORT_CIRCUIT
               palfrom 16 64 64 64
              }
         }
        }
ends

state player-newfloorplasma_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          subvar BOOTSTIME 1
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 8
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          subvar TEMPVAR2 1
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-newfloorplasma_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 1 mulvar TEMPVAR 1 addvar TEMPVAR 0 } // 1 dmg per tic (1.5625% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 3 mulvar TEMPVAR 1 addvar TEMPVAR 1 } // 1 to 4 dmg per tic (12.5% chance) [all other Characters]
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 setvar tempd 0
               ifvare SKILLLEVEL 3 setvar tempd 0
               ifvare SKILLLEVEL 4 setvar tempd 0
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 8 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
              }
              else setvar tempd 1
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state char_firedamage_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }
              state check-heatratio-player

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Fire Support / Ted**
               state support-fireresist

               state damagemod-dmgflr-general
              }

              //**********************************
              //*Support System [ESSence Support]*
              //**********************************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //**Overall Support / ESSence**
               state support-overallresist
               state damagemod-dmgflr-general         
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               // Equipment Slot #1
               ifvare PLAYEREQUIPSLOTITEM1 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #2
               ifvare PLAYEREQUIPSLOTITEM2 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #3
               ifvare PLAYEREQUIPSLOTITEM3 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #4
               ifvare PLAYEREQUIPSLOTITEM4 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-firetype
              }              
         }
        }
        else
        {
         ifrnd 8
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 2
              addvar TEMPVAR 1
              setvarvar tempe TEMPVAR
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 setvar tempd 0
               ifvare SKILLLEVEL 3 setvar tempd 0
               ifvare SKILLLEVEL 4 setvar tempd 0
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 8 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 9 { randvar tempd 1 addvar tempd 1 }
              }
              else setvar tempd 1
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // 1 to 3 dmg per tic (3.125% chance)
              state check-heatratio-player
 
              state dmgflr-defensecheat
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 16 8 0 0
         }
        }
ends

state player-newpurplelava_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 0 // ifrnd 256 = (256 - 256 = 0)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 192 // ifrnd 256 = (256 - 64 = 192)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          subvar BOOTSTIME 1
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 64
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          subvar TEMPVAR2 1
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-newpurplelava_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 0 // ifrnd 256 = (256 - 256 = 0)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 192 // ifrnd 256 = (256 - 64 = 192)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
           //**********************************
           //*Support System [ESSence Support]*
           //**********************************
           setvar DAMAGEMODIFIER 1000
           //**Overall Support / ESSence**
           state support-overallresist

           ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
           randvar TEMPMOD 1000
           ifvarvarl TEMPMOD DAMAGEMODIFIER
           { // ifvarvarl TEMPMOD DAMAGEMODIFIER

            //****************
            //*Support System*
            //****************
            setvar DAMAGEMODIFIER 1000

            //**Atomic Support / Duke**
            state support-atomicresist

            //**Poison Support / Jack**
            state support-poisonresist

            ifvarl DAMAGEMODIFIER 0 setvar DAMAGEMODIFIER 0
            randvar TEMPMOD 1000
            ifvarvarl TEMPMOD DAMAGEMODIFIER
            { // ifvarvarl TEMPMOD DAMAGEMODIFIER
   
             state getplayerhealthondmgflr

             //*********************
             //*Character Modifiers*
             //*********************
             ifvare CHARACTERSELECTED? 14 
             {
              ifrnd 25
              {
               ifrnd 153 
               {
                setvar TEMPVAR 0
                addvar TEMPVAR 1
                setvarvar tempe MAXHITPOINTS
                ifvare DMGFLRTYPE 0
                {
                 ifvare SKILLLEVEL 0 setvar tempd 0
                 ifvare SKILLLEVEL 1 setvar tempd 0
                 ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
                 ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
                 ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 1 }
                 ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 1 }
                 ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 2 }
                 ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 2 }
                 ifvare SKILLLEVEL 8 { randvar tempd 2 addvar tempd 2 }
                 ifvare SKILLLEVEL 9 { randvar tempd 2 addvar tempd 2 }
                }
                else setvar tempd 2
                mulvarvar tempe tempd
                ifvare TEMPVAR5 1 divvar tempe 2250
                else divvar tempe 1000
                ifvarl tempe 1 setvar tempe 1
                addvarvar TEMPVAR tempe

                //*********************
                //*Check Malakian Gems*
                //*********************
                setvarvar TEMP7 TEMPVAR
                state checkformalakiangem 
                setvarvar TEMPVAR TEMP7

                ifrnd 6 state addpoison

                //********
                //*Others*
                //********
                state checkplayerstatus_dmgfloor
                ifvare SHRUNK? 1
                {
                 ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
                }

                state dmgflr-defensecheat
                state dmgflr-steroids

                setvarvar TEMPDAMAGEVAR TEMPVAR
                state lisashield_misc
                setvarvar TEMPVAR TEMPDAMAGEVAR

                subvarvar temp TEMPVAR
                state setplayerhealthondmgflr
                // 1 dmg per tic (100% chance)
                ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
                else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
                ifvarg TEMPVAR 0 
                {
                 setvarvar PAINSOUNDFACTOR TEMPVAR
                 state checkpainfactor
                 state characterpainsounds

                 setvarvar DAMAGEHUEFACTOR TEMPVAR
                 state playerdamagehues-acidtype
                }
               } 
              }
             }
             else
             {
              setvar TEMPVAR 0
              addvar TEMPVAR 1         
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
               ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 2 }
               ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 2 }
               ifvare SKILLLEVEL 8 { randvar tempd 2 addvar tempd 2 }
               ifvare SKILLLEVEL 9 { randvar tempd 2 addvar tempd 2 }
              }
              else setvar tempd 2
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              ifvarg TEMPVAR 0 
              {
               ifvare CHARACTERSELECTED? 2 nullop
               else ifvare CHARACTERSELECTED? 3
               {
                ifvare BUBSYFORM? 1
                {
                 ifrnd 64 setvar TEMPVAR 1 else setvar TEMPVAR 0
                 ifrnd 3 state addpoison
                }
                else
                {
                 ifrnd 12 state addpoison
                }
               }
               else ifvare CHARACTERSELECTED? 4
               {
                ifvare SECTORLOTAG 2 ifvare WATER? 2 divvar TEMPVAR 6
                ifvare SECTORLOTAG 1 ifvare WATER? 1 { mulvar TEMPVAR 2 divvar TEMPVAR 7 }

                ifvare AMIFORM? 0 { mulvar TEMPVAR 4 divvar TEMPVAR 3 } // 133% Damage
                else ifvare AMIFORM? 1 divvar TEMPVAR 2 // 50% Damage
                else ifvare AMIFORM? 2 divvar TEMPVAR 3 // 33% Damage
                ifvarand PLAYERSTATUS? 256
                {
                 ifp pducking divvar TEMPVAR 25 else divvar TEMPVAR 5
                 ifvarl TEMPVAR 1 { ifrnd 26 setvar TEMPVAR 1 else setvar TEMPVAR 0 }
                }
                ifrnd 12 state addpoison
               }
               else ifvare CHARACTERSELECTED? 8
               {
                ifvare HAVEENERGYSHIELD? 1
                {
	           ifvare ENERGYSHIELDMODE 1 
                 {
                  ifvarg DAMAGEINCELL 0 nullop // CURRENTCELLS
                  else
                  {
                   ifrnd 12 state addpoison
                  }
                 }
                 else
                 {
                  ifrnd 12 state addpoison
                 }
                }
                else
                {
                 ifrnd 12 state addpoison

                }
               }
               else ifvare CHARACTERSELECTED? 12
               {
                ifrnd 4 { ifrnd 128 state addpoison }
               }
               else ifvare CHARACTERSELECTED? 14 nullop
               else ifvare CHARACTERSELECTED? 15
               {
                ifrnd 6 state addpoison
               }
               else
               {
                ifrnd 12 state addpoison
               }

               //********
               //*Others*
               //********
               state checkplayerstatus_dmgfloor
               ifvare SHRUNK? 1
               {
                ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
               }

              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage
              subvarvar temp TEMPVAR
              state setplayerhealthondmgflr
              // 1 dmg per tic (100% chance)
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor

               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-acidtype
              }
             }
            } // ifvarvarl TEMPMOD DAMAGEMODIFIER
           } // ifvarvarl TEMPMOD DAMAGEMODIFIER
         }
        }
        else
        {
         ifrnd 64
         {
             getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
             state getplayerhealthondmgflr
             setvar TEMPVAR 0
             addvar TEMPVAR 1
             setvarvar tempe TEMPVAR4
             ifvare DMGFLRTYPE 0
             {
              ifvare SKILLLEVEL 0 setvar tempd 0
              ifvare SKILLLEVEL 1 setvar tempd 0
              ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 0 }
              ifvare SKILLLEVEL 3 { randvar tempd 1 addvar tempd 0 }
              ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 1 }
              ifvare SKILLLEVEL 5 { randvar tempd 1 addvar tempd 1 }
              ifvare SKILLLEVEL 6 { randvar tempd 1 addvar tempd 2 }
              ifvare SKILLLEVEL 7 { randvar tempd 1 addvar tempd 2 }
              ifvare SKILLLEVEL 8 { randvar tempd 2 addvar tempd 2 }
              ifvare SKILLLEVEL 9 { randvar tempd 2 addvar tempd 2 }
             }
             else setvar tempd 2
             mulvarvar tempe tempd
             ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
             ifvarl tempe 1 setvar tempe 1
             addvarvar TEMPVAR tempe

             //*********************
             //*Check Malakian Gems*
             //*********************
             setvarvar TEMP7 TEMPVAR
             state checkformalakiangem 
             setvarvar TEMPVAR TEMP7

             state dmgflr-defensecheat
             subvarvar temp TEMPVAR
             state setplayerhealthondmgflr

             // 1 dmg per tic (25% chance)
             ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
             else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
             state showdamage_player-dmgflr_bs
             state showdamage_player-dmgflr

             ifvarg TEMPVAR 0 palfrom 16 0 8 0 
         }
        }
ends

state player-hotlava_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 192 // ifrnd 64 = (256 - 64 = 192)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 248 // ifrnd 8 = (256 - 8 = 248)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 1
          addvar TEMPVAR 5
          subvarvar BOOTSTIME TEMPVAR
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 16
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 1
          addvar TEMPVAR 5
          subvarvar TEMPVAR2 TEMPVAR
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-hotlava_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 192 // ifrnd 64 = (256 - 64 = 192)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 248 // ifrnd 8 = (256 - 8 = 248)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 1 mulvar TEMPVAR 5 addvar TEMPVAR 2 } // (0.044~-1.2% + 2 to 7) dmg per tic (3.125% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 4 mulvar TEMPVAR 9 addvar TEMPVAR 9 } // (0.1-2.7% + 9 to 45) dmg per tic (25% chance) [all other Characters]
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 randvar tempd 1
               ifvare SKILLLEVEL 1 randvar tempd 1
               ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 2 }
               ifvare SKILLLEVEL 3 { randvar tempd 2 addvar tempd 1 }
               ifvare SKILLLEVEL 4 { randvar tempd 2 addvar tempd 2 }
               ifvare SKILLLEVEL 5 { randvar tempd 3 addvar tempd 3 }
               ifvare SKILLLEVEL 6 { randvar tempd 4 addvar tempd 4 }
               ifvare SKILLLEVEL 7 { randvar tempd 6 addvar tempd 6 }
               ifvare SKILLLEVEL 8 { randvar tempd 9 addvar tempd 9 }
               ifvare SKILLLEVEL 9 { randvar tempd 14 addvar tempd 13 }
              } else { randvar tempd 1 addvar tempd 13 }
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe             

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************
              setvarvar TEMPDAMAGEVAR TEMPVAR
              state char_firedamage_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }
              state check-heatratio-player

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Atomic Support / Duke**
               state support-atomicresist

               //**Fire Support / Ted**
               state support-fireresist

               state damagemod-dmgflr-general
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               // Equipment Slot #1
               ifvare PLAYEREQUIPSLOTITEM1 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #2
               ifvare PLAYEREQUIPSLOTITEM2 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #3
               ifvare PLAYEREQUIPSLOTITEM3 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #4
               ifvare PLAYEREQUIPSLOTITEM4 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-firetype
              } 
         }
        }
        else
        {
         ifrnd 16
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 3
              mulvar TEMPVAR 6
              addvar TEMPVAR 5
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 randvar tempd 1
               ifvare SKILLLEVEL 1 randvar tempd 1
               ifvare SKILLLEVEL 2 { randvar tempd 1 addvar tempd 2 }
               ifvare SKILLLEVEL 3 { randvar tempd 2 addvar tempd 1 }
               ifvare SKILLLEVEL 4 { randvar tempd 2 addvar tempd 2 }
               ifvare SKILLLEVEL 5 { randvar tempd 3 addvar tempd 3 }
               ifvare SKILLLEVEL 6 { randvar tempd 4 addvar tempd 4 }
               ifvare SKILLLEVEL 7 { randvar tempd 6 addvar tempd 6 }
               ifvare SKILLLEVEL 8 { randvar tempd 9 addvar tempd 9 }
               ifvare SKILLLEVEL 9 { randvar tempd 14 addvar tempd 13 }
              } else { randvar tempd 1 addvar tempd 13 }
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // 6 to 23+ dmg per tic (6.25% chance)
              state check-heatratio-player
              state dmgflr-defensecheat
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 16 24 0 0 
         }
        }
ends

state player-amoebaacid_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 216 // ifrnd 40 = (256 - 40 = 216)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 251 // ifrnd 5 = (256 - 5 = 251)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 1
          addvar TEMPVAR 2
          subvarvar BOOTSTIME TEMPVAR
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 10
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 1
          addvar TEMPVAR 2
          subvarvar TEMPVAR2 TEMPVAR
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-amoebaacid_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 216 // ifrnd 40 = (256 - 40 = 216)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 251 // ifrnd 5 = (256 - 5 = 251)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 1 mulvar TEMPVAR 2 addvar TEMPVAR 1 } // (0-0.057777~% + 1 to 3) dmg per tic (1.953125% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 4 mulvar TEMPVAR 4 addvar TEMPVAR 4 } // (0-0.13% + 4 to 20) Dmg per tic (15.625% chance)
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 randvar tempd 1
               ifvare SKILLLEVEL 3 randvar tempd 1
               ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 5 { randvar tempd 2 addvar tempd 1 }
               ifvare SKILLLEVEL 6 { randvar tempd 2 addvar tempd 2 }
               ifvare SKILLLEVEL 7 { randvar tempd 3 addvar tempd 3 }
               ifvare SKILLLEVEL 8 { randvar tempd 5 addvar tempd 4 }
               ifvare SKILLLEVEL 9 { randvar tempd 7 addvar tempd 6 }
              } else { randvar tempd 1 addvar tempd 6 }
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************
              ifvare CHARACTERSELECTED? 3
              {
               ifvare BUBSYFORM? 1 divvar TEMPVAR 4
              }
              ifvare CHARACTERSELECTED? 4
              {
               ifvarand PLAYERSTATUS? 256
               {
                ifp pducking divvar TEMPVAR 25 else divvar TEMPVAR 5
               }
              }
              ifvare CHARACTERSELECTED? 14 divvar TEMPVAR 10
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Atomic Support / Duke**
               state support-atomicresist

               //**Poison Support / Jack**
               state support-poisonresist

               state damagemod-dmgflr-general
              }

              //**********************************
              //*Support System [ESSence Support]*
              //**********************************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //**Overall Support / ESSence**
               state support-overallresist
               state damagemod-dmgflr-general         
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage

              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-acidtype
              }              
         }
        }
        else
        {
         ifrnd 10
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 3
              mulvar TEMPVAR 3
              addvar TEMPVAR 2
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 setvar tempd 0
               ifvare SKILLLEVEL 1 setvar tempd 0
               ifvare SKILLLEVEL 2 randvar tempd 1
               ifvare SKILLLEVEL 3 randvar tempd 1
               ifvare SKILLLEVEL 4 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 5 { randvar tempd 2 addvar tempd 1 }
               ifvare SKILLLEVEL 6 { randvar tempd 2 addvar tempd 2 }
               ifvare SKILLLEVEL 7 { randvar tempd 3 addvar tempd 3 }
               ifvare SKILLLEVEL 8 { randvar tempd 5 addvar tempd 4 }
               ifvare SKILLLEVEL 9 { randvar tempd 7 addvar tempd 6 }
              } else { randvar tempd 1 addvar tempd 6 }
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // (0-0.086~% + 3 to 11 Dmg per tic) (3.90625% chance)
              state dmgflr-defensecheat
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 16 0 24 0
         }
        }
ends

state player-megalava_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 160 // ifrnd 96 = (256 - 96 = 160)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 244 // ifrnd 12 = (256 - 12 = 244)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 2
          addvar TEMPVAR 7
          subvarvar BOOTSTIME TEMPVAR
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 24
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 2
          addvar TEMPVAR 7
          subvarvar TEMPVAR2 TEMPVAR
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-megalava_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 160 // ifrnd 96 = (256 - 96 = 160)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 244 // ifrnd 12 = (256 - 12 = 244)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 2 mulvar TEMPVAR 38 addvar TEMPVAR 20 } // (0-0.057777~% + 20 to 76) dmg per tic (1.953125% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 5 mulvar TEMPVAR 75 addvar TEMPVAR 75 } // (0.01-0.67% + 75 to 450) dmg per tic (37.5% chance)
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 1 { randvar tempd 2 addvar tempd 1 }
               ifvare SKILLLEVEL 2 { randvar tempd 3 addvar tempd 2 }
               ifvare SKILLLEVEL 3 { randvar tempd 4 addvar tempd 3 }
               ifvare SKILLLEVEL 4 { randvar tempd 5 addvar tempd 5 }
               ifvare SKILLLEVEL 5 { randvar tempd 8 addvar tempd 7 }
               ifvare SKILLLEVEL 6 { randvar tempd 10 addvar tempd 10 }
               ifvare SKILLLEVEL 7 { randvar tempd 15 addvar tempd 15 }
               ifvare SKILLLEVEL 8 { randvar tempd 23 addvar tempd 22 }
               ifvare SKILLLEVEL 9 { randvar tempd 34 addvar tempd 33 }
              } else { randvar tempd 1 addvar tempd 33 }
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************
              setvarvar TEMPDAMAGEVAR TEMPVAR
              state char_firedamage_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }
              state check-heatratio-player

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Atomic Support / Duke**
               state support-atomicresist

               //**Fire Support / Ted**
               state support-fireresist

               state damagemod-dmgflr-general
              }

              //**********************************
              //*Support System [ESSence Support]*
              //**********************************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //**Overall Support / ESSence**
               state support-overallresist
               state damagemod-dmgflr-general         
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               // Equipment Slot #1
               ifvare PLAYEREQUIPSLOTITEM1 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #2
               ifvare PLAYEREQUIPSLOTITEM2 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #3
               ifvare PLAYEREQUIPSLOTITEM3 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #4
               ifvare PLAYEREQUIPSLOTITEM4 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage

              subvarvar temp TEMPVAR
              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-firetype
              } 
         }
        }
        else
        {
         ifrnd 24
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 3
              mulvar TEMPVAR 50
              addvar TEMPVAR 42
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 { randvar tempd 1 addvar tempd 1 }
               ifvare SKILLLEVEL 1 { randvar tempd 2 addvar tempd 1 }
               ifvare SKILLLEVEL 2 { randvar tempd 3 addvar tempd 2 }
               ifvare SKILLLEVEL 3 { randvar tempd 4 addvar tempd 3 }
               ifvare SKILLLEVEL 4 { randvar tempd 5 addvar tempd 5 }
               ifvare SKILLLEVEL 5 { randvar tempd 8 addvar tempd 7 }
               ifvare SKILLLEVEL 6 { randvar tempd 10 addvar tempd 10 }
               ifvare SKILLLEVEL 7 { randvar tempd 15 addvar tempd 15 }
               ifvare SKILLLEVEL 8 { randvar tempd 23 addvar tempd 22 }
               ifvare SKILLLEVEL 9 { randvar tempd 34 addvar tempd 33 }
              } else { randvar tempd 1 addvar tempd 33 }
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // (0.006~-0.4466~% + 50 to 192) dmg per tic (9.375% chance)
              state check-heatratio-player
              state dmgflr-defensecheat

              subvarvar temp TEMPVAR
              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 16 36 0 0 
         }
        }
ends

state player-ultralava_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 128 // ifrnd 128 = (256 - 128 = 128)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 3
          addvar TEMPVAR 12
          subvarvar BOOTSTIME TEMPVAR
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 32
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 3
          addvar TEMPVAR 12
          subvarvar TEMPVAR2 TEMPVAR
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-ultralava_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 128 // ifrnd 128 = (256 - 128 = 128)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 2 mulvar TEMPVAR 120 addvar TEMPVAR 64 } // (? + 64 to 304) dmg per tic (6.25% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 5 mulvar TEMPVAR 240 addvar TEMPVAR 240 } // (0.5-27.0% + 240 to 1440) dmg per tic (50% chance)
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 { randvar tempd 5 addvar tempd 5 } // 0.5%-1.0%
               ifvare SKILLLEVEL 1 { randvar tempd 8 addvar tempd 7 } // 0.8%-1.5%
               ifvare SKILLLEVEL 2 { randvar tempd 10 addvar tempd 10 } // 1.0%-2.0%
               ifvare SKILLLEVEL 3 { randvar tempd 15 addvar tempd 15 } // 1.5%-3.0%
               ifvare SKILLLEVEL 4 { randvar tempd 20 addvar tempd 20 } // 2.0%-4.0%
               ifvare SKILLLEVEL 5 { randvar tempd 30 addvar tempd 30 } // 3.0%-6.0%
               ifvare SKILLLEVEL 6 { randvar tempd 40 addvar tempd 40 } // 4.0%-8.0%
               ifvare SKILLLEVEL 7 { randvar tempd 60 addvar tempd 60 } // 6.0%-12.0%
               ifvare SKILLLEVEL 8 { randvar tempd 90 addvar tempd 90 } // 9.0%-18.0%
               ifvare SKILLLEVEL 9 { randvar tempd 135 addvar tempd 135 } // 13.5%-27.0%
              } else setvar tempd 135
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************
              setvarvar TEMPDAMAGEVAR TEMPVAR
              state char_firedamage_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }
              state check-heatratio-player

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Atomic Support / Duke**
               state support-atomicresist

               //**Fire Support / Ted**
               state support-fireresist

               state damagemod-dmgflr-general
              }

              //**********************************
              //*Support System [ESSence Support]*
              //**********************************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //**Overall Support / ESSence**
               state support-overallresist
               state damagemod-dmgflr-general         
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               // Equipment Slot #1
               ifvare PLAYEREQUIPSLOTITEM1 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #2
               ifvare PLAYEREQUIPSLOTITEM2 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #3
               ifvare PLAYEREQUIPSLOTITEM3 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #4
               ifvare PLAYEREQUIPSLOTITEM4 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage

              subvarvar temp TEMPVAR
              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-firetype
              }
         }
        }
        else
        {
         ifrnd 32
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 3
              mulvar TEMPVAR 160
              addvar TEMPVAR 133
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 { randvar tempd 5 addvar tempd 5 } // 0.5%-1.0%
               ifvare SKILLLEVEL 1 { randvar tempd 8 addvar tempd 7 } // 0.8%-1.5%
               ifvare SKILLLEVEL 2 { randvar tempd 10 addvar tempd 10 } // 1.0%-2.0%
               ifvare SKILLLEVEL 3 { randvar tempd 15 addvar tempd 15 } // 1.5%-3.0%
               ifvare SKILLLEVEL 4 { randvar tempd 20 addvar tempd 20 } // 2.0%-4.0%
               ifvare SKILLLEVEL 5 { randvar tempd 30 addvar tempd 30 } // 3.0%-6.0%
               ifvare SKILLLEVEL 6 { randvar tempd 40 addvar tempd 40 } // 4.0%-8.0%
               ifvare SKILLLEVEL 7 { randvar tempd 60 addvar tempd 60 } // 6.0%-12.0%
               ifvare SKILLLEVEL 8 { randvar tempd 90 addvar tempd 90 } // 9.0%-18.0%
               ifvare SKILLLEVEL 9 { randvar tempd 135 addvar tempd 135 } // 13.5%-27.0%
              } else setvar tempd 135
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // (0.333~-18.0% + 160 to 613) dmg per tic (12.5% chance)
              state check-heatratio-player
              state dmgflr-defensecheat

              subvarvar temp TEMPVAR
              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 16 48 0 0 
         }
        }
ends

state player-hypermagma_boots
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 32 // ifrnd 224 = (256 - 224 = 32)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 228 // ifrnd 28 = (256 - 28 = 228)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 6
          addvar TEMPVAR 28
          subvarvar BOOTSTIME TEMPVAR
          state playercheckboots
          setplayer[THISACTOR].boot_amount BOOTSTIME
         }
        }
        else
        {
         ifrnd 56
         {
          getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
          setvarvar fta fta_normal setvar ftq 75
          randvar TEMPVAR 6
          addvar TEMPVAR 28
          subvarvar TEMPVAR2 TEMPVAR
          state playercheckboots
          setactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
         }
        }
ends

state player-hypermagma_dmg
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
         else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
         else setvar TEMPVAR5 0
         ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 32 // ifrnd 224 = (256 - 224 = 32)
         else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 228 // ifrnd 28 = (256 - 28 = 228)
         state rndmizer256
         ifvarvarg RNDMIZER RNDMIZERLIMIT
         {
              state getplayerhealthondmgflr
              ifvare TEMPVAR5 1 { randvar TEMPVAR 3 mulvar TEMPVAR 400 addvar TEMPVAR 214 } // (? + 214 to 1414) dmg per tic (6.25% chance) [for ESSence/Cybanis]
              else { randvar TEMPVAR 6 mulvar TEMPVAR 800 addvar TEMPVAR 800 } // (2.0-108.0% + 800 to 5600) dmg per tic (87.5% chance)
              setvarvar tempe MAXHITPOINTS
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 { randvar tempd 20 addvar tempd 20 } // 2.0%-4.0%
               ifvare SKILLLEVEL 1 { randvar tempd 32 addvar tempd 32 } // 3.2%-6.4%
               ifvare SKILLLEVEL 2 { randvar tempd 40 addvar tempd 40 } // 4.0%-8.0%
               ifvare SKILLLEVEL 3 { randvar tempd 60 addvar tempd 60 } // 6.0%-12.0%
               ifvare SKILLLEVEL 4 { randvar tempd 80 addvar tempd 80 } // 8.0%-16.0%
               ifvare SKILLLEVEL 5 { randvar tempd 120 addvar tempd 120 } // 12.0%-24.0%
               ifvare SKILLLEVEL 6 { randvar tempd 160 addvar tempd 160 } // 16.0%-32.0%
               ifvare SKILLLEVEL 7 { randvar tempd 240 addvar tempd 240 } // 24.0%-48.0%
               ifvare SKILLLEVEL 8 { randvar tempd 360 addvar tempd 360 } // 36.0%-72.0%
               ifvare SKILLLEVEL 9 { randvar tempd 540 addvar tempd 540 } // 54.0%-108.0%
              } else setvar tempd 540
              mulvarvar tempe tempd
              ifvare TEMPVAR5 1 divvar tempe 2250
              else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              //*********************
              //*Character Modifiers*
              //*********************
              setvarvar TEMPDAMAGEVAR TEMPVAR
              state char_firedamage_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR
              ifvarl TEMPVAR 1 { ifrnd 128 setvar TEMPVAR 1 else setvar TEMPVAR 0 }

              //********
              //*Others*
              //********
              state checkplayerstatus_dmgfloor
              ifvare SHRUNK? 1
              {
               ifrnd 128 mulvar TEMPVAR 5 else mulvar TEMPVAR 4
              }
              state check-heatratio-player

              //****************
              //*Support System*
              //****************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000

               //**Atomic Support / Duke**
               state support-atomicresist

               //**Fire Support / Ted**
               state support-fireresist

               state damagemod-dmgflr-general
              }

              //**********************************
              //*Support System [ESSence Support]*
              //**********************************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               //**Overall Support / ESSence**
               state support-overallresist
               state damagemod-dmgflr-general         
              }

              //******************
              //*Equipment System*
              //******************
              ifvarg TEMPVAR 0
              {
               setvar DAMAGEMODIFIER 1000
               // Equipment Slot #1
               ifvare PLAYEREQUIPSLOTITEM1 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #2
               ifvare PLAYEREQUIPSLOTITEM2 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #3
               ifvare PLAYEREQUIPSLOTITEM3 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               // Equipment Slot #4
               ifvare PLAYEREQUIPSLOTITEM4 1 addvar DAMAGEMODIFIER -225 // Sun Ring
               state damagemod-dmgflr-general
              }

              state dmgflr-defensecheat
              state dmgflr-steroids

              setvarvar TEMPDAMAGEVAR TEMPVAR
              state lisashield_misc
              setvarvar TEMPVAR TEMPDAMAGEVAR

              state dmgfloor-pnulldamage

              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar PLAYERHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar PLAYERHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 
              {
               setvarvar PAINSOUNDFACTOR TEMPVAR
               state checkpainfactor
               state characterpainsounds

               setvarvar DAMAGEHUEFACTOR TEMPVAR
               state playerdamagehues-firetype
              }
         }
        }
        else
        {
         ifrnd 56
         {
              getactorvar[VEHICLEID].ENEMYMAXHP TEMPVAR4
              state getplayerhealthondmgflr
              randvar TEMPVAR 4
              mulvar TEMPVAR 533
              addvar TEMPVAR 443
              setvarvar tempe TEMPVAR4
              ifvare DMGFLRTYPE 0
              {
               ifvare SKILLLEVEL 0 { randvar tempd 20 addvar tempd 20 } // 2.0%-4.0%
               ifvare SKILLLEVEL 1 { randvar tempd 32 addvar tempd 32 } // 3.2%-6.4%
               ifvare SKILLLEVEL 2 { randvar tempd 40 addvar tempd 40 } // 4.0%-8.0%
               ifvare SKILLLEVEL 3 { randvar tempd 60 addvar tempd 60 } // 6.0%-12.0%
               ifvare SKILLLEVEL 4 { randvar tempd 80 addvar tempd 80 } // 8.0%-16.0%
               ifvare SKILLLEVEL 5 { randvar tempd 120 addvar tempd 120 } // 12.0%-24.0%
               ifvare SKILLLEVEL 6 { randvar tempd 160 addvar tempd 160 } // 16.0%-32.0%
               ifvare SKILLLEVEL 7 { randvar tempd 240 addvar tempd 240 } // 24.0%-48.0%
               ifvare SKILLLEVEL 8 { randvar tempd 360 addvar tempd 360 } // 36.0%-72.0%
               ifvare SKILLLEVEL 9 { randvar tempd 540 addvar tempd 540 } // 54.0%-108.0%
              } else setvar tempd 540
              mulvarvar tempe tempd
              ifvarg VEHICLETYPE -1 ifvarl VEHICLETYPE 3 divvar tempe 1500 else divvar tempe 1000
              ifvarl tempe 1 setvar tempe 1
              addvarvar TEMPVAR tempe

              //*********************
              //*Check Malakian Gems*
              //*********************
              setvarvar TEMP7 TEMPVAR
              state checkformalakiangem 
              setvarvar TEMPVAR TEMP7

              // (1.33~-72.0% + 533 to 2575) dmg per tic (21.875% chance)
              state check-heatratio-player
              state dmgflr-defensecheat
              subvarvar temp TEMPVAR

              state setplayerhealthondmgflr
              ifvarl TEMPVAR 0 setvar VEHICLEHPDAMAGED? -1
              else ifvarg TEMPVAR 0 setvar VEHICLEHPDAMAGED? 1
              state showdamage_player-dmgflr_bs
              state showdamage_player-dmgflr

              ifvarg TEMPVAR 0 palfrom 32 48 0 0 
         }
        }
ends

state player-dmgdisplaypart1
               setvar ATTACKINGACTORPAL 0
               setvarvar PLAYERDAMAGETEMP TEMPVAR
               setactor[THISACTOR].htpicnum -1
               ifvare VEHICLEID -1 setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
               ifvarg TEMPVAR 0 setvar HEALTHDAMAGETIMER 0
               setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 0
ends

state player-dmgdisplayceiling              
              ifvarg TEMPVAR 0
              {
               setvarvar ATTACKINGACTORPICNUM PLAYERCEILINGTILE
               state player-dmgdisplaypart1
              }
              else
              ifvarg CELLDAMAGETEMP 0
              {
               setvarvar ATTACKINGACTORPICNUM PLAYERCEILINGTILE
               state player-dmgdisplaypart1
              }
ends

state player-dmgdisplayfloor
              ifvarg TEMPVAR 0
              {
               setvarvar ATTACKINGACTORPICNUM PLAYERFLOORTILE
               state player-dmgdisplaypart1
              }
              else
              ifvarg CELLDAMAGETEMP 0
              {
               setvarvar ATTACKINGACTORPICNUM PLAYERFLOORTILE
               state player-dmgdisplaypart1
              }
ends

state player-dmgdisplaytileemul
              ifvarg TEMPVAR 0
              {
               setvarvar ATTACKINGACTORPICNUM TILEEMULATION
               state player-dmgdisplaypart1
              }
              else
              ifvarg CELLDAMAGETEMP 0
              {
               setvarvar ATTACKINGACTORPICNUM TILEEMULATION
               state player-dmgdisplaypart1
              }
ends

//
//
//

state player_do_floorslime_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorslime_boots
       else
       {
        state player-newfloorslime_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_floorslime_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorslime_boots
       else
       {
        state player-newfloorslime_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_floorslime_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorslime_boots
       else
       {
        state player-newfloorslime_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_floorslime_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorslime_boots
       else
       {
        state player-newfloorslime_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_floorslime_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 254 // ifrnd 2 = (256 - 2 = 254)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 4
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_hurtrail_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0
       {
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 10
         {
          ifvare NETHRAFORM? 0
          {
           setvar CEILINGDAMAGETYPE? 0
           state player-newhurtrail_dmg-nethra
          }
          else state player-newhurtrail_boots-nethra
         }
         else state player-newhurtrail_boots
        }
        else state player-newhurtrail_boots
       }
       else
       {
        state player-newhurtrail_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_hurtrail_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0
       {
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 10
         {
          ifvare NETHRAFORM? 0
          {
           setvar FLOORDAMAGETYPE? 0
           state player-newhurtrail_dmg-nethra
          }
          else state player-newhurtrail_boots-nethra
         }
         else state player-newhurtrail_boots
        }
        else state player-newhurtrail_boots
       }
       else
       {
        state player-newhurtrail_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_hurtrail_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0
       {
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 10
         {
          ifvare NETHRAFORM? 0
          {
           setvar EMUCEILINGDAMAGETYPE? 0
           state player-newhurtrail_dmg-nethra
          }
          else state player-newhurtrail_boots-nethra
         }
         else state player-newhurtrail_boots
        }
        else state player-newhurtrail_boots
       }
       else
       {
        state player-newhurtrail_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_hurtrail_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0
       {
        ifvare VEHICLEID -1
        {
         ifvare CHARACTERSELECTED? 10
         {
          ifvare NETHRAFORM? 0
          {
           setvar EMUFLOORDAMAGETYPE? 0
           state player-newhurtrail_dmg-nethra
          }
          else state player-newhurtrail_boots-nethra
         }
         else state player-newhurtrail_boots
        }
        else state player-newhurtrail_boots
       }
       else
       {
        state player-newhurtrail_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_hurtrail_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 8
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_floorplasma_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorplasma_boots
       else
       {
        state player-newfloorplasma_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_floorplasma_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorplasma_boots
       else
       {
        state player-newfloorplasma_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_floorplasma_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorplasma_boots
       else
       {
        state player-newfloorplasma_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_floorplasma_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-newfloorplasma_boots
       else
       {
        state player-newfloorplasma_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_floorplasma_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 252 // ifrnd 4 = (256 - 4 = 252)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 8
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_purplelava_checks1_c
        ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
        ifvarg TEMPVAR2 0 state player-newpurplelava_boots
        else
        {
         state player-newpurplelava_dmg
         state player-dmgdisplayceiling
         setvar TEMPVAR 0
        }
ends

state player_do_purplelava_checks1_f
        ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
        ifvarg TEMPVAR2 0 state player-newpurplelava_boots
        else
        {
         state player-newpurplelava_dmg
         state player-dmgdisplayfloor
         setvar TEMPVAR 0
        }
ends

state player_do_purplelava_checks1_ec
        ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
        ifvarg TEMPVAR2 0 state player-newpurplelava_boots
        else
        {
         state player-newpurplelava_dmg
         state player-dmgdisplaytileemul
         setvar TEMPVAR 0
        }
ends

state player_do_purplelava_checks1_ef
        ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
        ifvarg TEMPVAR2 0 state player-newpurplelava_boots
        else
        {
         state player-newpurplelava_dmg
         state player-dmgdisplaytileemul
         setvar TEMPVAR 0
        }
ends

state player_do_purplelava_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 0 // ifrnd 256 = (256 - 256 = 0)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 224 // ifrnd 32 = (256 - 32 = 224)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 64
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_hotlava_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hotlava_boots
       else
       {
        state player-hotlava_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_hotlava_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hotlava_boots
       else
       {
        state player-hotlava_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_hotlava_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hotlava_boots
       else
       {
        state player-hotlava_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_hotlava_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hotlava_boots
       else
       {
        state player-hotlava_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_hotlava_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 192 // ifrnd 64 = (256 - 64 = 192)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 248 // ifrnd 8 = (256 - 8 = 248)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 16
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_amoebaacid_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-amoebaacid_boots
       else
       {
        state player-amoebaacid_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_amoebaacid_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-amoebaacid_boots
       else
       {
        state player-amoebaacid_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_amoebaacid_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-amoebaacid_boots
       else
       {
        state player-amoebaacid_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_amoebaacid_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-amoebaacid_boots
       else
       {
        state player-amoebaacid_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_amoebaacid_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 216 // ifrnd 40 = (256 - 40 = 216)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 251 // ifrnd 5 = (256 - 5 = 251)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 10
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_megalava_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-megalava_boots
       else
       {
        state player-megalava_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_megalava_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-megalava_boots
       else
       {
        state player-megalava_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_megalava_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-megalava_boots
       else
       {
        state player-megalava_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_megalava_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-megalava_boots
       else
       {
        state player-megalava_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_megalava_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 160 // ifrnd 96 = (256 - 96 = 160)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 244 // ifrnd 12 = (256 - 12 = 244)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 24
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_ultralava_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-ultralava_boots
       else
       {
        state player-ultralava_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_ultralava_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-ultralava_boots
       else
       {
        state player-ultralava_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_ultralava_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-ultralava_boots
       else
       {
        state player-ultralava_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_ultralava_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-ultralava_boots
       else
       {
        state player-ultralava_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_ultralava_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 128 // ifrnd 128 = (256 - 128 = 128)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 240 // ifrnd 16 = (256 - 16 = 240)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 32
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

state player_do_hypermagma_checks1_c
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hypermagma_boots
       else
       {
        state player-hypermagma_dmg
        state player-dmgdisplayceiling
       }
ends

state player_do_hypermagma_checks1_f
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hypermagma_boots
       else
       {
        state player-hypermagma_dmg
        state player-dmgdisplayfloor
       }
ends

state player_do_hypermagma_checks1_ec
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hypermagma_boots
       else
       {
        state player-hypermagma_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_hypermagma_checks1_ef
       ifvare VEHICLEID -1 setvarvar TEMPVAR2 BOOTSTIME else getactorvar[VEHICLEID].ENEMYBOOTSAMOUNT TEMPVAR2
       ifvarg TEMPVAR2 0 state player-hypermagma_boots
       else
       {
        state player-hypermagma_dmg
        state player-dmgdisplaytileemul
       }
ends

state player_do_hypermagma_checks2
       ifvare VEHICLEID -1
       {
        ifvare CHARACTERSELECTED? 6 setvar TEMPVAR5 1
        else ifvare CHARACTERSELECTED? 9 setvar TEMPVAR5 1
        else setvar TEMPVAR5 0
        ifvare TEMPVAR5 0 setvar RNDMIZERLIMIT 32 // ifrnd 224 = (256 - 224 = 32)
        else ifvare TEMPVAR5 1 setvar RNDMIZERLIMIT 228 // ifrnd 28 = (256 - 28 = 228)
        state rndmizer256
        ifvarvarg RNDMIZER RNDMIZERLIMIT
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
       else
       {
        ifrnd 56
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       }
ends

//*****************************************
//*End of DamageHazard Formulas and States*
//*****************************************

state checkmoneyforbooby
 ifvarn MONEYID -1
 {
  getactor[MONEYID].picnum TEMPVAR
  ifvare TEMPVAR MONEYBAG
  {
   getactorvar[MONEYID].TEMP4 TEMPVAR
   ifvarg TEMPVAR 0 setvar MONEYID -1
   else setvar MONEYRIGGED 0
  }
  else
  {
   getactorvar[MONEYID].ACTORFLAGS TEMPVAR
   ifvarand TEMPVAR 16384 setvar MONEYID -1 // Set to NOT appear on radar
   else
   {
    ifvarand TEMPVAR 4096 setvar MONEYRIGGED 1
    else ifvarand TEMPVAR 8192 setvar MONEYID -1
    else setvar MONEYRIGGED 0
   }
  }
 }
ends

// Money-Detector
state moneyfinder
addvar MONEYRTIME 1
ifvarg MONEYRTIME 3 // 6
{
 setvar MONEYRTIME 0

 // Will Search for Highest Denominations first and Smallest ones last

 // Very Short Range - 2048 Units
 findnearsprite ONEBILLIONDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEMILLIONDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDTHOUSANDDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENTHOUSANDDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVETHOUSANDDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONETHOUSANDDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEHUNDREDDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite EIGHTYDOLLARBUNDLE 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIFTYDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWENTYDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARBUNDLE 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NINEDOLLARBUNDLE 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARBUNDLE 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARBUNDLE 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEDOLLAR 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite SACDOLLAR 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite HALFDOLLAR 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite QUARTER 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite DIME 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NICKEL 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite PENNY 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite MONEYBAG 2048 MONEYID state checkmoneyforbooby
 // Short Range - 4096 Units
 ifvare MONEYID -1 findnearsprite ONEBILLIONDOLLARS 2048 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEBILLIONDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEMILLIONDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDTHOUSANDDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENTHOUSANDDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVETHOUSANDDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONETHOUSANDDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEHUNDREDDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite EIGHTYDOLLARBUNDLE 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIFTYDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWENTYDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARBUNDLE 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NINEDOLLARBUNDLE 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARBUNDLE 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARBUNDLE 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARS 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEDOLLAR 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite SACDOLLAR 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite HALFDOLLAR 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite QUARTER 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite DIME 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NICKEL 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite PENNY 4096 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite MONEYBAG 4096 MONEYID state checkmoneyforbooby
 // Short-Medium Range - 8192 Units
 ifvare MONEYID -1 findnearsprite ONEBILLIONDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEMILLIONDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDTHOUSANDDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENTHOUSANDDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVETHOUSANDDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONETHOUSANDDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEHUNDREDDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite EIGHTYDOLLARBUNDLE 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIFTYDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWENTYDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARBUNDLE 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NINEDOLLARBUNDLE 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARBUNDLE 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARBUNDLE 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARS 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEDOLLAR 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite SACDOLLAR 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite HALFDOLLAR 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite QUARTER 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite DIME 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NICKEL 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite PENNY 8192 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite MONEYBAG 8192 MONEYID state checkmoneyforbooby
 // Medium-Long Range - 16384 Units
 ifvare MONEYID -1 findnearsprite ONEBILLIONDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEMILLIONDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDTHOUSANDDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENTHOUSANDDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVETHOUSANDDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONETHOUSANDDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEHUNDREDDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite EIGHTYDOLLARBUNDLE 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIFTYDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWENTYDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARBUNDLE 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NINEDOLLARBUNDLE 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARBUNDLE 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARBUNDLE 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARS 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEDOLLAR 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite SACDOLLAR 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite HALFDOLLAR 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite QUARTER 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite DIME 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NICKEL 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite PENNY 16384 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite MONEYBAG 16384 MONEYID state checkmoneyforbooby
 // Long Range - 32768 Units
 ifvare MONEYID -1 findnearsprite ONEBILLIONDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEMILLIONDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDTHOUSANDDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENTHOUSANDDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVETHOUSANDDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONETHOUSANDDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEHUNDREDDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEHUNDREDDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite EIGHTYDOLLARBUNDLE 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIFTYDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWENTYDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARBUNDLE 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TENDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NINEDOLLARBUNDLE 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARBUNDLE 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite FIVEDOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARBUNDLE 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite TWODOLLARS 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite ONEDOLLAR 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite SACDOLLAR 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite HALFDOLLAR 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite QUARTER 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite DIME 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite NICKEL 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite PENNY 32768 MONEYID state checkmoneyforbooby
 ifvare MONEYID -1 findnearsprite MONEYBAG 32768 MONEYID state checkmoneyforbooby

 ifvare MONEYID -1
 {
  setvar MONEYANG -1 
  break
 }
 else
 {
  canseespr MONEYID THISACTOR MONEYSEE

  getactor[MONEYID].x MONEYX
  getplayer[THISACTOR].posx x
  subvarvar MONEYX x

  getactor[MONEYID].y MONEYY
  getplayer[THISACTOR].posy y
  subvarvar MONEYY y

  getangle MONEYANG MONEYX MONEYY
  getplayer[THISACTOR].ang tempb
  subvarvar MONEYANG tempb
  addvar MONEYANG 1024

  ldist MONEYDIST THISACTOR MONEYID
  setvar temp 32768
  subvarvar temp MONEYDIST
  ifvarl temp 6144 setvar temp 6144
  setvarvar MONEYDIST temp
 }
}
ends

state charchecktriadrefractor
 getactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 ifvarand TEMPVAR 32
 {
  subvar TEMPVAR 32
  setactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 }
ends

state charchecktriadragnarok
 getactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 ifvarand TEMPVAR 64
 {
  subvar TEMPVAR 64
  setactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 }
ends

state charcheckaquaprotection
 getactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 ifvarand TEMPVAR 256
 {
  subvar TEMPVAR 256
  setactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 }
ends

state charchecktriadblitzkrieg
 getactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 ifvarand TEMPVAR 2048
 {
  subvar TEMPVAR 2048
  setactorvar[CHARACTERARRAY].CHARACTERSTATUS? TEMPVAR
 }
ends

state setmoneyflags
  ifvarg tempe 0 { addlogvar tempe killit } // for if a money item is "assimilated" into a nearby moneybag
  ifvare SKILLSET? 0
  {
   ifspritepal 0 
   {
    cstat 32
    getactor[THISACTOR].x RANDOMSPAWNX
    getactor[THISACTOR].y RANDOMSPAWNY
    randvar RANDOMMOVEMENT 64  // Determines the x range
    ifrnd 128 addvarvar RANDOMSPAWNX RANDOMMOVEMENT else subvarvar RANDOMSPAWNX RANDOMMOVEMENT
    setactor[THISACTOR].x RANDOMSPAWNX
    randvar RANDOMMOVEMENT 64  // Determines the y range
    ifrnd 128 addvarvar RANDOMSPAWNY RANDOMMOVEMENT else subvarvar RANDOMSPAWNY RANDOMMOVEMENT
    setactor[THISACTOR].y RANDOMSPAWNY
    randvar RANDOMSPAWNANGLE 2047 // Determines the facing angle
    setactor[THISACTOR].ang RANDOMSPAWNANGLE
   }
   else 
   ifspritepal 3 cstat 32
   else cstat 16

   sizeat 1 1
   getactor[THISACTOR].cstat TEMP
   ifvarand TEMP 1 subvar TEMP 1
   ifvarand TEMP 256 subvar TEMP 256
   ifvarand TEMP 1024 nullop else addvar TEMP 1024
   setactor[THISACTOR].cstat TEMP

   setvar SKILLSET? 1
  }
ends

state bonusitemvarience
           setvarvar ITEMSEEKC temp
           ifvare PUBLICBETA? 0 divvar ITEMSEEKC 500 else divvar ITEMSEEKC 200
           ifspritepal 3 mulvar ITEMSEEKC 4
           ifspritepal 9 mulvar ITEMSEEKC 9
           setvarvar tempc temp
           ifvare PUBLICBETA? 0 divvar tempc 1000 else divvar tempc 400
           ifspritepal 3 mulvar tempc 4
           ifspritepal 9 mulvar tempc 9
           randvarvar tempb tempc
           ifrnd 128 addvarvar ITEMSEEKC tempb else subvarvar ITEMSEEKC tempb
           getactorvar[ITEMSEEK].ENEMYLEVEL TEMP
           ifvarg TEMP 25 ifvarl TEMP 51 { mulvar ITEMSEEKC 3 divvar ITEMSEEKC 2 } 
           ifvarg TEMP 50 ifvarl TEMP 76 { mulvar ITEMSEEKC 4 divvar ITEMSEEKC 2 } 
           ifvarg TEMP 75 ifvarl TEMP 101 { mulvar ITEMSEEKC 5 divvar ITEMSEEKC 2 } 

           ifspritepal 9 { ifvarl ITEMSEEKC 9 setvar ITEMSEEKC 9 }
           else ifspritepal 3 { ifvarl ITEMSEEKC 4 setvar ITEMSEEKC 4 }
           else ifvarl ITEMSEEKC 1 setvar ITEMSEEKC 1
           ifvarand ACTORFLAGS 128 mulvar ITEMSEEKC 2
           ifvarand ACTORFLAGS 256 mulvar ITEMSEEKC 4
           addvarvar temp ITEMSEEKC
ends

state bonusgrabactor
   ifvarand ACTORFLAGS 4 nullop
   else
   {
    globalsound STATBONUSGRAB
   }
ends

state maxhpapbonusgive2
          getactorvar[ITEMSEEK].ENEMYMAXHP temp
          ifvarg ITEMSEEKB 0
          {
           ifvarvarl temp STATLIMIT
           {
            state bonusitemvarience
            addvarvar ITEMSEEKB ITEMSEEKC
            ifvarvarg ITEMSEEKB STATLIMITMAXIMUM setvarvar ITEMSEEKB STATLIMITMAXIMUM
            ifvarvarg temp STATLIMIT setvarvar temp STATLIMIT
            setactorvar[ITEMSEEK].ENEMYMAXHP temp
            state showhealing_actorhp
           }
           setactorvar[ITEMSEEK].ENEMYHP ITEMSEEKB

           getactorvar[ITEMSEEK].ENEMYAP TEMPVAR3
           getactorvar[ITEMSEEK].ENEMYMAXAP temp
           ifvarvarl temp STATLIMIT
           {
            state bonusitemvarience
            ifvarg TEMPVAR3 0 addvarvar TEMPVAR3 ITEMSEEKC
            ifvarvarg TEMPVAR3 STATLIMITMAXIMUM setvarvar TEMPVAR3 STATLIMITMAXIMUM
            ifvarvarg temp STATLIMIT setvarvar temp STATLIMIT
            setactorvar[ITEMSEEK].ENEMYMAXAP temp
            ifvarg TEMPVAR3 0 state showhealing_actorap
           }          
           setactorvar[ITEMSEEK].ENEMYAP TEMPVAR3
           state resetitemtarget
           state bonusgrabactor

           state getitemseekerspecies
           ifvarand ACTORFLAGS 4 nullop
           else
           {
            ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT A MAX HP/AP BONUS! :(
            ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT A MAX HP/AP BONUS! :O
           }
           state enemygrabitemflash
           setvar WORLDTILESHUFFLES 0
           state getworldtile
          }
ends

state atkdefbonusgive2
          ifvarg ITEMSEEKB 0
          {
           getactorvar[ITEMSEEK].ACTORATTACK temp
           ifvarvarl temp STATLIMIT
           {
            state bonusitemvarience
            setactorvar[ITEMSEEK].ACTORATTACK temp
            state resetitemtarget
            state bonusgrabactor
           }
 
           getactorvar[ITEMSEEK].ACTORDEFENSE temp
           ifvarvarl temp STATLIMIT
           {
            state bonusitemvarience
            setactorvar[ITEMSEEK].ACTORDEFENSE temp
            state resetitemtarget
            state bonusgrabactor
           }
 
           state getitemseekerspecies
           ifvarand ACTORFLAGS 4 nullop
           else
           {
            ifvare ITEMSEEKSPECIESTYPE 0 redefinequote 185 ^10AN ENEMY GOT AN ATK/DEF BONUS! :(
            ifvare ITEMSEEKSPECIESTYPE 1 redefinequote 185 ^15A CIVILIAN GOT AN ATK/DEF BONUS! :O
           }
           state enemygrabitemflash
           setvar WORLDTILESHUFFLES 0
           state getworldtile
          }
ends

state hyperatomsetcharacter
	          getactorvar[CHARACTERARRAY].CHARACTERHP temp
                ifvarg temp 0
                {
                 setactorvar[CHARACTERARRAY].CHARACTERAPABSORB 1000
                 getactorvar[CHARACTERARRAY].CHARACTERMAXHP TEMPVAR
                 mulvar TEMPVAR 2
                 ifvarvarg TEMPVAR STATLIMITATOMIC setvarvar TEMPVAR STATLIMITATOMIC
                 setactorvar[CHARACTERARRAY].CHARACTERHP TEMPVAR
                 getactorvar[CHARACTERARRAY].CHARACTERMAXAP TEMPVAR
                 mulvar TEMPVAR 2
                 ifvarvarg TEMPVAR STATLIMITATOMIC setvarvar TEMPVAR STATLIMITATOMIC
                 setactorvar[CHARACTERARRAY].CHARACTERAP TEMPVAR
                 mulvar TEMPVAR 2
                 ifvarvarg TEMPVAR STATLIMITATOMIC setvarvar TEMPVAR STATLIMITATOMIC
                 setactorvar[CHARACTERARRAY].CHARACTERFA TEMPVAR
                }
ends

state checklisamoney
 getactor[THISACTOR].pal MONEYPAL
 ifvarn RETURN -1 setactor[RETURN].pal MONEYPAL
 ifvare CHARACTERSELECTED? 8
 {
  ifvarvarl LISAMONEYTURNS LISAMONEYTURNS2 addvar LISAMONEYTURNS 1 else killit 
 }
 else killit 
ends

state test21
  cstat 2 // 2 or 514
  ifcount 1 killit
ends

state killattachedobject
   getactor[THISACTOR].picnum TEMP
   ifvare TEMP LEVELRANKSTAR setactorvar[PARENTID].STARCHILD -1
   else ifvare TEMP HPLIFEMETER setactorvar[PARENTID].HPBARCHILD -1
   else ifvare TEMP APLIFEMETER setactorvar[PARENTID].APBARCHILD -1
   else ifvare TEMP POWERUPICONSTRIP setactorvar[PARENTID].POWERUPSTRIPCHILD -1
   else ifvare TEMP PICKUPMULTIICON setactorvar[MULTIICONPARENT].MULTIICONCHILD -1
   else ifvare TEMP POINTERARROW { setactorvar[PARENTID].POINTERICONCHILD -1 setactorvar[PARENTID].RADARARROWSET? 0 }
   setvar PARENTID -1
   setactor[THISACTOR].cstat 32768
   killit
ends

state checkattachedobjectstatus
ifactor INVULNICON
{
 ifvarvarn PARENTID PLAYERID
 {
  ifvarn PARENTID -1 getactorvar[PARENTID].SKILLSET? TEMPVAR
  ifvarn TEMPVAR 0
  { 
   ifvarn PARENTID -1 getactor[PARENTID].statnum TEMPVAR
   ifvare TEMPVAR 1024 
   {
    setactor[PARENTID].extra -1
    state killattachedobject
   }
  }
 }
}
else
{
 ifvarn ATTACHEDOBJECTS? 0
 {
  ifvarvarn PARENTID PLAYERID
  {
   ifvarn PARENTID -1 getactorvar[PARENTID].SKILLSET? TEMPVAR
   ifvarn TEMPVAR 0
   { 
    ifvarn PARENTID -1 getactor[PARENTID].statnum TEMPVAR
    ifvare TEMPVAR 1024 
    {
     setactor[PARENTID].extra -1
     state killattachedobject
    }
   }
  }
 }
 else
 {
  setactor[PARENTID].extra -1
  state killattachedobject
 }
}
ends

state eventload3
 ifspritepal 0 sizeat 80 80 
 else ifspritepal 3 sizeat 80 80 
 else ifspritepal 9 sizeat 80 80 
 else ifspritepal 24 sizeat 48 48
 else sizeat 40 40
 state getenemylevel2 
ends

state eventload6
 ifspritepal 17 sizeat 50 50 
 else ifspritepal 20 sizeat 60 60 
 else sizeat 40 40
 state getenemylevel2 
ends

state keypadhandscannerdamage
 ifvare CHEATGOD 0
 {
  ifvarl INVULNTIME 1
  {
   ifvare DEATHSWITCHDELAY 0
   {
    ifvarg xvelsav 0 setvarvar tempe xvelsav
    else ifvare xvelsav 0 break
    else ifvarl xvelsav 0
    {
     setvarvar tempe MAXHITPOINTS
     mulvarvar tempe xvelsav
     mulvar tempe -1
     divvar tempe 1000
    }

    ifvare extrasav -1 // Normal Damagetype
    {
     // Nyx Gloves Deterrant
     state checkfornyxgloves ifvare DAMAGEMODIFIER 0 palfrom 16 16 16 16

     ifvare CHARACTERSELECTED? 3
     {
      ifvare BUBSYFORM? 1
      {
       mulvar tempe 2
       divvar tempe 5
      }
     }
     else
     ifvare CHARACTERSELECTED? 4
     {
      ifvare AMIFORM? 0 { mulvar tempe 4 divvar tempe 3 }
      else ifvare AMIFORM? 1 divvar tempe 2
      else ifvare AMIFORM? 2 divvar tempe 3
      ifvarand PLAYERSTATUS? 256
      {
       ifp pducking divvar tempe 25 else divvar tempe 5
      }
     }
     else
     ifvare CHARACTERSELECTED? 6
     {
      ifvare ESSENCEFORM? 0
      {
       mulvar tempe 2
       divvar tempe 5
      }
     }
     else
     ifvare CHARACTERSELECTED? 9
     {
      mulvar tempe 3
      divvar tempe 5
     }
     else
     ifvare CHARACTERSELECTED? 13
     {
      ifvare MINAKOFORM? 0 { mulvar tempe 4 divvar tempe 3 }
      else ifvare MINAKOFORM? 1 divvar tempe 2
      else ifvare MINAKOFORM? 2 divvar tempe 3
     }
     else ifvare CHARACTERSELECTED? 14 divvar tempe 3
    }
    else
    ifvare extrasav 0 // Electrical Damagetype
    {
     sound SHORT_CIRCUIT state sparkstate
     // Nyx Gloves Deterrant
     state checkfornyxgloves ifvare DAMAGEMODIFIER 0 palfrom 16 32 32 32

     setvarvar TEMPDAMAGEVAR tempe
     state char_elecdamage_misc
     setvarvar tempe TEMPDAMAGEVAR
    }
    else
    ifvare extrasav 1 // Freezing Damagetype
    {
     // Nyx Gloves Deterrant
     state checkfornyxgloves ifvare DAMAGEMODIFIER 0 palfrom 16 0 0 32

     setvarvar TEMPDAMAGEVAR tempe
     state char_icedamage_misc
     setvarvar tempe TEMPDAMAGEVAR
     ifrnd 106 state addslow_overridevehicle
    }
    else
    ifvare extrasav 2 // Fire Damagetype
    {
     // Nyx Gloves Deterrant
     state checkfornyxgloves ifvare DAMAGEMODIFIER 0 palfrom 16 64 32

     setvarvar TEMPDAMAGEVAR tempe
     state char_firedamage_misc
     setvarvar tempe TEMPDAMAGEVAR
    }
    else
    ifvare extrasav 3 // Poison Damagetype
    {
     // Nyx Gloves Deterrant
     state checkfornyxgloves ifvare DAMAGEMODIFIER 0 palfrom 16 0 64

     ifvare CHARACTERSELECTED? 2
     {
      // Nyx Gloves Deterrant
      state checkfornyxgloves
      ifvare DAMAGEMODIFIER 0
      {
       mulvar tempe -4
       divvar tempe 3
       sound ABSORB_DAMAGE
      }
     }
     else
     ifvare CHARACTERSELECTED? 3
     {
      ifvare BUBSYFORM? 1
      {
       mulvar tempe 2
       divvar tempe 5
      }

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     ifvare CHARACTERSELECTED? 4
     {
      ifvare AMIFORM? 0 { mulvar tempe 4 divvar tempe 3 }
      else ifvare AMIFORM? 1 divvar tempe 2
      else ifvare AMIFORM? 2 divvar tempe 3

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     ifvare CHARACTERSELECTED? 6
     {
      ifvare ESSENCEFORM? 0
      {
       mulvar tempe 2
       divvar tempe 5
      }

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     ifvare CHARACTERSELECTED? 8
     {
      ifvare HAVEENERGYSHIELD? 1 
      {
       ifvare ENERGYSHIELDMODE 1 
       {
        ifvarg DAMAGEINCELL 0 nullop
        else
        {
         // Nyx Gloves Deterrant
         state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
        }
       }
       else
       {
        // Nyx Gloves Deterrant
        state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
       }
      }
      else
      {
       // Nyx Gloves Deterrant
       state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
      }
     }
     else
     ifvare CHARACTERSELECTED? 9
     {
      mulvar tempe 3
      divvar tempe 5

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     ifvare CHARACTERSELECTED? 12
     {
      mulvar tempe 2
      divvar tempe 3

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     ifvare CHARACTERSELECTED? 13
     {
      ifvare MINAKOFORM? 0 { mulvar tempe 4 divvar tempe 3 }
      else ifvare MINAKOFORM? 1 divvar tempe 2
      else ifvare MINAKOFORM? 2 divvar tempe 3

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     ifvare CHARACTERSELECTED? 14
     {
      divvar tempe 3

      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
     else
     {
      // Nyx Gloves Deterrant
      state checkfornyxgloves ifvare DAMAGEMODIFIER 0 { ifrnd 212 state addpoison_overridevehicle }
     }
    }

          //*********************
          //*Check Malakian Gems*
          //*********************
          setvarvar TEMP7 tempe
          state checkformalakiangem 
          setvarvar tempe TEMP7

          //****************
          //*Support System*
          //****************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000

           ifvare extrasav 0 // Electrical Damagetype
           {
            //**Electric Support / Nethra**
            state support-electricresist
           }
           ifvare extrasav 1 // Freeze Damagetype
           {
            //**Ice Support / Ami & Nethra**
            state support-iceresist
           }
           ifvare extrasav 2 // Fire Damagetype
           {
            //**Fire Support / Ted**
            state support-fireresist
           }
           ifvare extrasav 3 // Poison Damagetype
           {
            //**Poison Support / Jack**
            state support-poisonresist
           }

           state damagemod-tempvar          
          }

          //*********************************
          //*Support System [ESSence Support*
          //*********************************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000
           //**Overall Support / ESSence**
           state support-overallresist
           state damagemod-tempvar          
          }

          //******************
          //*Equipment System*
          //******************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000
           ifvare extrasav 0 // Electrical Damagetype
           {
            // Equipment Slot #1
            ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
            // Equipment Slot #2
            ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
            // Equipment Slot #3
            ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
            // Equipment Slot #4
            ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           }
           ifvare extrasav 1 // Freeze Damagetype
           {
            // Equipment Slot #1
            ifvare PLAYEREQUIPSLOTITEM1 2 addvar DAMAGEMODIFIER -225 // Aqua Ring
            // Equipment Slot #2
            ifvare PLAYEREQUIPSLOTITEM2 2 addvar DAMAGEMODIFIER -225 // Aqua Ring
            // Equipment Slot #3
            ifvare PLAYEREQUIPSLOTITEM3 2 addvar DAMAGEMODIFIER -225 // Aqua Ring
            // Equipment Slot #4
            ifvare PLAYEREQUIPSLOTITEM4 2 addvar DAMAGEMODIFIER -225 // Aqua Ring
           }
           ifvare extrasav 2 // Fire Damagetype
           {
            // Equipment Slot #1
            ifvare PLAYEREQUIPSLOTITEM1 1 addvar DAMAGEMODIFIER -250 // Sun Ring
            // Equipment Slot #2
            ifvare PLAYEREQUIPSLOTITEM2 1 addvar DAMAGEMODIFIER -250 // Sun Ring
            // Equipment Slot #3
            ifvare PLAYEREQUIPSLOTITEM3 1 addvar DAMAGEMODIFIER -250 // Sun Ring
            // Equipment Slot #4
            ifvare PLAYEREQUIPSLOTITEM4 1 addvar DAMAGEMODIFIER -250 // Sun Ring
           }
/*
           ifvare extrasav 3 // Poison Damagetype
           {
           }
*/
           state damagemod-tempvar          
          }
          // Nyx Gloves Deterrant
          ifvarg tempe 0
          {
           state checkfornyxgloves
           ifvarg DAMAGEMODIFIER 0 setvar tempe 0
          }

      ifvare DAMAGEMODIFIER 0 { ifvare DEFENSECHEAT 1 { ifvarg tempe 1 { divvar tempe 1000 ifvarl tempe 1 setvar tempe 1 state cheatersound } } }

      setvarvar TEMPDAMAGEVAR tempe
      state lisashield_misc
      setvarvar tempe TEMPDAMAGEVAR

      setvarvar tempb CURRENTHITPOINTS
      subvarvar tempb tempe
      ifvarl tempe 0 setvar PLAYERHPDAMAGED? -1
      else ifvarg tempe 0 setvar PLAYERHPDAMAGED? 1
      ifvarl tempb 0 setvar tempb 0
      ifvarvarg tempb MAXHITPOINTSATOMIC setvarvar tempb MAXHITPOINTSATOMIC
      setactor[PLAYERID].htpicnum -1
      setvarvar CURRENTHITPOINTS tempb

    ifvarn SHOWDAMAGEPLAYER 0
    {
     ifvarg CELLDAMAGETEMP 0
     {
      setvarvar SHOWDAMAGE CELLDAMAGETEMP
      setvar SHOWDAMAGETYPE 2
      setvarvar SHOWDAMAGEACTORID PLAYERID
      state showdamage
     }
    }
    ifvarg FULLSHIELDDAMAGE 0
    {
     ifactor KEYPAD setvar ATTACKINGACTORPICNUM KEYPAD
     ifactor COMPACTHANDSCANNER setvar ATTACKINGACTORPICNUM COMPACTHANDSCANNER
     ifactor COMPACTHANDSCANNER2 setvar ATTACKINGACTORPICNUM COMPACTHANDSCANNER2
     ifactor HANDSCANNER setvar ATTACKINGACTORPICNUM HANDSCANNER
     ifactor HANDSCANNER2 setvar ATTACKINGACTORPICNUM HANDSCANNER2
     ifactor NEWPLUG setvar ATTACKINGACTORPICNUM NEWPLUG
     getactor[THISACTOR].pal TEMP
     setvarvar ATTACKINGACTORPAL TEMP
     setvar ATTACKERDISPLAYTIMER 0 setvar BIOSHIELDNULLDAMAGE 0
     ifvarg FULLSHIELDDAMAGE 0 setvar CELLDAMAGETIMER 0
    }

    ifvarg tempe 0
    {
     ifvarn SHOWDAMAGEPLAYER 0
     {
      setvarvar SHOWDAMAGE tempe
      // addlogvar tempe
      setvar SHOWDAMAGETYPE 0
      setvarvar SHOWDAMAGEACTORID PLAYERID
      state showdamage
     }
    }
    else ifvarl tempe 0
    {
     setvarvar TEMPHEALTH tempe
     mulvar TEMPHEALTH -1
     state showhealing_playerhp
    }
    
    ifvarg tempe 0
    {
     setvarvar PAINSOUNDFACTOR tempe
     state checkpainfactor

     ifactor KEYPAD setvar ATTACKINGACTORPICNUM KEYPAD
     ifactor COMPACTHANDSCANNER setvar ATTACKINGACTORPICNUM COMPACTHANDSCANNER
     ifactor COMPACTHANDSCANNER2 setvar ATTACKINGACTORPICNUM COMPACTHANDSCANNER2
     ifactor HANDSCANNER setvar ATTACKINGACTORPICNUM HANDSCANNER
     ifactor HANDSCANNER2 setvar ATTACKINGACTORPICNUM HANDSCANNER2
     ifactor NEWPLUG setvar ATTACKINGACTORPICNUM NEWPLUG
     getactor[THISACTOR].pal TEMP
     setvarvar ATTACKINGACTORPAL TEMP
     setvarvar PLAYERDAMAGETEMP tempe
     setactor[THISACTOR].htpicnum -1
     setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
     setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 0
     ifvarg tempe 0 setvar HEALTHDAMAGETIMER 0

     state characterpainsounds

     setvarvar DAMAGEHUEFACTOR tempe
     ifvare extrasav -1 state playerdamagehues-normaltype
     else ifvare extrasav 0 state playerdamagehues-electrictype
     else ifvare extrasav 1 state playerdamagehues-icetype
     else ifvare extrasav 2 state playerdamagehues-firetype
     else ifvare extrasav 3 state playerdamagehues-acidtype
    }
   }
  }
  else
  {
   ifvarn xvelsav 0
   {
    sound INVULNITEM3
    palfrom 16 16 16 16
   }
  }
 }
ends

action SCANNEROFF 0
action SCANNERON 1

state loadhandscanner
 getactor[THISACTOR].hitag hitagsav // makes the passcode
 getactor[THISACTOR].lotag lotagsav // lotag to activate/deactivate
 getactor[THISACTOR].extra extrasav // damage type [-1 = Normal, 0 = Electrical, 1 = Freeze, 2 = Fire, etc] 
 getactor[THISACTOR].xvel xvelsav // security damage (when incorrect code is entered) [+ = exact, - = %-based] 
 getactor[THISACTOR].yvel yvelsav // sound that plays when handscanner fails [0 defaults to Tripbomb Beep]
 getactor[THISACTOR].zvel zvelsav // sound that plays when handscanner succeeds [0 defaults to Handscanner sound]
 ifvare yvelsav 0 setvar yvelsav 16
 ifvare zvelsav 0 setvar zvelsav 495
 setactor[THISACTOR].hitag 0
 setactor[THISACTOR].lotag 0 
 setactor[THISACTOR].extra 0 
 setactor[THISACTOR].xvel 0 
 setactor[THISACTOR].yvel 0 
 setactor[THISACTOR].zvel 0 
ends

state characterusescannersuccess
         globalsound SCANNER_SUCCESS
         getplayer[THISACTOR].i temp
         operateactivators lotagsav 0 // temp 
         operatemasterswitches lotagsav
         operaterespawns lotagsav
         state checkforforcefields
         globalsoundvar zvelsav
         redefinequote 334 ^23ACCESS GRANTED!
         setvarvar fta fta_normal setvar ftq 334
         action SCANNERON
         setvar tempe 26
ends

state characterusescannerfail
         globalsound LASERTRIP_ARMING
         ifvare CHARACTERSELECTED? 1 redefinequote 334 ^10DUKE CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 2 redefinequote 334 ^10JACK CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 3 redefinequote 334 ^10BUBSY CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 4 redefinequote 334 ^10AMI CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 5 redefinequote 334 ^10HIGA CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 6 redefinequote 334 ^10ESSENCE CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 7 redefinequote 334 ^10TED CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 8 redefinequote 334 ^10LISA CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 9 redefinequote 334 ^10CYBANIS CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 10 
         { 
          ifvare NETHRAFORM? 0 redefinequote 334 ^10NETHRA CANNOT ACCESS THIS SCANNER!
          ifvare NETHRAFORM? 1 redefinequote 334 ^10CHRISTINA CANNOT ACCESS THIS SCANNER!
         }
         ifvare CHARACTERSELECTED? 11 redefinequote 334 ^10PAULA CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 12 redefinequote 334 ^10LORI CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 13 redefinequote 334 ^10MINAKO CANNOT ACCESS THIS SCANNER!
         ifvare CHARACTERSELECTED? 14
         {
          ifvare PUBLICBETA? 0
          {
           redefinequote 334 ^10NAFERIA CANNOT ACCESS THIS SCANNER!
          }
          else
          {
           ifvare debugtoggle 0 redefinequote 334 ^10??????? CANNOT ACCESS THIS SCANNER!
           ifvare debugtoggle 1 redefinequote 334 ^10HINOTORI CANNOT ACCESS THIS SCANNER!          
          }
         }
         ifvare CHARACTERSELECTED? 15 redefinequote 334 ^10MAKEN CANNOT ACCESS THIS SCANNER!
         setvarvar fta fta_normal setvar ftq 334
         globalsoundvar yvelsav
         state keypadhandscannerdamage
         action SCANNEROFF
         setvar tempe 0
ends

state handscannercode
 state useswitchcheckwall
 ifactor HANDSCANNER
 {
  setvar OBJECTWIDTH 32
  setvar OBJECTHEIGHT 32
 }
 ifactor HANDSCANNER2
 {
  setvar OBJECTWIDTH 32
  setvar OBJECTHEIGHT 32
 }
 ifactor HANDSCANNER
 {
  setvar OBJECTWIDTH 32
  setvar OBJECTHEIGHT 32
 }
 ifactor COMPACTHANDSCANNER
 {
  setvar OBJECTWIDTH 23
  setvar OBJECTHEIGHT 24
 }
 ifactor COMPACTHANDSCANNER2
 {
  setvar OBJECTWIDTH 23
  setvar OBJECTHEIGHT 24
 }
 state getspritecenterz
 setvarvar KEYSCANNERZUP OBJECTCENTERZ
 subvarvar KEYSCANNERZUP OBJECTDIFF2
 setvarvar KEYSCANNERZDOWN OBJECTCENTERZ
 addvarvar KEYSCANNERZDOWN OBJECTDIFF2

 ifvarg tempe 0 subvar tempe 1
 else { ifaction SCANNERON action SCANNEROFF }

 ifpdistl 1536
 {
  ifvare TEMP2 1
  {
   ifp pfacing
   {
    ifhitspace
    {
     ifcansee 
     {
      getactor[PLAYERID].z temp
      subvar temp 6144
      ifvarvarg temp KEYSCANNERZUP
      ifvarvarl temp KEYSCANNERZDOWN
      ifvare com_pause 0 // There are lot of conditions on this line. The last one is there to ensure proper timing. 
      { 
       state stopsearchsounds

       ifvare CHARACTERSELECTED? 1 { ifvarand hitagsav 1 state characterusescannersuccess else state characterusescannerfail } // Checks Duke if he's the current character...
       ifvare CHARACTERSELECTED? 2 { ifvarand hitagsav 2 state characterusescannersuccess else state characterusescannerfail } // Checks Jack if he's the current character...
       ifvare CHARACTERSELECTED? 3 { ifvarand hitagsav 4 state characterusescannersuccess else state characterusescannerfail } // Checks Bubsy if he's the current character...
       ifvare CHARACTERSELECTED? 4 { ifvarand hitagsav 8 state characterusescannersuccess else state characterusescannerfail } // Checks Ami if she's the current character...
       ifvare CHARACTERSELECTED? 5 { ifvarand hitagsav 16 state characterusescannersuccess else state characterusescannerfail } // Checks Higa if he's the current character...
       ifvare CHARACTERSELECTED? 6 { ifvarand hitagsav 32 state characterusescannersuccess else state characterusescannerfail } // Checks ESSence if he's the current character...
       ifvare CHARACTERSELECTED? 7 { ifvarand hitagsav 64 state characterusescannersuccess else state characterusescannerfail } // Checks Ted if he's the current character...
       ifvare CHARACTERSELECTED? 8 { ifvarand hitagsav 128 state characterusescannersuccess else state characterusescannerfail } // Checks Lisa if she's the current character...
       ifvare CHARACTERSELECTED? 9 { ifvarand hitagsav 256 state characterusescannersuccess else state characterusescannerfail } // Checks Cybanis if he's the current character...
       ifvare CHARACTERSELECTED? 10 { ifvarand hitagsav 512 state characterusescannersuccess else state characterusescannerfail } // Checks Christina if she's the current character...
       ifvare CHARACTERSELECTED? 11 { ifvarand hitagsav 1024 state characterusescannersuccess else state characterusescannerfail } // Checks Paula if she's the current character...
       ifvare CHARACTERSELECTED? 12 { ifvarand hitagsav 2048 state characterusescannersuccess else state characterusescannerfail } // Checks Lori if she's the current character...
       ifvare CHARACTERSELECTED? 13 { ifvarand hitagsav 4096 state characterusescannersuccess else state characterusescannerfail } // Checks Minako if she's the current character...
       ifvare CHARACTERSELECTED? 14 { ifvarand hitagsav 8192 state characterusescannersuccess else state characterusescannerfail } // Checks ???????? if she's the current character...
       ifvare CHARACTERSELECTED? 15 { ifvarand hitagsav 16384 state characterusescannersuccess else state characterusescannerfail } // Checks Maken if she's the current character...
       setvar WORLDTILESHUFFLES 0
       state getworldtile
       setvar com_pause 10 // This sets a delay between presses of space so that everything doesn't happen at once.
      }
     }
    }
   }
  }
 }
ends

action ACCESSOFF 0
action ACCESSON 1

state character_keycard_sounds
  ifvare CHARACTERSELECTED? 1
  {
   randvar RNDVOICE 3
   ifvare RNDVOICE 0 sound DUKE_KEYCARD1
   ifvare RNDVOICE 1 sound DUKE_KEYCARD2
   ifvare RNDVOICE 2 sound DUKE_KEYCARD3
   ifvare RNDVOICE 3 sound DUKE_KEYCARD4
  }
  ifvare CHARACTERSELECTED? 8
  {
   randvar RNDVOICE 3
   ifvare RNDVOICE 0 sound LISA_KEYCARD1
   ifvare RNDVOICE 1 sound LISA_KEYCARD2
   ifvare RNDVOICE 2 sound LISA_KEYCARD3
   ifvare RNDVOICE 3 sound LISA_KEYCARD4
  }
  ifvare CHARACTERSELECTED? 15
  {
   randvar RNDVOICE 3
   ifvare RNDVOICE 0 sound MAKEN_KEYCARD1
   ifvare RNDVOICE 1 sound MAKEN_KEYCARD2
   ifvare RNDVOICE 2 sound MAKEN_KEYCARD3
   ifvare RNDVOICE 3 sound MAKEN_KEYCARD4
  }
ends

state keyscannerarraycheck
  setvar ARRAYPOSITION 0 // Sprite IDs >.>
  whilevarn ARRAYPOSITION 16383
  {
   getactor[ARRAYPOSITION].statnum tempb
   ifvarn tempb 1024
   {
    getactor[ARRAYPOSITION].picnum tempb
    ifvarg tempb 4086 ifvarl tempb 4091 // ACCESSSWITCH3/ACCESSSWITCH4
    {
     getactorvar[ARRAYPOSITION].lotagsav tempb
     ifvarvare lotagsav tempb setactorvar[ARRAYPOSITION].tempe 1
    }
   }
   
   addvar ARRAYPOSITION 1
   ifvarg ARRAYPOSITION 16383 break
  }
ends

state keyscannerstart
         setplayer[THISACTOR].access_incs 1
         setvarvar tempc THISACTOR
         setplayer[THISACTOR].access_spritenum tempc
ends

state keyscannercode // For both ACCESSWITCH3 and ACCESSSWITCH4

ifvare SKILLSET? 0 { action ACCESSOFF setvar SKILLSET? 1 }
ifvare tempe 0 action ACCESSOFF else action ACCESSON
getplayer[THISACTOR].access_incs tempd
state useswitchcheckwall

setvar OBJECTWIDTH 64
setvar OBJECTHEIGHT 32
state getspritecenterz
setvarvar KEYSCANNERZUP OBJECTCENTERZ
subvarvar KEYSCANNERZUP OBJECTDIFF2
setvarvar KEYSCANNERZDOWN OBJECTCENTERZ
addvarvar KEYSCANNERZDOWN OBJECTDIFF2

ifvare tempd 0 {
ifvare mainmenu 0
{
 ifpdistl 2048 ifvare TEMP2 1
 {
  ifp pfacing
  {
   ifhitspace
   {
    ifcansee 
    {
     getactor[PLAYERID].z temp
     subvar temp 6144
     ifvarvarg temp KEYSCANNERZUP
     ifvarvarl temp KEYSCANNERZDOWN
     ifvare com_pause 0 // There are lot of conditions on this line. The last one is there to ensure proper timing. 
     { 
      state stopsearchsounds
      ifaction ACCESSOFF
      {
       ifspritepal 0
       {
        ifvarand ACCESSCARDS? 1 state keyscannerstart
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^16BLUE^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       else
       ifspritepal 21
       {
        ifvarand ACCESSCARDS? 2 state keyscannerstart
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^21RED^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       else
       ifspritepal 23
       {
        ifvarand ACCESSCARDS? 4 state keyscannerstart
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^23YELLOW^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       else
       ifspritepal 22
       {
        ifvarand ACCESSCARDS? 8
        {
         state keyscannerstart
         setvar param 8
        }
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^22GREEN^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       else
       ifspritepal 12
       {
        ifvarand ACCESSCARDS? 16
        {
         state keyscannerstart
         setvar param 16
        }
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^12SILVER^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       else
       ifspritepal 15
       {
        ifvarand ACCESSCARDS? 32
        {
         state keyscannerstart
         setvar param 32
        }
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^15BROWN^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       else
       ifspritepal 24
       {
        ifvarand ACCESSCARDS? 64
        {
         state keyscannerstart
         setvar param 64
        }
        else
        {
         ifvare CHARACTERSELECTED? 15 state keyscannerstart
         else
         {
          redefinequote 334 ^24BLOODY^0 ACCESS CARD REQUIRED
          setvarvar fta fta_normal setvar ftq 334
          state character_keycard_sounds
         }
        }
       }
       setvar com_pause 10 // This sets a delay between presses of space so that everything doesn't happen at once.
      }
     }
    }
   }
  }
 }
}
               } // ifvare tempd
//

      ifvarvare tempc THISACTOR
      {
       getplayer[THISACTOR].access_incs TEMP
       ifvarg TEMP 0 setplayer[THISACTOR].movement_lock 31 else setplayer[THISACTOR].movement_lock 0

       ifvare TEMP 12
       {
         getplayer[THISACTOR].i temp
         operateactivators lotagsav 0 // temp
         operatemasterswitches lotagsav
         operaterespawns lotagsav
         state checkforforcefields
         ifvarn CHARACTERSELECTED? 15 subvarvar ACCESSCARDS? param
         setvar param 0
         setplayer[THISACTOR].got_access ACCESSCARDS?

         setvar WORLDTILESHUFFLES 0
         state getworldtile
         redefinequote 334 ^23UNLOCKED
         setvarvar fta fta_normal setvar ftq 334
         ifvare hitagsav 0 soundonce SWITCH_ON
         else soundoncevar hitagsav
         action ACCESSON

         state keyscannerarraycheck

       }

       ifvare TEMP 21
       {
        setplayer[THISACTOR].movement_lock 0
        setvar tempc -1
        setplayer[THISACTOR].access_spritenum tempc
       }
      }
ends

state spawnairbubble
 ifvarg framerate 24
 {
  espawn AIRBUBBLE
  state bubblesounds
  getactor[THISACTOR].z TEMP
  addvar TEMP -1024
  setactor[RETURN].z TEMP
  setactorvar[RETURN].temp temp
  setactorvar[RETURN].tempb tempb
  setactorvar[RETURN].tempc tempc
  setactor[RETURN].cstat 2
 }
 else
 {
  ifrnd 32
  {
   ifvarg framerate 6
   {
    espawn AIRBUBBLE
    state bubblesounds
    getactor[THISACTOR].z TEMP
    addvar TEMP -1024
    setactor[RETURN].z TEMP
    setactorvar[RETURN].temp temp
    setactorvar[RETURN].tempb tempb
    setactorvar[RETURN].tempc tempc
    setactor[RETURN].cstat 2
   }
   else
   {
    ifrnd 32
    {
     espawn AIRBUBBLE
     state bubblesounds
     getactor[THISACTOR].z TEMP
     addvar TEMP -1024
     setactor[RETURN].z TEMP
     setactorvar[RETURN].temp temp
     setactorvar[RETURN].tempb tempb
     setactorvar[RETURN].tempc tempc
     setactor[RETURN].cstat 2
    }
   }
  }
 }
ends

state radararrow
 ifvare oldskoolmode 0
 {
  state itemfullbright
  getactor[PARENTID].x temp
  setactor[THISACTOR].x temp
  getactor[PARENTID].y temp
  setactor[THISACTOR].y temp
  getactor[PARENTID].z temp
  setactor[THISACTOR].z temp

  getactorvar[PARENTID].ENEMYLEVEL RANKSTARLEVEL
  ifvare RANKSTARLEVEL 0 setactor[THISACTOR].pal 15
  ifvarg RANKSTARLEVEL 0 ifvarl RANKSTARLEVEL 11 setactor[THISACTOR].pal 0
  ifvarg RANKSTARLEVEL 10 ifvarl RANKSTARLEVEL 21 setactor[THISACTOR].pal 16
  ifvarg RANKSTARLEVEL 20 ifvarl RANKSTARLEVEL 31 setactor[THISACTOR].pal 22
  ifvarg RANKSTARLEVEL 30 ifvarl RANKSTARLEVEL 41 setactor[THISACTOR].pal 14
  ifvarg RANKSTARLEVEL 40 ifvarl RANKSTARLEVEL 51 setactor[THISACTOR].pal 12
  ifvarg RANKSTARLEVEL 50 ifvarl RANKSTARLEVEL 61 setactor[THISACTOR].pal 13
  ifvarg RANKSTARLEVEL 60 ifvarl RANKSTARLEVEL 71 setactor[THISACTOR].pal 23
  ifvarg RANKSTARLEVEL 70 ifvarl RANKSTARLEVEL 81 setactor[THISACTOR].pal 7
  ifvarg RANKSTARLEVEL 80 ifvarl RANKSTARLEVEL 91 setactor[THISACTOR].pal 21
  ifvarg RANKSTARLEVEL 90 ifvarl RANKSTARLEVEL 100 setactor[THISACTOR].pal 10
  ifvare RANKSTARLEVEL 100 setactor[THISACTOR].pal 6


  getactor[PARENTID].ang temp
  setactor[THISACTOR].ang temp

// X-Size
  getactor[PARENTID].xrepeat temp
  getactorvar[PARENTID].ACTORFLAGS tempc
  ifvarand tempc 512 // Elite Monsters will have larger arrows than normal monsters
  {
   getactor[PARENTID].xrepeat tempe
   divvar tempe 2
   addvarvar temp tempe
  }
  divvar temp 4
  setactor[THISACTOR].xrepeat temp
// Y-Size
  getactor[PARENTID].yrepeat temp
  getactorvar[PARENTID].ACTORFLAGS tempc
  ifvarand tempc 512 // Elite Monsters will have larger arrows than normal monsters
  {
   getactor[PARENTID].yrepeat tempe
   divvar tempe 2
   addvarvar temp tempe
  }
  divvar temp 4
  setactor[THISACTOR].yrepeat temp

  ifvare AMI? 1
  {
   ifvare HAVEMERCURYCOMPUTER? 1
   {
    ifvare debugtoggle 0
     setactor[THISACTOR].cstat 32800 // Sets Flat and Invisible "invisible sprites are still visible on automap if flat"
    else
     setactor[THISACTOR].cstat 32 // Sets Flat
   }
   else
   {
    ifvare debugtoggle 0
     setactor[THISACTOR].cstat 32768 // Sets Invisible
    else
     setactor[THISACTOR].cstat 32 // Sets Flat
   }
  }
  else
  {
   ifvare debugtoggle 0
    setactor[THISACTOR].cstat 32768 // Sets Invisible
   else
    setactor[THISACTOR].cstat 32 // Sets Flat
  }
 }
 else setactor[THISACTOR].cstat 32768 // Sets Invisible
ends

state iconpositioning
  getactor[PARENTID].x TESTX 
  getactor[PARENTID].y TESTY
  getactor[PARENTID].z TESTZ
  getactor[PARENTID].xrepeat TESTXREPEAT1 
  getactor[PARENTID].yrepeat TESTYREPEAT1 
  getactorvar[PARENTID].ACTORSHEIGHT LIFEMETERZ
  mulvarvar LIFEMETERZ TESTYREPEAT1
  mulvar LIFEMETERZ 4
  setvarvar EXTRAZ TESTYREPEAT1
  mulvar EXTRAZ 4
  getactor[PARENTID].picnum TEMP
  ifvare TEMP APLAYER 
  {
   getactor[PARENTID].cstat TEMP
   ifvarand TEMP 8
   {
    getactorvar[PLAYERID].VEHICLEID TEMPVAR3
    ifvare TEMPVAR3 -1
    {
     ifvare CHARACTERSELECTED? 6 mulvar EXTRAZ 68  
     else ifvare CHARACTERSELECTED? 9 mulvar EXTRAZ 72
     else mulvar EXTRAZ 24
    }
    else mulvar EXTRAZ 40

    mulvar EXTRAZ -1
    mulvar LIFEMETERZ -1 
   }
   else
   {
    getactorvar[PLAYERID].VEHICLEID TEMPVAR3
    ifvare TEMPVAR3 -1
    {
     ifvare CHARACTERSELECTED? 6 mulvar EXTRAZ 76
     else ifvare CHARACTERSELECTED? 9 mulvar EXTRAZ 80
     else mulvar EXTRAZ 32
    }
    else mulvar EXTRAZ 48
   }
  } 
  else
  ifvare TEMP NAKED1 // NAKED1 is already "Upside Down"
  {
   getactor[PARENTID].cstat TEMP
   ifvarand TEMP 8 mulvar EXTRAZ 24 
   else
   {
    mulvar EXTRAZ 28
    mulvar EXTRAZ -1
    mulvar LIFEMETERZ -1 
   }
  } 
  else
  {
   getactor[PARENTID].cstat TEMP
   ifvarand TEMP 8
   {
    mulvar EXTRAZ 28
    mulvar EXTRAZ -1
    mulvar LIFEMETERZ -1 
   }
   else mulvar EXTRAZ 24 
  }
  subvarvar TESTZ LIFEMETERZ // Subtract from the original Z var
  subvarvar TESTZ EXTRAZ // Subtract from the original Z var
  state itemfullbright
  divvar TESTXREPEAT1 4
  setactor[THISACTOR].xrepeat TESTXREPEAT1
  divvar TESTYREPEAT1 4
  setactor[THISACTOR].yrepeat TESTYREPEAT1
  ifvarvare PARENTID PLAYERID addvarvar TESTZ VIEWCAMERAZDIFF
  setactor[THISACTOR].x TESTX
  setactor[THISACTOR].y TESTY 
  setactor[THISACTOR].z TESTZ
  getactor[PARENTID].sectnum TEMP3
  setactor[THISACTOR].sectnum TEMP3
ends

action ICONSTRIP0
action ICONSTRIP1 1
action ICONSTRIP2 2
action ICONSTRIP3 3
action ICONSTRIP4 4
action ICONSTRIP5 5
action ICONSTRIP6 6
action ICONSTRIP7 7
action ICONSTRIP8 8
action ICONSTRIP9 9
action ICONSTRIP10 10
action ICONSTRIP11 11
action ICONSTRIP12 12
action ICONSTRIP13 13
action ICONSTRIP14 14
action ICONSTRIP15 15
action ICONSTRIP16 16
action ICONSTRIP17 17
action ICONSTRIP18 18
action ICONSTRIP19 19
action ICONSTRIP20 20
action ICONSTRIP21 21
action ICONSTRIP22 22
action ICONSTRIP23 23
action ICONSTRIP24 24
action ICONSTRIP25 25
action ICONSTRIP26 26
action ICONSTRIP27 27
action ICONSTRIP28 28
action ICONSTRIP29 29
action ICONSTRIP30 30
action ICONSTRIP31 31

state iconstripconditions
 ifvare oldskoolmode 0
 {
  ifvare lifebartogglemode 1
  {
   state iconpositioning
 
   setactor[THISACTOR].cstat 0
   getactor[PARENTID].picnum tempb
   ifvare tempb APLAYER
   {
    getactorvar[PLAYERID].VEHICLEID TEMPVAR3
    ifvare TEMPVAR3 -1 getactorvar[PARENTID].POWERUPBITFIELD tempe  else getactorvar[TEMPVAR3].ENEMYPOWERUPBITFIELD tempe
   }
   else getactorvar[PARENTID].ENEMYPOWERUPBITFIELD tempe

   ifvare tempe 0 state killattachedobject // action ICONSTRIP0
   else ifvare tempe 1 action ICONSTRIP1
   else ifvare tempe 2 action ICONSTRIP2
   else ifvare tempe 3 action ICONSTRIP3
   else ifvare tempe 4 action ICONSTRIP4
   else ifvare tempe 5 action ICONSTRIP5
   else ifvare tempe 6 action ICONSTRIP6
   else ifvare tempe 7 action ICONSTRIP7
   else ifvare tempe 8 action ICONSTRIP8
   else ifvare tempe 9 action ICONSTRIP9
   else ifvare tempe 10 action ICONSTRIP10
   else ifvare tempe 11 action ICONSTRIP11
   else ifvare tempe 12 action ICONSTRIP12
   else ifvare tempe 13 action ICONSTRIP13
   else ifvare tempe 14 action ICONSTRIP14
   else ifvare tempe 15 action ICONSTRIP15
   else ifvare tempe 16 action ICONSTRIP16
   else ifvare tempe 17 action ICONSTRIP17
   else ifvare tempe 18 action ICONSTRIP18
   else ifvare tempe 19 action ICONSTRIP19
   else ifvare tempe 20 action ICONSTRIP20
   else ifvare tempe 21 action ICONSTRIP21
   else ifvare tempe 22 action ICONSTRIP22
   else ifvare tempe 23 action ICONSTRIP23
   else ifvare tempe 24 action ICONSTRIP24
   else ifvare tempe 25 action ICONSTRIP25
   else ifvare tempe 26 action ICONSTRIP26
   else ifvare tempe 27 action ICONSTRIP27
   else ifvare tempe 28 action ICONSTRIP28
   else ifvare tempe 29 action ICONSTRIP29
   else ifvare tempe 30 action ICONSTRIP30
   else ifvare tempe 31 action ICONSTRIP31
  }
  else setactor[THISACTOR].cstat 32768 // state killattachedobject
 }
 else setactor[THISACTOR].cstat 32768 // state killattachedobject
ends

state artipickupsounds
 ifvare CHARACTERSELECTED? 1 // Duke
 {
  ifrnd 85 sound WAR_AMBIENCE10 
  else ifrnd 128 sound WAR_AMBIENCE5 
  else sound WAR_AMBIENCE8
 }
 else
 ifvare CHARACTERSELECTED? 5 // Lo Wang
 {
  ifrnd 32 sound WANG_GRABART8
  else ifrnd 36 sound WANG_GRABART7
  else ifrnd 43 sound WANG_GRABART6
  else ifrnd 51 sound WANG_GRABART5
  else ifrnd 64 sound WANG_GRABART4
  else ifrnd 85 sound WANG_GRABART3
  else ifrnd 128 sound WANG_GRABART2
  else sound WANG_GRABART1
 }
ends

// Falling Damage for NPCs/Monster

state enemyfalldamagesounds
ifvarg ENEMYHP 0
{
 state monsterpainsounds2
 ifactor EMPTYTANK sound METALTHUD
 ifactor TANK sound METALTHUD
 ifactor SCORPIONTANK sound METALTHUD
}
ends

 state resetfallresist_nonplayer
  setvarvar ACTORFALLRESIST ACTORMAXFALLRESIST setvar ACTORFALLCOUNTER 0
 ends

state checkfallcounter_nonplayer
 getsector[THISACTOR].lotag temp
 ifvare temp 2 // Under Water
 {
  ifvarn ACTORFALLING? 0 setvar ACTORFALLING? 0 
  ifvarn ACTORFALLCOUNTER 0 setvar ACTORFALLCOUNTER 0
  ifvarvarn ACTORFALLRESIST ACTORMAXFALLRESIST setvarvar ACTORFALLRESIST ACTORMAXFALLRESIST
 }
 else
 {
  getactor[THISACTOR].zvel ACTORZVEL
  ifvarg ACTORZVEL 0 // positive zvel = falling/lowering
  {
   setvar ACTORFALLING? 1
   ifvarg ACTORZVEL 2559
   {
    ifvare ACTORFALLING? 1 
    {
     ifvarg ACTORFALLRESIST 0
     {
      ifvare mainmenu 0 { ifvarl ENEMYINVULNTIME 1 subvar ACTORFALLRESIST 1 else state resetfallresist_nonplayer }
     }
     else
     {
      ifvare mainmenu 0 { ifvarl ENEMYINVULNTIME 1 addvar ACTORFALLCOUNTER 1 else state resetfallresist_nonplayer }
      ifvarl ACTORFALLRESIST 0
      {
       ifvare mainmenu 0 { ifvarl ENEMYINVULNTIME 1 addvar ACTORFALLRESIST 1 else state resetfallresist_nonplayer }
       ifvare mainmenu 0 { ifvarl ENEMYINVULNTIME 1 addvar ACTORFALLCOUNTER 1 else state resetfallresist_nonplayer }
      }
     }
    }
   }
  }
  else
  {
   ifvare ACTORFALLING? 1
   {
    ifvare ACTORZVEL 0 // Stopped
    {
     iffloordistl 8 // On the ground...
     {
      getsector[THISACTOR].lotag temp
      ifvare temp 2 nullop	  // Lands in underwater sector: Since The NPC/Enemy lands in water, no fall damage is received
      else ifvare temp 1 nullop   // Lands in sinkable water/sector: Since The NPC/Enemy lands in water, no fall damage is received
      else // Lands on hard surface
      {
       ifvare mainmenu 0
       {
        ifvarl ENEMYINVULNTIME 1
        {
         // Deal Fall-based damage >.>
         ifvarg ACTORFALLCOUNTER 8
         {
          setvarvar ACTORFALLDAMAGE ENEMYMAXHP
          ifvarg ACTORFALLCOUNTER 7
          {
           setvar ACTORFALLDAMAGERATIO 80
           setvarvar TEMPVAR2 ACTORFALLCOUNTER
           subvar TEMPVAR2 8
           mulvarvar TEMPVAR2 17
           addvarvar ACTORFALLDAMAGERATIO TEMPVAR2
          }
          randvar TEMPVAR 51
          subvarvar ACTORFALLDAMAGERATIO TEMPVAR
          ifvarl ACTORFALLDAMAGERATIO 0 setvar ACTORFALLDAMAGERATIO 0
          ifvarg ACTORFALLDAMAGERATIO 8320 setvar ACTORFALLDAMAGERATIO 8320
          // Up to 244
          mulvarvar ACTORFALLDAMAGE ACTORFALLDAMAGERATIO
          divvar ACTORFALLDAMAGE 1000
          ifvarl ACTORFALLDAMAGE 0 setvar ACTORFALLDAMAGE 0
          ifvarvarg ACTORFALLDAMAGE STATLIMITATOMIC setvarvar ACTORFALLDAMAGE STATLIMITATOMIC

          setvarvar tempb ENEMYHP
          subvarvar tempb ACTORFALLDAMAGE
          ifvarg ACTORFALLDAMAGE 0 setvar ENEMYHPDAMAGED? 1
          ifvarg ACTORFALLDAMAGE 0
          {
           setvarvar SHOWDAMAGE ACTORFALLDAMAGE
           setvar SHOWDAMAGETYPE 0
           setvarvar SHOWDAMAGEACTORID THISACTOR
           state showdamage
          }
          ifvarl tempb 0 setvar tempb 0
          setactor[THISACTOR].htowner THISACTOR
          setactor[THISACTOR].htpicnum -1
          setvarvar ENEMYHP tempb
          ifvarl ENEMYHP 1
          {
           setactor[THISACTOR].extra 0
           setactor[THISACTOR].htowner THISACTOR
           setactor[THISACTOR].htpicnum SHOTSPARK1
           setactor[THISACTOR].htextra 8000
          }
          state enemyfalldamagesounds
         }
        }
       }
      }       
      ifvarn ACTORFALLING? 0 setvar ACTORFALLING? 0 
      ifvarn ACTORFALLCOUNTER 0 setvar ACTORFALLCOUNTER 0
      ifvarvarn ACTORFALLRESIST ACTORMAXFALLRESIST setvarvar ACTORFALLRESIST ACTORMAXFALLRESIST
     }
     else // An enemy [ie LIZTROOP] is Jetpacking out of their fall...
     {
      ifvarn ACTORFALLING? 0 setvar ACTORFALLING? 0 
      ifvarn ACTORFALLCOUNTER 0 setvar ACTORFALLCOUNTER 0
      ifvarvarn ACTORFALLRESIST ACTORMAXFALLRESIST setvarvar ACTORFALLRESIST ACTORMAXFALLRESIST
     }
    }
    else
    ifvarl ACTORZVEL 0 // flying/rising
    {
     ifvarn ACTORFALLING? 0 setvar ACTORFALLING? 0 
     ifvarn ACTORFALLCOUNTER 0 setvar ACTORFALLCOUNTER 0
     ifvarvarn ACTORFALLRESIST ACTORMAXFALLRESIST setvarvar ACTORFALLRESIST ACTORMAXFALLRESIST
    }
   }
  }
 }
ends

state freezeblast-freezefloors2
 getactor[THISACTOR].sectnum tempc
 getactorvar[tempc].SUBMERGABLESECTOR? tempf
 ifvare tempf 0
 {
  getactorvar[tempc].FLOORFREEZABLE? tempf
  ifvare tempf 1
  {
   getactorvar[tempc].FLOORTEMPFREEZESTATE tempe
   ifvare tempe 0
   {
    iffloordistl 8
    {
     getactor[THISACTOR].extra TEMPVAR
     setvarvar TEMP PLAYERATTACK
     mulvar TEMP 3
     divvar TEMP 4
     addvarvar TEMPVAR TEMP
     ifvare CHARACTERSELECTED? 4 mulvar TEMPVAR 3
     else ifvare CHARACTERSELECTED? 8 { mulvar TEMPVAR 7 divvar TEMPVAR 4 }
     else ifvare CHARACTERSELECTED? 10 mulvar TEMPVAR 2
     ifvarg QUADTIME 0 mulvar TEMPVAR 4
     divvar TEMPVAR 2
     getactorvar[tempc].FLOORHEALTH tempd
     subvarvar tempd TEMPVAR
     ifrnd 85 sound LANDLAVA_HEAVY
     else ifrnd 128 sound LANDLAVA_LIGHT
     else sound LANDLAVA
     espawn SMALLSMOKE

     ifvare CHARACTERSELECTED? 4 setvar TEMPVAR4 60 
     else ifvare CHARACTERSELECTED? 8 setvar TEMPVAR4 40
     else ifvare CHARACTERSELECTED? 10 setvar TEMPVAR4 45
     else setvar TEMPVAR4 30
     setactor[RETURN].xrepeat TEMPVAR4 setactor[RETURN].yrepeat TEMPVAR4

     setactor[RETURN].cstat 514
     ifvarl tempd 0 setvar tempd 0
     setactorvar[tempc].FLOORHEALTH tempd
     getactorvar[tempc].FLOORMAXHEALTH tempg
     ifvare tempd 0 ifvarg tempg 1
     {
      ifvarg tempc -1 ifvarl tempc 4096
      {
       getactorvar[tempc].FLOORTEMPFREEZENUMBERB tempe
       setsector[tempc].floorpicnum tempe
       getactorvar[tempc].FLOORTEMPLOTAGB tempe
       setsector[tempc].lotag tempe
       sound SOMETHINGFROZE
       setactorvar[tempc].FLOORFREEZETIME 138
       setactorvar[tempc].FLOORTEMPFREEZESTATE 1
      }
     }
     killit
    }
   }
  }  
 }
ends

state freezeblast-freezefloors
 getsector[THISACTOR].lotag temp
 ifvare temp 2 nullop
 else getsector[THISACTOR].floorpicnum tempb

 ifvare tempb NEWFLOORPLASMA state freezeblast-freezefloors2
 else ifvare tempb HOTLAVA state freezeblast-freezefloors2
 else ifvare tempb MEGALAVA state freezeblast-freezefloors2
 else ifvare tempb ULTRALAVA state freezeblast-freezefloors2
 else ifvare tempb HYPERMAGMA state freezeblast-freezefloors2
ends

 state pipebombexplodeonlava
  addstrength 1 setactor[THISACTOR].htextra 1
 ends

state pipebomb-checkfloor
 getsector[THISACTOR].lotag temp
 ifvare temp 2 getsector[THISACTOR].ceilingpicnum tempb else getsector[THISACTOR].floorpicnum tempb

 ifvare tempb NEWFLOORPLASMA
 {
  ifvare temp 2 { ifrnd 16 state pipebombexplodeonlava } else { iffloordistl 4 { ifrnd 16 state pipebombexplodeonlava } }
 }
 else
 ifvare tempb HOTLAVA
 {
  ifvare temp 2 { ifrnd 64 state pipebombexplodeonlava } else { iffloordistl 4 { ifrnd 64 state pipebombexplodeonlava } }
 }
 else
 ifvare tempb MEGALAVA
 {
  ifvare temp 2 { ifrnd 96 state pipebombexplodeonlava } else { iffloordistl 4 { ifrnd 96 state pipebombexplodeonlava } }
 }
 else
 ifvare tempb ULTRALAVA
 {
  ifvare temp 2 { ifrnd 128 state pipebombexplodeonlava } else { iffloordistl 4 { ifrnd 128 state pipebombexplodeonlava } }
 }
 else
 ifvare tempb HYPERMAGMA
 {
  ifvare temp 2 { ifrnd 224 state pipebombexplodeonlava } else { iffloordistl 4 { ifrnd 128 state pipebombexplodeonlava } }
 }

 getsector[THISACTOR].hitag temp
 ifvare temp NEWFLOORPLASMA
 {
  iffloordistl 4
  {
   ifrnd 16 { addstrength 1 setactor[THISACTOR].htextra 1 }
  }
 }
 else
 ifvare temp HOTLAVA
 {
  iffloordistl 4
  {
   ifrnd 64 { addstrength 1 setactor[THISACTOR].htextra 1 }
  }
 }
 else
 ifvare temp MEGALAVA
 {
  iffloordistl 4
  {
   ifrnd 96 { addstrength 1 setactor[THISACTOR].htextra 1 }
  }
 }
 else
 ifvare temp ULTRALAVA
 {
  iffloordistl 4
  {
   ifrnd 128 { addstrength 1 setactor[THISACTOR].htextra 1 }
  }
 }
 else
 ifvare temp HYPERMAGMA
 {
  iffloordistl 4
  {
   ifrnd 128 { addstrength 1 setactor[THISACTOR].htextra 1 }
  }
 }
ends



move PHOLDING
move INIT

move CRATEPUSH-RUN 104
move CRATEPUSH-WALK 104

move CRATEPULL-RUN -128
move CRATEPULL-WALK -128

// Physics Code Below

state getpushpullspeeds
 ifmove CRATEPUSH-WALK
 {
//  setactor[THISACTOR].xvel 64
  getactor[THISACTOR].ang TEMPVAR4
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y 
  getplayer[THISACTOR].posx TEMP2
  getplayer[THISACTOR].posy TEMP3 
  subvarvar x TEMP2
  subvarvar y TEMP3
  getangle angvar TEMP2 TEMP3
  setactor[THISACTOR].ang angvar
  getactorvar[PLAYERID].ACTORXVEL TEMPVAR5
  mulvar TEMPVAR5 60
  divvar TEMPVAR5 100
  ifp pwalking mulvar TEMPVAR5 3
  randvar TEMP4 1
  addvarvar TEMPVAR5 TEMP4
  setactor[THISACTOR].xvel TEMPVAR5
  setactor[THISACTOR].ang TEMPVAR4
 }
 ifmove CRATEPUSH-RUN
 {
//  setactor[THISACTOR].xvel 128
  getactor[THISACTOR].ang TEMPVAR4
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y 
  getplayer[THISACTOR].posx TEMP2
  getplayer[THISACTOR].posy TEMP3 
  subvarvar x TEMP2
  subvarvar y TEMP3
  getangle angvar TEMP2 TEMP3
  setactor[THISACTOR].ang angvar
  getactorvar[PLAYERID].ACTORXVEL TEMPVAR5
  mulvar TEMPVAR5 60
  divvar TEMPVAR5 100
  ifp pwalking mulvar TEMPVAR5 3
  randvar TEMP4 1
  addvarvar TEMPVAR5 TEMP4
  setactor[THISACTOR].xvel TEMPVAR5
  setactor[THISACTOR].ang TEMPVAR4
 }
 ifmove CRATEPULL-WALK
 {
//  setactor[THISACTOR].xvel -64
  getactor[THISACTOR].ang TEMPVAR4
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y 
  getplayer[THISACTOR].posx TEMP2
  getplayer[THISACTOR].posy TEMP3 
  subvarvar x TEMP2
  subvarvar y TEMP3
  getangle angvar TEMP2 TEMP3
  setactor[THISACTOR].ang angvar
  getactorvar[PLAYERID].ACTORXVEL TEMPVAR5
  mulvar TEMPVAR5 60
  divvar TEMPVAR5 100
  ifp pwalking mulvar TEMPVAR5 2
  randvar TEMP4 1
  subvarvar TEMPVAR5 TEMP4
  setactor[THISACTOR].xvel TEMPVAR5
  setactor[THISACTOR].ang TEMPVAR4
 }
 ifmove CRATEPULL-RUN
 {
//  setactor[THISACTOR].xvel -128
  getactor[THISACTOR].ang TEMPVAR4
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y 
  getplayer[THISACTOR].posx TEMP2
  getplayer[THISACTOR].posy TEMP3 
  subvarvar x TEMP2
  subvarvar y TEMP3
  getangle angvar TEMP2 TEMP3
  setactor[THISACTOR].ang angvar
  getactorvar[PLAYERID].ACTORXVEL TEMPVAR5
  mulvar TEMPVAR5 60
  divvar TEMPVAR5 100
  ifp pwalking mulvar TEMPVAR5 2
  randvar TEMP4 1
  subvarvar TEMPVAR5 TEMP4
  setactor[THISACTOR].xvel TEMPVAR5
  setactor[THISACTOR].ang TEMPVAR4
 }
ends

state getstrengthratio
 setvarvar STRENGTHRATIO PLAYERLIFTSTRENGTHTEMP
 mulvar STRENGTHRATIO 100
 divvarvar STRENGTHRATIO ACTORWEIGHT
// addlogvar STRENGTHRATIO

 setvar ACTORPHYSICSFLAGS 0
 ifvarvarg STRENGTHRATIO PUSHRATIO addvar ACTORPHYSICSFLAGS 1
 ifvarvarg STRENGTHRATIO PULLRATIO addvar ACTORPHYSICSFLAGS 2
 ifvarvarg STRENGTHRATIO GRABRATIO addvar ACTORPHYSICSFLAGS 4
 ifvarvarg STRENGTHRATIO LIFTRATIO addvar ACTORPHYSICSFLAGS 8
ends

state getstrengthratio2
 setvarvar STRENGTHRATIO PLAYERLIFTSTRENGTHTEMP
 mulvar STRENGTHRATIO 100
 getactorvar[SPRITEID-HOLDING].ACTORWEIGHT TEMP
 divvarvar STRENGTHRATIO TEMP
// addlogvar STRENGTHRATIO

 setactorvar[SPRITEID-HOLDING].ACTORPHYSICSFLAGS 0
 setvar TEMP2 0
 ifvarvarg STRENGTHRATIO PUSHRATIO addvar TEMP2 1
 ifvarvarg STRENGTHRATIO PULLRATIO addvar TEMP2 2
 ifvarvarg STRENGTHRATIO GRABRATIO addvar TEMP2 4
 ifvarvarg STRENGTHRATIO LIFTRATIO addvar TEMP2 8
 setactorvar[SPRITEID-HOLDING].ACTORPHYSICSFLAGS TEMP2
ends

state calcmovementphysics
  getactor[THISACTOR].xvel ACTORPHYSICSVELS
  
  setvarvar PHYSICSTEMPB LIFTRATIO
  addvarvar PHYSICSTEMPB GRABRATIO
  divvar PHYSICSTEMPB 2

  setvarvar PHYSICSTEMPC STRENGTHRATIO
  mulvar PHYSICSTEMPC 100
  divvarvar PHYSICSTEMPC PHYSICSTEMPB

  ifvarl PHYSICSTEMPC 60 setvar PHYSICSTEMPC 60
  ifvarg PHYSICSTEMPC 512 setvar PHYSICSTEMPC 512
  mulvarvar ACTORPHYSICSVELS PHYSICSTEMPC
  divvar ACTORPHYSICSVELS 100

//  addlogvar ACTORPHYSICSVELS
  setactor[THISACTOR].xvel ACTORPHYSICSVELS
ends

state positionholding
 getplayer[THISACTOR].horiz zdist
 ifvarvarg STRENGTHRATIO LIFTRATIO
 {
  ifvarvare SPRITEID-HOLDING SPRITEID-TELEKENESIS_P
  {
   subvar zdist 100
   mulvar zdist -32
  }
  else
  {
   subvar zdist 75
   mulvar zdist -24
  }
 }
 else
 {
  subvar zdist 100
  mulvar zdist -32
 }
 addvarvar mz zdist
 rotatepoint x y digx y angvar mx my
 updatesectorz mx my mz temp
 ifvarn temp -1
 {
  changespritesect SPRITEID-HOLDING temp
  setactor[SPRITEID-HOLDING].x mx
  setactor[SPRITEID-HOLDING].y my
  ifvarn PICKUPVELS 0
  {
   getactor[SPRITEID-HOLDING].z tempb
   ifvarvarg mz tempb setvarvar mz tempb
  }
  setactor[SPRITEID-HOLDING].z mz
 }
ends

state holdingcode
 ifvarn SPRITEID-HOLDING -1
 {
  ifvarvare SPRITEID-HOLDING SPRITEID-TELEKENESIS_P soundonce WIERDSHOT_FLY
  getactor[SPRITEID-HOLDING].statnum temp
  ifvare temp 1024 { setvar SPRITEID-HOLDING -1 setvar PICKUPVELS -12 }
  ifvarn SPRITEID-HOLDING -1
  {
   getactor[SPRITEID-HOLDING].picnum picnum
   ifvarvarn picnum PICNUM-HOLDING { setvar SPRITEID-HOLDING -1 setvar PICKUPVELS -12 }
  }
  ifvarn SPRITEID-HOLDING -1
  {
   getplayer[THISACTOR].posz mz
   state getstrengthratio2
   ifvarvarg STRENGTHRATIO LIFTRATIO
   {
    ifvarvare SPRITEID-HOLDING SPRITEID-TELEKENESIS_P
    {
     addvar mz 3072
    }
    else
    {
     subvar mz 3072 // 3072
    }
   }
   else
   {
    addvar mz 3072
   }
   setvarvar temp PICKUPVELS
   ifvarvarg STRENGTHRATIO LIFTRATIO
   {
    ifvarvare SPRITEID-HOLDING SPRITEID-TELEKENESIS_P
    {
     mulvar temp 640
    }
    else
    {
     mulvar temp 960 // 960
    }
   }
   else
   {
    mulvar temp 640
   }
   addvarvar mz temp
   getplayer[THISACTOR].posx x
   getplayer[THISACTOR].posy y
   setvarvar digx x
   addvar digx 320 //480
   ifvare PICNUM-HOLDING CRATE1 addvar digx 80
   ifvare PICNUM-HOLDING CRATE2 addvar digx 80
   getactor[THISACTOR].clipdist TEMP
   mulvar TEMP 3
   divvar TEMP 4
   addvarvar digx TEMP

   getplayer[THISACTOR].ang angvar
   state positionholding
   ifvare temp -1 ifvare PICKUPVELS 0 // object not in sector
   {
    getactorvar[SPRITEID-HOLDING].BOUNCESND temp
    ifvarn temp -1 soundoncevar temp
    subvar digx 96
    state positionholding
    ifvare temp -1 ifvarvarn SPRITEID-HOLDING SPRITEID-TELEKENESIS_P
    {
     getactorvar[SPRITEID-HOLDING].initcstat temp
     ifvare ACTORTHROWTIMER 0 setactor[SPRITEID-HOLDING].cstat temp
     setactor[SPRITEID-HOLDING].x x
     setactor[SPRITEID-HOLDING].y y
     //subvar mz 6144
     setactor[SPRITEID-HOLDING].z mz
     setvar SPRITEID-HOLDING -1
     setvar PICKUPVELS -12
    }
   }	
   ifvarg PICKUPVELS 0 subvar PICKUPVELS 1
  }
 } 
 else setvar DROPFLAG 0 // in the player, droptile is 1 only when pressing alt-fire should drop the gg's sprite
 ifvarl PICKUPVELS 0 addvar PICKUPVELS 1
ends

state movespriteprep
 changespritestat THISACTOR 1
 getplayer[THISACTOR].posx mx
 getplayer[THISACTOR].posy my
 getactor[THISACTOR].x x
 getactor[THISACTOR].y y
 subvarvar mx x
 subvarvar my y
 getangle angvar mx my
 cos xvel angvar
 sin yvel angvar
ends

state telekenesisgrabstate
 ifvare initcstat -1 getactor[THISACTOR].cstat initcstat

 setvar temp 0
 ifvarvare THISACTOR scannedsprite setvar temp 1
 ifvarvare THISACTOR SPRITEID-TELEKENESIS_P setvar temp 1
 ifpdistl 1024 setvar temp 1
 ifvarvare SPRITEID-HOLDING THISACTOR setvar temp 0
 ifvarg ACTORWEIGHT 450 setvar temp 0 // 100
 findplayer xydist
 ifvare temp 1
 {
  setvar FALLFLAG 1
  setvarvar SPRITEID-TELEKENESIS_P THISACTOR
  ifactor TOILET break
  ifactor HYDRENT break
  state movespriteprep
  shiftvarr xydist 6
  getactorvar[SPRITEID-TELEKENESIS_P].ACTORWEIGHT tempb
  ifvarl tempb 20 setvar tempb 20
  //shiftvarr tempb 1
  addvarvar xydist tempb
  shiftvarr xydist 2
  divvarvar xvel xydist
  divvarvar yvel xydist
  getplayer[THISACTOR].posz mz
  addvar mz 2048
  getactor[THISACTOR].z z
  ifvarvarl mz z { setactor[THISACTOR].zvel -256 ifpdistg 1024 setvar zvel -4096 } else setvar zvel -1024
  movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
  ifpdistl 1024 //RETRIEVEDISTANCE
  {
   ifvarand initcstat 64 subvar initcstat 64
   setvarvar temp initcstat
   ifvarand temp 1 subvar temp 1
   setactor[THISACTOR].cstat temp
   move PHOLDING faceplayer geth getv
   setvarvar SPRITEID-HOLDING THISACTOR
   soundonce KICK_HIT
   getactor[THISACTOR].picnum PICNUM-HOLDING
  }
  break
 }
 else // SHAKE IT BABY!
 {
  ifactor TOILET break
  ifactor HYDRENT break
  getactor[THISACTOR].ang angvar
  randvar temp 32
  ifrnd 128 mulvar temp -1
  addvarvar angvar temp
  setactor[THISACTOR].ang angvar
  state movespriteprep
	
  shiftvarr xydist 6
  setvarvar tempb ACTORWEIGHT
  ifvarl tempb 20 setvar tempb 20
  shiftvarr tempb 1
  addvarvar xydist tempb
  shiftvarr xydist 1
  divvarvar xvel xydist
  divvarvar yvel xydist
  randvar zvel 644
  subvarvar zvel xydist
  mulvar zvel -1
  ifvarg zvel 0 setvar zvel 0
  ifvarl zvel -256 iffloordistl 16 setactor[THISACTOR].zvel -256
  movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN	
 }	
ends

state telekenesispickupcode
 ifvare CHARACTERSELECTED? 9 // ifvare gravgun YES
 {
  ifvare SPRITEID-HOLDING -1
   ifvare SPRITEID-TELEKENESIS_P -1
     ifvarand bits 262144
      ifvare PICKUPVELS 0
       ifcanseetarget
       {
        ifp pfacing
         state telekenesisgrabstate
/*
        else
         ifpdistl 1280 state telekenesisgrabstate
*/
       }
       else
       ifvarvare SPRITEID-TELEKENESIS_P THISACTOR
        ifvare SPRITEID-HOLDING -1
         state telekenesisgrabstate
 }
ends

/*
state grabobject_fail
         redefinequote 413 ^10THIS OBJECT IS TOO HEAVY FOR

         ifvare CHARACTERSELECTED? 1 redefinequote 414 ^10 DUKE
         ifvare CHARACTERSELECTED? 2 redefinequote 414 ^10 JACK
         ifvare CHARACTERSELECTED? 3 redefinequote 414 ^10 BUBSY
         ifvare CHARACTERSELECTED? 4 redefinequote 414 ^10 AMI
         ifvare CHARACTERSELECTED? 5 redefinequote 414 ^10 HIGA
         ifvare CHARACTERSELECTED? 6 redefinequote 414 ^10 ESSENCE
         ifvare CHARACTERSELECTED? 7 redefinequote 414 ^10 TED
         ifvare CHARACTERSELECTED? 8 redefinequote 414 ^10 LISA
         ifvare CHARACTERSELECTED? 9 redefinequote 414 ^10 CYBANIS
         ifvare CHARACTERSELECTED? 10
         {
          ifvare NETHRAFORM? 0 redefinequote 414 ^10 NETHRA
          ifvare NETHRAFORM? 1 redefinequote 414 ^10 CHRISTINA
         }
         ifvare CHARACTERSELECTED? 11 redefinequote 414 ^10 PAULA
         ifvare CHARACTERSELECTED? 12 redefinequote 414 ^10 LORI
         ifvare CHARACTERSELECTED? 13 redefinequote 414 ^10 MINAKO
         ifvare CHARACTERSELECTED? 14
         {
          ifvare PUBLICBETA? 0
          {
           ifvare debugtoggle 0 redefinequote 414 ^10 NAFERIA
           ifvare debugtoggle 1 redefinequote 414 ^10 HINOTORI
          }
          ifvare PUBLICBETA? 1
          {
           ifvare debugtoggle 0 redefinequote 414 ^10 ???????
           ifvare debugtoggle 1 redefinequote 414 ^10 HINOTORI
          }
         }
         ifvare CHARACTERSELECTED? 15 redefinequote 414 ^10 MAKEN

         redefinequote 415 ^10 TO LIFT! >_<
         qstrcat 413 414
         qstrcat 413 415
         setvarvar fta 100 setvar ftq 413
         soundonce MENU_ERROR
ends
*/

state grabpullquote
       ifvarg ACTORPHYSICSFLAGS 0
       {
        ifvare mainmenu 0
        {
         ifvare ACTORPHYSICSFLAGS 1
         {
          redefinequote 413 ^20YOU CAN PUSH THIS OBJECT BY HITTING "^0
          getkeyname 414 6 0
          qstrcat 413 414
          redefinequote 415 ^20"!
          qstrcat 413 415
         }
         else
         ifvare ACTORPHYSICSFLAGS 3
         {
          redefinequote 413 ^20YOU CAN PUSH/PULL THIS OBJECT BY HITTING "^0
          getkeyname 414 6 0
          qstrcat 413 414
          redefinequote 415 ^20"!
          qstrcat 413 415
         }
         setvarvar fta 6 setvar ftq 413       
        }
       }
ends

state grabconditions
     ifp ponground
     {
      ifvare SPRITEID-HOLDING -1
      {
       ifvarg MANTLINGTIMER 0
       {
        ifhitspace
        {
         ifvarand extbits 1 // moving forward
         {
          ifp pducking break
          state stopsearchsounds
          setvar temp 0
          ifp pwalking setvar temp 1
          ifvare temp 1
          {
           ifmove CRATEPUSH-WALK nullop else
           move CRATEPUSH-WALK geth
          }
          else
          ifvare temp 0
          {
           ifmove CRATEPUSH-RUN nullop else
           move CRATEPUSH-RUN geth
          }
          getplayer[THISACTOR].ang angvar
          setactor[THISACTOR].ang angvar
          cstator 2
          soundonce DUMPSTER_MOVE // 148
          setvar ACTORPUSHTIMER 3
          setvar PLAYERPUSHINGTIMER 3

          randvar PHYSICSTEMPB 6
          addvar PHYSICSTEMPB 24
          // addlogvar PHYSICSTEMPB
          ifvarl INVULNTIME 1
          {
           ifvarl DEATHSWITCHDELAY 1
           {
            subvarvar MANTLINGTIMEREXTRA PHYSICSTEMPB
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1 
             addvar MANTLINGTIMEREXTRA 100
            }
            ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
           }
           else
           {
            ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
            {
             setvarvar MANTLINGTIMER MANTLINGTIMERMAX
             subvarvar MANTLINGTIMER 1
            }
           }
          }
          else
          {
           ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
           {
            setvarvar MANTLINGTIMER MANTLINGTIMERMAX
            subvarvar MANTLINGTIMER 1
           }
          }
         }
         else
         {
          ifvarand extbits 2 nullop else state grabpullquote
          ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
         }
        }
        else
        {
         state grabpullquote
         ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
        }
       }
      }
      else
      {
       ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
      }
     }
     else
     {
      ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
     }
ends

state pullconditions
     ifp ponground
     {
      ifvare SPRITEID-HOLDING -1
      {
       ifvarg MANTLINGTIMER 0
       {
        ifhitspace
        {
         ifvarand extbits 2 // moving backwards
         {
          ifp pducking break
          state stopsearchsounds
          setvar temp 0
          ifp pwalking setvar temp 1
          ifvare temp 1
          {
           ifmove CRATEPULL-WALK nullop else
           move CRATEPULL-WALK geth
          }
          else
          {
           ifmove CRATEPULL-RUN nullop else
           move CRATEPULL-RUN geth
          }
          getplayer[THISACTOR].ang angvar
          setactor[THISACTOR].ang angvar
          cstator 2
          soundonce DUMPSTER_MOVE // 148
          setvar ACTORPUSHTIMER -3
          setvar PLAYERPUSHINGTIMER -3

          randvar PHYSICSTEMPB 8
          addvar PHYSICSTEMPB 32
          // addlogvar PHYSICSTEMPB
          ifvarl INVULNTIME 1
          {
           ifvarl DEATHSWITCHDELAY 1
           {
            subvarvar MANTLINGTIMEREXTRA PHYSICSTEMPB
            ifvarl MANTLINGTIMEREXTRA 1
            {
             subvar MANTLINGTIMER 1 
             addvar MANTLINGTIMEREXTRA 100
            }
            ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
           }
           else
           {
            ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
            {
             setvarvar MANTLINGTIMER MANTLINGTIMERMAX
             subvarvar MANTLINGTIMER 1
            }
           }
          }
          else
          {
           ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
           {
            setvarvar MANTLINGTIMER MANTLINGTIMERMAX
            subvarvar MANTLINGTIMER 1
           }
          }
         }
         else
         {
          ifvarand extbits 1 nullop else state grabpullquote
          ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
         }
        }
        else
        {
         state grabpullquote
         ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
        }
       }
      }
      else
      {
       ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
      }
     }
     else
     {
      ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
     }
ends

state pickupconditions
      ifvare PICKUPVELS 0
      {
       getactorvar[PLAYERID].VEHICLEID tempvehicleid
       ifvare tempvehicleid -1
       {
        ifvare PLAYERPUSHINGTIMER 0
        {
         ifvare SPRITEID-HOLDING -1
         {
          ifvarg MANTLINGTIMER 0
          {
           ifhitspace
           {
            ifcanseetarget addvar targetlock 2
            ifvarg targetlock 3 setvar targetlock 3
            ifvarvare scannedsprite THISACTOR setvar targetlock 3
 	              
            ifvarg targetlock 2
            {
             ifvare initcstat -1 getactor[THISACTOR].cstat initcstat
             ifvarand initcstat 64 subvar initcstat 64 // one sided not allowed
             setvarvar temp initcstat
             ifvarand temp 1 subvar temp 1
             setactor[THISACTOR].cstat temp
             setvar ACTORTHROWTIMER 10
             setvarvar SPRITEID-HOLDING THISACTOR
             resetcount
             setactor[THISACTOR].pitch 0
             setactor[THISACTOR].roll 0
             getactor[THISACTOR].picnum PICNUM-HOLDING
             ifvare CHARACTERSELECTED? 1 soundonce DUKE_GRUNT
             ifvare CHARACTERSELECTED? 8 soundonce LISA_WALLGRAB
             ifvare CHARACTERSELECTED? 15 soundonce MAKEN_MELEE3
             state stopsearchsounds
             ifmove PHOLDING nullop else move PHOLDING faceplayer
             setvar PICKUPVELS 13 // initiates picking up sequence
            }
           }
           else
           {
            ifvarg ACTORPHYSICSFLAGS 3
            {
             ifvare mainmenu 0
             {
              ifvare ACTORPHYSICSFLAGS 7
              {
               redefinequote 413 ^20YOU CAN GRAB THIS OBJECT BY HITTING "^0
               getkeyname 414 6 0
               qstrcat 413 414
               redefinequote 415 ^20"!
               qstrcat 413 415
              }
              else
              ifvare ACTORPHYSICSFLAGS 15
              {
               redefinequote 413 ^20YOU CAN LIFT THIS OBJECT BY HITTING "^0
               getkeyname 414 6 0
               qstrcat 413 414
               redefinequote 415 ^20"!
               qstrcat 413 415
              }
              setvarvar fta 6 setvar ftq 413       
             }
            }
           }
          }
         }
        }
       }
      }
ends

state pickupcode
 state getstrengthratio
 ifvarg targetlock 0 subvar targetlock 1

 ifp pshrunk nullop
 else
 {
  ifvarand ACTORPHYSICSFLAGS 4
  {
   ifp palive
   {
    ifp pfacing
    {
     ifpdistl 1024
     {
      state pickupconditions
     }
    }
   }
  }
  else
  {
   ifvarg ACTORPHYSICSFLAGS 0
   {
    ifvarand ACTORPHYSICSFLAGS 1
    {
     ifp phigher
     {
      ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
     }
     else
     {
      ifp pfacing 
      {
       ifp palive
       {
        ifpdistl 1280
        {
         state grabconditions
        }
        else
        {
         ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
        }
       }
       else
       {
        ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
       }
      }
      else
      {
       ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
      }
     }
    }
    ifvarand ACTORPHYSICSFLAGS 2
    {
     ifp phigher
     {
      ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
     }
     else
     {
      ifp pfacing 
      {
       ifp palive
       {
        ifpdistl 1280
        {
         state pullconditions
        }
        else
        {
         ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
        }
       }
       else
       {
        ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
       }
      }
      else
      {
       ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
      }
     }
    }
   }
   else
   {
    ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
    ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
    ifp palive
    {
     ifp pfacing
     {
      ifp ponground
      {
       ifpdistl 1152 // 1280
       {
        ifvare mainmenu 0
        {
         redefinequote 413 ^10YOU ARE NOT STRONG ENOUGH TO MOVE THIS OBJECT IN ANY WAY!
         setvarvar fta 6 setvar ftq 413       
         ifhitspace
         {
          state getpartime
          addvar upresstime 1
          ifvarvare temppartime upresstime nullop else
          {
           ifvare CHARACTERSELECTED? 1 soundonce DUKE_SEARCH1A
           ifvare CHARACTERSELECTED? 2 soundonce JACK_WALLPUSH1
           ifvare CHARACTERSELECTED? 5 soundonce WANG_SEARCH1
           ifvare CHARACTERSELECTED? 6 soundonce ESSENCE_WALLPUSH1
           ifvare CHARACTERSELECTED? 8 soundonce LISA_WALLPUSH1
           ifvare CHARACTERSELECTED? 8 soundonce CYBANIS_WALLPUSH1
           ifvare CHARACTERSELECTED? 15 soundonce MAKEN_WALLPUSH1
          }
          setvarvar upresstime temppartime
         }
        }
       }
      }
     }
    }
   }
  }
 }
 state telekenesispickupcode
ends


state pickupcode2 // for non actors
 state getstrengthratio
 ifvarg targetlock 0 subvar targetlock 1

 findplayer xydist

 ifp pshrunk nullop
 else
 {
  ifvarand ACTORPHYSICSFLAGS 4
  {
   ifp palive
   {
    ifp pfacing
    {
     ifvarl xydist 1024
     {
      state pickupconditions
     }
    }
   }
  }
  else
  {
   ifvarg ACTORPHYSICSFLAGS 0
   {
    ifvarand ACTORPHYSICSFLAGS 1
    {
     ifp phigher
     {
      ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
     }
     else
     {
      ifp pfacing 
      {
       ifp palive
       {
        ifvarl xydist 1280
        {
         state grabconditions
        }
        else
        {
         ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
        }
       }
       else
       {
        ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
       }
      }
      else
      {
       ifvarg ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER 1
      }
     }
    }
    ifvarand ACTORPHYSICSFLAGS 2
    {
     ifp phigher
     {
      ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
     }
     else
     {
      ifp pfacing 
      {
       ifp palive
       {
        ifvarl xydist 1280
        {
         state pullconditions
        }
        else
        {
         ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
        }
       }
       else
       {
        ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
       }
      }
      else
      {
       ifvarl ACTORPUSHTIMER 0 subvar ACTORPUSHTIMER -1
      }
     }
    }
   }
   else
   {
    ifp palive
    {
     ifp pfacing
     {
      ifp ponground
      {
       ifvarl xydist 1152 // 1280
       {
        ifvare mainmenu 0
        {
         redefinequote 413 ^10YOU ARE NOT STRONG ENOUGH TO MOVE THIS OBJECT IN ANY WAY!
         setvarvar fta 6 setvar ftq 413       
         ifhitspace
         {
          state getpartime
          addvar upresstime 1
          ifvarvare temppartime upresstime nullop else
          {
           ifvare CHARACTERSELECTED? 1 soundonce DUKE_SEARCH1A
           ifvare CHARACTERSELECTED? 2 soundonce JACK_WALLPUSH1
           ifvare CHARACTERSELECTED? 5 soundonce WANG_SEARCH1
           ifvare CHARACTERSELECTED? 6 soundonce ESSENCE_WALLPUSH1
           ifvare CHARACTERSELECTED? 8 soundonce LISA_WALLPUSH1
           ifvare CHARACTERSELECTED? 8 soundonce CYBANIS_WALLPUSH1
           ifvare CHARACTERSELECTED? 15 soundonce MAKEN_WALLPUSH1
          }
          setvarvar upresstime temppartime
         }
        }
       }
      }
     }
    }
   }
  }
 }
 state telekenesispickupcode
ends

move ITEMFLY 384
move ITEMFLY2 480
move ITEMSHOOT 1536 // 2048

state throwitem
 state stopsearchsounds
 setvar SPRITEID-HOLDING -1
 setvar PICKUPVELS -12
 setvar FALLFLAG 1

 setvarvar temp ACTORWEIGHT

 ifvarl temp 40 setvar WEIGHTFLAG 36 else
 ifvarl temp 80 setvar WEIGHTFLAG 26 else
 setvar WEIGHTFLAG 16
ends


state moveitem
 setactor[THISACTOR].htcgg 0
 ifvare CHARACTERSELECTED? 9 cstator 256

 ifvarvare SPRITEID-HOLDING THISACTOR ifvarvare SPRITEID-TELEKENESIS_P THISACTOR
 {
  getplayer[THISACTOR].i HOLDINGID
  getactorvar[HOLDINGID].DROPFLAG digz
  ifvarand bits 262144 
  {
   state stopsearchsounds
   ifvare digz 1
   {
    setvar SPRITEID-HOLDING -1 
    ifvarand initcstat 64 subvar initcstat 64
    // addlogvar initcstat
    setactor[THISACTOR].cstat initcstat
    setvar SPRITEID-TELEKENESIS_P -1 
    setvar PICKUPVELS -12 
    setvar FALLFLAG 1 
   }
  }
  else
  {
   setactorvar[HOLDINGID].DROPFLAG 1
   ifvarand bits 4 
   {
    // getplayer[THISACTOR].ammo_amount 11 temp
    setvar temp 64
    ifvarg temp 0
    {
     // orvar gravonce 2
     // subvar temp 1
     // setplayer[THISACTOR].ammo_amount 11 temp
     sound WIERDSHOT_FLY // sound GRAVSHOOT

     // throw it
     setvar SPRITEID-HOLDING -1
     setvar SPRITEID-TELEKENESIS_P -1
     move ITEMSHOOT geth
     setvar WEIGHTFLAG 32
     setvar FALLFLAG 1 // used to tell objects that haven't fallen before that they should start now
     setvar PICKUPVELS -12
     ifvarand initcstat 64 subvar initcstat 64
     // addlogvar initcstat
     setactor[THISACTOR].cstat initcstat
     spriteflags 16
     getplayer[THISACTOR].ang angvar
     setactor[THISACTOR].ang angvar
     getplayer[THISACTOR].horiz temp
     subvar temp 100
     mulvar temp -120
     subvar zvel -2048
     ifvarl temp -16384 setvar temp -16384
     ifvarg temp 16384 setvar temp 16384
     setactor[THISACTOR].zvel temp
    }
   }
  }
  break
 }

 ifvarvare SPRITEID-HOLDING THISACTOR 
 {
  state stopsearchsounds

  ifvare mainmenu 0
  {
   // Putting the Item Down Manually
   ifhitspace ifvare PICKUPVELS 0
   {
    // addlogvar initcstat
    setactor[THISACTOR].cstat initcstat
    setvar SPRITEID-HOLDING -1
    setvar PICKUPVELS -12
    setvar FALLFLAG 1
   }

   ifvarvarn SPRITEID-HOLDING SPRITEID-TELEKENESIS_P // Do not drain meter if Cybanis is using telekenesis to hold the item
   {
    ifvarg STRENGTHRATIO 79 ifvarl STRENGTHRATIO 92 setvar PHYSICSTEMPB 90 // 80-91 [11]
    else ifvarg STRENGTHRATIO 91 ifvarl STRENGTHRATIO 106 setvar PHYSICSTEMPB 85 // 92-105 [13]
    else ifvarg STRENGTHRATIO 105 ifvarl STRENGTHRATIO 122 setvar PHYSICSTEMPB 80 // 106-121 [15]
    else ifvarg STRENGTHRATIO 121 ifvarl STRENGTHRATIO 140 setvar PHYSICSTEMPB 75 // 122-139 [17]
    else ifvarg STRENGTHRATIO 139 ifvarl STRENGTHRATIO 160 setvar PHYSICSTEMPB 70 // 140-159 [19]
    else ifvarg STRENGTHRATIO 159 ifvarl STRENGTHRATIO 181 setvar PHYSICSTEMPB 65 // 160-180 [20]
    else ifvarg STRENGTHRATIO 180 ifvarl STRENGTHRATIO 203 setvar PHYSICSTEMPB 60 // 181-202 [21]
    else ifvarg STRENGTHRATIO 202 ifvarl STRENGTHRATIO 225 setvar PHYSICSTEMPB 55 // 203-224 [21]
    else ifvarg STRENGTHRATIO 224 ifvarl STRENGTHRATIO 248 setvar PHYSICSTEMPB 50 // 225-247 [22]
    else ifvarg STRENGTHRATIO 247 ifvarl STRENGTHRATIO 271 setvar PHYSICSTEMPB 45 // 248-270 [22]
    else ifvarg STRENGTHRATIO 270 ifvarl STRENGTHRATIO 295 setvar PHYSICSTEMPB 40 // 271-294 [23]
    else ifvarg STRENGTHRATIO 294 ifvarl STRENGTHRATIO 319 setvar PHYSICSTEMPB 35 // 295-318 [23]
    else ifvarg STRENGTHRATIO 318 ifvarl STRENGTHRATIO 344 setvar PHYSICSTEMPB 30 // 319-343 [24]
    else ifvarg STRENGTHRATIO 343 ifvarl STRENGTHRATIO 369 setvar PHYSICSTEMPB 25 // 344-368 [24]
    else ifvarg STRENGTHRATIO 368 ifvarl STRENGTHRATIO 395 setvar PHYSICSTEMPB 20 // 369-394 [25]
    else ifvarg STRENGTHRATIO 394 ifvarl STRENGTHRATIO 421 setvar PHYSICSTEMPB 15 // 395-420 [25]
    else ifvarg STRENGTHRATIO 420 ifvarl STRENGTHRATIO 448 setvar PHYSICSTEMPB 10 // 421-447 [26]
    else ifvarg STRENGTHRATIO 447 setvar PHYSICSTEMPB 5 // 448+
    ifp ponsteroids divvar PHYSICSTEMPB 2
 
    ifvarl INVULNTIME 1
    {
     ifvarl DEATHSWITCHDELAY 1
     {
      subvarvar MANTLINGTIMEREXTRA PHYSICSTEMPB
      ifvarl MANTLINGTIMEREXTRA 1
      {
       subvar MANTLINGTIMER 1 
       addvar MANTLINGTIMEREXTRA 100
      }
      ifvarl MANTLINGTIMER 0 setvar MANTLINGTIMER 0
     }
     else
     {
      ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
      {
       setvarvar MANTLINGTIMER MANTLINGTIMERMAX
       subvarvar MANTLINGTIMER 1
      }
     }
    }
    else
    {
     ifvarvare MANTLINGTIMER MANTLINGTIMERMAX
     {
      setvarvar MANTLINGTIMER MANTLINGTIMERMAX
      subvarvar MANTLINGTIMER 1
     }
    }

   }
 
   // Dropping the Item if Strength/Mantle Runs Out
   ifvarl MANTLINGTIMER 1
   {
    // addlogvar initcstat
    setactor[THISACTOR].cstat initcstat
    setvar SPRITEID-HOLDING -1
    setvar PICKUPVELS -12
    setvar FALLFLAG 1
   }

   ifvarvarg STRENGTHRATIO GRABRATIO nullop
   else
   {
    // addlogvar initcstat
    setactor[THISACTOR].cstat initcstat
    setvar SPRITEID-HOLDING -1
    setvar PICKUPVELS -12
    setvar FALLFLAG 1
   }
  }

  setvar PHYSICSTEMPC 0
/*
  // don't know whether ifhitweapon has been called before this point, so it gets ugly
  getactor[THISACTOR].htextra temp
  ifwasweapon KNEE { setvar PHYSICSTEMPC 1 ifvarl temp 1 setactor[THISACTOR].htpicnum -1 }
  ifvarg temp 0
  {
   getactor[THISACTOR].htpicnum tempb
   ifvare tempb KNEE
   setvar PHYSICSTEMPC 1
  }	
*/
  ifvare mainmenu 0 { ifvarand bits 4 setvar PHYSICSTEMPC 1 }
  ifvare PICKUPVELS 0
  {
   ifvare PHYSICSTEMPC 1
   {
    state throwitem
    mulvar WEIGHTFLAG 2
   }
  }
  break
 }

 ifvare CHARACTERSELECTED? 9
 {
  getactor[THISACTOR].htextra temp
  ifvarg temp 0
  {
   getactor[THISACTOR].htpicnum picnum
   ifvare picnum SHOTSPARK1
   {
    getactor[THISACTOR].htowner HOLDINGID
    getactor[HOLDINGID].picnum picnum
    ifvare picnum APLAYER ifvarl ACTORWEIGHT 160
    {
     setvar WEIGHTFLAG 26

     ifvarl ACTORWEIGHT 40 move ITEMSHOOT geth
     else
     ifvarl ACTORWEIGHT 60 move ITEMFLY2 geth
     else
     ifvarl ACTORWEIGHT 100 move ITEMFLY geth

     setactor[THISACTOR].htowner THISACTOR
     spriteflags 16
     setvar FALLFLAG 1
     getplayer[THISACTOR].ang angvar
     setactor[THISACTOR].ang angvar
     getplayer[THISACTOR].horiz temp
     subvar temp 100
     mulvar temp -60
     ifvarl temp -6144 setvar temp -6144
     ifvarg temp 6144 setvar temp 6144
     getactor[THISACTOR].zvel tempb
     addvarvar temp tempb
     setactor[THISACTOR].zvel temp
     iffloordistl 8
     {
      getactor[THISACTOR].z z
      subvar z 1024
      setactor[THISACTOR].z z
      setactor[THISACTOR].zvel -2048
     }
    }
   }
  }
 }

 ifmove 0
 {
  ifvarl ACTORWEIGHT 1 setvar ACTORWEIGHT 40
  move INIT
 }

 ifvarg WEIGHTFLAG 0 
 {
  // ifactor 1769 ifrnd 16 spawn NEWBLOOD1
  // ifactor 2202 ifrnd 16 spawn NEWBLOOD1

  ifmove ITEMFLY nullop
  else ifmove ITEMSHOOT nullop
  else ifmove ITEMFLY2 nullop
  else
  {
   ifactor CRATE1 move ITEMFLY geth
   else ifactor CRATE2 move ITEMFLY geth
   else ifvare WEIGHTFLAG 13 move ITEMFLY geth
   else move ITEMFLY2 geth

   spriteflags 16
   setvar FALLFLAG 1
   ifvare WEIGHTFLAG 13 setactor[THISACTOR].zvel -1024 // for when thrown by an enemy
   else
   {
    getplayer[THISACTOR].ang angvar
    setactor[THISACTOR].ang angvar
    getplayer[THISACTOR].horiz temp
    subvar temp 100
    mulvar temp -80 //-60
    ifvarl temp -6144 setvar temp -6144
    ifvarg temp 6144 setvar temp 6144
    getactor[THISACTOR].zvel tempb
    addvarvar temp tempb
    // ACTORWEIGHT adjustment
    ifvarl temp 0 ifvarg ACTORWEIGHT 40 
    divvar temp 2

    setactor[THISACTOR].zvel temp
   }
  }

  getactor[THISACTOR].htmovflag RETURN	
  ifvare RETURN 0
  {
/*
   findnearactorz SHOOTME 480 10240 HOLDINGID 
   ifvarn HOLDINGID -1 { getactorvar[HOLDINGID].myspawner RETURN subvar RETURN 16384 }
*/
   findnearactorz DEALER 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz STAND1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz STAND3 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz STAND4 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE2 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE3 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE5 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE6 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE7 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DANCE9 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ROBOTDOG 960 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ROBOTDOG2 960 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz PRESIDENTCLINTON 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz COP1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz COP2 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz PUNKDUDE 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz SITTINGDUDE 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM2 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM3 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM4 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM5 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM6 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM7 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM9 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz FEM10 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz TOUGHGAL 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz WOMAN 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz NAKED1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz PODFEM1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ANIMEGIRL1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ANIMEGIRL2 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ANIMEGIRL3 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ANIMEGIRL4 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz EGG 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz GREENSLIME 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz SHARK 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz ROTATEGUN 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz LIZTROOP 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz PIGCOP 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz RECON 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz LIZMAN 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz DRONE 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz OCTABRAIN 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz COMMANDER 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz NEWBEAST 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz TANK 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz SCORPIONTANK 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz BOSS1 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz BOSS2 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz BOSS3 480 10240 HOLDINGID
   ifvare HOLDINGID -1 findnearactorz BOSS4 480 10240 HOLDINGID
   ifvarn HOLDINGID -1 { setvarvar RETURN HOLDINGID subvar RETURN 16384 }
  }
  ifvarn RETURN -1
  {
   // hit something
   addvar RETURN 16384
   ifvarl RETURN 16384
       
   ifvarg RETURN -1
   {
    // impact sound
    getactor[RETURN].statnum tempb
    setvarvar tempb ACTORWEIGHT
    ifvarvarg STRENGTHRATIO LIFTRATIO
    {
     // addlogvar LIFTRATIO
     randvar TEMP3 15
     addvar TEMP3 130
     mulvarvar tempb TEMP3
     divvar tempb 100
    }
    mulvar tempb 2
    ifmove ITEMSHOOT nullop else shiftvarr tempb 2
    // add something to prevent ridiculous things, like bottles destroying garbage cans 

    ifmove ITEMFLY ifvarl ACTORWEIGHT 1 nullop
    else
    {
     sound THROWSMACK
     setactor[RETURN].htextra tempb
     setactor[RETURN].htpicnum CRATE1 // SHOTSPARK1
     setactor[RETURN].htowner PLAYERID // PLAYERID
     getactor[THISACTOR].ang angvar
     setactor[RETURN].htang angvar
    }
   }
   ifmove ITEMSHOOT 
   {
    sound THROWSMACK
    setvarvar tempb ACTORWEIGHT
    mulvar tempb 2
    move ITEMFLY2 geth  
    setactor[THISACTOR].htextra tempb
    setactor[THISACTOR].htpicnum CRATE2 //SHOTSPARK1
    setactor[THISACTOR].htowner PLAYERID // PLAYERID
   }
   else
   ifmove ITEMFLY2 move ITEMFLY geth
   else
   {
    getactor[THISACTOR].owner HOLDINGID
    ifvarvarn RETURN HOLDINGID
    ifvarg WEIGHTFLAG 1 setvar WEIGHTFLAG 1
   }
  }

  iffloordistl 4 
  {
   ifvarg WEIGHTFLAG 6
   {
    ifvarg ACTORWEIGHT 40 subvar WEIGHTFLAG 2
    subvar WEIGHTFLAG 2
    ifvarn BOUNCESND -1 soundvar BOUNCESND
    getactor[THISACTOR].z z
    subvar z 1024
    setactor[THISACTOR].z z
    setvarvar temp WEIGHTFLAG
    mulvar temp -64
    setactor[THISACTOR].zvel temp
   }
  }
  subvar WEIGHTFLAG 1
  iffloordistl 2 nullop else 
  ifvare SECTORLOTAG 2 nullop else ifinwater nullop else
  ifvare WEIGHTFLAG 0 setvar WEIGHTFLAG 1
  ifvare WEIGHTFLAG 0
  move INIT
 }
ends

state checkphysicsmoves
 ifmove ITEMFLY
 {
  setactor[THISACTOR].xvel 384
  state calcmovementphysics
 }
 ifmove ITEMFLY2
 {
  setactor[THISACTOR].xvel 480
  state calcmovementphysics
 }
 ifmove ITEMSHOOT
 {
  setactor[THISACTOR].xvel 1536
  // state calcmovementphysics
 }
ends

state setpickupflags
 ifactor SUPERATOM setactor[THISACTOR].pal 16
 else ifactor SUPERSHIELD setactor[THISACTOR].pal 24
 else getactor[THISACTOR].pal ACTORNATURALPAL

 getactor[THISACTOR].yvel lotagsav
 setactor[THISACTOR].yvel 0
 getactor[THISACTOR].zvel ACTORFLAGS
 setactor[THISACTOR].zvel 0
 changespritestat THISACTOR 1
 sleeptime 0 

 ifvarand ACTORFLAGS 1 // Makes Pickup Completely Invisible [cstat 32768]
 {
  getactor[THISACTOR].cstat TEMP
  ifvarand TEMP 32768 nullop
  else
  {
   addvar TEMP 32768
   setactor[THISACTOR].cstat TEMP
  }
 }
/*
 ifvarand ACTORFLAGS 2 // Silent Pickup For Players [no sounds, screen flashes or messages] // combine with 4 to create silent pickup for both
 {
 }

 ifvarand ACTORFLAGS 4 // Silent Pickup For Monsters [no sounds or messages] // combine with 2 to create silent pickup for both
 {
 }

 ifvarand ACTORFLAGS 8 // Player cannot pickup object // Combine with 16 to make an ungrabbable item // Combine with 16 to make an ungrabbable item
 {
 }

 ifvarand ACTORFLAGS 16 // Monster cannot pickup object [only affects things monsters can normally pick up] // Combine with 8 to make an ungrabbable item
 {
 }

 ifvarand ACTORFLAGS 32 // Inverses Fall Properties [items that normally fall will hover/float, items that normally float/hover will fall]
 {
 }

 ifvarand ACTORFLAGS 64
 {
 }

 ifvarand ACTORFLAGS 128 // Object is worth double[2x] the normal pickup amount // combine with 256 to make octopule[8x] the normal amount
 {
 }

 ifvarand ACTORFLAGS 256 // Object is worth quadruple[4x] the normal pickup amount // combine with 128 to make octopule[8x] the normal amount
 {
 }

 ifvarand ACTORFLAGS 512 // Grabbing the object triggers special effects [i.e. spawning objects/monsters, activating objects/forcefields, opening/unlocking doors, etc. Set "yvel" to the lotag of the activator/forcefield/respawn sprites]
 {
 }
*/
 ifvarand ACTORFLAGS 1024 // Makes pickup invisible to all but the Nightvision Goggles & Mercury VR Visor
 {
  ifvarand ACTORFLAGS 2048 subvar ACTORFLAGS 1024
  else ifvarand ACTORFLAGS 2049 subvar ACTORFLAGS 1024
  else ifvarand ACTORFLAGS 1 subvar ACTORFLAGS 1024
  else
  {
   getactor[THISACTOR].cstat TEMP
   ifvarand TEMP 32768 nullop
   else
   {
    addvar TEMP 32768
    setactor[THISACTOR].cstat TEMP
   }
  }
 }
//
 ifvarand ACTORFLAGS 2048 // Makes pickup invisible to all but the Mercury VR Visor
 {
  getactor[THISACTOR].cstat TEMP
  ifvarand ACTORFLAGS 1 subvar ACTORFLAGS 2048
  else
  {
   getactor[THISACTOR].cstat TEMP
   ifvarand TEMP 32768 nullop
   else
   {
    addvar TEMP 32768
    setactor[THISACTOR].cstat TEMP
   }
  }
 }
/*
 ifvarand ACTORFLAGS 4096 // Object is booby-trapped, but still gives you the pickup
 {
 }

 ifvarand ACTORFLAGS 8192 // Object is booby-trapped, and will NOT give you the pickup value at all
 {
 }
*/
 ifvarand ACTORFLAGS 16384 // Special Flag #1
 {
  ifactor SHIELD setvar ARMORISUSED? 1
  ifactor SUPERSHIELD setvar ARMORISUSED? 1
  ifactor COLORSHIELD setvar ARMORISUSED? 1
 }
/*
 ifvarand ACTORFLAGS 32768 // ?
 {
 }
*/
ends

state checkitemflags
  changespritestat THISACTOR 1
  sleeptime 0
  ifvarand ACTORFLAGS 1 // Completely Invisible
  {
   getactor[THISACTOR].cstat TEMP
   ifvarand TEMP 32768 nullop
   else
   {
    addvar TEMP 32768
    setactor[THISACTOR].cstat TEMP
   }
  }
  else
  ifvarand ACTORFLAGS 1024 // Invisible except for NV Goggles & VR Visor
  {
   ifvare NIGHTVISION 1
   {
    getactor[THISACTOR].cstat TEMP
    ifvarand TEMP 32768
    {
     subvar TEMP 32768
     setactor[THISACTOR].cstat TEMP
    }
   }
   else
   {
    getactor[THISACTOR].cstat TEMP
    ifvarand TEMP 32768 nullop
    else
    {
     addvar TEMP 32768
     setactor[THISACTOR].cstat TEMP
    }
   }
  }
  else
  ifvarand ACTORFLAGS 2048 // Invisible except for VR Visor
  {
   ifvare CHARACTERSELECTED? 4
   {
    ifvare NIGHTVISION 1
    {
     getactor[THISACTOR].cstat TEMP
     ifvarand TEMP 32768
     {
      subvar TEMP 32768
      setactor[THISACTOR].cstat TEMP
     }
    }
    else
    {
     getactor[THISACTOR].cstat TEMP
     ifvarand TEMP 32768 nullop
     else
     {
      addvar TEMP 32768
      setactor[THISACTOR].cstat TEMP
     }
    }
   }
   else
   {
    getactor[THISACTOR].cstat TEMP
    ifvarand TEMP 32768 nullop
    else
    {
     addvar TEMP 32768
     setactor[THISACTOR].cstat TEMP
    }
   }
  }
  ifvare CHARACTERSELECTED? 4
  {
   ifvare NIGHTVISION 1
   {
    ifvarand ACTORFLAGS 4096 setactor[THISACTOR].pal 6
    else ifvarand ACTORFLAGS 8192 setactor[THISACTOR].pal 6
    else setactor[THISACTOR].pal ACTORNATURALPAL
   }
   else setactor[THISACTOR].pal ACTORNATURALPAL
  }
  else setactor[THISACTOR].pal ACTORNATURALPAL
//
  getactor[THISACTOR].cstat TEMP
  ifvarand TEMP 1 subvar TEMP 1 // Items Should not be able to block you
  ifvarand TEMP 256 subvar TEMP 256 // Items Should not be shootable
  ifvarand TEMP 1024 nullop else addvar TEMP 1024
  setactor[THISACTOR].cstat TEMP
  
ends

state checkitemflags2
 ifvarand ACTORFLAGS 128 setvar tempf 2 else setvar tempf 1
 ifvarand ACTORFLAGS 256 setvar tempg 4 else setvar tempg 1
 setvarvar temph tempf
 mulvarvar temph tempg
 ifvarg temph 1
 {
  ifvare SHOWMULTIICONS? 1
  {
   ifcanseetarget
   {
    setvar MULTIPLIERITEMCANSEE? 1
    ifvare MULTIICONCHILD -1
    {
     espawn PICKUPMULTIICON
     setactorvar[RETURN].MULTIICONPARENT THISACTOR
     setactorvar[THISACTOR].MULTIICONCHILD RETURN
    }
   }
   else setvar MULTIPLIERITEMCANSEE? 0
  }
 }
ends

state fallflags
 ifvarand ACTORFLAGS 32 nullop else fall
ends

state fallflags2
 ifvarand ACTORFLAGS 32 fall
ends

state setknockback_player

 getuserdef[THISACTOR].god temp
 ifvare temp 1 break
 ifvarg INVULNTIME 0 break
 ifvarg DEATHSWITCHDELAY 0 break

 getplayer[THISACTOR].posx mx
 getplayer[THISACTOR].posy my
 getactor[THISACTOR].x x
 getactor[THISACTOR].y y

 subvarvar mx x
 subvarvar my y
 getangle knockbackang mx my
 setvar knockback 10
 ifvare CHARACTERSELECTED? 1 sound DUKE_LAND_HURT
 ifvare CHARACTERSELECTED? 5 sound WANG_LONGTERM_PAIN6
 ifvare CHARACTERSELECTED? 8 sound LISA_FALLDAMAGE
 ifvare CHARACTERSELECTED? 9 sound CYBANIS_FALLDAMAGE1
 ifvare CHARACTERSELECTED? 15 sound MAKEN_FALLDAMAGE1
ends

state dmgflr-checkinvulntime
 ifvare VEHICLEID -1 setvarvar tempf INVULNTIME else getactorvar[VEHICLEID].ENEMYINVULNTIME tempf
ends

// HUBS

state SEHUBSTATE

 ifvare hubwait YES // wait for the player to leave the sector before re-activating
 break

 // don't change maps if this map just loaded
 // this avoids problem caused by scroll lock being placed in a map changing sector
 getplayer[THISACTOR].player_par hubtemp
 ifvarl hubtemp 4
 break

 // don't change maps if the player is at the edge of the sector
 // this avoids problem of the player going back and forth between maps with slight movement
 getplayer[THISACTOR].cursectnum hubtempb
 getplayer[THISACTOR].posx hubxoff
 getplayer[THISACTOR].posy hubyoff
 addvar hubxoff 128
 addvar hubyoff 128
 updatesector hubxoff hubyoff hubtemp
 ifvarvarn hubtempb hubtemp break
 subvar hubxoff 256
 updatesector hubxoff hubyoff hubtemp
 ifvarvarn hubtempb hubtemp break
 subvar hubyoff 256
 updatesector hubxoff hubyoff hubtemp
 ifvarvarn hubtempb hubtemp break
 addvar hubxoff 256
 updatesector hubxoff hubyoff hubtemp
 ifvarvarn hubtempb hubtemp break

 getactor[THISACTOR].shade hubtemp
 ifvare hubtemp 10
 {
  setvar hubxoff 0
  setvar hubyoff 0
  setvar hubzoff 0
 }
 else
 {
  getactor[THISACTOR].x hubtemp
  getplayer[THISACTOR].posx hubxoff
  subvarvar hubxoff hubtemp
  getactor[THISACTOR].y hubtemp
  getplayer[THISACTOR].posy hubyoff
  subvarvar hubyoff hubtemp
  getactor[THISACTOR].z hubtemp
  getplayer[THISACTOR].posz hubzoff
  addvar hubzoff 8192
  subvarvar hubzoff hubtemp
  ifvare hubact1 1 { setvar hubxoff 0 setvar hubyoff 0 setvar hubzoff 0 }
 }

 setvarvar hubpdestination hubhitag
 getactor[THISACTOR].pal hubtemp
 setvar hubplayerwait 2
 getplayer[THISACTOR].ang hubpang
 getplayer[THISACTOR].got_access hubsavekeys
 savemapstate
 startlevel VOLUME hubtemp
ends

state projectilehitscan
 // the sprite ID of the scanning projectile has been put in TEMPVAR5 before this state is called
 getactor[TEMPVAR5].x x
 getactor[TEMPVAR5].y y
 getactor[TEMPVAR5].z z
 getactor[TEMPVAR5].sectnum mysector
 getactor[TEMPVAR5].ang angvar
 getactor[TEMPVAR5].zvel zvel
 getactor[TEMPVAR5].xvel xvel
 shiftvarl zvel 14
 ifvare xvel 0 setvar xvel 1
 divvarvar zvel xvel
 cos mycos angvar
 sin mysin angvar
 hitscan x y z mysector mycos mysin zvel hitsector hitwall hitsprite hitx hity hitz clipmask
ends

state atmbroken_dealdamage
  ifvare mainmenu 0
  {
      state stopsearchsounds
      ifvare DEATHSWITCHDELAY 0
      {
       ifvare CHEATGOD 0
       {
        ifvarl INVULNTIME 1
        {
          sound SHORT_CIRCUIT state sparkstate
          randvar tempe 3
          addvar tempe 2
          setvarvar tempd SKILLLEVEL
          addvar tempd 1
          ifvarl tempd 1 setvar tempd 1
          mulvarvar tempe tempd
          setvarvar tempd SKILLLEVEL
          addvar tempd 1
          divvar tempd 2
          ifvarl tempd 1 setvar tempd 1
          mulvarvar tempe tempd
          ifrnd 85 mulvar tempe 3 else ifrnd 128 mulvar tempe 5 else mulvar tempe 7

          setvarvar TEMPDAMAGEVAR tempe
          state char_elecdamage_misc
          setvarvar tempe TEMPDAMAGEVAR

          //*********************
          //*Check Malakian Gems*
          //*********************
          setvarvar TEMP7 tempe
          state checkformalakiangem 
          setvarvar tempe TEMP7

          //****************
          //*Support System*
          //****************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000

           //**Electric Support / Nethra**
           state support-electricresist
           state damagemod-tempvar          
          }

          //*********************************
          //*Support System [ESSence Support*
          //*********************************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000
           //**Overall Support / ESSence**
           state support-overallresist
           state damagemod-tempvar          
          }

          //******************
          //*Equipment System*
          //******************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000
           // Equipment Slot #1
           ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           // Equipment Slot #2
           ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           // Equipment Slot #3
           ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           // Equipment Slot #4
           ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           state damagemod-tempvar          
          }
          // Nyx Gloves Deterrant
          ifvarg tempe 0
          {
           state checkfornyxgloves
           ifvarg DAMAGEMODIFIER 0 setvar tempe 0
          }

          ifvare DAMAGEMODIFIER 0 { ifvare DEFENSECHEAT 1 { ifvarg tempe 1 { divvar tempe 1000 ifvarl tempe 1 setvar tempe 1 state cheatersound } } }

          setvarvar TEMPDAMAGEVAR tempe
          state lisashield_misc
          setvarvar tempe TEMPDAMAGEVAR
   
          setvarvar tempb CURRENTHITPOINTS
          subvarvar tempb tempe
          ifvarl tempe 0 setvar PLAYERHPDAMAGED? -1
          else ifvarg tempe 0 setvar PLAYERHPDAMAGED? 1
          ifvarl tempb 0 setvar tempb 0
          ifvarvarg tempb MAXHITPOINTSATOMIC setvarvar tempb MAXHITPOINTSATOMIC
          setactor[PLAYERID].htpicnum -1
          setvarvar CURRENTHITPOINTS tempb
   
          ifvarn SHOWDAMAGEPLAYER 0
          {
           ifvarg CELLDAMAGETEMP 0
           {
            setvarvar SHOWDAMAGE CELLDAMAGETEMP
            setvar SHOWDAMAGETYPE 2
            setvarvar SHOWDAMAGEACTORID PLAYERID
            state showdamage
           }
          }
          ifvarg FULLSHIELDDAMAGE 0
          {
           setvar ATTACKINGACTORPICNUM 888
           getactor[THISACTOR].pal TEMP
           setvarvar ATTACKINGACTORPAL TEMP
           setvar ATTACKERDISPLAYTIMER 0 setvar BIOSHIELDNULLDAMAGE 0
           ifvarg FULLSHIELDDAMAGE 0 setvar CELLDAMAGETIMER 0
          }
   
          ifvarn SHOWDAMAGEPLAYER 0
          {
           ifvarg tempe 0
           {
            setvarvar SHOWDAMAGE tempe
            // addlogvar tempe
            setvar SHOWDAMAGETYPE 0
            setvarvar SHOWDAMAGEACTORID PLAYERID
            state showdamage
           }
           else ifvarl tempe 0
           {
            setvarvar TEMPHEALTH tempe
            mulvar TEMPHEALTH -1
            state showhealing_playerhp
           }
          }

          ifvarg tempe 0
          {
           setvarvar PAINSOUNDFACTOR tempe
           state checkpainfactor

           setvar ATTACKINGACTORPICNUM 888
           getactor[THISACTOR].pal TEMP
           setvarvar ATTACKINGACTORPAL TEMP
           setvarvar PLAYERDAMAGETEMP tempe
           setactor[THISACTOR].htpicnum -1
           setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
           setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 0
           ifvarg tempe 0 setvar HEALTHDAMAGETIMER 0

           state characterpainsounds
           setvarvar DAMAGEHUEFACTOR tempe
           state playerdamagehues-electrictype
          }
   
        } 
        else
        {
         sound INVULNITEM3
         palfrom 0 0 0 0
        }
       } 
      } 
  }
ends

state plug_dealdamage
  ifvare mainmenu 0
  {
   ifp pfacing
   {
    ifhitspace
    {
     ifcansee 
     {
      state stopsearchsounds
      ifvare DEATHSWITCHDELAY 0
      {
       ifvare CHEATGOD 0
       {
        ifvarl INVULNTIME 1
        {
         getactor[PLAYERID].z temp
         subvar temp 6144
         ifvarvarg temp KEYSCANNERZUP
         ifvarvarl temp KEYSCANNERZDOWN
         ifvare com_pause 0
         { 
          sound SHORT_CIRCUIT state sparkstate
          randvar tempe 3
          addvar tempe 2
          setvarvar tempd SKILLLEVEL
          addvar tempd 1
          ifvarl tempd 1 setvar tempd 1
          mulvarvar tempe tempd
          setvarvar tempd SKILLLEVEL
          addvar tempd 1
          divvar tempd 2
          ifvarl tempd 1 setvar tempd 1
          mulvarvar tempe tempd
   
          setvarvar TEMPDAMAGEVAR tempe
          state char_elecdamage_misc
          setvarvar tempe TEMPDAMAGEVAR

          //*********************
          //*Check Malakian Gems*
          //*********************
          setvarvar TEMP7 tempe
          state checkformalakiangem 
          setvarvar tempe TEMP7

          //****************
          //*Support System*
          //****************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000

           //**Electric Support / Nethra**
           state support-electricresist
           state damagemod-tempvar          
          }

          //*********************************
          //*Support System [ESSence Support*
          //*********************************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000
           //**Overall Support / ESSence**
           state support-overallresist
           state damagemod-tempvar          
          }

          //******************
          //*Equipment System*
          //******************
          ifvarg tempe 0
          {
           setvar DAMAGEMODIFIER 1000
           // Equipment Slot #1
           ifvare PLAYEREQUIPSLOTITEM1 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           // Equipment Slot #2
           ifvare PLAYEREQUIPSLOTITEM2 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           // Equipment Slot #3
           ifvare PLAYEREQUIPSLOTITEM3 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           // Equipment Slot #4
           ifvare PLAYEREQUIPSLOTITEM4 3 addvar DAMAGEMODIFIER -238 // Plasma Ring
           state damagemod-tempvar          
          }
          // Nyx Gloves Deterrant
          ifvarg tempe 0
          {
           state checkfornyxgloves
           ifvarg DAMAGEMODIFIER 0 setvar tempe 0
          }

          ifvare DAMAGEMODIFIER 0 { ifvare DEFENSECHEAT 1 { ifvarg tempe 1 { divvar tempe 1000 ifvarl tempe 1 setvar tempe 1 state cheatersound } } }

          setvarvar TEMPDAMAGEVAR tempe
          state lisashield_misc
          setvarvar tempe TEMPDAMAGEVAR
   
          setvarvar tempb CURRENTHITPOINTS
          subvarvar tempb tempe
          ifvarl tempe 0 setvar PLAYERHPDAMAGED? -1
          else ifvarg tempe 0 setvar PLAYERHPDAMAGED? 1
          ifvarl tempb 0 setvar tempb 0
          ifvarvarg tempb MAXHITPOINTSATOMIC setvarvar tempb MAXHITPOINTSATOMIC
          setactor[PLAYERID].htpicnum -1
          setvarvar CURRENTHITPOINTS tempb
   
          ifvarn SHOWDAMAGEPLAYER 0
          {
           ifvarg CELLDAMAGETEMP 0
           {
            setvarvar SHOWDAMAGE CELLDAMAGETEMP
            setvar SHOWDAMAGETYPE 2
            setvarvar SHOWDAMAGEACTORID PLAYERID
            state showdamage
           }
          }
          ifvarg FULLSHIELDDAMAGE 0
          {
           setvar ATTACKINGACTORPICNUM 5175
           getactor[THISACTOR].pal TEMP
           setvarvar ATTACKINGACTORPAL TEMP
           setvar ATTACKERDISPLAYTIMER 0 setvar BIOSHIELDNULLDAMAGE 0
           ifvarg FULLSHIELDDAMAGE 0 setvar CELLDAMAGETIMER 0
          }
   
          ifvarn SHOWDAMAGEPLAYER 0
          {
           ifvarg tempe 0
           {
            setvarvar SHOWDAMAGE tempe
            // addlogvar tempe
            setvar SHOWDAMAGETYPE 0
            setvarvar SHOWDAMAGEACTORID PLAYERID
            state showdamage
           }
           else ifvarl tempe 0
           {
            setvarvar TEMPHEALTH tempe
            mulvar TEMPHEALTH -1
            state showhealing_playerhp
           }
          }

          ifvarg tempe 0
          {
           setvarvar PAINSOUNDFACTOR tempe
           state checkpainfactor

           setvar ATTACKINGACTORPICNUM 5175
           getactor[THISACTOR].pal TEMP
           setvarvar ATTACKINGACTORPAL TEMP
           setvarvar PLAYERDAMAGETEMP tempe
           setactor[THISACTOR].htpicnum -1
           setvarvar TEMPHITCHARACTERVAR CHARACTERSELECTED?
           setvar ATTACKERDISPLAYTIMER 0 setvar NULLDAMAGE 0
           ifvarg tempe 0 setvar HEALTHDAMAGETIMER 0

           state characterpainsounds
           setvarvar DAMAGEHUEFACTOR tempe
           state playerdamagehues-electrictype
          }
   
          setvar com_pause 10 // This sets a delay between presses of space so that everything doesn't happen at once.
         }
        } 
        else
        {
         ifvare com_pause 0
         { 
          sound INVULNITEM3
          palfrom 0 0 0 0
          setvar com_pause 10 // This sets a delay between presses of space so that everything doesn't happen at once.
         }
        }
       } 
      } 
     }
    }
   }
  }
ends

// Extraneous States
// End Extraneous States

