Advertisement
scroton

GMOTA Ice Missile script

Apr 11th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.09 KB | None | 0 0
  1. script "IceMissileScript" (void) /* Call this in the missile's XDeath state with "CallACS("IceMissileScript")" */
  2. {
  3.   int proj_rad, proj_height, proj_x, proj_y, proj_z, tar_x, tar_y, tar_z, tar_rad, tar_height;
  4.  
  5.   proj_rad = GetActorProperty(0, APROP_Radius) << 16; /* Get the radius of the projectile (converted to fixed point) */
  6.   proj_height = GetActorProperty(0, APROP_Height) << 16; /* Get the height of the projectile (converted to fixed point) */
  7.  
  8.   proj_x = GetActorX(0); /* Get projectile X position */
  9.   proj_y = GetActorY(0); /* Get projectile Y position */
  10.   proj_z = GetActorZ(0); /* Get projectile Z position */
  11.  
  12.   /* Now set activator to the projectile's tracer (what the monster was trying to hit) to get
  13.      information about the actor without having to use tids */
  14.   SetActivator(0,AAPTR_TRACER);
  15.  
  16.   tar_rad = GetActorProperty(0, APROP_Radius) << 16; /* Get the radius of the target (converted to fixed point) */
  17.   tar_height = GetActorProperty(0, APROP_Height) << 16; /* Get the height of the target (converted to fixed point) */
  18.  
  19.   tar_x = GetActorX(0); /* Get target X position */
  20.   tar_y = GetActorY(0); /* Get target Y position */
  21.   tar_z = GetActorZ(0); /* Get target Z position */
  22.  
  23.   /* Now we compare the positions, because just hitting a shootable target (since it was called
  24.      from the XDeath state) does not guarantee it hit the actor the monster was aiming at. */
  25.  
  26.   /* If you don't understand what stuff like "||" (or) or "&&" (and) is, google "ZDoom ACS
  27.      operators; they are also the same as C's operators in pretty much all cases */
  28.  
  29.   /* We check Z positions first */
  30.   if( ( (proj_z >= tar_z && proj_z <= (tar_z + tar_height)) /* If projectile's bottom is between the target's bottom and top */
  31.     || ((proj_z + proj_height) >= tar_z && (proj_z + proj_height) <= (tar_z + tar_height)) ) /* OR if projectile's top is between the target's bottom and top */
  32.  
  33.   /* Note that the above assumes that the projectile is shorter than the actor--if the
  34.      projectile is taller than the actor (or could be taller than the actor if you're
  35.      not certain) then you'd have to check the inverse of the above as well */
  36.  
  37.    && /* AND */
  38.  
  39.   /* Now we check position on the XY plane */
  40.     ( VectorLength(tar_x - proj_x, tar_y - proj_y) /* The distance between the two positions... */
  41.  
  42.   /* ..is less than or equal to the sum of the two actor's radii (using hypotenuse of radii
  43.      because in (G)ZDoom actors are square, not round, and radius refers to distance from
  44.      the actor's center to the nearest side (not corner), or effectively 1/2 of the length
  45.      of a single side of the actor's cube hitbox */
  46.      <= (VectorLength(proj_rad, proj_rad) + VectorLength(tar_rad, tar_rad)) )
  47.      
  48.      && !GetActorProperty(0, APROP_Invulnerable) /* AND the target (player) is not invulnerable */
  49.      
  50.      ){  /* If all above conditions are met, then.. */
  51.  
  52.   GiveInventory("ItemName",1); /* Give the current activator (the monster's target and what the projectile hit
  53.   an inventory item "ItemName" which should be a CustomInventory item; since you can put all decorate action
  54.   functions in the item's pickup state (such as A_GiveInventory and others--basically whatever you have currently
  55.   happening in the pain sate) this allows you to set the what the effect does in Decorate rather than ACS so you
  56.   don't have to modify this script and can work in Decorate instead. */
  57.  
  58.   /* If there ends up being more effects you want that are only available in ACS, add them here right after this line */
  59.  
  60.   } /* End of IF statement */
  61.  
  62.   /* Don't need to add an ELSE since if the IF condition isn't met the script will just stop on it's own */
  63.  
  64.   /* It's worth noting that by adding a script argument (instead of the "(void)" up there now) you could
  65.      easily have this script work for other projectiles, and have the same script be used by multiple
  66.      projectiles and do different things for each; it's very easy to do and either I or someone else that
  67.      knows ACS could help you, or if you want to try it yourself look up "ACS switch statement" */
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement