Advertisement
Guest User

Punish campers xd! v1

a guest
Feb 3rd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.36 KB | None | 0 0
  1. /** script settings **/
  2. const uint checkCampInterval=80;         //how often to check for camping (gameticks)
  3. /*********************/
  4.  
  5. /** level settings: define camp areas **/
  6. array<array<array<int>>> campArea = {
  7.  /* A camparea is a rectangle referred to by its top left and bottom right corner
  8. x,y -----------
  9.     |         |
  10.     |         |
  11.     ----------- a,b                                                              */
  12. //  camparea(x,y)   camparea(a,b)   allowed camp time(gameticks)
  13.     {{29,12},       {40,12},        {500}},      //camparea #0: on top of seek pu
  14.     {{64,05},       {101,19},       {500}}       //camparea #1: the rf area
  15. };
  16. //it doesn't seem like you can have mixed arrays in AS
  17. //so we just put the strings in a separatr array
  18. array<string> campAreaName = {           
  19.   "above seeks",                          //camparea #0
  20.   "in the rf area"                        //camparea #1
  21. };
  22. /******** end of level settings ********/
  23.  
  24. /** script globals **/
  25. const uint campAreas = campArea.length(); //save the number of campAreas for easy reference
  26. array<int> campTime(campAreas,0);         //initialize campTime for all areas as 0 gameticks
  27. /********************/
  28.  
  29.  
  30. /** This function checks if a player is in a certain camparea        **/
  31. /** and returns two bools: 1) whether the player is in the camp area **/
  32. /** and 2) whether they have been there for too long                 **/
  33. array<bool> isInCampArea(int player, int camparea) {    //use an array<bool> to return multiple bools
  34.     array<bool> returnThis = {false, false};            //we assume that the player is not camping
  35.                                                                      //      (and not for too long)
  36.     int maxCamp = campArea[camparea][2][0];             //store a bunch of information in temporary
  37.     int xCamp = campArea[camparea][0][0];               //variables for easier reading
  38.     int aCamp = campArea[camparea][1][0];
  39.     int yCamp = campArea[camparea][0][1];
  40.     int bCamp = campArea[camparea][1][1];
  41.     int xPos = jjPlayers[player].xPos / 32;
  42.     int yPos = jjPlayers[player].yPos / 32;
  43.  
  44.     if ((xPos >= xCamp)&&(xPos <= aCamp)&&(yPos >= yCamp)&&(yPos <= bCamp)) {   //is player in camparea?
  45.        campTime[camparea] += checkCampInterval;
  46.        returnThis[0] = true;                                                    //set bool is camping
  47.        jjPlayers[player].showText("You are camping " + campAreaName[camparea]); //display text (looks stupid if
  48.        if (maxCamp < campTime[camparea]) {                                         // camping is checked too often)
  49.           returnThis[1] = true;                                                 //set bool camped for too long
  50.        }
  51.     }
  52.     else campTime[camparea] = 0;                                                //player not camping -> reset timer
  53.  
  54.     return returnThis;                                                          //return the (possibly altered) bool
  55. }
  56.  
  57. /** You guys know what this one does already! **/
  58. void onPlayer() {
  59.     if (jjGameTicks % checkCampInterval == 0) {                             //(thanks Artem/Foly)
  60.         for (uint i=0; i < campAreas;i++) {                                 //loop through all camp areas
  61.             //^uint to avoid warning "Signed/Unsigned mismatch"
  62.             array<bool> isCamping = isInCampArea(p.localPlayerID, i);       //check player and area, store result
  63.             if (isCamping[0]) {                                             //is current player in camparea #1?
  64.                 if (isCamping[1]) {                                         //has current player been there for too long?
  65.                     jjChat("I camped for too long " + campAreaName[i] + ". Now I die :c");
  66.                     p.health = 0;                                           //kill the player
  67.                     campTime[i] = 0;                                        //reset timer
  68.                 }
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement