SHOW:
|
|
- or go back to the newest paste.
| 1 | /* | |
| 2 | - | Punish campers xd! v1.1 |
| 2 | + | Punish campers xd! v2.0 |
| 3 | ||
| 4 | - | changes: |
| 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 | - | // camparea(x,y) camparea(a,b) allowed camp time(gameticks) |
| 27 | + | |
| 28 | - | {{29,12}, {40,12}, {250}}, //camparea #0: on top of seek pu
|
| 28 | + | |
| 29 | - | {{64,05}, {101,19}, {500}}, //camparea #1: the rf area
|
| 29 | + | |
| 30 | - | {{30,49}, {64,56}, {250}}, //at carrot
|
| 30 | + | |
| 31 | - | {{30,14}, {41,19}, {250}} //in the seek box
|
| 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 | - | //so we just put the strings in a separatr array |
| 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 | - | "at carrot", |
| 38 | + | {{30,15}, {41,15}, {250}, {3}}, //camparea #3: rectangle2
|
| 39 | - | "in the seek box" |
| 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 | - | const uint campAreas = campArea.length(); //save the number of campAreas for easy reference |
| 44 | + | |
| 45 | - | array<int> campTime(campAreas,0); //initialize campTime for all areas as 0 gameticks |
| 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 | - | array<bool> isInCampArea(int player, int camparea) { //use an array<bool> to return multiple bools
|
| 52 | + | |
| 53 | ||
| 54 | /** script globals **/ | |
| 55 | - | int maxCamp = campArea[camparea][2][0]; //store a bunch of information in temporary |
| 55 | + | uint campAreas = 0; |
| 56 | - | int xCamp = campArea[camparea][0][0]; //variables for easier reading |
| 56 | + | uint campAreasRealLength; |
| 57 | - | int aCamp = campArea[camparea][1][0]; |
| 57 | + | array<int> campTime; |
| 58 | - | int yCamp = campArea[camparea][0][1]; |
| 58 | + | |
| 59 | - | int bCamp = campArea[camparea][1][1]; |
| 59 | + | |
| 60 | - | int xPos = jjPlayers[player].xPos / 32; |
| 60 | + | void onLevelLoad() {
|
| 61 | - | int yPos = jjPlayers[player].yPos / 32; |
| 61 | + | campAreasRealLength = campArea.length(); |
| 62 | for (uint i=0; i < campAreasRealLength;i++) {
| |
| 63 | - | if ((xPos >= xCamp)&&(xPos <= aCamp)&&(yPos >= yCamp)&&(yPos <= bCamp)) { //is player in camparea?
|
| 63 | + | campAreas = campArea[i][3][0]; |
| 64 | - | campTime[camparea] += checkCampInterval; //update camptime |
| 64 | + | |
| 65 | - | returnThis[0] = true; //set bool is camping |
| 65 | + | campAreas++; |
| 66 | - | if (maxCamp < campTime[camparea]) { // camping is checked too often)
|
| 66 | + | campTime.resize(campAreas); |
| 67 | - | returnThis[1] = true; //set bool camped for too long |
| 67 | + | |
| 68 | - | } |
| 68 | + | |
| 69 | /********************/ | |
| 70 | - | else {
|
| 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 | } |