Advertisement
skroton

pickup point thing

May 25th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.59 KB | None | 0 0
  1. /* this all done on shitty phone so no promises and this might be crap and not work at all */
  2.  
  3. /* absolute value function because there's not a native abs() acs function */
  4. function int abs (int x)
  5. {
  6.   if (x < 0)
  7.     return -x;
  8.   return x;
  9. }
  10.  
  11. /* 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 */
  12. 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 */
  13. {
  14.   int check; /* check for later, value at declaration is zero */
  15.  
  16.   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 */
  17.   {
  18.     case 0:
  19.       SetActivator(0, AAPTR_PLAYER1);
  20.       break;
  21.     case 1:
  22.       SetActivator(0, AAPTR_PLAYER2);
  23.       break;
  24.     case 2:
  25.       SetActivator(0, AAPTR_PLAYER3);
  26.       break;
  27.     case 3:
  28.       SetActivator(0, AAPTR_PLAYER4);
  29.       break;
  30.     case 4:
  31.       SetActivator(0, AAPTR_PLAYER5);
  32.       break;
  33.     case 5:
  34.       SetActivator(0, AAPTR_PLAYER6);
  35.       break;
  36.     case 6:
  37.       SetActivator(0, AAPTR_PLAYER7);
  38.       break;
  39.     case 7
  40.       SetActivator(0, AAPTR_PLAYER8);
  41.       break;
  42.   }
  43.  
  44.   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 */
  45.   {
  46.     check = 1; /* set check to a positive value  so it can return a true value */
  47.   }
  48.  
  49.   return check;
  50. }
  51.  
  52. script "pointpickup" enter /* the actual pickup script */
  53. {
  54.  
  55. /* 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 */  
  56.  
  57.   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 */
  58.  
  59.   int a_x, a_y, a_z; /* actor x, y, z coordinates */
  60.   int p_x, p_y, p_z; /* player x, y, z coordinates */
  61.  
  62.   int max_dist, max_xy_dist, max_z_dist; /* maximum total distance, maximum horizontal distance, and maximum vertical height to allow pickup */
  63.  
  64. /* disregard this section, this is more painful than I thought on a phone so I'm simplifying this for now */
  65.   int use_r_h; /* switch to use radius and height in distance checks */
  66.   int a_radius, a_height; /* actor radius and height to include in distance checks */
  67.   int p_radius, p_height; /* player radius and height to include in distance checks */
  68.   int p_a_xy_angle; /* angle calculated from player to actor xy points to use with radius in max distance checks */
  69.  
  70.   str class; /* class name of actor being picked up*/
  71.  
  72.   /* 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 */
  73.  
  74.   max_dist = 128.0;
  75.   max_xy_dist = 64.0;
  76.   max_z_dist = 64.0;
  77.  
  78.   /* note that you could set these distance maximums later, and base what they are upon what class the actor being picked up is */
  79.  
  80.   player_num = PlayerNumber(); /* retrieve player number, before the loop is ever started and before we start changing activators */
  81.  
  82.   while(true) /* will continually loop */
  83.   {
  84.     if( (GetPlayerInput(0, INPUT_BUTTONS) & BT_USE) /* if one of the buttons the player is pressing this tic is the use button */
  85.     && /* AND */
  86.     !(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 */
  87.     { /* then */
  88.       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 */
  89.       if(target_check) /* if setactivator worked */
  90.       {
  91.         class = GetActorClass(0); /* get actor class name string for use later */
  92.  
  93.         a_x = GetActorX(0); /* get actor x position in fixed point */
  94.         a_y = GetActorY(0); /* get actor y position in fixed point */
  95.         a_z = GetActorZ(0); /* get actor z position in fixed point */
  96.  
  97.         actor_tid = UniqueTID(); /* get a unique tid to assign to actor */
  98.         Thing_ChangeTID(0, actor_tid); /* now assign that tid to the actor */
  99.  
  100.         SetActivator_Player(player_num); /* now set activator back to player using custom function defined above */
  101.  
  102.         p_x = GetActorX(0); /* get player x position in fixed point */
  103.         p_y = GetActorY(0); /* get player y position in fixed point */
  104.         p_z = GetActorZ(0); /* get player z position in fixed point */
  105.  
  106. int max_dist, max_xy_dist, max_z_dist
  107.  
  108.         if( (VectorLength(VectorLength((ax - 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 */
  109.         && /* AND */
  110.         (VectorLength((ax - 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 */
  111.         && /* AND */
  112.         (abs(a_z - p_z) <= max_z_dist) ) /* if vertical distance between player and actor is less than or equal to max_z_dist */
  113.         { /* then */
  114.  
  115.           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 */
  116.  
  117.           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 */
  118.  
  119.           Thing_Remove(actor_tid); /* remove the actor from the map */
  120.  
  121.         }
  122.       }
  123.       else /* if setactivator failed */
  124.       {
  125.         SetActivator_Player(player_num); /* set activator back to player using custom function defined above */
  126.       }
  127.  
  128.     }
  129.  
  130.   delay(1); /* delay for one tic before starting loop again */
  131.  
  132.   }
  133.  
  134. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement