Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Punish campers xd! v1.1
- changes:
- -had to recreate the onPlayer function, because it wouldn't work for clients :S
- -moved a message out of isInCampArea()
- -killed player with .kill() instead of .health=0 (thx cooba)
- improvements needed:
- -show time remaining in campspot (could be achieved with the timer functions, I assume)
- -don't kill players if the game is stopped (the AngelScript implementation needs a new bool)
- -the chat is sent as teamchat if the player last used teamchat
- -you regain health if you die on purpose with flag xd
- */
- /** script settings **/
- const uint checkCampInterval=70; //how often to check for camping (gameticks) 70 = one second
- /*********************/
- /** 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}, {250}}, //camparea #0: on top of seek pu
- {{64,05}, {101,19}, {500}}, //camparea #1: the rf area
- {{30,49}, {64,56}, {250}}, //at carrot
- {{30,14}, {41,19}, {250}} //in the seek box
- };
- //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
- "at carrot",
- "in the seek box"
- };
- /******** 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; //update camptime
- returnThis[0] = true; //set bool is camping
- 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
- }
- /** onPlayer wouldn't work for me ;S **/
- void realOnPlayer(int pID) {
- 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(pID, i); //check player and area, store result
- if (isCamping[0]) { //is current player in camparea #1?
- jjPlayers[pID].showText("You are camping " + campAreaName[i]); //display text (looks stupid if
- if (isCamping[1]) { //has current player been there for too long?
- /** WHAT SHOULD HAPPEN IF THE PLAYER CAMPS FOR TOO LONG??? **/
- jjChat("I camped for too long " + campAreaName[i] + ". Now I die :c");
- jjPlayers[pID].kill(); //kill the player
- campTime[i] = 0; //reset timer
- /** ^-^ **/
- }
- }
- }
- }
- }
- void onMain() {
- /** emulating onPlayer **/
- for (uint i=0; i < 32;i++) {
- if ((jjPlayers[i].isActive)&&(jjPlayers[i].isLocal)) realOnPlayer(i);
- }
- /************************/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement