Advertisement
Guest User

Untitled

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