Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** script settings **/
- const uint checkCampInterval=80; //how often to check for camping (gameticks)
- /*********************/
- /** level settings: define camp areas **/
- array<array<array<int>>> campArea = {
- /* A camparea is a rectangle referred to by its top left and bottom right corner
- x,y -----------
- | |
- | |
- ----------- a,b */
- // camparea(x,y) camparea(a,b) allowed camp time(gameticks)
- {{29,12}, {40,12}, {500}}, //camparea #0: on top of seek pu
- {{64,05}, {101,19}, {500}} //camparea #1: the rf area
- };
- //it doesn't seem like you can have mixed arrays in AS
- //so we just put the strings in a separatr array
- array<string> campAreaName = {
- "above seeks", //camparea #0
- "in the rf area" //camparea #1
- };
- /******** end of level settings ********/
- /** script globals **/
- const uint campAreas = campArea.length(); //save the number of campAreas for easy reference
- array<int> campTime(campAreas,0); //initialize campTime for all areas as 0 gameticks
- /********************/
- /** This function checks if a player is in a certain camparea **/
- /** and returns two bools: 1) whether the player is in the camp area **/
- /** and 2) whether they have been there for too long **/
- array<bool> isInCampArea(int player, int camparea) { //use an array<bool> to return multiple bools
- array<bool> returnThis = {false, false}; //we assume that the player is not camping
- // (and not for too long)
- int maxCamp = campArea[camparea][2][0]; //store a bunch of information in temporary
- int xCamp = campArea[camparea][0][0]; //variables for easier reading
- int aCamp = campArea[camparea][1][0];
- int yCamp = campArea[camparea][0][1];
- int bCamp = campArea[camparea][1][1];
- int xPos = jjPlayers[player].xPos / 32;
- int yPos = jjPlayers[player].yPos / 32;
- if ((xPos >= xCamp)&&(xPos <= aCamp)&&(yPos >= yCamp)&&(yPos <= bCamp)) { //is player in camparea?
- campTime[camparea] += checkCampInterval;
- returnThis[0] = true; //set bool is camping
- jjPlayers[player].showText("You are camping " + campAreaName[camparea]); //display text (looks stupid if
- if (maxCamp < campTime[camparea]) { // camping is checked too often)
- returnThis[1] = true; //set bool camped for too long
- }
- }
- else campTime[camparea] = 0; //player not camping -> reset timer
- return returnThis; //return the (possibly altered) bool
- }
- /** You guys know what this one does already! **/
- void onPlayer() {
- if (jjGameTicks % checkCampInterval == 0) { //(thanks Artem/Foly)
- for (uint i=0; i < campAreas;i++) { //loop through all camp areas
- //^uint to avoid warning "Signed/Unsigned mismatch"
- array<bool> isCamping = isInCampArea(p.localPlayerID, i); //check player and area, store result
- if (isCamping[0]) { //is current player in camparea #1?
- if (isCamping[1]) { //has current player been there for too long?
- jjChat("I camped for too long " + campAreaName[i] + ". Now I die :c");
- p.health = 0; //kill the player
- campTime[i] = 0; //reset timer
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement