Punish campers! xd

Version:

4.0

Added on:

04 Feb 2013 14:27

Tags:

Description:
Illustrating what tiles are marked for camparea #3:



It was a bit tricky to select the right ones, because when you jump into a tile above you your head (atleast as spaz) sticks into it a bit (the right outer side of the seekbox). I also made a small alteration to the comparison code, changing (xPos <= aCamp) to (xPos < aCamp). Not sure why it's better, but trial and error tells me that it is so.
  1. /*
  2. Punish campers xd! v2.1
  3.  
  4. changes v2.1:
  5. -made onPlayer work thanks to Violet
  6. -made it not needed to state maxcamp for every sub-area
  7. -added timer by letting the "you are camping" text show every second
  8. -the "you are camping message" disappears when you stop camping
  9.  in order for that to happen as soon as possible, I have lowered checkCampInterval to 10
  10.  (you have to use something that 70 is evenly divisible with)
  11.  
  12. changes v2.0:
  13. -made non-rectangular camp areas possible
  14.  
  15. changes v1.1:
  16. -had to recreate the onPlayer function, because it wouldn't work for clients :S
  17. -moved a message out of isInCampArea()
  18. -killed player with .kill() instead of .health=0 (thx cooba)
  19.  
  20. improvements needed:
  21. -don't kill players if the game is stopped (the AngelScript implementation needs a new bool)
  22. -the chat is sent as teamchat if the player last used teamchat
  23. -you regain health if you die on purpose with flag xd
  24. */
  25.  
  26. /** script settings **/
  27. const uint checkCampInterval=10;      //how often to check for camping (gameticks) 70 = one second
  28. /*********************/
  29.  
  30. /** level settings: define camp areas **/
  31. array<array<array<int>>> campArea = {
  32.  /* A camparea is a rectangle referred to by its top left and bottom right corner
  33. x,y -----------
  34.     |         |
  35.     |         |
  36.     ----------- a,b                                                              */
  37. //  camparea(x,y)  camparea(a,b)  allowed camp  id
  38.                                  // time(gameticks) (needed for new shapes)
  39.   {{29,12},     {41,12},        {280},      {0}},        //camparea #0: on top of seek pu
  40.   {{64,05},     {101,19},       {490},      {1}},        //camparea #1: the rf area
  41.   {{30,49},     {64,56},     {280},      {2}},    //camparea #2: at carrot
  42.                  
  43.                   //the script will only pay attention to the first camp time for the entire camparea id
  44.   {{31,14},     {41,14},     {280},      {3}},     //camparea #3: rectangle1
  45.   {{30,15},     {41,15},     {},        {3}},       //camparea #3: rectangle2
  46.   {{30,16},     {41,16},     {},        {3}},       //camparea #3: rectangle3
  47.   {{31,17},     {41,17},     {},        {3}},       //camparea #3: rectangle4
  48.   {{32,18},     {39,18},     {},        {3}},       //camparea #3: rectangle5
  49.   {{35,19},     {38,19},     {},        {3}}       //camparea #3: rectangle6
  50. };
  51. //it doesn't seem like you can have mixed arrays in AS
  52. //so we just put the strings in a separate array
  53. array<string> campAreaName = {        
  54.   "above seeks",              //camparea #0
  55.   "in the rf area",              //camparea #1
  56.   "at the carrot",              //camparea #2
  57.   "in the seek box"              //camparea #3
  58. };
  59. /******** end of level settings ********/
  60.  
  61. /** script globals **/
  62. uint campAreas = 0;
  63. uint campAreasRealLength;
  64. array<int> campTime;
  65.  
  66.  
  67. void onLevelLoad() {
  68.   campAreasRealLength = campArea.length();
  69.   for (uint i=0; i < campAreasRealLength;i++) {
  70.     campAreas = campArea[i][3][0];
  71.   }
  72.   campAreas++;
  73.   campTime.resize(campAreas);
  74. }
  75.  
  76. /********************/
  77.  
  78.  
  79. /** This function checks if a player is in a certain camparea        **/
  80. /** and returns two bools: 1) whether the player is in the camp area **/
  81. /** and 2) whether they have been there for too long                 **/
  82. array<bool> isInCampArea(int pID, int camparea) {  //use an array<bool> to return multiple bools
  83.   array<bool> returnThis = {false, false, false};      //we assume that the player is not camping
  84.                                                                    //      (and not for too long)
  85.  
  86.   int maxCamp = 0;
  87.   int xPos = jjPlayers[pID].xPos / 32;
  88.   int yPos = jjPlayers[pID].yPos / 32;
  89.                          
  90.   for (uint j=0; j < campAreasRealLength;j++) {        
  91.     if (campArea[j][3][0] == camparea)  {      //all parts of the camp area
  92.      
  93.       if (maxCamp == 0) maxCamp = campArea[j][2][0];        //store a bunch of information in temporary                                  
  94.       int xCamp = campArea[j][0][0];                //variables for easier reading
  95.       int aCamp = campArea[j][1][0];
  96.       int yCamp = campArea[j][0][1];
  97.       int bCamp = campArea[j][1][1];
  98.      
  99.       if ((xPos >= xCamp)&&(xPos < aCamp)&&(yPos >= yCamp)&&(yPos <= bCamp)) {   //is player in camparea?
  100.          returnThis[0] = true;                             //set bool is camping
  101.       }
  102.      
  103.       }
  104.   }
  105.  
  106.  
  107.   if (!returnThis[0]) {
  108.     if (campTime[camparea] > 0) {
  109.       returnThis[2] = true; //was camping
  110.     }
  111.     campTime[camparea] = 0;                          //player not camping -> reset timer
  112.   }
  113.   else campTime[camparea] += checkCampInterval;                  //update camptime  
  114.  
  115.   if (maxCamp < campTime[camparea]) {                                        
  116.     returnThis[1] = true;                           //set bool camped for too long
  117.   }
  118.  
  119.  
  120.   return returnThis;                                //return the (possibly altered) bool
  121. }
  122.  
  123. void onPlayer() {
  124.   int pID = p.playerID;
  125.   if (jjGameTicks % checkCampInterval == 0) {                      //(thanks Artem/Foly)
  126.     for (uint i=0; i < campAreas;i++) {                        //loop through all camp areas
  127.         //^uint to avoid warning "Signed/Unsigned mismatch"
  128.       array<bool> isCamping = isInCampArea(pID, i);                //check player and area, store result
  129.       if (isCamping[0]) {                              //is current player in camparea #1?
  130.         int remainingSecs = ((campArea[i][2][0] - campTime[i]) / 70);
  131.         if (jjGameTicks % 70 == 0) jjPlayers[pID].showText("You are camping " + campAreaName[i] + ". Dead in " + formatInt(remainingSecs,"l") + " seconds.");       //display text (looks stupid if
  132.                                               // camping is checked too often)
  133.         if (isCamping[1]) {                             //has current player been there for too long?
  134.        
  135.           /** WHAT SHOULD HAPPEN IF THE PLAYER CAMPS FOR TOO LONG??? **/
  136.           jjChat("I camped for too long " + campAreaName[i] + ". Now I die :c");
  137.           jjPlayers[pID].kill();                        //kill the player
  138.           campTime[i] = 0;                          //reset timer
  139.           /**                          ^-^                           **/
  140.          
  141.         }
  142.       }
  143.       else {
  144.         if (isCamping[2]) jjPlayers[pID].showText(" "); //was camping
  145.       }
  146.     }
  147.   }
  148. }