Advertisement
Guest User

Chrome's Son

a guest
Oct 19th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Usage: if (target_in_sight(obj))
  2. //It's laggy sometimes but it works
  3. var xx,yy,zz,faceDir,facePitch,ii,target,seen;
  4. target=argument0;
  5. xx=x;
  6. yy=y;
  7. zz=z+(height-4);
  8. faceDir=point_direction(x,y,target.x,target.y);
  9. facePitch=-point_direction_3d(x,y,z+(height-4),target.x,target.y,target.z+random(target.height));
  10. seen=false;
  11. //Works as is, don't increase range or lower length, or you'll murder your memory
  12. repeat (global.drawRange/1.1)
  13. {
  14.     xx+=lengthdir_x(1,faceDir);
  15.     yy+=lengthdir_y(1,faceDir);
  16.     zz+=lengthdir_y(1,facePitch);
  17.     ii=collision_point(xx,yy,obj_wall_basic,true,false);
  18.     if !(ii==noone)
  19.     {
  20.         if (zz>=ii.z2 && zz<=ii.z1)
  21.         {
  22.             break
  23.         }
  24.         else
  25.         {
  26.             continue
  27.         }
  28.     }
  29.     ii=collision_point(xx,yy,obj_wall_high_basic,true,false);
  30.     if !(ii==noone)
  31.     {
  32.         if (zz>=ii.z2 && zz<=ii.z1)
  33.         {
  34.             break
  35.         }
  36.         else
  37.         {
  38.             continue
  39.         }
  40.     }
  41.     ii=collision_point(xx,yy,obj_wall_low_basic,true,false);
  42.     if !(ii==noone)
  43.     {
  44.         if (zz>=ii.z2 && zz<=ii.z1)
  45.         {
  46.             break
  47.         }
  48.         else
  49.         {
  50.             continue
  51.         }
  52.     }
  53.     ii=collision_point(xx,yy,obj_floor_basic,true,false);
  54.     if !(ii==noone)
  55.     {
  56.         if (zz>=ii.z && zz<=ii.z)
  57.         {
  58.             break
  59.         }
  60.         else
  61.         {
  62.             continue
  63.         }
  64.     }
  65.     ii=collision_point(xx,yy,obj_ceiling_basic,true,false);
  66.     if !(ii==noone)
  67.     {
  68.         if (zz>=ii.z && zz<=ii.z)
  69.         {
  70.             break
  71.         }
  72.         else
  73.         {
  74.             continue
  75.         }
  76.     }
  77.     ii=collision_point(xx,yy,obj_block_basic,true,false);
  78.     if !(ii==noone)
  79.     {
  80.         if (zz>=ii.z2 && zz<=ii.z1)
  81.         {
  82.             break
  83.         }
  84.         else
  85.         {
  86.             continue
  87.         }
  88.     }
  89.     ii=collision_point(xx,yy,obj_slope_basic,true,false);
  90.     if !(ii==noone)
  91.     {
  92.         var point;
  93.         if (ii.slopeDir==90)
  94.         {
  95.             point=ii.z1+(point_distance(x,y,ii.x,y)/1.36);
  96.         }
  97.         if (ii.slopeDir==180)
  98.         {
  99.             point=ii.z1-point_distance(x,y,ii.x,y);
  100.         }
  101.         if (zz>=point && zz<=point)
  102.         {
  103.             break
  104.         }
  105.         else
  106.         {
  107.             continue
  108.         }
  109.     }
  110.     ii=collision_point(xx,yy,target,true,false)
  111.     if !(ii==noone)
  112.     {
  113.         if (zz>=ii.z && zz<=(ii.z+ii.height))
  114.         {
  115.             seen=true;
  116.             break
  117.         }
  118.         else
  119.         {
  120.             continue
  121.         }
  122.     }
  123. }
  124. debugX=xx;
  125. debugY=yy;
  126. debugZ=zz;
  127. return (seen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement