1
0

polls.pwn 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Poll System
  11. Winterfield
  12. Next Generation Gaming, LLC
  13. (created by Next Generation Gaming Development Team)
  14. * Copyright (c) 2016, Next Generation Gaming, LLC
  15. *
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without modification,
  19. * are not permitted in any case.
  20. *
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <YSI\y_hooks>
  35. CMD:polls(playerid, params[])
  36. {
  37. szMiscArray[0] = 0;
  38. for(new i; i < MAX_POLLS; i++)
  39. {
  40. DeletePVar(playerid, "pVoting");
  41. if(strfind(PlayerInfo[playerid][pPrisonReason], "Vacant", true) == -1)
  42. {
  43. format(szMiscArray, sizeof(szMiscArray), "%s\n%d | %s", szMiscArray, i, Polls[i][PollQuestion]);
  44. }
  45. }
  46. ShowPlayerDialogEx(playerid, DIALOG_POLLS, DIALOG_STYLE_LIST, "NG:RP Polls", szMiscArray, "Select", "Cancel");
  47. return 1;
  48. }
  49. CMD:editpolls(playerid, params[])
  50. {
  51. if(PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1)
  52. {
  53. DeletePVar(playerid, "pEditingPoll");
  54. szMiscArray[0] = 0;
  55. for(new i; i < MAX_POLLS; i++)
  56. {
  57. format(szMiscArray, sizeof(szMiscArray), "%s\n%d | %s", szMiscArray, i, Polls[i][PollQuestion]);
  58. }
  59. ShowPlayerDialogEx(playerid, DIALOG_EDITPOLLS, DIALOG_STYLE_LIST, "NG:RP Polls | Edit", szMiscArray, "Select", "Cancel");
  60. }
  61. return 1;
  62. }
  63. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  64. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  65. switch(dialogid)
  66. {
  67. case DIALOG_POLLS:
  68. {
  69. switch(listitem)
  70. {
  71. case 0 .. MAX_POLLS:
  72. {
  73. if(PlayerInfo[playerid][HasVoted][listitem] > 0) return SendClientMessage(playerid, COLOR_WHITE, "You have already voted on this poll!");
  74. SetPVarInt(playerid, "pVoting", listitem);
  75. for(new i; i < MAX_POLLS_CHOICES; i++)
  76. {
  77. format(szMiscArray, sizeof(szMiscArray), "%s\n%d | %s", szMiscArray, i, PollChoices[listitem][i]);
  78. }
  79. ShowPlayerDialogEx(playerid, DIALOG_POLLS_VOTE, DIALOG_STYLE_LIST, "NG:RP Polls | Vote", szMiscArray, "Select", "Cancel");
  80. }
  81. }
  82. }
  83. case DIALOG_POLLS_VOTE:
  84. {
  85. switch(listitem)
  86. {
  87. case 0 .. MAX_POLLS_CHOICES:
  88. {
  89. PlayerInfo[playerid][HasVoted][GetPVarInt(playerid, "pVoting")] = gettime();
  90. Polls[GetPVarInt(playerid, "pVoting")][PollVotes][listitem] += 1;
  91. SavePoll(GetPVarInt(playerid, "pVoting"));
  92. }
  93. }
  94. }
  95. case DIALOG_EDITPOLLS:
  96. {
  97. switch(listitem)
  98. {
  99. case 0 .. MAX_POLLS:
  100. {
  101. SetPVarInt(playerid, "pEditingPoll", listitem);
  102. ShowPlayerDialogEx(playerid, DIALOG_EDITPOLLS2, DIALOG_STYLE_LIST, "NG:RP Polls | Edit", "Edit Question\nEdit Choices\nReset Poll", "Select", "Cancel");
  103. }
  104. }
  105. }
  106. case DIALOG_EDITPOLLS2:
  107. {
  108. switch(listitem)
  109. {
  110. case 0: ShowPlayerDialogEx(playerid, DIALOG_EDITPOLLS_NAME, DIALOG_STYLE_MSGBOX, "NG:RP Polls | Edit Question", "Please enter the question for the poll below.", "Okay", "Cancel");
  111. case 1:
  112. {
  113. szMiscArray[0] = 0;
  114. DeletePVar(playerid, "pEditingPollChoice");
  115. for(new i; i < MAX_POLLS_CHOICES; i++)
  116. {
  117. format(szMiscArray, sizeof(szMiscArray), "%s\n%d | %s", szMiscArray, i, PollChoices[GetPVarInt(playerid, "pEditingPoll")][i]);
  118. }
  119. ShowPlayerDialogEx(playerid, DIALOG_EDITPOLLS_CHOICES, DIALOG_STYLE_LIST, "NG:RP Polls | Edit Choices", szMiscArray, "Select", "Cancel");
  120. }
  121. case 2:
  122. {
  123. ResetPoll(GetPVarInt(playerid, "pEditingPoll"));
  124. }
  125. }
  126. }
  127. }
  128. return 0;
  129. }
  130. /*CheckPlayerPollStatus(playerid)
  131. {
  132. for(new i; i < MAX_POLLS; i++) if(PlayerInfo[playerid][HasVoted][i] < Polls[i][LastReset]) PlayerInfo[playerid][HasVoted][i] = 0;
  133. return 1;
  134. }*/
  135. ResetPoll(id)
  136. {
  137. format(Polls[id][PollQuestion], 256, "Vacant");
  138. for(new i; i < MAX_POLLS_CHOICES; i++) format(PollChoices[id][i], 255, "Vacant");
  139. foreach(new i: Player)
  140. {
  141. if(PlayerInfo[i][HasVoted][id] > 0) PlayerInfo[i][HasVoted][id] = 0;
  142. }
  143. Polls[id][LastReset] = gettime();
  144. SavePoll(id);
  145. return 1;
  146. }
  147. SavePoll(id)
  148. {
  149. szMiscArray[0] = 0;
  150. new mistring[64];
  151. for(new i; i < MAX_POLLS; i++)
  152. {
  153. format(szMiscArray, sizeof szMiscArray, "UPDATE `polls` SET `Question` = '%s'", Polls[id][PollQuestion]);
  154. for(i = 0; i != MAX_POLLS_CHOICES; ++i) format(szMiscArray, sizeof szMiscArray, "%s, `Choice%d` = '%s'", szMiscArray, i, PollChoices[id][i]);
  155. for(i = 0; i != MAX_POLLS_CHOICES; ++i)
  156. {
  157. format(mistring, sizeof(mistring), "%s%d", mistring, Polls[id][PollVotes][i]);
  158. strcat(mistring, "|");
  159. }
  160. format(szMiscArray, sizeof szMiscArray, "%s, `Votes` = '%s'", szMiscArray, mistring);
  161. }
  162. format(szMiscArray, sizeof szMiscArray, "%s WHERE `id` = %d", szMiscArray, id + 1);
  163. mysql_tquery(MainPipeline, szMiscArray, false, "OnQueryFinish", "i", SENDDATA_THREAD);
  164. return 1;
  165. }