Advertisement
Guest User

TeamSystem.cs

a guest
Aug 6th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. function roundFloat(%value)
  2. {
  3. return mFloatLength(%value, 0);
  4. }
  5. function BBB_System::generateTeams(%BBB)
  6. {
  7. //Fetches a list of all players who exist and aren't spectating.
  8. %count = clientGroup.getCount();
  9. for(%i=0;%i<%count;%i++)
  10. {
  11. %client = clientGroup.getObject(%i);
  12. if(isObject(%client.player) && !%client.spectator)
  13. {
  14. if(%str $= "")
  15. %str = %client.player;
  16. else
  17. %str = %str SPC %client.player;
  18. }
  19. }
  20. for(%i=0;%i<%count;%i++)
  21. {
  22. %client = clientGroup.getObject(%i);
  23. if(!isObject(%client.player) || %client.spectator)
  24. {
  25. if(%str2 $= "")
  26. %str2 = %client;
  27. else
  28. %str2 = %str2 SPC %client;
  29. }
  30. }
  31. //Tells the system to get to work and create all the teams.
  32. %count = getWordCount(%str); //Gives out the total length of the list so we can use it accordingly.
  33. %str = %BBB.generateTraitors(%str,%count);
  34. %str = %BBB.generateDetectives(%str,%count);
  35. %BBB.generateInnocent(%str);
  36. %BBB.createFormattedTraitorList();
  37. }
  38. function BBB_System::generateTraitors(%BBB,%str,%count)
  39. {
  40. //Creates your traitors.
  41. %passes = %count/4; //We want atleast one out of every 6 players to be a traitor. The traitor count will increase every 6n players.
  42. if(%passes <= 0.25)
  43. %passes = 1; //Forces exactly one traitor per round, even if they are the only player.
  44. else
  45. %passes = roundFloat(%passes); //Rounds the previous number to closet number, in reality making %count/4 result in every 6th player.
  46. for(%i=0; %i<%passes; %i++)
  47. {
  48. %length = getWordCount(%str) - 1; //In a list containing 1 player (Who occupies slot number 0) this will essentially stop there from somehow not being a traitor.
  49. %pos = getRandom(0,%length);
  50. %player = getWord(%str,%pos);
  51. %player.makeRole("Traitor",1);
  52. commandToClient(%player.client,'BBBR_ReconstructShopGUI');
  53. %str = removeWord(%str,%pos);
  54. }
  55. return %str;
  56. }
  57. function BBB_System::generateDetectives(%BBB,%str,%count)
  58. {
  59. //Creates your detectives.
  60. %passes = %count/8;
  61. %passes = mFloor(%passes); //As oppossed to rounding our detectives we always force the detective to occur every 8th player.
  62. for(%i=0;%i<%passes;%i++)
  63. {
  64. %length = getWordCount(%str) - 1;
  65. %pos = getRandom(0,%length);
  66. %player = getWord(%str,%pos);
  67. %player.makeRole("Detective",0);
  68. commandToClient(%player.client,'BBBR_ReconstructShopGUI');
  69. %str = removeWord(%str,%pos);
  70. }
  71. return %str;
  72. }
  73. function BBB_System::generateInnocent(%BBB,%str,%count)
  74. {
  75. //Takes anyone left in the system and forces them to be an innocent.
  76. %count = getWordCount(%str);
  77. for(%i=0;%i<%count;%i++)
  78. {
  79. %player = getWord(%str,0);
  80. %player.makeRole("Innocent",0);
  81. %str = removeWord(%str,0);
  82. }
  83. }
  84. function player::makeRole(%player,%role,%alliance)
  85. {
  86. %BBB = BBB_System;
  87. %client = %player.client;
  88. //Corrects the counter and un-detectifies any player put into the system if they already had a role.
  89. if(%player.isTraitor !$= "")
  90. {
  91. if(%player.isTraitor)
  92. %BBB.TraitorCount --;
  93. else
  94. %BBB.InnocentCount --;
  95. %player.unMountImage(2);
  96. %client.applyBodyColors();
  97. %client.applyBodyParts();
  98. }
  99.  
  100. //Sets the players values
  101. %player.isTraitor = %alliance;
  102. %player.role = %role;
  103. //Changes the alliance counts accordingly.
  104. if(%alliance)
  105. %BBB.TraitorCount ++;
  106. else
  107. %BBB.InnocentCount ++;
  108. //Gives detetives their well earned hat.
  109. if(%role $= "Detective")
  110. {
  111. %player.mountImage(DetectiveImage,2);
  112. for(%op = 0;$hat[%op] !$= "";%op++)
  113. {
  114. %player.hideNode($hat[%op]); //Hides all hats.
  115. }
  116. for(%qw = 0;$accent[%qw] !$= "";%qw++)
  117. {
  118. %player.hideNode($accent[%qw]);
  119. }
  120. %player.hasArmor = true;
  121. %player.credits = 2;
  122. }
  123. //Sets the list of Traitors so we can just fetch things from it.
  124. if(%role $= "Traitor")
  125. {
  126. if(%BBB.TraitorList $= "")
  127. %BBB.TraitorList = %player.client;
  128. else
  129. %BBB.TraitorList = %BBB.TraitorList SPC %player.client;
  130. %player.credits = 2;
  131. }
  132. commandToClient(%client,'centerPrint',"\c4You have been selected to be a(n)" @ BBB_System.RoleColor[%role] SPC %role @ "\c4.", 5);
  133. }
  134. function BBB_System::createFormattedTraitorList(%BBB)
  135. {
  136. %List = %BBB.TraitorList;
  137. %count = getWordCount(%List);
  138. %baseString = "\c3Fellow Traitors\c6:";
  139. for(%i = 0; %i < %count; %i ++)
  140. {
  141. %client = getWord(%List,%i);
  142. if(isObject(%client.player))
  143. %addString = "\c0" @ %client.name;
  144. else
  145. %addString = "\c7" @ %client.name;
  146. %baseString = %baseString SPC %addString;
  147. }
  148. %BBB.UITList = %baseString;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement