Advertisement
Guest User

codebosta

a guest
Jan 26th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4. #include <cstrike>
  5. #include <multicolors>
  6. #include <smlib>
  7. #include <Total/Sheriff>
  8. #include <Total/Functions>
  9. #include <Total/Master>
  10. #include <Total/Innocent>
  11.  
  12. new bool:sheriff[MAXPLAYERS];
  13. new guardVotes[MAXPLAYERS];
  14.  
  15. new Handle:t_showResultVotes;
  16. new Handle:t_addRandSheriff;
  17. new String:shAn[256];
  18. new bool:MensagemZoeira = false;
  19.  
  20. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max){
  21. CreateNative("isSheriff", Native_isSheriff);
  22. CreateNative("addSheriff", Native_addSheriff);
  23. CreateNative("removeSheriff", Native_removeSheriff);
  24. CreateNative("getTotalSheriffs", Native_getTotalSheriffs);
  25. }
  26.  
  27. public OnPluginStart(){
  28. HookEvent("round_start", roundStart);
  29. HookEvent("player_death", playerDeath);
  30. CreateTimer(3.0, PrintMsg, _, TIMER_REPEAT);
  31.  
  32. AddCommandListener(changeSheriffCommand, "say");
  33. AddCommandListener(changeSheriffCommand, "say_team");
  34. }
  35.  
  36. public Action:roundStart(Handle:event, const String:name[], bool:dontBroadcast){
  37. MensagemZoeira = false;
  38. resetTimers();
  39. resetSheriffs();
  40. resetVotes();
  41. startTimers();
  42.  
  43. //Mostrar votação de XERIFES
  44. if(getTotalGuardsAlive() > 0)
  45. for(new i = 1; i <= MaxClients; i++)
  46. if(isPrisonerAlive(i)){
  47. new Handle: showGuards = CreateMenu(showVote);
  48.  
  49. SetMenuTitle(showGuards, "[TJB] Votacao para XERIFE:");
  50.  
  51. for(new l = 1; l <= MaxClients; l++)
  52. if(isGuardAlive(l)){
  53. new String:guardName[32], String:guardID[2];
  54.  
  55. GetClientName(l, guardName, sizeof(guardName));
  56. Format(guardID, sizeof(guardID), "%i", l);
  57.  
  58. AddMenuItem(showGuards, guardID, guardName);
  59. }
  60.  
  61. //Mostrar para o PRISIONEIRO
  62. SetMenuExitButton(showGuards, true);
  63. DisplayMenu(showGuards, i, 9);
  64. }
  65. }
  66.  
  67. public OnGameFrame()
  68. {
  69. for(new i=1;i<MaxClients;i++)
  70. {
  71. if(IsValidClient(i) && GetClientTeam(i) == 3 && MensagemZoeira)
  72. {
  73. PrintHintText(i,shAn);
  74. }
  75. }
  76. }
  77.  
  78. public showVote(Handle: menu, MenuAction: action, id, strOpt){
  79. if(action == MenuAction_Select){
  80. new String: guardID[2], String: option[2];
  81.  
  82. GetMenuItem(menu, strOpt, option, 2);
  83.  
  84. for(new i = 1; i <= MaxClients; i++){
  85. Format(guardID, 2, "%.i", i);
  86.  
  87. if(StrEqual(option, guardID))
  88. if(isGuardAlive(i)){
  89. guardVotes[i]++;
  90. CPrintToChat(id, "{lightred}[TJB] {default}Voce votou no guarda: {lightblue}%N", i);
  91.  
  92. break;
  93. }
  94. }
  95. }
  96. }
  97.  
  98. public Action:changeSheriffCommand(client, const String:command[], argc){
  99. new String:text[16];
  100. GetCmdArgString(text, sizeof(text));
  101.  
  102. //Comando para mudar de SHERIFF
  103. if(client > 0){
  104. if(isGuardAlive(client) && isSheriff(client))
  105. if(StrEqual("\"!cg\"", text) || StrEqual("!cg", text)){
  106. if(getTotalGuardsAlive() > getTotalSheriffs()){
  107. new Handle: showChangeSheriff = CreateMenu(changeSheriff);
  108.  
  109. SetMenuTitle(showChangeSheriff, "[TJB] Trocar XERIFE com:");
  110.  
  111. for(new l = 1; l <= MaxClients; l++)
  112. if(isGuardAlive(l) && !isSheriff(l)){
  113. new String:guardName[32], String:guardID[2];
  114.  
  115. GetClientName(l, guardName, 32);
  116. Format(guardID, 2, "%.i", l);
  117.  
  118. AddMenuItem(showChangeSheriff, guardID, guardName);
  119. }
  120.  
  121. SetMenuExitButton(showChangeSheriff, true);
  122. DisplayMenu(showChangeSheriff, client, 10);
  123. }
  124. else CPrintToChat(client, "{lightred}[TJB] {default}Nao foi possivel exibir a listas de {lightblue}guardas{default}...");
  125.  
  126. return Plugin_Handled;
  127. }
  128. }
  129.  
  130. return Plugin_Continue;
  131. }
  132.  
  133. public Action:f_showResultVotes(Handle:timer){
  134. t_showResultVotes = INVALID_HANDLE;
  135.  
  136. if(getTotalGuardsAlive() > 0){
  137. new String: topName[20], String: segName[20];
  138. new topVote = 0, topID = 1;
  139. new segVote = 0, segID = 1;
  140.  
  141. //Computador os votos
  142. for(new i = 1; i <= MaxClients; i++){
  143. if(guardVotes[i] > topVote){
  144. segVote = topVote;
  145. segID = topID;
  146.  
  147. topVote = guardVotes[i];
  148. topID = i;
  149. }
  150. else if(guardVotes[i] > segVote){
  151. segVote = guardVotes[i];
  152. segID = i;
  153. }
  154. }
  155.  
  156. Format(shAn, sizeof(shAn), "Xerife(s):");
  157.  
  158. //Dar XERIFE para o mais votado
  159. if(topVote > 0){
  160. if(isGuardAlive(topID)){
  161. GetClientName(topID, topName, sizeof(topName));
  162.  
  163. addSheriff(topID);
  164. Format(shAn, sizeof(shAn), "%s\n %s - %i voto(s)", shAn, topName, topVote);
  165. }
  166. else t_addRandSheriff = CreateTimer(2.0, f_addRandSheriff);
  167. }
  168. else t_addRandSheriff = CreateTimer(2.0, f_addRandSheriff);
  169.  
  170. //Dar XERIFE para o segundo votado
  171. if(segVote > 0){
  172. if(isGuardAlive(segID)){
  173. GetClientName(segID, segName, sizeof(segName));
  174. Format(shAn, sizeof(shAn), "%s\n %s - %i voto(s)", shAn, segName, segVote);
  175. addSheriff(segID);
  176. }
  177. else t_addRandSheriff = CreateTimer(2.0, f_addRandSheriff);
  178. }
  179. else t_addRandSheriff = CreateTimer(2.0, f_addRandSheriff);
  180.  
  181. //Aparecer a MSG se não for vazia
  182. if(!StrEqual(shAn, "Xerife(s):"))
  183. {
  184. MensagemZoeira = true;
  185. }
  186. else
  187. {
  188. MensagemZoeira = false;
  189. }
  190. }
  191. }
  192.  
  193. public Action:f_addRandSheriff(Handle:timer)
  194. {
  195. t_addRandSheriff = INVALID_HANDLE;
  196.  
  197. if(getTotalGuardsAlive() > getTotalSheriffs())
  198. while(true){
  199. new rg = GetRandomInt(1, MaxClients);
  200.  
  201. if(isGuardAlive(rg) && !isSheriff(rg)){
  202. addSheriff(rg);
  203.  
  204. break;
  205. }
  206. else if(getTotalGuardsAlive() == 0)
  207. break;
  208. }
  209. }
  210.  
  211. public Action:playerDeath(Handle:event, const String:name[], bool:dontBroadcast){
  212. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  213.  
  214. if(isSheriff(client)){
  215. removeSheriff(client);
  216. t_addRandSheriff = CreateTimer(2.0, f_addRandSheriff);
  217. }
  218. }
  219.  
  220. public OnClientDisconnect(client){
  221. if(isSheriff(client)){
  222. removeSheriff(client);
  223. t_addRandSheriff = CreateTimer(2.0, f_addRandSheriff);
  224. }
  225. }
  226.  
  227.  
  228. //Métodos FUNÇÕES
  229. public changeSheriff(Handle: menu, MenuAction: action, id, strOpt){
  230. if(action == MenuAction_Select){
  231. new String: guardID[2], String: option[2];
  232.  
  233. GetMenuItem(menu, strOpt, option, 2);
  234.  
  235. for(new i = 1; i <= MaxClients; i++){
  236. Format(guardID, 2, "%.i", i);
  237.  
  238. if(StrEqual(option, guardID))
  239. if(isGuardAlive(i) && !isSheriff(i)){
  240. if(isMaster(id)){
  241. CPrintToChatAll("{lightred}[TJB]{default} O guarda {lightblue}%N{default} nao e mais o {lightblue}MESTRE{default}.", id);
  242. removeMaster();
  243. }
  244.  
  245. SetEntityModel(id, "models/player/elis/po/police.mdl");
  246. removeSheriff(id);
  247. addSheriff(i);
  248. break;
  249. }
  250. }
  251. }
  252. }
  253.  
  254. public Native_addSheriff(Handle:plugin, numParams){
  255. new client = GetNativeCell(1);
  256.  
  257. if(!isSheriff(client))
  258. if(isGuardAlive(client)){
  259. sheriff[client] = true;
  260. SetEntityModel(client, "models/player/mapeadores/kaem/policeADM/policeadm.mdl");
  261.  
  262. CPrintToChatAll("{lightred}[TJB]{default} O guarda {lightblue}%N{default} agora e um {orange}XERIFE{default}!!!", client);
  263. }
  264. }
  265.  
  266. public startTimers(){
  267. t_showResultVotes = CreateTimer(10.0, f_showResultVotes);
  268. }
  269.  
  270. public resetTimers(){
  271. clearTimer(t_showResultVotes);
  272. clearTimer(t_addRandSheriff);
  273. }
  274.  
  275. public resetSheriffs(){
  276. for(new i = 1; i <= MaxClients; i++)
  277. removeSheriff(i);
  278. }
  279.  
  280. public resetVotes(){
  281. for(new i = 1; i <= MaxClients; i++)
  282. guardVotes[i] = 0;
  283. }
  284.  
  285.  
  286. //Métodos GET
  287. public Native_isSheriff(Handle:plugin, numParams){
  288. new client = GetNativeCell(1);
  289.  
  290. return sheriff[client];
  291. }
  292.  
  293. public Native_removeSheriff(Handle:plugin, numParams){
  294. new client = GetNativeCell(1);
  295.  
  296. sheriff[client] = false;
  297. }
  298.  
  299. public Native_getTotalSheriffs(Handle:plugin, numParams){
  300. new total = 0;
  301.  
  302. for(new i = 1; i <= MaxClients; i++)
  303. if(isSheriff(i))
  304. total++;
  305.  
  306. return total;
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement