Advertisement
Guest User

CoreFunctions.cs

a guest
Aug 6th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.93 KB | None | 0 0
  1. function generateDNA() //Creates a random string of DNA for detectives. Wait, doesn't this mean two players can have the same DNA? %0.00001693508 chance of it happening, go play the lottery.
  2. {
  3.     for(%i=0;%i<5;%i++)
  4.     {
  5.         %part = getRandom(0,9);
  6.         if(%dna $= "")
  7.             %dna = %part;
  8.         else
  9.             %dna = %dna SPC %part;
  10.     }
  11.     return getSubStr(sha1(%dna), 0, 6);
  12. }
  13. function player::getFormattedRole(%player) //This is a little bit of shorthand I wrote to get a formatted copy of a player's role, complete with color.
  14. {
  15.     if(%player.role $= "") //If for some ungodful reason they don't have a role?
  16.         return "\c3Unidentified"; //They're unidentified.
  17.     return BBB_System.RoleColor[%player.role] @ %player.role; //Remember that shit in the server.cs? That contains the color definitions.
  18. }
  19. function gameConnection::provideAmmoUpdate(%client,%type) //We only ever update the ammo UI if something happens to change ammo. For example, if a gun is fired or switched or reloaded. Otherwise we don't give a shit.
  20. {
  21.     if(%client.hasBBBRClient) //If we've gotten a handshake from the client, they deserve our shiny-ass UI
  22.         %client.cycleUIBBB();
  23.     else
  24.     {
  25.         %player = %client.player;
  26.         %slot = %player.currTool;
  27.         %curTool = %player.tool[%slot];
  28.         commandToClient(%client,'centerPrint',"<just:right><font:impact:24><color:fff000>"@%type@" Ammo <font:impact:34>\c6" @ %player.toolAmmo[%slot] @ " / " @ %client.quantity[%type] @ "", 4, 2, 3, 4);
  29.     }
  30. }
  31. function gameConnection::cycleUIBBB(%client) //This is the Spicy UI control, for both GUI and GUIless
  32. {
  33.     %BBB = BBB_System;
  34.     %player = %client.player; //I'm a lazy fuck okay?
  35.     if(%client.hasBBBRClient) //We send very specialized data every second to the player if they have a GUI
  36.     {
  37.         if(isObject(%player)) //If we're alive, we need to gather all the information to send to the client.
  38.         {
  39.             %hp = 100 - mFloatLength(%player.getDamageLevel(),0); //I have no fucking memory why I do this. I guess sometimes damageLevels aren't perfect.
  40.             %curAmmo = "--"; //We display ammo as --/-- by default. It looks nice for non-ammo based weapons.
  41.             %maxAmmo = "--";
  42.             %leftAmmo = "--";
  43.             %slot = %player.currTool;
  44.             %curTool = %player.tool[%slot];
  45.             if(%curTool.typeAmmo !$= "") //If there's an ammo to be used, let's display it correctly yeah?
  46.             {
  47.                 %curAmmo = %player.toolAmmo[%slot]; //Technically it means items that don't use ammo can use the GUI ammo display but. Whatever.
  48.                 %maxAmmo = %curTool.maxAmmo;
  49.                 %leftAmmo = %client.quantity[%curTool.typeAmmo];
  50.             }
  51.             commandToClient(%client,'BBBR_UpdateHUDData',%hp,%player.role,%BBB.timeDisplay,%BBB.currentSec,%BBB.maxSeconds,%curAmmo,%maxAmmo,%leftAmmo);
  52.         }
  53.         else
  54.             commandToClient(%client,'BBBR_UpdateHUDData',0,"Spectator",%BBB.timeDisplay,%BBB.currentSec,%BBB.maxSeconds,"--","--","--"); //I set up a predefined set of information of that dude is dead. lol.
  55.         if(%player.isTraitor)
  56.             commandToClient(%client,'bottomPrint',"<just:left>" @ %BBB.UITList, 2); //We have no specialized GUI for displaying traitors so. Lets just make use of bottom print.
  57.     }
  58.     else
  59.     { //We're gonna build the UI as we go!
  60.         if(isObject(%player)) //Again if they're alive or dead changes whether we build this as we go.
  61.         {
  62.             %DL = %player.getDamageLevel();
  63.  
  64.             %color = %player.getHealthColoring();
  65.             %hexColor = rgbToHex(%color);
  66.             %UIString = "\c3Health\c6: <color:" @ %hexColor @ ">" @ (100 - %DL); //Adds a fresh gradient if the player's health goes down. Rainbow from Green-Red as HP drops.
  67.  
  68.             %dmMarks = mCeil((100 - mFloatLength(%DL,0)) / 10);
  69.             %stringMark = BBB_System.MarkList[%dmMarks]; //Remember the server.cs? We defined a shitty healthbar there.
  70.  
  71.             %UIString = %UIString SPC "<color:" @ %hexColor @">" @ %stringMark;
  72.             %UIString = %UIString SPC "\c3Role\c6:" SPC %player.getFormattedRole();
  73.         }
  74.         else
  75.             %UIString = "\c3Health\c6: <color:ff0000>0 <color:ff0000>|||||||||| \c3Role\c6: \c7Spectator\c3";
  76.         %UIString = %UIString SPC "<just:right>\c3Time\c6:" SPC %BBB.timeDisplay; //We tack on the time at the end.
  77.         if(%player.isTraitor)
  78.             %UIString = %UIString NL "<just:left>" @ %BBB.UITList; //Traitor's gonna trait, they gotta know their allies.
  79.         commandToClient(%client,'bottomPrint',%UIString, 2);
  80.     }
  81. }
  82. function BBB_System::clearBots(%BBB)
  83. {
  84.     %count = botSimGroup.getCount(); //We're gonna remove any bot we make. For jesus and for glory.
  85.     for(%i=0;%i<%count;%i++)
  86.     {
  87.         %bot = botSimGroup.getObject(0);
  88.         botSimGroup.remove(%bot);
  89.         %bot.delete();
  90.     }
  91. }
  92. function AIPlayer::addBotToGroup(%bot) //So we can remove bots, whenever any bot is made or added, they are added to our simgroup to be deleted later.
  93. {
  94.     botSimGroup.add(%bot);
  95. }
  96. function BBB_System::createAnnouncement(%BBB,%msg) //Shorthand for laziness. Yeah, yeah I know.
  97. {
  98.     announce("\c2Game\c6:" SPC %msg);
  99.     %BBB.Log_Event(true,%msg); //We have to have something in our logs, right?
  100. }
  101. function player::removePlayer(%player,%BBB) //This is an interesting one. We call remove player if: A client disconnects and have a body, a player dies, a player fucking dies. You get the idea. We want the round to end eventually.
  102. {
  103.     if(%player.isTraitor)
  104.     {
  105.         %BBB.TraitorCount --;
  106.         %BBB.createFormattedTraitorList(); //If a traitor dies let's fix some shit yeah?
  107.         return; //I'm not graceful okay?
  108.     }
  109.     %BBB.InnocentCount --;
  110. }
  111. function GameConnection::freeCamera(%this) //Spectator fly-by camera boys.
  112. {
  113.     %cam = %this.camera;
  114.     if(!isObject(%cam))
  115.         return;
  116.     %this.camera.setMode(observer);
  117.     %this.setControlObject(%this.camera);
  118. }
  119. function BBB_System::testVictory(%BBB) //We check for victory kind of oftenly. So let's not fuck this up, yeah?
  120. {
  121.     if(%BBB.TraitorCount <= 0 && !%BBB.resetting) //If for some godless reason we go negative? Yeah lets reset, unless we're resetting.
  122.     {
  123.         %BBB.createAnnouncement("The Innocent have succeeded. Resetting in 5 seconds...");
  124.         %BBB.schedule(5000,resetBBB);
  125.         %BBB.resetting = true;
  126.     }
  127.     else if(%BBB.InnocentCount <= 0 && !%BBB.resetting)
  128.     {
  129.         %BBB.createAnnouncement("The Innocent have failed. Resetting in 5 seconds...");
  130.         %BBB.schedule(5000,resetBBB);
  131.         %BBB.resetting = true;
  132.     }
  133. }
  134. function BBB_System::onTimerTick(%BBB) //Everytime the timer ticks down ONE second, we refresh just about. Everything.
  135. {
  136.     %count = clientGroup.getCount();
  137.     for(%i = 0; %i < %count; %i++)
  138.     {
  139.         %client = clientGroup.getObject(%i);
  140.         %player = %client.player;
  141.         if(isObject(%player))
  142.         {
  143.             %color = %player.getHealthColoring(); //We change the player name color if they get hurt. Detectives have a different color gradient.
  144.             %player.setShapeNameColor(%color);
  145.         }
  146.         %client.cycleUIBBB(); //We get ever client's UI to refresh with the timer.
  147.     }
  148. }
  149. function BBB_System::timer(%BBB,%minutes,%seconds)
  150. {
  151.     BBB_System.onTimerTick();
  152.     %seconds --;
  153.     if(%seconds < 0 && %minutes > 0) //Yeah. I should have kept track in seconds and made use of Modulus, don't murder me.
  154.     {
  155.         %seconds = 59;
  156.         %minutes --;
  157.     }
  158.     %BBB.minutes = %minutes;
  159.     %BBB.seconds = %seconds;
  160.     %BBB.currentSec = (%minutes * 60) + %seconds; //Total seconds that had elapsed.
  161.     if(strLen(%seconds) != 2) //All this fancy shit just adds 0s where they need to be so our timer display looks nice and tidy.
  162.         %secondDisplay = %seconds @ 0;
  163.     else
  164.         %secondDisplay = %seconds;
  165.     if(%seconds < 10)
  166.         %secondDisplay = 0 @ %seconds;
  167.     %BBB.timeDisplay = %minutes @ ":" @ %secondDisplay;
  168.     %BBB.timer = %BBB.schedule(1000,timer,%BBB.minutes,%BBB.seconds);
  169.     if(%minutes == 0 && %seconds == 0) //If the teams get a time out instead of a regular victory.
  170.     {
  171.         cancel(%BBB.timer);
  172.         BBB_System.onTimerTick();
  173.         %BBB.timeDisplay = "0:00";
  174.         %BBB.schedule(5000,resetBBB);
  175.         %BBB.resetting = true;
  176.         %BBB.createAnnouncement("Neither alliance is victorious. Resetting in 5 seconds...");
  177.     }
  178. }
  179. function serverCMDResetBBB(%client) //Well if admins wanna reset, admins wanna reset. Mostly for debug usage.
  180. {
  181.     if(%client.isAdmin)
  182.     {
  183.         BBB_System.resetting = true;
  184.         BBB_System.createAnnouncement("Admin\c3" SPC %client.name SPC "\c6has reset BBB to take effect in 3 seconds.");
  185.         BBB_System.schedule(3000,resetBBB);
  186.     }
  187. }
  188. function BBB_System::resetBBB(%BBB) //We handle all the resetting here. I mean, all of the fucking resetting.
  189. {
  190.     cancel(%BBB.timer); //No more countdown.
  191.     if(isObject($DefaultMiniGame))
  192.         $DefaultMiniGame.reset(0); //Default minigame reset command
  193.     %BBB.resetting = false; //These are our zeros, yadda yadda
  194.     %BBB.match = false;
  195.     %count = clientGroup.getCount();
  196.     for(%i=0;%i<%count;%i++)
  197.     {
  198.         %client = clientGroup.getObject(%i);
  199.         if(%client.hasSpawnedOnce && !%client.spectator) //If a client is set to spectator mode for whatever reason, let's not spawn them. If they're not done loading? Definitely don't spawn them.
  200.             %client.instantrespawn();
  201.     }
  202.     %BBB.currentDeathID = 0;
  203.     %BBB.traitorList = "";
  204.     %BBB.TraitorCount = 0;
  205.     %BBB.InnocentCount = 0;
  206.     %BBB.timeDisplay = "0:00";
  207.     BBB_System.clearBots();
  208.     %totalIncrease = 0;
  209.     for(%i=0;%i<%count;%i++)
  210.     {
  211.         %client = clientGroup.getObject(%i);
  212.         if(!%client.spectator && isObject(%client.player))
  213.             %totalIncrease ++;
  214.     }
  215.     %bonusMin = mFloor(%totalIncrease / 4);
  216.     %bonusSec = (%totalIncrease % 4) * 15; //We add fifteen seconds per player. Because... I'm not sure lmao.
  217.     %totalMin = 7 + %bonusMin;
  218.     %totalSec = 30 + %bonusSec;
  219.     %BBB.maxSeconds = %totalMin * 60 + %totalSec;
  220.     if(%totalSec > 60)
  221.     {
  222.         %totalSec %= 30;
  223.         %totalMin ++;
  224.     }
  225.     %BBB.timer(%totalMin,%totalSec);
  226.     %BBB.schedule(30000,beginBBB);
  227. }
  228. function BBB_System::beginBBB(%BBB) //For when the server is launched.
  229. {
  230.     %BBB.match = true;
  231.     %BBB.generateTeams();
  232. }
  233. function BBB_System::Log_Event(%BBB,%timeStamp,%text)
  234. {
  235.     if(%text $= "")
  236.         return;
  237.     %finish = "";
  238.     %date = strreplace(getsubstr(getDateTime(),0,8),"/","-");
  239.     if(%timeStamp)
  240.         %finish = "[" @ getsubstr(getDateTime(),9,8) @ "]";
  241.     else
  242.         %finish = "(" @ %BBB.timeDisplay @ ")";
  243.     %file = new FileObject();
  244.     %file.openForAppend("config/BBBR/Logs/" @ %date @ ".txt");
  245.     %file.writeline(%finish @ %text);
  246.     %file.close();
  247.     %file.delete();
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement