SHARE
TWEET

point pickup that's not working but compiles

skroton May 26th, 2016 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #library "point"
  2.  
  3.  
  4. #include "zcommon.acs"
  5.  
  6.  
  7. /* this all done on shitty phone so no promises and this might be crap and not work at all */
  8.  
  9. /* absolute value function because there's not a native abs() acs function */
  10. function int abs (int x)
  11. {
  12.   if (x < 0)
  13.     return -x;
  14.   return x;
  15. }
  16.  
  17. /* function for setting player as activator, works in ZDoom without giving any player a tid, if you want this for zandronum you will have to do something like give each player a tid on start and store them in an array, unless there's a zandronum specific function (there are quite a few) that helps with this that I'm not aware of */
  18. function int SetActivator_Player (int player_num) /* player_num doesn't have to be same name as variable passed to it, can be whatever you want */
  19. {
  20.   int check; /* check for later, value at declaration is zero */
  21.  
  22.   switch(player_num) /* switch for player number, player numbers start at 0, so player 1 has a player number of 0 and player 8 has a player number of 7 */
  23.   {
  24.     case 0:
  25.       SetActivator(0, AAPTR_PLAYER1);
  26.       break;
  27.     case 1:
  28.       SetActivator(0, AAPTR_PLAYER2);
  29.       break;
  30.     case 2:
  31.       SetActivator(0, AAPTR_PLAYER3);
  32.       break;
  33.     case 3:
  34.       SetActivator(0, AAPTR_PLAYER4);
  35.       break;
  36.     case 4:
  37.       SetActivator(0, AAPTR_PLAYER5);
  38.       break;
  39.     case 5:
  40.       SetActivator(0, AAPTR_PLAYER6);
  41.       break;
  42.     case 6:
  43.       SetActivator(0, AAPTR_PLAYER7);
  44.       break;
  45.     case 7:
  46.       SetActivator(0, AAPTR_PLAYER8);
  47.       break;
  48.   }
  49.  
  50.   if(player_num == PlayerNumber()) /* the player number is the same as the intended player number, meaning setactivator was successful; setactivator has its own return value, but this returns false if the pointer is null, which is basically but not quite exactly what this is checking */
  51.   {
  52.     check = 1; /* set check to a positive value  so it can return a true value */
  53.   }
  54.  
  55.   return check;
  56. }
  57.  
  58. script "pointpickup" enter /* the actual pickup script */
  59. {
  60.  
  61. /* all the variables below are just getting declared right now, they don't have any values (well they do, but it's all 0) and don't do anything yet */  
  62.  
  63.   int actor_tid, player_num, target_check; /* tid to assign to actor being picked up, player number, check for if player is pointing at something */
  64.  
  65.   int a_x, a_y, a_z; /* actor x, y, z coordinates */
  66.   int p_x, p_y, p_z; /* player x, y, z coordinates */
  67.  
  68.   int max_dist, max_xy_dist, max_z_dist; /* maximum total distance, maximum horizontal distance, and maximum vertical height to allow pickup */
  69.  
  70. /* disregard this section, this is more painful than I thought on a phone so I'm simplifying this for now */
  71.   int use_r_h; /* switch to use radius and height in distance checks */
  72.   int a_radius, a_height; /* actor radius and height to include in distance checks */
  73.   int p_radius, p_height; /* player radius and height to include in distance checks */
  74.   int p_a_xy_angle; /* angle calculated from player to actor xy points to use with radius in max distance checks */
  75.  
  76.   str class; /* class name of actor being picked up*/
  77.  
  78.   /* now the distance maximums have their value set, the rest will be set during script; these need to be set in fixed point to work correctly, so make sure the values you set them to use a decimal point */
  79.  
  80.   max_dist = 128.0;
  81.   max_xy_dist = 64.0;
  82.   max_z_dist = 64.0;
  83.  
  84.   /* note that you could set these distance maximums later, and base what they are upon what class the actor being picked up is */
  85.  
  86.   player_num = PlayerNumber(); /* retrieve player number, before the loop is ever started and before we start changing activators */
  87.  
  88.   while(true) /* will continually loop */
  89.   {
  90.     if( (GetPlayerInput(0, INPUT_BUTTONS) & BT_USE) /* if one of the buttons the player is pressing this tic is the use button */
  91. /*    && /* AND */
  92. /*    !(GetPlayerInput(0, INPUT_OLDBUTTONS) & BT_USE)*/ ) /* none of the buttons the player was pressing last tic were the use button, meaning they just started  pressing the use button this tic */
  93.     { /* then */
  94.       target_check = SetActivator(0, AAPTR_PLAYER_GETTARGET); /* set activator to actor under player crosshair, sets target_check to 1 if there is such an actor and 0 if not */
  95.       if(target_check) /* if setactivator worked */
  96.       {
  97.         class = GetActorClass(0); /* get actor class name string for use later */
  98.  
  99.         a_x = GetActorX(0); /* get actor x position in fixed point */
  100.         a_y = GetActorY(0); /* get actor y position in fixed point */
  101.         a_z = GetActorZ(0); /* get actor z position in fixed point */
  102.  
  103.         actor_tid = UniqueTID(); /* get a unique tid to assign to actor */
  104.         Thing_ChangeTID(0, actor_tid); /* now assign that tid to the actor */
  105.  
  106.         SetActivator_Player(player_num); /* now set activator back to player using custom function defined above */
  107.  
  108.         p_x = GetActorX(0); /* get player x position in fixed point */
  109.         p_y = GetActorY(0); /* get player y position in fixed point */
  110.         p_z = GetActorZ(0); /* get player z position in fixed point */
  111.  
  112.         if( (VectorLength(VectorLength((a_x - p_x), (a_y - p_y)), (a_z - p_z)) <= max_dist) /* if total distance between player and actor is less than or equal to max_dist */
  113.         && /* AND */
  114.         (VectorLength((a_x - p_x), (a_y - p_y)) <= max_xy_dist) /* if horizontal distance between player and actor is less than or equal to max_xy_dist */
  115.         && /* AND */
  116.         (abs(a_z - p_z) <= max_z_dist) ) /* if vertical distance between player and actor is less than or equal to max_z_dist */
  117.         { /* then */
  118.  
  119.           log(s: "You take the ", s:class ); /* print class name of actor for debugging; APROP_NAMETAG only works with checkactorproperty, and can only be compared, not retrieved. If you want to have a name that's not the decorate class name, recommend 2D string array with class name in first part of each set and what you want to print in second part of set, then have loop to compare class to each first part of set in array until you get a match, then print corresponding string in second part of set */
  120.  
  121.           StrCmp(class, "string to compare"); /* this is what you would use to compare the actor class name to in order to make decisions based on that, returns 0 if the strings being compared are the same; see: http://zdoom.org/wiki/StrCmp */
  122.  
  123.           Thing_Remove(actor_tid); /* remove the actor from the map */
  124.  
  125.         }
  126.       }
  127.       else /* if setactivator failed */
  128.       {
  129.         SetActivator_Player(player_num); /* set activator back to player using custom function defined above */
  130.       }
  131.  
  132.     }
  133.  
  134.   delay(1); /* delay for one tic before starting loop again */
  135.  
  136.   }
  137.  
  138. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top