Advertisement
Guest User

Punish campers xd! v2.0

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