Advertisement
D0nyAlcap0ney

scrGoGetWeapon - Updated Fix w/ Array

Apr 22nd, 2024
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Game Maker 3.64 KB | Source Code | 0 0
  1. validweapon [0] = 0
  2. validweapon [1] = 1
  3. validweapon [2] = 2
  4. validweapon [3] = 3
  5. validweapon [4] = 4
  6. validweapon [5] = 5
  7. validweapon [6] = 6
  8. validweapon [7] = 7
  9. validweapon [8] = 17
  10. validweapon [9] = 28
  11. validweapon [10] = 31
  12. globalvar check;
  13. scrMoveSolidOn()
  14. if weaponfind= 0 {
  15. i = 0
  16. target = 0
  17. if checkreload > 0 checkreload -= 1
  18. else {
  19. checkreload = 10
  20. global.check = 0
  21. while i < instance_number(objWeapon) and global.check = 0 {
  22. target = scrInstanceNearest(objWeapon, i)
  23. if instance_exists(target) {
  24.  // Check if the image_index is within the valid range
  25.                 var isValidWeapon = false;
  26.                 var j;
  27.                 for (j = 0; j < array_length_1d(validweapon); j++) {
  28.                     if (validweapon[j] == target.image_index) {
  29.                         isValidWeapon = true;
  30.                         break;
  31.                     }
  32.                 }
  33.                 if (isValidWeapon) {
  34. if !scrCollisionLineExt(x,y,target.x,target.y,4,objSolid,objShootThrough,objDoorV) {
  35. global.check=1
  36. weaponfind=1
  37. }
  38. }
  39. }
  40. i += 1
  41. }
  42. }
  43.  
  44. if weaponfind = 0 and instance_exists(objPlayer) {
  45. dist = point_distance(x,y,objPlayer.x,objPlayer.y)
  46. if dist < 64 {
  47. dir = point_direction(objPlayer.x,objPlayer.y,x,y)
  48. direction = dir - 180
  49. scrMoveSolidOn()
  50. if place_free(x+lengthdir_x(1,dir),y+lengthdir_y(1,dir)) {
  51. x+=lengthdir_x(1,dir)
  52. y+=lengthdir_y(1,dir)
  53. }
  54. scrMoveSolidOff()
  55. image_speed=0.1
  56. }
  57. }
  58.  
  59. } else {
  60. if !instance_exists(target) {
  61.     weaponfind = 0 speed = 0
  62.     } else {
  63.         speed=2
  64.         direction = point_direction(x,y,target.x,target.y)
  65.         image_speed = 0.2
  66.         if place_meeting(x,y,target) {
  67.         my_id = -123123
  68.        
  69. if target.image_index = 0 {
  70.     my_id = instance_create(x, y, objEnemy) my_id.sprite_index = sprEWalkM16
  71.     }
  72.     else if target.image_index=1 {
  73.             my_id = instance_create(x, y, objEnemy) my_id.sprite_index = sprEWalkShotgun
  74.             }
  75.     else if target.image_index=2 {
  76.             my_id = instance_create (x, y, objEnemyMelee) my_id.sprite_index = sprEWalkClub
  77.             }
  78.     else if target.image_index=3 {
  79.             my_id = instance_create (x, y, objEnemyMelee) my_id.sprite_index = sprEWalkPipe
  80.             }
  81.     else if target.image_index=4 {
  82.             my_id = instance_create (x, y, objEnemyMelee) my_id.sprite_index = sprEWalkBat
  83.             }
  84.     else if target.image_index=5 {
  85.             my_id = instance_create (x, y, objEnemyMelee) my_id.sprite_index = sprEWalkKnife
  86.             }
  87.     else if target.image_index=6 {
  88.             my_id = instance_create (x, y, objEnemy) my_id.sprite_index = sprEWalkDoubleBarrel
  89.             }
  90.     else if target.image_index=7 {
  91.             my_id = instance_create (x, y, objEnemy) my_id.sprite_index = sprEWalkSilencer
  92.             }
  93.     else if target.image_index=17 {
  94.             my_id = instance_create (x, y, objEnemyMelee) my_id.sprite_index = sprEWalkCrowbar
  95.             }
  96.     else if target.image_index=28 {
  97.             my_id = instance_create (x, y, objEnemyMelee) my_id.sprite_index = sprEWalkKatana
  98.             }
  99.     else if target.image_index=31 {
  100.             my_id = instance_create (x, y, objEnemy) my_id.sprite_index = sprEWalkFAL
  101.             } else exit
  102.  
  103.     if instance_exists(target) my_id.ammo=target.ammo
  104. audio_play_sound(sndPickupWeapon,0,false)
  105. with target instance_destroy()
  106. with my_id {
  107.     if scrMovingPlayerExists() scrChasePlayer(path, objPlayer.x, objPlayer.y)
  108.     }
  109. instance_destroy()
  110. }
  111.  
  112. if !place_free(x+hspeed*3,y+vspeed*3) {
  113. if !place_free(x+hspeed*3,y) hspeed=-hspeed
  114. if !place_free(x,y+vspeed*3) vspeed=-vspeed
  115. weaponfind=0
  116. }
  117.  
  118. }
  119. }
  120.  
  121. //scrMoveSolidOff()
  122. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement