Advertisement
D0nyAlcap0ney

scrGoGetWeapon - Final Version, for tutorial

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