1
0

dynpolls2.pwn 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. // DOWNLOAD LINK: http://www.filedropper.com/pollingsystem
  2. // This is the dump for the polls table: http://www.filedropper.com/polls
  3. /* The following change was made to `accounts`:
  4. ALTER TABLE `accounts` ADD `PollKeyA` VARCHAR(128) NOT NULL AFTER `GuardsGiven`, ADD `PollKeyB` VARCHAR(128) NOT NULL AFTER `PollKeyA`, ADD `PollKeyC` VARCHAR(128) NOT NULL AFTER `PollKeyB`; */
  5. /*
  6. Next Generation Gaming Development Team
  7. Project Name: Dynamic Polling System
  8. Author: Westen (westen@ng-gaming.net)
  9. Documentation: https://docs.google.com/document/d/1emwrE9iCG4ZomJZ5s_BskzHcSBQXlJ7nnRIkR8ChpXs/
  10. */
  11. #include <YSI\y_hooks>
  12. #define MIN_POLL_OPTIONS (2) // No point having a poll for 1 option.
  13. #define DEFAULT_POLL_OPTIONS (4)
  14. #define MAX_POLL_OPTIONS (6)
  15. #define MAX_POLLS (3)
  16. #define MAX_POLL_TYPES (5)
  17. /*
  18. -- ENUMS --
  19. */
  20. enum PollingInformation
  21. {
  22. poll_iID,
  23. poll_szTitle[64], // The max chars a dialog can hold = 64.
  24. poll_iOptions, // The number of options available.
  25. poll_szOption1[35],
  26. poll_szOption2[35],
  27. poll_szOption3[35],
  28. poll_szOption4[35],
  29. poll_szOption5[35],
  30. poll_szOption6[35],
  31. poll_iOptionResults[6], // An array storing the votes.
  32. poll_szPlacedBy[MAX_PLAYER_NAME],
  33. poll_iInterior,
  34. poll_iVirtualWorld,
  35. poll_iNation,
  36. Float:poll_fLocation[3],
  37. poll_szUniqueKey[128],
  38. poll_iCreationDate,
  39. poll_iExpirationDate, // Expiration dates are in unix so are integers.
  40. poll_iType,
  41. poll_iTypeRank,
  42. poll_iTypeID, // TypeID = the group / business that the poll is restricted to.
  43. Text3D:poll_textLabel,
  44. poll_iPickupID
  45. };
  46. new PollInfo[MAX_POLLS][PollingInformation];
  47. new PollTypes[5][] = {"None", "VIP", "Group", "Business", "Admin"};
  48. /*
  49. -- FUNCTIONS & CALLBACKS --
  50. */
  51. stock ShowPlayerEditPollDialog(playerid)
  52. {
  53. new szTitle[64], iPollID = GetPVarInt(playerid, "iEditingPoll");
  54. if(PollInfo[iPollID][poll_iID] == -1) return 0;
  55. format(szTitle, sizeof szTitle, "Editing Poll | ID: %d", iPollID);
  56. new szNation[25];
  57. if(PollInfo[iPollID][poll_iNation] == 0) format(szNation, sizeof szNation, "San Andreas");
  58. else if(PollInfo[iPollID][poll_iNation] == 1) format(szNation, sizeof szNation, "New Robada");
  59. else format(szNation, sizeof szNation, "None");
  60. format(szMiscArray, sizeof szMiscArray, "{FFFFFF}Title: {5EC7EB}%s\n{FFFFFF}No. of Options: {5EC7EB}%d\n{FFFFFF}Edit Options\nEdit Position\nType: {5EC7EB}%s (%d)\n{FFFFFF}Type Rank: {5EC7EB}%d{FFFFFF}\nType ID (group/business): {5EC7EB}%d\n{FFFFFF}Nation: {5EC7EB}%s\n{FFFFFF}Expiration Date: {5EC7EB}%s",
  61. PollInfo[iPollID][poll_szTitle], PollInfo[iPollID][poll_iOptions], PollTypes[PollInfo[iPollID][poll_iType]], PollInfo[iPollID][poll_iType], PollInfo[iPollID][poll_iTypeRank], PollInfo[iPollID][poll_iTypeID], szNation, date(PollInfo[iPollID][poll_iExpirationDate], 1));
  62. return ShowPlayerDialogEx(playerid, DIALOG_EDIT_POLL, DIALOG_STYLE_LIST, szTitle, szMiscArray, "Select", "Cancel");
  63. }
  64. stock ParsePollType(type) return PollTypes[type];
  65. stock CalculatePlayerPollKeys(playerid)
  66. {
  67. new iFound[3];
  68. for(new i = 0; i < MAX_POLLS; i++)
  69. {
  70. if(PollInfo[i][poll_iID] != -1)
  71. {
  72. // Are any of the 3 keys that I have stored the same as any currently existing polls'?
  73. if(!strcmp(PlayerInfo[playerid][pPollKey1], PollInfo[i][poll_szUniqueKey])) iFound[0] = 1;
  74. if(!strcmp(PlayerInfo[playerid][pPollKey2], PollInfo[i][poll_szUniqueKey])) iFound[1] = 1;
  75. if(!strcmp(PlayerInfo[playerid][pPollKey3], PollInfo[i][poll_szUniqueKey])) iFound[2] = 1;
  76. }
  77. }
  78. // If not, then that key is reset.
  79. if(iFound[0] == 0) format(PlayerInfo[playerid][pPollKey1], 128, "Invalid Key");
  80. if(iFound[1] == 0) format(PlayerInfo[playerid][pPollKey2], 128, "Invalid Key");
  81. if(iFound[2] == 0) format(PlayerInfo[playerid][pPollKey3], 128, "Invalid Key");
  82. }
  83. stock GenerateRandomCharacter() return (random(1000) % 2 == 0) ? (65 + random(26)) : (97 + random(26)); // Decides whether it's upper / lower case, then generates a random ascii character based on that.
  84. // valstr fix by Slice
  85. stock FIX_valstr(dest[], value, bool:pack = false)
  86. {
  87. // format can't handle cellmin properly
  88. static const cellmin_value[] = !"-2147483648";
  89. if (value == cellmin)
  90. pack && strpack(dest, cellmin_value, 12) || strunpack(dest, cellmin_value, 12);
  91. else
  92. format(dest, 12, "%d", value), pack && strpack(dest, dest, 12);
  93. }
  94. #define valstr FIX_valstr
  95. forward LoadPoll();
  96. public LoadPoll()
  97. {
  98. new rows;
  99. cache_get_row_count(rows);
  100. for(new row; row < rows; row++)
  101. {
  102. cache_get_value_name_int(row, "ID", PollInfo[row][poll_iID]);
  103. cache_get_value_name(row, "Title", PollInfo[row][poll_szTitle], 64);
  104. cache_get_value_name_int(row, "Options", PollInfo[row][poll_iOptions]);
  105. cache_get_value_name(row, "Option1", PollInfo[row][poll_szOption1], 35);
  106. cache_get_value_name(row, "Option2", PollInfo[row][poll_szOption2], 35);
  107. cache_get_value_name(row, "Option3", PollInfo[row][poll_szOption3], 35);
  108. cache_get_value_name(row, "Option4", PollInfo[row][poll_szOption4], 35);
  109. cache_get_value_name(row, "Option5", PollInfo[row][poll_szOption5], 35);
  110. cache_get_value_name(row, "Option6", PollInfo[row][poll_szOption6], 35);
  111. for(new i = 0; i < 6; i++) // Might work. Not too sure yet. Hoping it does?
  112. {
  113. format(szMiscArray, sizeof szMiscArray, "OptionResult%d", i + 1);
  114. cache_get_value_name_int(row, szMiscArray, PollInfo[row][poll_iOptionResults][i]);
  115. }
  116. cache_get_value_name_int(row, "Nation", PollInfo[row][poll_iNation]);
  117. cache_get_value_name(row, "PlacedBy", PollInfo[row][poll_szPlacedBy], MAX_PLAYER_NAME);
  118. cache_get_value_name_int(row, "Interior", PollInfo[row][poll_iInterior]);
  119. cache_get_value_name_int(row, "VirtualWorld", PollInfo[row][poll_iVirtualWorld]);
  120. cache_get_value_name_float(row, "LocationX", PollInfo[row][poll_fLocation][0]);
  121. cache_get_value_name_float(row, "LocationY", PollInfo[row][poll_fLocation][1]);
  122. cache_get_value_name_float(row, "LocationZ", PollInfo[row][poll_fLocation][2]);
  123. cache_get_value_name_int(row, "CreationDate", PollInfo[row][poll_iCreationDate]);
  124. cache_get_value_name_int(row, "ExpirationDate", PollInfo[row][poll_iExpirationDate]);
  125. cache_get_value_name_int(row, "Type", PollInfo[row][poll_iType]);
  126. cache_get_value_name_int(row, "TypeRank", PollInfo[row][poll_iTypeRank]);
  127. cache_get_value_name_int(row, "TypeID", PollInfo[row][poll_iTypeID]);
  128. cache_get_value_name(row, "UniqueKey", PollInfo[row][poll_szUniqueKey], 128);
  129. format(szMiscArray, sizeof szMiscArray, "Polling Station (ID: %d)\n{5EC7EB}%s\n{FFFF00}/vote", row, PollInfo[row][poll_szTitle]);
  130. PollInfo[row][poll_textLabel] = CreateDynamic3DTextLabel(szMiscArray, 0xFFFF00FF, PollInfo[row][poll_fLocation][0], PollInfo[row][poll_fLocation][1], PollInfo[row][poll_fLocation][2], 10.00, INVALID_PLAYER_ID,INVALID_VEHICLE_ID, 0, PollInfo[row][poll_iVirtualWorld], PollInfo[row][poll_iInterior]);
  131. PollInfo[row][poll_iPickupID] = CreateDynamicPickup(1239, 1, PollInfo[row][poll_fLocation][0], PollInfo[row][poll_fLocation][1], PollInfo[row][poll_fLocation][2], PollInfo[row][poll_iVirtualWorld], PollInfo[row][poll_iInterior]);
  132. printf("Poll %d (%s) loaded.", row, PollInfo[row][poll_szTitle]);
  133. }
  134. print("Polls loaded successfully.");
  135. return 1;
  136. }
  137. forward poll_MySQL_Load();
  138. public poll_MySQL_Load()
  139. {
  140. print("Dynamic Polling System Loading");
  141. mysql_tquery(MainPipeline, "SELECT * FROM `polls`", "LoadPoll", "");
  142. return 1;
  143. }
  144. hook OnGameModeInit()
  145. {
  146. for(new i = 0; i < MAX_POLLS; i++) PollInfo[i][poll_iID] = -1; // Reset all the IDs.
  147. SetTimer("poll_MySQL_Load", 2500, false); // Adding a timer because hooks are called before the primary callback, so if I try to load before the main callback, then I won't be able to connect to the database.
  148. }
  149. hook OnGameModeExit()
  150. {
  151. for(new i = 0; i < MAX_POLLS; i++) poll_MySQL_Save(i);
  152. }
  153. hook OnPlayerConnect(playerid)
  154. {
  155. format(PlayerInfo[playerid][pPollKey1], 128, "Invalid Key");
  156. format(PlayerInfo[playerid][pPollKey2], 128, "Invalid Key");
  157. format(PlayerInfo[playerid][pPollKey3], 128, "Invalid Key");
  158. print("Reset keys.");
  159. SetTimerEx("poll_Player_ResetKeys", 1500, false, "i", playerid);
  160. return 1;
  161. }
  162. forward poll_Player_ResetKeys(playerid);
  163. public poll_Player_ResetKeys(playerid)
  164. {
  165. CalculatePlayerPollKeys(playerid);
  166. return 1;
  167. }
  168. forward poll_MySQL_Save(i);
  169. public poll_MySQL_Save(i)
  170. {
  171. // This is split into 2 queries to make it easier to handle.
  172. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "UPDATE `polls` SET `Title`='%e', `Options`=%d, `PlacedBy`='%e', `Interior`=%d, `VirtualWorld`=%d, `UniqueKey`='%s', `Type`=%d, `TypeRank`=%d, `TypeID`=%d, `CreationDate`=%d, `Nation`=%d, `ExpirationDate`=%d WHERE `ID`=%d",
  173. PollInfo[i][poll_szTitle],
  174. PollInfo[i][poll_iOptions],
  175. PollInfo[i][poll_szPlacedBy],
  176. PollInfo[i][poll_iInterior],
  177. PollInfo[i][poll_iVirtualWorld],
  178. PollInfo[i][poll_szUniqueKey],
  179. PollInfo[i][poll_iType],
  180. PollInfo[i][poll_iTypeRank],
  181. PollInfo[i][poll_iTypeID],
  182. PollInfo[i][poll_iCreationDate],
  183. PollInfo[i][poll_iNation],
  184. PollInfo[i][poll_iExpirationDate],
  185. i + 1);
  186. mysql_tquery(MainPipeline, szMiscArray, "PollSaved", "i", i);
  187. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "UPDATE `polls` SET `Option1`='%e', `Option2`='%e', `Option3`='%e', `Option4`='%e', `Option5`='%e', `Option6`='%e', `OptionResult1`=%d, `OptionResult2`=%d, `OptionResult3`=%d, `OptionResult4`=%d, `OptionResult5`=%d, `OptionResult6`=%d WHERE `ID`=%d",
  188. PollInfo[i][poll_szOption1],
  189. PollInfo[i][poll_szOption2],
  190. PollInfo[i][poll_szOption3],
  191. PollInfo[i][poll_szOption4],
  192. PollInfo[i][poll_szOption5],
  193. PollInfo[i][poll_szOption6],
  194. PollInfo[i][poll_iOptionResults][0],
  195. PollInfo[i][poll_iOptionResults][1],
  196. PollInfo[i][poll_iOptionResults][2],
  197. PollInfo[i][poll_iOptionResults][3],
  198. PollInfo[i][poll_iOptionResults][4],
  199. PollInfo[i][poll_iOptionResults][5],
  200. i + 1);
  201. mysql_tquery(MainPipeline, szMiscArray, "OnQueryFinish", "");
  202. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "UPDATE `polls` SET `LocationX`=%f, `LocationY`=%f, `LocationZ`=%f WHERE `ID`=%d",
  203. PollInfo[i][poll_fLocation][0], PollInfo[i][poll_fLocation][1], PollInfo[i][poll_fLocation][2], i + 1);
  204. mysql_tquery(MainPipeline, szMiscArray, "OnQueryFinish", "");
  205. szMiscArray[0] = 0;
  206. return 1;
  207. }
  208. forward PollSaved(pollid);
  209. public PollSaved(pollid)
  210. {
  211. format(szMiscArray, sizeof szMiscArray, "Poll ID %d (%s) has been saved.", pollid, PollInfo[pollid][poll_szTitle]);
  212. print(szMiscArray);
  213. Log("logs/polls.log", szMiscArray);
  214. return 1;
  215. }
  216. forward NewPollCreated(pollid);
  217. public NewPollCreated(pollid)
  218. {
  219. format(szMiscArray, sizeof szMiscArray, "Poll ID %d has been created by %s, title: %s.", pollid, PollInfo[pollid][poll_szPlacedBy], PollInfo[pollid][poll_szTitle]);
  220. print(szMiscArray);
  221. Log("logs/polls.log", szMiscArray);
  222. return 1;
  223. }
  224. forward PollDeleted(pollid);
  225. public PollDeleted(pollid)
  226. {
  227. format(szMiscArray, sizeof szMiscArray, "Poll ID %d (%s) has been deleted by %s.", pollid, PollInfo[pollid][poll_szTitle], PollInfo[pollid][poll_szPlacedBy]);
  228. print(szMiscArray);
  229. Log("logs/polls.log", szMiscArray);
  230. format(PollInfo[pollid][poll_szPlacedBy], MAX_PLAYER_NAME, "");
  231. format(PollInfo[pollid][poll_szTitle], 25, "");
  232. PollInfo[pollid][poll_iID] = -1;
  233. }
  234. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  235. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  236. switch(dialogid)
  237. {
  238. /*
  239. #define DIALOG_EDIT_POLL (6183)
  240. #define DIALOG_EDIT_TITLE (6184)
  241. #define DIALOG_EDIT_NOOPTIONS (6185)
  242. #define DIALOG_EDIT_SHOWOPTIONS (6186)
  243. #define DIALOG_EDIT_OPTION (6187)
  244. Title | No. of Options | Edit Options | Edit Position
  245. */
  246. case DIALOG_EDIT_POLL:
  247. {
  248. if(!response)
  249. {
  250. DeletePVar(playerid, "iEditingPoll");
  251. return 0;
  252. }
  253. switch(listitem)
  254. {
  255. case 0: ShowPlayerDialogEx(playerid, DIALOG_EDIT_TITLE, DIALOG_STYLE_INPUT, "Editing Poll Title", "Input the desired poll title in the box below.\nNOTE: Poll titles are between 2 and 64 characters.", "Edit", "Cancel");
  256. case 1: ShowPlayerDialogEx(playerid, DIALOG_EDIT_NOOPTIONS, DIALOG_STYLE_INPUT, "Editing Option Amount", "Input the desired number of options in the box below.\nNOTE: Option amounts are between 2 and 6.", "Edit", "Cancel");
  257. case 2:
  258. {
  259. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  260. new szBody[300];
  261. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption1]);
  262. strcat(szBody, szMiscArray);
  263. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption2]);
  264. strcat(szBody, szMiscArray);
  265. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption3]);
  266. if(PollInfo[iPollID][poll_iOptions] >= 3) strcat(szBody, szMiscArray);
  267. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption4]);
  268. if(PollInfo[iPollID][poll_iOptions] >= 4) strcat(szBody, szMiscArray);
  269. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption5]);
  270. if(PollInfo[iPollID][poll_iOptions] >= 5) strcat(szBody, szMiscArray);
  271. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption6]);
  272. if(PollInfo[iPollID][poll_iOptions] == 6) strcat(szBody, szMiscArray);
  273. format(szMiscArray, sizeof szMiscArray, "Poll %d | Options", iPollID);
  274. ShowPlayerDialogEx(playerid, DIALOG_EDIT_SHOWOPTIONS, DIALOG_STYLE_LIST, szMiscArray, szBody, "Edit", "Cancel");
  275. szMiscArray[0] = 0;
  276. }
  277. case 3:
  278. {
  279. new
  280. Float:fPos[3],
  281. iInterior,
  282. iVW;
  283. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  284. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  285. iVW = GetPlayerVirtualWorld(playerid);
  286. iInterior = GetPlayerInterior(playerid);
  287. format(szMiscArray, sizeof szMiscArray, "%s has edited poll ID %d's (%s) position from X: %f | Y: %f | Z: %f (Int: %d | VW: %d) to X: %f | Y: %f | Z: %f (Int: %d | VW: %d)", GetPlayerNameEx(playerid), iPollID, PollInfo[iPollID][poll_szTitle],
  288. PollInfo[iPollID][poll_fLocation][0], PollInfo[iPollID][poll_fLocation][1], PollInfo[iPollID][poll_fLocation][2], PollInfo[iPollID][poll_iInterior], PollInfo[iPollID][poll_iVirtualWorld],
  289. fPos[0], fPos[1], fPos[2], iInterior, iVW);
  290. print(szMiscArray);
  291. Log("logs/polls.log", szMiscArray);
  292. for(new i = 0; i < 3; i++) PollInfo[iPollID][poll_fLocation][i] = fPos[i];
  293. PollInfo[iPollID][poll_iInterior] = iInterior;
  294. PollInfo[iPollID][poll_iVirtualWorld] = iVW;
  295. #if defined TEXTLABEL_DEBUG
  296. Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, PollInfo[iPollID][poll_textLabel], E_STREAMER_EXTRA_ID, 8);
  297. #endif
  298. DestroyDynamic3DTextLabel(PollInfo[iPollID][poll_textLabel]);
  299. DestroyDynamicPickup(PollInfo[iPollID][poll_iPickupID]);
  300. format(szMiscArray, sizeof szMiscArray, "Polling Station (ID: %d)\n{5EC7EB}%s\n{FFFF00}/vote", iPollID, PollInfo[iPollID][poll_szTitle]);
  301. PollInfo[iPollID][poll_textLabel] = CreateDynamic3DTextLabel(szMiscArray, 0xFFFF00FF, fPos[0], fPos[1], fPos[2], 10.00, INVALID_PLAYER_ID,INVALID_VEHICLE_ID, 0, PollInfo[iPollID][poll_iVirtualWorld], PollInfo[iPollID][poll_iInterior]);
  302. PollInfo[iPollID][poll_iPickupID] = CreateDynamicPickup(1239, 1, fPos[0], fPos[1], fPos[2], PollInfo[iPollID][poll_iVirtualWorld], PollInfo[iPollID][poll_iInterior]);
  303. SendClientMessageEx(playerid, COLOR_WHITE, "Poll position edited successfully.");
  304. poll_MySQL_Save(iPollID);
  305. DeletePVar(playerid, "iEditingPoll");
  306. szMiscArray[0] = 0;
  307. }
  308. case 4:
  309. {
  310. new iPollID = GetPVarInt(playerid, "iEditingPoll"), szBody[256], szTitle[64];
  311. format(szTitle, sizeof szTitle, "Editing Type | Current %s (%d)", PollTypes[PollInfo[iPollID][poll_iType]], PollInfo[iPollID][poll_iType]);
  312. for(new i = 0; i < sizeof PollTypes; i++)
  313. {
  314. format(szMiscArray, sizeof szMiscArray, "%s (ID: %d)\n", PollTypes[i], i);
  315. strcat(szBody, szMiscArray);
  316. }
  317. ShowPlayerDialogEx(playerid, DIALOG_EDIT_SHOWTYPES, DIALOG_STYLE_LIST, szTitle, szBody, "Edit", "Cancel");
  318. }
  319. case 5: ShowPlayerDialogEx(playerid, DIALOG_EDIT_TYPERANK, DIALOG_STYLE_INPUT, "Editing Type Rank", "Input the desired rank in the box below.", "Edit", "Cancel");
  320. case 6:
  321. {
  322. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  323. if(PollInfo[iPollID][poll_iType] == 2 || PollInfo[iPollID][poll_iType] == 3) ShowPlayerDialogEx(playerid, DIALOG_EDIT_TYPEID, DIALOG_STYLE_INPUT, "Editing Type ID", "Input the desired group / business ID in the box below.", "Edit", "Cancel");
  324. else return SendClientMessageEx(playerid, COLOR_GRAD2, "The current poll type does not support specific IDs.");
  325. }
  326. case 7:
  327. {
  328. ShowPlayerDialogEx(playerid, DIALOG_EDIT_NATION, DIALOG_STYLE_LIST, "Editing Nation Restriction", "No Nation Restriction\nSan Andreas\nNew Robada", "Edit", "Cancel");
  329. }
  330. case 8: ShowPlayerDialogEx(playerid, DIALOG_EDIT_EXPIRATIONDATE, DIALOG_STYLE_INPUT, "Editing Expiration Date", "Input the desired amount of days at which you want the poll to expire (note - this is from the creation date).", "Edit", "Cancel");
  331. }
  332. }
  333. case DIALOG_EDIT_TITLE:
  334. {
  335. if(!response)
  336. {
  337. DeletePVar(playerid, "iEditingPoll");
  338. return 0;
  339. }
  340. if(strlen(inputtext) >= 2 && strlen(inputtext) < 64)
  341. {
  342. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  343. format(PollInfo[iPollID][poll_szTitle], 64, inputtext);
  344. format(szMiscArray, sizeof szMiscArray, "Polling Station (ID: %d)\n{5EC7EB}%s\n{FFFF00}/vote", iPollID, PollInfo[iPollID][poll_szTitle]);
  345. UpdateDynamic3DTextLabelText(PollInfo[iPollID][poll_textLabel], 0xFFFF00FF, szMiscArray);
  346. ShowPlayerEditPollDialog(playerid);
  347. poll_MySQL_Save(iPollID);
  348. SendClientMessageEx(playerid, COLOR_WHITE, "Poll title edited successfully.");
  349. }
  350. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid title length. Lengths are between 2 and 64 characters.");
  351. }
  352. case DIALOG_EDIT_NOOPTIONS:
  353. {
  354. if(!response)
  355. {
  356. DeletePVar(playerid, "iEditingPoll");
  357. return 0;
  358. }
  359. new iOptionAmt = strval(inputtext), iPollID = GetPVarInt(playerid, "iEditingPoll");
  360. if(iOptionAmt > 1 && iOptionAmt < 7)
  361. {
  362. PollInfo[iPollID][poll_iOptions] = iOptionAmt;
  363. ShowPlayerEditPollDialog(playerid);
  364. poll_MySQL_Save(iPollID);
  365. SendClientMessageEx(playerid, COLOR_WHITE, "Poll option amount edited successfully.");
  366. }
  367. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid option amount. Amounts are between 2 and 6.");
  368. }
  369. case DIALOG_EDIT_SHOWOPTIONS:
  370. {
  371. if(!response)
  372. {
  373. DeletePVar(playerid, "iEditingPoll");
  374. return 0;
  375. }
  376. SetPVarInt(playerid, "iEditingOption", listitem + 1);
  377. ShowPlayerDialogEx(playerid, DIALOG_EDIT_OPTION, DIALOG_STYLE_INPUT, "Editing Option Value", "Input the desired option value in the box below.\nNOTE: Valid lengths are between 2 and 35 characters.", "Edit", "Cancel");
  378. }
  379. case DIALOG_EDIT_OPTION:
  380. {
  381. if(!response)
  382. {
  383. DeletePVar(playerid, "iEditingPoll");
  384. DeletePVar(playerid, "iEditingOption");
  385. return 0;
  386. }
  387. if(strlen(inputtext) >= 2 && strlen(inputtext) <= 35)
  388. {
  389. new iOpt = GetPVarInt(playerid, "iEditingOption"), iPollID = GetPVarInt(playerid, "iEditingPoll");
  390. switch(iOpt)
  391. {
  392. case 1: format(PollInfo[iPollID][poll_szOption1], 35, inputtext);
  393. case 2: format(PollInfo[iPollID][poll_szOption2], 35, inputtext);
  394. case 3: format(PollInfo[iPollID][poll_szOption3], 35, inputtext);
  395. case 4: format(PollInfo[iPollID][poll_szOption4], 35, inputtext);
  396. case 5: format(PollInfo[iPollID][poll_szOption5], 35, inputtext);
  397. case 6: format(PollInfo[iPollID][poll_szOption6], 35, inputtext);
  398. }
  399. SendClientMessageEx(playerid, COLOR_WHITE, "Poll option edited successfully.");
  400. ShowPlayerEditPollDialog(playerid);
  401. poll_MySQL_Save(iPollID);
  402. }
  403. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid option length. Valid lengths are between 2 and 35 characters.");
  404. }
  405. case DIALOG_VOTE:
  406. {
  407. if(!response)
  408. {
  409. DeletePVar(playerid, "iVotingOnPoll");
  410. return 0;
  411. }
  412. new iPollID = GetPVarInt(playerid, "iVotingOnPoll");
  413. CalculatePlayerPollKeys(playerid);
  414. if(!strcmp(PlayerInfo[playerid][pPollKey1], "Invalid Key")) format(PlayerInfo[playerid][pPollKey1], 128, PollInfo[iPollID][poll_szUniqueKey]);
  415. else if(!strcmp(PlayerInfo[playerid][pPollKey2], "Invalid Key")) format(PlayerInfo[playerid][pPollKey2], 128, PollInfo[iPollID][poll_szUniqueKey]);
  416. else if(!strcmp(PlayerInfo[playerid][pPollKey3], "Invalid Key")) format(PlayerInfo[playerid][pPollKey3], 128, PollInfo[iPollID][poll_szUniqueKey]);
  417. else
  418. {
  419. SendClientMessageEx(playerid, COLOR_GRAD2, "An error has occured - you have voted on all current polls. Your vote has been voided.");
  420. return 0;
  421. }
  422. PollInfo[iPollID][poll_iOptionResults][listitem]++;
  423. format(szMiscArray, sizeof szMiscArray, "%s (%d) (IP: %s) has voted on poll %s (%d), for option %d.", GetPlayerNameEx(playerid), GetPlayerSQLId(playerid), GetPlayerIpEx(playerid), PollInfo[iPollID][poll_szTitle],
  424. iPollID, listitem + 1);
  425. Log("logs/pollvotes.log", szMiscArray);
  426. szMiscArray[0] = 0;
  427. poll_MySQL_Save(iPollID);
  428. SendClientMessageEx(playerid, COLOR_WHITE, "Your vote has been counted!");
  429. }
  430. case DIALOG_EDIT_SHOWTYPES:
  431. {
  432. if(!response)
  433. {
  434. DeletePVar(playerid, "iEditingPoll");
  435. return 0;
  436. }
  437. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  438. PollInfo[iPollID][poll_iType] = listitem;
  439. SendClientMessageEx(playerid, COLOR_WHITE, "Poll type edited successfully.");
  440. ShowPlayerEditPollDialog(playerid);
  441. poll_MySQL_Save(iPollID);
  442. }
  443. case DIALOG_EDIT_TYPERANK:
  444. {
  445. if(!response)
  446. {
  447. DeletePVar(playerid, "iEditingPoll");
  448. return 0;
  449. }
  450. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  451. new iRank = strval(inputtext), maxrank = 0;
  452. switch(PollInfo[iPollID][poll_iType]) // {"None", "VIP", "Group", "Business", "Admin"};
  453. {
  454. case 1: maxrank = 4; // Plat VIP.
  455. case 2: maxrank = 10; // 10 ranks.
  456. case 3: maxrank = 5; // 5 business ranks.
  457. case 4: maxrank = 99999;
  458. }
  459. if(iRank >= 0 && iRank <= maxrank)
  460. {
  461. PollInfo[iPollID][poll_iTypeRank] = iRank;
  462. SendClientMessageEx(playerid, COLOR_WHITE, "Poll type rank edited successfully.");
  463. ShowPlayerEditPollDialog(playerid);
  464. poll_MySQL_Save(iPollID);
  465. }
  466. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid rank specified for your type.");
  467. }
  468. case DIALOG_EDIT_TYPEID:
  469. {
  470. if(!response)
  471. {
  472. DeletePVar(playerid, "iEditingPoll");
  473. return 0;
  474. }
  475. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  476. new iGroupID = strval(inputtext);
  477. switch(PollInfo[iPollID][poll_iType])
  478. {
  479. case 2:
  480. {
  481. if(iGroupID >= 0 && iGroupID <= MAX_GROUPS)
  482. {
  483. PollInfo[iPollID][poll_iTypeID] = iGroupID;
  484. SendClientMessageEx(playerid, COLOR_WHITE, "Poll type ID edited successfully.");
  485. ShowPlayerEditPollDialog(playerid);
  486. }
  487. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid group ID specified.");
  488. }
  489. case 3:
  490. {
  491. if(iGroupID >= 0 && iGroupID <= MAX_BUSINESSES)
  492. {
  493. PollInfo[iPollID][poll_iTypeID] = iGroupID;
  494. SendClientMessageEx(playerid, COLOR_WHITE, "Poll type ID edited successfully.");
  495. ShowPlayerEditPollDialog(playerid);
  496. }
  497. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid group ID specified.");
  498. }
  499. }
  500. }
  501. case DIALOG_EDIT_NATION:
  502. {
  503. if(!response)
  504. {
  505. DeletePVar(playerid, "iEditingPoll");
  506. return 0;
  507. }
  508. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  509. switch(listitem)
  510. {
  511. case 0: PollInfo[iPollID][poll_iNation] = -1;
  512. case 1: PollInfo[iPollID][poll_iNation] = 0;
  513. case 2: PollInfo[iPollID][poll_iNation] = 1;
  514. default: return 1; // some sort of error occured here so we just gonna move along
  515. }
  516. poll_MySQL_Save(iPollID);
  517. SendClientMessage(playerid, COLOR_WHITE, "Poll nation restriction edited successfully.");
  518. }
  519. case DIALOG_EDIT_EXPIRATIONDATE:
  520. {
  521. if(!response)
  522. {
  523. DeletePVar(playerid, "iEditingPoll");
  524. return 0;
  525. }
  526. new iPollID = GetPVarInt(playerid, "iEditingPoll");
  527. new iDays = strval(inputtext);
  528. if(iDays > 0 && iDays < 100)
  529. {
  530. PollInfo[iPollID][poll_iExpirationDate] = gettime() + (60 * 60 * (24 * iDays));
  531. SendClientMessageEx(playerid, COLOR_WHITE, "Poll expiration date edited successfully.");
  532. poll_MySQL_Save(iPollID);
  533. ShowPlayerEditPollDialog(playerid);
  534. }
  535. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid date. Polls may only run for up to 99 days.");
  536. }
  537. }
  538. return 0;
  539. }
  540. /*
  541. -- COMMANDS --
  542. */
  543. CMD:createpoll(playerid, params[])
  544. {
  545. if(PlayerInfo[playerid][pAdmin] >= 1337 || PlayerInfo[playerid][pPR] > 0)
  546. {
  547. new iPollID = -1, szTitle[64];
  548. if(sscanf(params, "s[64]", szTitle)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /createpoll [title]");
  549. // Get next poll ID.
  550. for(new i = 0; i < MAX_POLLS; i++)
  551. {
  552. if(PollInfo[i][poll_iID] == -1)
  553. {
  554. iPollID = i;
  555. break;
  556. }
  557. }
  558. if(iPollID != -1)
  559. {
  560. PollInfo[iPollID][poll_iID] = iPollID;
  561. format(PollInfo[iPollID][poll_szTitle], 25, szTitle);
  562. PollInfo[iPollID][poll_iOptions] = 4;
  563. format(PollInfo[iPollID][poll_szOption1], 35, "Nothing");
  564. format(PollInfo[iPollID][poll_szOption2], 35, "Nothing");
  565. format(PollInfo[iPollID][poll_szOption3], 35, "Nothing");
  566. format(PollInfo[iPollID][poll_szOption4], 35, "Nothing");
  567. format(PollInfo[iPollID][poll_szOption5], 35, "Nothing");
  568. format(PollInfo[iPollID][poll_szOption6], 35, "Nothing");
  569. for(new i = 0; i < MAX_POLL_OPTIONS; i++)
  570. {
  571. PollInfo[iPollID][poll_iOptionResults][i] = 0; // Reset all votes.
  572. }
  573. new szPlacedByName[MAX_PLAYER_NAME];
  574. GetPlayerName(playerid, szPlacedByName, MAX_PLAYER_NAME);
  575. format(PollInfo[iPollID][poll_szPlacedBy], MAX_PLAYER_NAME, szPlacedByName);
  576. new
  577. Float:fPos[3];
  578. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  579. for(new i = 0; i < 3; i++) PollInfo[iPollID][poll_fLocation][i] = fPos[i]; // Setting location.
  580. PollInfo[iPollID][poll_iInterior] = GetPlayerInterior(playerid);
  581. PollInfo[iPollID][poll_iVirtualWorld] = GetPlayerVirtualWorld(playerid);
  582. format(szMiscArray, sizeof szMiscArray, "Polling Station (ID: %d)\n{5EC7EB}%s\n{FFFF00}/vote", iPollID, PollInfo[iPollID][poll_szTitle]);
  583. PollInfo[iPollID][poll_textLabel] = CreateDynamic3DTextLabel(szMiscArray, 0xFFFF00FF, fPos[0], fPos[1], fPos[2], 10.00, INVALID_PLAYER_ID,INVALID_VEHICLE_ID, 0, PollInfo[iPollID][poll_iVirtualWorld], PollInfo[iPollID][poll_iInterior]);
  584. PollInfo[iPollID][poll_iPickupID] = CreateDynamicPickup(1239, 1, fPos[0], fPos[1], fPos[2], PollInfo[iPollID][poll_iVirtualWorld], PollInfo[iPollID][poll_iInterior]);
  585. PollInfo[iPollID][poll_iType] = 0;
  586. PollInfo[iPollID][poll_iTypeRank] = 0;
  587. PollInfo[iPollID][poll_iTypeID] = 0;
  588. PollInfo[iPollID][poll_iNation] = -1;
  589. PollInfo[iPollID][poll_iCreationDate] = gettime();
  590. PollInfo[iPollID][poll_iExpirationDate] = gettime() + 432000; // 5 days.
  591. for(new i = 0; i < 12; i++) PollInfo[iPollID][poll_szUniqueKey][i] = GenerateRandomCharacter();
  592. format(szMiscArray, sizeof szMiscArray, "Poll ID %d created (topic: %s). You can edit it using /editpoll %d.", iPollID, PollInfo[iPollID][poll_szTitle], iPollID);
  593. SendClientMessageEx(playerid, COLOR_WHITE, szMiscArray);
  594. SendClientMessageEx(playerid, COLOR_WHITE, "It is set to expire automatically in 5 days.");
  595. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "INSERT INTO `polls` VALUES(%d, '%e', %d, '%e', '%e', '%e', '%e', '%e', '%e', %d, %d, %d, %d, %d, %d, '%e', %d, %d, %f, %f, %f, '%s', %d, %d, %d, %d, %d, %d)",
  596. iPollID + 1,
  597. PollInfo[iPollID][poll_szTitle],
  598. PollInfo[iPollID][poll_iOptions],
  599. PollInfo[iPollID][poll_szOption1],
  600. PollInfo[iPollID][poll_szOption2],
  601. PollInfo[iPollID][poll_szOption3],
  602. PollInfo[iPollID][poll_szOption4],
  603. PollInfo[iPollID][poll_szOption5],
  604. PollInfo[iPollID][poll_szOption6],
  605. PollInfo[iPollID][poll_iOptionResults][0],
  606. PollInfo[iPollID][poll_iOptionResults][1],
  607. PollInfo[iPollID][poll_iOptionResults][2],
  608. PollInfo[iPollID][poll_iOptionResults][3],
  609. PollInfo[iPollID][poll_iOptionResults][4],
  610. PollInfo[iPollID][poll_iOptionResults][5],
  611. PollInfo[iPollID][poll_szPlacedBy],
  612. PollInfo[iPollID][poll_iInterior],
  613. PollInfo[iPollID][poll_iVirtualWorld],
  614. PollInfo[iPollID][poll_fLocation][0],
  615. PollInfo[iPollID][poll_fLocation][1],
  616. PollInfo[iPollID][poll_fLocation][2],
  617. PollInfo[iPollID][poll_szUniqueKey],
  618. PollInfo[iPollID][poll_iCreationDate],
  619. PollInfo[iPollID][poll_iExpirationDate],
  620. PollInfo[iPollID][poll_iType],
  621. PollInfo[iPollID][poll_iTypeRank],
  622. PollInfo[iPollID][poll_iTypeID],
  623. PollInfo[iPollID][poll_iNation]);
  624. mysql_tquery(MainPipeline, szMiscArray, "NewPollCreated", "i", iPollID);
  625. szMiscArray[0] = 0;
  626. }
  627. else SendClientMessageEx(playerid, COLOR_GRAD2, "No more polls can be created.");
  628. }
  629. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  630. return 1;
  631. }
  632. CMD:deletepoll(playerid, params[])
  633. {
  634. if(PlayerInfo[playerid][pAdmin] >= 1337 || PlayerInfo[playerid][pPR] > 0)
  635. {
  636. new iPollID;
  637. if(sscanf(params, "d", iPollID)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /deletepoll [poll ID]");
  638. if(iPollID >= 0 && iPollID < MAX_POLLS)
  639. {
  640. if(PollInfo[iPollID][poll_iID] != -1)
  641. {
  642. PollInfo[iPollID][poll_iOptions] = 4;
  643. format(PollInfo[iPollID][poll_szOption1], 35, "Nothing");
  644. format(PollInfo[iPollID][poll_szOption2], 35, "Nothing");
  645. format(PollInfo[iPollID][poll_szOption3], 35, "Nothing");
  646. format(PollInfo[iPollID][poll_szOption4], 35, "Nothing");
  647. format(PollInfo[iPollID][poll_szOption5], 35, "Nothing");
  648. format(PollInfo[iPollID][poll_szOption6], 35, "Nothing");
  649. PollInfo[iPollID][poll_iOptionResults][0] = 0;
  650. PollInfo[iPollID][poll_iOptionResults][1] = 0;
  651. PollInfo[iPollID][poll_iOptionResults][2] = 0;
  652. PollInfo[iPollID][poll_iOptionResults][3] = 0;
  653. PollInfo[iPollID][poll_iOptionResults][4] = 0;
  654. PollInfo[iPollID][poll_iOptionResults][5] = 0;
  655. PollInfo[iPollID][poll_iInterior] = 0;
  656. PollInfo[iPollID][poll_iVirtualWorld] = 0;
  657. PollInfo[iPollID][poll_iNation] = -1;
  658. mysql_format(MainPipeline, szMiscArray, sizeof szMiscArray, "DELETE FROM `polls` WHERE `ID`=%d", iPollID + 1);
  659. mysql_tquery(MainPipeline, szMiscArray, "PollDeleted", "i", iPollID);
  660. DestroyDynamic3DTextLabel(PollInfo[iPollID][poll_textLabel]);
  661. DestroyDynamicPickup(PollInfo[iPollID][poll_iPickupID]);
  662. SendClientMessageEx(playerid, COLOR_WHITE, "Poll deleted successfully.");
  663. }
  664. else SendClientMessageEx(playerid, COLOR_GRAD2, "This poll does not exist.");
  665. }
  666. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid poll ID specified.");
  667. }
  668. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  669. return 1;
  670. }
  671. CMD:editpoll(playerid, params[])
  672. {
  673. if(PlayerInfo[playerid][pAdmin] >= 1337 || PlayerInfo[playerid][pPR] > 0)
  674. {
  675. new iPollID;
  676. if(sscanf(params, "d", iPollID)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /editpoll [poll id]");
  677. if(iPollID >= 0 && iPollID < MAX_POLLS)
  678. {
  679. if(PollInfo[iPollID][poll_iID] != -1)
  680. {
  681. SetPVarInt(playerid, "iEditingPoll", iPollID);
  682. ShowPlayerEditPollDialog(playerid);
  683. }
  684. else SendClientMessageEx(playerid, COLOR_GRAD2, "This poll does not exist.");
  685. }
  686. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid poll ID specified.");
  687. }
  688. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  689. return 1;
  690. }
  691. CMD:viewpollresults(playerid, params[])
  692. {
  693. if(PlayerInfo[playerid][pAdmin] >= 1337 || PlayerInfo[playerid][pPR] > 0)
  694. {
  695. new iPollID;
  696. if(sscanf(params, "d", iPollID)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /viewpollresults [poll id]");
  697. if(iPollID >= 0 && iPollID < MAX_POLLS)
  698. {
  699. if(PollInfo[iPollID][poll_iID] != -1)
  700. {
  701. SendClientMessageEx(playerid, COLOR_GREEN, "_______________________________________");
  702. format(szMiscArray, sizeof szMiscArray, "Poll ID: %d | Title: %s", iPollID, PollInfo[iPollID][poll_szTitle]);
  703. SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  704. format(szMiscArray, sizeof szMiscArray, "Option #1 (%s): %d votes.", PollInfo[iPollID][poll_szOption1], PollInfo[iPollID][poll_iOptionResults][0]);
  705. SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  706. format(szMiscArray, sizeof szMiscArray, "Option #2 (%s): %d votes.", PollInfo[iPollID][poll_szOption2], PollInfo[iPollID][poll_iOptionResults][1]);
  707. SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  708. format(szMiscArray, sizeof szMiscArray, "Option #3 (%s): %d votes.", PollInfo[iPollID][poll_szOption3], PollInfo[iPollID][poll_iOptionResults][2]);
  709. if(PollInfo[iPollID][poll_iOptions] >= 3) SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  710. format(szMiscArray, sizeof szMiscArray, "Option #4 (%s): %d votes.", PollInfo[iPollID][poll_szOption4], PollInfo[iPollID][poll_iOptionResults][3]);
  711. if(PollInfo[iPollID][poll_iOptions] >= 4) SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  712. format(szMiscArray, sizeof szMiscArray, "Option #5 (%s): %d votes.", PollInfo[iPollID][poll_szOption5], PollInfo[iPollID][poll_iOptionResults][4]);
  713. if(PollInfo[iPollID][poll_iOptions] >= 5) SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  714. format(szMiscArray, sizeof szMiscArray, "Option #6 (%s): %d votes.", PollInfo[iPollID][poll_szOption6], PollInfo[iPollID][poll_iOptionResults][5]);
  715. if(PollInfo[iPollID][poll_iOptions] >= 6) SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  716. SendClientMessageEx(playerid, COLOR_GREEN, "_______________________________________");
  717. }
  718. else SendClientMessageEx(playerid, COLOR_GRAD2, "This poll does not exist.");
  719. }
  720. else SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid poll ID specified.");
  721. }
  722. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  723. return 1;
  724. }
  725. CMD:vote(playerid, params[])
  726. {
  727. new iPollID = -1;
  728. if(PlayerInfo[playerid][pConnectHours] < 2) return SendClientMessage(playerid, COLOR_GRAD2, "You do not have enough playing hours to vote in this poll.");
  729. for(new i = 0; i < MAX_POLLS; i++)
  730. {
  731. if(IsPlayerInRangeOfPoint(playerid, 2.0, PollInfo[i][poll_fLocation][0], PollInfo[i][poll_fLocation][1], PollInfo[i][poll_fLocation][2]) && GetPlayerInterior(playerid) == PollInfo[i][poll_iInterior] && GetPlayerVirtualWorld(playerid) == PollInfo[i][poll_iVirtualWorld])
  732. {
  733. iPollID = i;
  734. break;
  735. }
  736. }
  737. if(iPollID != -1)
  738. {
  739. if(!strcmp(PlayerInfo[playerid][pPollKey1], PollInfo[iPollID][poll_szUniqueKey]) || !strcmp(PlayerInfo[playerid][pPollKey2], PollInfo[iPollID][poll_szUniqueKey]) || !strcmp(PlayerInfo[playerid][pPollKey3], PollInfo[iPollID][poll_szUniqueKey]))
  740. {
  741. SendClientMessageEx(playerid, COLOR_GRAD2, "You have already voted on this poll.");
  742. return 1;
  743. }
  744. else
  745. {
  746. if(gettime() < PollInfo[iPollID][poll_iExpirationDate])
  747. {
  748. new iCanUse = 0;
  749. switch(PollInfo[iPollID][poll_iType])
  750. { // new PollTypes[5][] = {"None", "VIP", "Group", "Business", "Admin"};
  751. case 0: iCanUse = 1;
  752. case 1: if(PlayerInfo[playerid][pDonateRank] >= PollInfo[iPollID][poll_iTypeRank]) iCanUse = 1;
  753. case 2: if(PlayerInfo[playerid][pMember] == PollInfo[iPollID][poll_iTypeID] && PlayerInfo[playerid][pRank] >= PollInfo[iPollID][poll_iTypeRank]) iCanUse = 1;
  754. case 3: if(PlayerInfo[playerid][pBusiness] == PollInfo[iPollID][poll_iTypeID] && PlayerInfo[playerid][pBusinessRank] >= PollInfo[iPollID][poll_iTypeRank]) iCanUse = 1;
  755. case 4: if(PlayerInfo[playerid][pAdmin] >= PollInfo[iPollID][poll_iTypeRank]) iCanUse = 1;
  756. }
  757. if(PollInfo[iPollID][poll_iNation] != -1)
  758. {
  759. if(PollInfo[iPollID][poll_iNation] == 0 && PlayerInfo[playerid][pNation] != 0) return SendClientMessage(playerid, COLOR_GRAD2, "This poll is restricted to San Andreas - you cannot vote in it.");
  760. else if(PollInfo[iPollID][poll_iNation] == 1 && PlayerInfo[playerid][pNation] != 1) return SendClientMessage(playerid, COLOR_GRAD2, "This poll is restricted to New Robada - you cannot vote in it.");
  761. }
  762. if(iCanUse) // Just in case?
  763. {
  764. SetPVarInt(playerid, "iVotingOnPoll", iPollID);
  765. new szBody[300];
  766. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption1]);
  767. strcat(szBody, szMiscArray);
  768. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption2]);
  769. strcat(szBody, szMiscArray);
  770. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption3]);
  771. if(PollInfo[iPollID][poll_iOptions] >= 3) strcat(szBody, szMiscArray);
  772. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption4]);
  773. if(PollInfo[iPollID][poll_iOptions] >= 4) strcat(szBody, szMiscArray);
  774. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption5]);
  775. if(PollInfo[iPollID][poll_iOptions] >= 5) strcat(szBody, szMiscArray);
  776. format(szMiscArray, sizeof szMiscArray, "%s\n", PollInfo[iPollID][poll_szOption6]);
  777. if(PollInfo[iPollID][poll_iOptions] == 6) strcat(szBody, szMiscArray);
  778. format(szMiscArray, sizeof szMiscArray, "Poll %d | Options", iPollID);
  779. ShowPlayerDialogEx(playerid, DIALOG_VOTE, DIALOG_STYLE_LIST, PollInfo[iPollID][poll_szTitle], szBody, "Edit", "Cancel");
  780. szMiscArray[0] = 0;
  781. }
  782. else SendClientMessageEx(playerid, COLOR_GRAD2, "This poll is restricted - you are not permitted to vote.");
  783. }
  784. else SendClientMessageEx(playerid, COLOR_GRAD2, "This poll has expired.");
  785. }
  786. }
  787. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not in range of any polling stations.");
  788. return 1;
  789. }
  790. CMD:pollhelp(playerid, params[]) {
  791. if(PlayerInfo[playerid][pAdmin] >= 1337 || PlayerInfo[playerid][pPR] > 0) SendClientMessageEx(playerid, COLOR_GRAD2, "/createpoll, /deletepoll, /editpoll, /viewpollresults, /vote.");
  792. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  793. return 1;
  794. }
  795. CMD:polls(playerid, params[]) {
  796. if(PlayerInfo[playerid][pAdmin] >= 1337 || PlayerInfo[playerid][pPR] > 0) {
  797. SendClientMessage(playerid, COLOR_GREEN, "_______________________________________");
  798. new iPollCount = 0;
  799. new szNation[25];
  800. for(new i = 0; i < MAX_POLLS; i++) {
  801. if(PollInfo[i][poll_iID] != -1) {
  802. if(PollInfo[i][poll_iNation] == -1) format(szNation, sizeof szNation, "None");
  803. else if(PollInfo[i][poll_iNation] == 0) format(szNation, sizeof szNation, "San Andreas");
  804. else if(PollInfo[i][poll_iNation] == 1) format(szNation, sizeof szNation, "New Robada");
  805. iPollCount++;
  806. format(szMiscArray, sizeof(szMiscArray), "Poll ID: %d | Title / Topic: %s | No. of Options: %d | Placed By: %s (Unique Key: %s) | Nation: %s", i, PollInfo[i][poll_szTitle], PollInfo[i][poll_iOptions], PollInfo[i][poll_szPlacedBy], PollInfo[i][poll_szUniqueKey], szNation);
  807. SendClientMessage(playerid, COLOR_GRAD2, szMiscArray);
  808. }
  809. }
  810. if(iPollCount == 0) SendClientMessage(playerid, COLOR_GREY, "There are currently no active polls.");
  811. else SendClientMessage(playerid, COLOR_GREY, "To go to a poll, use /gotopoll [poll id]");
  812. SendClientMessage(playerid, COLOR_GREEN, "_______________________________________");
  813. }
  814. else SendClientMessage(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  815. return 1;
  816. }
  817. CMD:gotopoll(playerid, params[]) {
  818. if(PlayerInfo[playerid][pAdmin] < 1337 && PlayerInfo[playerid][pPR] == 0) return SendClientMessage(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
  819. new iPollID;
  820. if(sscanf(params, "d", iPollID)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /gotopoll [poll id]");
  821. if(iPollID < 0 || iPollID >= MAX_POLLS) return SendClientMessage(playerid, COLOR_GRAD2, "Invalid poll specified.");
  822. if(PollInfo[iPollID][poll_iID] == -1) return SendClientMessage(playerid, COLOR_GRAD2, "This poll does not exist.");
  823. SetPlayerPos(playerid, PollInfo[iPollID][poll_fLocation][0], PollInfo[iPollID][poll_fLocation][1], PollInfo[iPollID][poll_fLocation][2]);
  824. SetPlayerInterior(playerid, PollInfo[iPollID][poll_iInterior]);
  825. SetPlayerVirtualWorld(playerid, PollInfo[iPollID][poll_iVirtualWorld]);
  826. format(szMiscArray, sizeof szMiscArray, "You have teleported to poll ID %d successfully.", iPollID);
  827. SendClientMessage(playerid, COLOR_WHITE, szMiscArray);
  828. return 1;
  829. }