| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /*
- /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
- | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
- | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
- | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
- | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
- | $$\ $$$| $$ \ $$ | $$ \ $$| $$
- | $$ \ $$| $$$$$$/ | $$ | $$| $$
- |__/ \__/ \______/ |__/ |__/|__/
- Election System
- Jingles
- Next Generation Gaming, LLC
- (created by Next Generation Gaming Development Team)
-
- * Copyright (c) 2016, Next Generation Gaming, LLC
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are not permitted in any case.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <YSI\y_hooks>
- hook OnGameModeInit() {
- LoadElections();
- }
- hook OnGameModeExit() {
- UnloadElections();
- }
- LoadElections() {
- SetGVarInt("ElectionArea", CreateDynamicSphere(366.54, 159.09, 1008.38, 100));
- return 1;
- }
- UnloadElections() {
-
- DestroyDynamicArea(GetGVarInt("ElectionArea"));
- DeleteGVar("ElectionArea");
- }
- hook OnPlayerEnterDynamicArea(playerid, areaid) {
- if(areaid == GetGVarInt("ElectionArea")) SendClientMessage(playerid, COLOR_WHITE, "You have entered an election area - press ~k~~CONVERSATION_YES~ to vote");
- return 1;
- }
- hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
- if(newkeys & KEY_YES && IsPlayerInDynamicArea(playerid, GetGVarInt("ElectionArea"))) {
- ShowElectionMenu(playerid);
- }
- return 1;
- }
- hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
- szMiscArray[0] = 0;
- switch(dialogid) {
- case ELECTIONS: {
- szMiscArray[0] = 0;
- if(!response) return SendClientMessage(playerid, COLOR_WHITE, "You have not cast a vote");
- if(strcmp(inputtext, "Add Candidate") == 0) {
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You're not an admin.");
- return ShowPlayerDialogEx(playerid, ELECTIONS_ADD, DIALOG_STYLE_INPUT, "Add candidate", "Please enter the candidates name", "Select", "Cancel");
- }
- if(strcmp(inputtext, "Remove Candidate") == 0) {
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You're not an admin.");
- new
- szTemp[MAX_PLAYER_NAME],
- iCount = GetGVarInt("CandidateCount");
- for(new i = 0; i < iCount; ++i) {
- szTemp[0] = 0;
- GetGVarString("CandidateName", szTemp, sizeof(szTemp), i);
- format(szMiscArray, sizeof(szMiscArray), "%s\n%s", szMiscArray, szTemp);
- }
- return ShowPlayerDialogEx(playerid, ELECTIONS_REMOVE, DIALOG_STYLE_LIST, "Gov Elections", szMiscArray, "Select", "Cancel");
- }
- if(strcmp(inputtext, "Start Elections") == 0) {
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You're not an admin.");
- SendClientMessageToAll(COLOR_WHITE, "[ELECTION NEWS] The elections have been started.");
- SendClientMessageToAll(COLOR_WHITE, "[ELECTION NEWS] Head over to your local city hall to vote!");
- SetGVarInt("ElectionActive", 1);
- return 1;
- }
- if(strcmp(inputtext, "End Elections") == 0) {
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You're not an admin.");
- DeleteGVar("ElectionActive");
- return CountVotes(playerid);
- }
- if(listitem <= GetGVarInt("CandidateCount")) {
- return CastVote(playerid, listitem);
- }
- }
- case ELECTIONS_ADD: {
- if(!response || isnull(inputtext) || IsNumeric(inputtext)) return 1;
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You're not an admin.");
- new iOptionID = GetGVarInt("CandidateCount");
- SetGVarString("CandidateName", inputtext, iOptionID);
- iOptionID++;
- SetGVarInt("CandidateCount", iOptionID);
- format(szMiscArray, sizeof(szMiscArray), "You added %s as candidate no. %d", inputtext, iOptionID);
- SendClientMessageEx(playerid, COLOR_YELLOW, szMiscArray);
- format(szMiscArray, sizeof(szMiscArray), "%s added %s as election candidate no. %d", GetPlayerNameExt(playerid), inputtext, iOptionID);
- Log("logs/elections.log", szMiscArray);
- }
- case ELECTIONS_REMOVE: {
- if(!response) return 1;
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_GREY, "You're not an admin.");
- new szName[MAX_PLAYER_NAME],
- iCount = GetGVarInt("CandidateCount");
- GetGVarString("CandidateName", szName, sizeof(szName), listitem);
- DeleteGVar("CandidateName", listitem);
- SetGVarInt("CandidateCount", iCount - 1);
- format(szMiscArray, sizeof(szMiscArray), "You removed %s as candidate no. %d", szName, listitem);
- SendClientMessageEx(playerid, COLOR_YELLOW, szMiscArray);
- format(szMiscArray, sizeof(szMiscArray), "%s removed %s as election candidate no. %d", GetPlayerNameExt(playerid), szName, listitem);
- Log("logs/elections.log", szMiscArray);
- }
- }
- return 0;
- }
- CastVote(playerid, iOptionID) {
- szMiscArray[0] = 0;
- if(PlayerInfo[playerid][pNation] != 0) return SendClientMessage(playerid, COLOR_GREY, "You're not a San Andreas Citizen.");
- mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "SELECT * FROM `electionresults` WHERE `ip` = '%s'", PlayerInfo[playerid][pIP]);
- mysql_tquery(MainPipeline, szMiscArray, "OnIPVoteCheck", "ii", playerid, iOptionID);
- return 1;
- }
- forward OnIPVoteCheck(playerid, iOptionID);
- public OnIPVoteCheck(playerid, iOptionID)
- {
- new iRows;
- cache_get_row_count(iRows);
- szMiscArray[0] = 0;
- if(iRows > 0) {
- return SendClientMessageEx(playerid, COLOR_WHITE, "You have voted already!");
- } else {
- mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "SELECT * FROM `electionresults` WHERE `accountid` = '%d'", PlayerInfo[playerid][pId]);
- mysql_tquery(MainPipeline, szMiscArray, "OnCastVote", "ii", playerid, iOptionID);
- }
- return 1;
- }
- forward OnCastVote(playerid, iOptionID);
- public OnCastVote(playerid, iOptionID) {
- new iRows;
- cache_get_row_count(iRows);
- szMiscArray[0] = 0;
- if(iRows > 0) {
- return SendClientMessageEx(playerid, COLOR_WHITE, "You have voted already!");
- }
- else {
- mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "INSERT INTO `electionresults` (`accountid`, `optionid`, `ip`) VALUES ('%d', '%d', '%s')", PlayerInfo[playerid][pId], iOptionID, PlayerInfo[playerid][pIP]);
- mysql_tquery(MainPipeline, szMiscArray, "OnFinaliseVote", "ii", playerid, iOptionID);
- }
- return 1;
- }
- forward OnFinaliseVote(playerid, iOptionID);
- public OnFinaliseVote(playerid, iOptionID) {
- if(!mysql_errno(MainPipeline)) SendClientMessage(playerid, COLOR_WHITE, "You have cast your vote!");
- return 1;
- }
- CountVotes(playerid) {
- if(GetGVarInt("CandidateCount") == 0) return SendClientMessageEx(playerid, COLOR_RED, "There are no candidates, therefore no count can be made.");
- else mysql_tquery(MainPipeline, "SELECT `optionid` FROM `electionresults`", "OnCountVotes", "i", playerid);
- return 1;
- }
- forward OnCountVotes(playerid);
- public OnCountVotes(playerid) {
- new
- iRows,
- iCount,
- iTemp,
- szTemp[MAX_PLAYER_NAME],
- iCandidates = GetGVarInt("CandidateCount");
- szMiscArray[0] = 0;
- cache_get_row_count(iRows);
- while(iCount < iRows) {
- cache_get_value_name_int(iCount, "optionid", iTemp);
- SetGVarInt("Results", GetGVarInt("Results", iTemp)+1, iTemp);
- iCount++;
- }
- SendClientMessageToAll(COLOR_WHITE, "[ELECTION NEWS] Ladies and gentlemen, the elections have concluded and here are the results:");
- for(new i = 0; i < iCandidates; ++i) {
- GetGVarString("CandidateName", szTemp, sizeof(szTemp), i);
- format(szMiscArray, sizeof(szMiscArray), "%s - %d votes.", szTemp, GetGVarInt("Results", i));
- SendClientMessageToAll(COLOR_WHITE, szMiscArray);
- }
- return 1;
- }
- ShowElectionMenu(playerid) {
- if(PlayerInfo[playerid][pConnectHours] < 32 && PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_WHITE, "You have not played enough to vote.");
- szMiscArray[0] = 0;
- new
- szTemp[MAX_PLAYER_NAME],
- iCount = GetGVarInt("CandidateCount");
- for(new i = 0; i < iCount; i++) {
- szTemp[0] = 0;
- GetGVarString("CandidateName", szTemp, sizeof(szTemp), i);
- format(szMiscArray, sizeof(szMiscArray), "%s\n%s", szMiscArray, szTemp);
- }
- if(PlayerInfo[playerid][pAdmin] >= 1337 && !GetGVarType("ElectionActive")) strcat(szMiscArray, "\nAdd Candidate\nRemove Candidate\nStart Elections");
- if(PlayerInfo[playerid][pAdmin] >= 1337 && GetGVarType("ElectionActive")) strcat(szMiscArray, "\nEnd Elections");
- return ShowPlayerDialogEx(playerid, ELECTIONS, DIALOG_STYLE_LIST, "Gov Elections", szMiscArray, "Select", "Close");
- }
- CMD:elections(playerid, params[]) {
- if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
- switch(GetGVarInt("ElectionActive")) {
- case 0: {
- SendClientMessageEx(playerid, COLOR_YELLOW, "You have enabled the elections.");
- return SetGVarInt("ElectionActive", 1);
- }
- case 1: {
- SendClientMessageEx(playerid, COLOR_YELLOW, "You have disabled the elections.");
- return DeleteGVar("ElectionActive");
- }
- }
- return 1;
- }
|