Advertisement
Guest User

Punish campers xd! v1.1

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