Advertisement
Guest User

Untitled

a guest
May 4th, 2012
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 KB | None | 0 0
  1. /*
  2.  
  3. POLL SYSTEM BY BRITAS / DEIVIDAS
  4.  
  5. SKYPE: WIKIS666
  6.  
  7. */
  8.  
  9. #include <a_samp>
  10. #include <zcmd>
  11. #include <sscanf2>
  12. //
  13. #define RED 0xFF0000FF
  14. #define YELLOW 0xFFFF00FF
  15. #define WHITE 0xFFFFFFFF
  16. #define MAX_QUESTION_SIZE 24
  17. #define MAX_VARIANT_SIZE 15
  18. #define GUI_DIALOG_ID 10
  19.  
  20. new Text:Textdraw0 [MAX_PLAYERS],
  21. bool:Balsavo [MAX_PLAYERS];
  22. enum PollVariables
  23. {
  24. yVariant[MAX_VARIANT_SIZE],
  25. nVariant[MAX_VARIANT_SIZE],
  26. Question[MAX_QUESTION_SIZE],
  27. bool:Start,
  28. yCount,
  29. nCount,
  30. GeneralCount,
  31. Organizator
  32. }
  33. new Poll[PollVariables];
  34.  
  35. public OnFilterScriptInit()
  36. {
  37. NullVariables();
  38. for(new i; i < MAX_PLAYERS; i++)
  39. {
  40. Textdraw0[i] = TextDrawCreate(434.000000, 110.000000, " ~y~:: ~w~APKLAUSA ~y~::~n~~n~~r~(?):~w~ Ka jus?~n~~n~~p~(Y)~w~ Nieko.~n~~p~(N)~w~ Eik nx!~n~~n~Spausk ~y~Y~w~ arba ~y~N");
  41. TextDrawBackgroundColor(Textdraw0[i], 255);
  42. TextDrawFont(Textdraw0[i], 2);
  43. TextDrawLetterSize(Textdraw0[i], 0.320000, 0.899999);
  44. TextDrawColor(Textdraw0[i], -1);
  45. TextDrawSetOutline(Textdraw0[i], 0);
  46. TextDrawSetProportional(Textdraw0[i], 1);
  47. TextDrawSetShadow(Textdraw0[i], 0);
  48. TextDrawUseBox(Textdraw0[i], 1);
  49. TextDrawBoxColor(Textdraw0[i], 572661640);
  50. TextDrawTextSize(Textdraw0[i], 647.000000, 0.000000);
  51. }
  52. return 1;
  53. }
  54.  
  55. public OnFilterScriptExit()
  56. {
  57. return 1;
  58. }
  59.  
  60. COMMAND:start(playerid,params[])
  61. {
  62. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "[]: {ffffff}This command only RCON administration.");
  63. new Masyvas[((265 + MAX_VARIANT_SIZE) + MAX_VARIANT_SIZE) + MAX_QUESTION_SIZE];
  64. format(Masyvas,sizeof Masyvas,"{ffff00}1.{ffffff} Set poll question. ({ff0000}%s{ffffff})\n{ffff00}2.{ffffff} Set Y variant. ({ff0000}%s{ffffff})\n{ffff00}3.{ffffff} Set N variant. ({ff0000}%s{ffffff})\n{ffff00}4.{ffffff} %s.\n{ffff00}5.{ffffff} Null parameters.",Poll[Question],Poll[yVariant],Poll[nVariant],(Poll[Start]) ? ("Stop poll") : ("Start poll"));
  65. ShowPlayerDialog(playerid, GUI_DIALOG_ID, DIALOG_STYLE_LIST, "{ffffff}Poll settings", Masyvas, "Set", "Close");
  66. return 1;
  67. }
  68.  
  69. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  70. {
  71. switch(dialogid)
  72. {
  73. case GUI_DIALOG_ID:
  74. {
  75. switch(listitem)
  76. {
  77. case 0: if(response) return ShowPlayerDialog(playerid, (GUI_DIALOG_ID + 1), DIALOG_STYLE_INPUT, "{ffffff}Set poll question", "{ffffff}Enter a poll question text.\n{ff0000}[!] - There must be no longer than 24 characters.", "Set", "Close");
  78. case 1: if(response) return ShowPlayerDialog(playerid, (GUI_DIALOG_ID + 2), DIALOG_STYLE_INPUT, "{ffffff}Set Y variant", "{ffffff}Enter a Y variant text.\n{ff0000}[!] - There must be no longer than 15 characters.", "Set", "Close");
  79. case 2: if(response) return ShowPlayerDialog(playerid, (GUI_DIALOG_ID + 3), DIALOG_STYLE_INPUT, "{ffffff}Set N variant", "{ffffff}Enter a N variant text.\n{ff0000}[!] - There must be no longer than 15 characters.", "Set", "Close");
  80. case 3:
  81. {
  82. if(response)
  83. {
  84. new Masyvas[169];
  85. if(Poll[Start])
  86. {
  87. Poll[Start] = false;
  88. format(Masyvas,135,"{ffff00}Y variant votes: {ff0000}%d {ffff00}people(-s).\n{ffff00}N variant votes: {ff0000}%d {ffff00}people(-s).",Poll[yCount],Poll[nCount]);
  89. ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{ffffff}Results", Masyvas, " ", "");
  90. for(new i; i < MAX_PLAYERS; i++)
  91. {
  92. if(IsPlayerConnected(i)) TextDrawHideForPlayer(i, Textdraw0[i]);
  93. }
  94. NullVariables();
  95. return 1;
  96. }
  97. else
  98. {
  99. if(!strcmp(Poll[Question],"None",true)) return SendClientMessage(playerid, RED, "[]: {ffffff}The question is not entered.");
  100. else if(!strcmp(Poll[yVariant],"None",true)) return SendClientMessage(playerid, RED, "[]: {ffffff}The Y variant is not entered.");
  101. else if(!strcmp(Poll[nVariant],"None",true)) return SendClientMessage(playerid, RED, "[]: {ffffff}The N variant is not entered.");
  102. Poll[Start] = true;
  103. SendClientMessageToAll(WHITE, "[ . ]: {ffff00}Poll start! Everybody can vote.");
  104. Poll[Organizator] = playerid;
  105. for(new i; i < MAX_PLAYERS; i++)
  106. {
  107. if(IsPlayerConnected(i))
  108. {
  109. TextDrawShowForPlayer(playerid, Textdraw0[i]);
  110. format(Masyvas,169," ~y~:: ~w~POLL ~y~::~n~~n~~r~(?):~w~ %s~n~~n~~p~(Y)~w~ %s~n~~p~(N)~w~ %s~n~~n~PRESS ~y~Y~w~ OR ~y~N",Poll[Question],Poll[yVariant],Poll[nVariant]);
  111. TextDrawSetString(Textdraw0[i], Masyvas);
  112. Poll[GeneralCount]++;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. case 4:
  119. {
  120. if(response)
  121. {
  122. NullVariables();
  123. SendClientMessage(playerid, YELLOW, "[ * ]: {ffffff} Parameters clear.");
  124. }
  125. }
  126. }
  127. }
  128. case (GUI_DIALOG_ID + 1):
  129. {
  130. if(response)
  131. {
  132. if(isnull(inputtext)) return ShowPlayerDialog(playerid, (GUI_DIALOG_ID + 1), DIALOG_STYLE_INPUT, "{ffffff}Set poll question", "{ffffff}Enter a poll question text.\n{ff0000}[!] - There must be no longer than 24 characters.", "Set", "Close");
  133. else if(strlen(inputtext) > MAX_QUESTION_SIZE) return SendClientMessage(playerid, RED, "[]: {ffffff}The question is too long.");
  134.  
  135. format(Poll[Question], strlen(inputtext) + 1, "%s", inputtext);
  136. SendClientMessage(playerid, YELLOW, "[ * ]: {ffffff} Poll question set.");
  137. }
  138. }
  139. case (GUI_DIALOG_ID + 2):
  140. {
  141. if(response)
  142. {
  143. if(isnull(inputtext)) return ShowPlayerDialog(playerid, (GUI_DIALOG_ID + 2), DIALOG_STYLE_INPUT, "{ffffff}Set Y variant", "{ffffff}Enter a Y variant text.\n{ff0000}[!] - There must be no longer than 15 characters.", "Set", "Close");
  144. else if(strlen(inputtext) > MAX_VARIANT_SIZE) return SendClientMessage(playerid, RED, "[]: {ffffff}Per ilgas tekstas.");
  145.  
  146. format(Poll[yVariant], strlen(inputtext) + 1, "%s", inputtext);
  147. SendClientMessage(playerid, YELLOW, "[ * ]: {ffffff} Y variant set.");
  148. }
  149. }
  150. case (GUI_DIALOG_ID + 3):
  151. {
  152. if(response)
  153. {
  154. if(isnull(inputtext)) return ShowPlayerDialog(playerid, (GUI_DIALOG_ID + 3), DIALOG_STYLE_INPUT, "{ffffff}Set N variant", "{ffffff}Enter a N variant text.\n{ff0000}[!] - There must be no longer than 15 characters.", "Set", "Close");
  155. else if(strlen(inputtext) > MAX_VARIANT_SIZE) return SendClientMessage(playerid, RED, "[]: {ffffff}Per ilgas tekstas.");
  156.  
  157. format(Poll[nVariant], strlen(inputtext) + 1, "%s", inputtext);
  158. SendClientMessage(playerid, YELLOW, "[ * ]: {ffffff} N variant set.");
  159. }
  160. }
  161. }
  162. return 1;
  163. }
  164.  
  165. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  166. {
  167. if(Poll[Start])
  168. {
  169. if(!Balsavo[playerid])
  170. {
  171. if(newkeys == KEY_YES)
  172. {
  173. Poll[yCount]++;
  174. Balsavo[playerid] = false;
  175. if((Poll[yCount] + Poll[nCount]) == Poll[GeneralCount])
  176. {
  177. new Masyvas[135];
  178. Poll[Start] = false;
  179. format(Masyvas,135,"{ffff00}Y variant votes: {ff0000}%d {ffff00}people(-s).\n{ffff00}N variant votes: {ff0000}%d {ffff00}people(-s).",Poll[yCount],Poll[nCount]);
  180. ShowPlayerDialog(Poll[Organizator], 0, DIALOG_STYLE_MSGBOX, "{ffffff}Results", Masyvas, " ", "");
  181. for(new i; i < MAX_PLAYERS; i++)
  182. {
  183. if(IsPlayerConnected(i)) TextDrawHideForPlayer(i, Textdraw0[i]);
  184. }
  185. NullVariables();
  186. }
  187. }
  188. else if(newkeys == KEY_NO)
  189. {
  190. Poll[nCount]++;
  191. Balsavo[playerid] = false;
  192. if((Poll[yCount] + Poll[nCount]) == Poll[GeneralCount])
  193. {
  194. new Masyvas[135];
  195. Poll[Start] = false;
  196. format(Masyvas,135,"{ffff00}Y variant votes: {ff0000}%d {ffff00}people(-s).\n{ffff00}N variant votes: {ff0000}%d {ffff00}people(-s).",Poll[yCount],Poll[nCount]);
  197. ShowPlayerDialog(Poll[Organizator], 0, DIALOG_STYLE_MSGBOX, "{ffffff}Rezultatai", Masyvas, " ", "");
  198. for(new i; i < MAX_PLAYERS; i++)
  199. {
  200. if(IsPlayerConnected(i)) TextDrawHideForPlayer(i, Textdraw0[i]);
  201. }
  202. NullVariables();
  203. }
  204. }
  205. }
  206. }
  207. return 1;
  208. }
  209.  
  210. stock NullVariables()
  211. {
  212. format(Poll[yVariant], 5, "None");
  213. format(Poll[nVariant], 5, "None");
  214. format(Poll[Question], 5, "None");
  215. Poll[Start] = false;
  216. Poll[yCount] = 0;
  217. Poll[nCount] = 0;
  218. Poll[GeneralCount] = 0;
  219. Poll[Organizator] = INVALID_PLAYER_ID;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement