Advertisement
PinkiePie5892

Generic Block Weldong Code

Sep 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Generic Block: Step Event
  2.  
  3. event_inherited()
  4.  
  5.  if point_distance(mouse_x,mouse_y,x,y)<=20
  6.  {
  7.   if mouse_check_button(mb_left)
  8.   {
  9.    if pointer.grabbed==noone
  10.    {
  11.     if welded==true
  12.     {
  13.      var _dir=-1
  14.      for (var _i=0; _i<array_height_2d(parent.hardPoint) _i++)
  15.      {
  16.       if parent.hardPoint[_i,0]==id
  17.       {
  18.        _dir = (hardPoint[_i,2]+180)mod 360;
  19.        parent.hardPoint[_i,0]=noone;
  20.        welded=false;
  21.        break;
  22.       }
  23.      }
  24.      
  25.      for(var _i=0; _i<array_height_2d(hardPoint) _i++)
  26.      {
  27.       if hardPoint[_i,2]+angle== _dir
  28.       {
  29.        hardPoint[_i,0]=noone
  30.        audio_play_sound(sound_unblock,0,0)
  31.        break;
  32.  
  33.       }
  34.      }
  35.     }
  36.     pointer.grabbed=id
  37.    }
  38.   }
  39.  }
  40.  
  41.  
  42. if pointer.grabbed == id {
  43.     if !mouse_check_button( mb_left ) {
  44.         var _id        = noone;
  45.         var _point    = 0;
  46.         var _last    = 0;
  47.         var _me        = id;
  48.            
  49.         with ( block ) {
  50.            
  51.             if _me == id { continue }
  52.                
  53.             if point_distance( mouse_x, mouse_y, x, y, ) < 30 {
  54.                 for ( var _i = 0; _i < array_height_2d( hardPoint ); _i++ ) {
  55.                     var _x        = x + lengthdir_x( hardPoint[ _i, 1 ], hardPoint[ _i, 2 ] + angle );
  56.                     var _y        = y + lengthdir_y( hardPoint[ _i, 1 ], hardPoint[ _i, 2 ] + angle );
  57.                     var _dist    = point_distance( mouse_x, mouse_y, _x, _y );
  58.                    
  59.        
  60.                    
  61.                     if hardPoint[ _i, 0 ] == noone && _dist < hardPointSize && hardPoint[ _i, 3 ] & _me.componentType > 0 {
  62.                         if _id == noone || _dist < _last {
  63.                             _last    = _dist;
  64.                             _id        = id;
  65.                             _point    = _i;
  66.                                
  67.                         }
  68.                            
  69.                     }
  70.                
  71.                 }
  72.                    
  73.             }
  74.                
  75.         }
  76.         if _id != noone {
  77.             _id.hardPoint[ _point, 0 ] = id;
  78.             welded    = true;
  79.             parent    = _id;
  80.            
  81.             var _dir = (_id.hardPoint[_point,2]+180)mod 360;
  82.            
  83.             for (var _i=0; _i<array_height_2d(hardPoint) _i++)
  84.             {
  85.              if hardPoint[_i,2]+angle==_dir{
  86.              hardPoint[_i,0]=-1
  87.              break;
  88.              }
  89.             }
  90.             audio_play_sound(sound_block,0,0)                
  91.         }
  92.         pointer.grabbed    = noone;
  93.  
  94.     } else {
  95.         x    = mouse_x;
  96.         y    = mouse_y;
  97.  
  98.     }
  99.    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement