Advertisement
Guest User

Untitled

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