ZiPoNz

Z-Survey-ENG - Version 1

Apr 19th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.71 KB | None | 0 0
  1. //Survey - filterscript by ZiPoNz ©- Version: 1
  2. #include <a_samp>
  3. #define STitle 514
  4. #define SText 515
  5. #define MaxTime 30
  6. new bool:SurveyOn = false, bool:AChose[MAX_PLAYERS] = false, Title[30], YesNo[2];
  7. public OnPlayerCommandText(playerid, cmdtext[])
  8. {
  9.     new cmd[128], idx;
  10.     cmd = strtok(cmdtext, idx);
  11.     if(!strcmp(cmdtext, "/survey", true))
  12.     {
  13.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] Your'e not admin rcon.");
  14.         if(SurveyOn) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] There's already survey on.");
  15.         return ShowPlayerDialog(playerid, STitle, DIALOG_STYLE_INPUT, "Create a new survey: Title.", "Please write the title of your survey.", "Next", "Cancel");
  16.     }
  17.     if(!strcmp(cmd, "/stopsurvey", true))
  18.     {
  19.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] Your'e not admin rcon.");
  20.         new AName[24], string[128];
  21.         GetPlayerName(playerid, AName, 24);
  22.         SurveyOn = false;
  23.         YesNo[0] = 0, YesNo[1] = 0;
  24.         format(string, 128, "The administrator %s stopped the survey.", AName);
  25.         return SendClientMessageToAll(0xFFFFFF00, string);
  26.     }
  27.     if(!strcmp(cmd, "/vote", true))
  28.     {
  29.         if(!SurveyOn) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] There's no survey on in the server.");
  30.         if(AChose[playerid]) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] You are already voted at this survey, please wait!");
  31.         cmd = strtok(cmdtext, idx);
  32.         if(!strlen(cmd)) return SendClientMessage(playerid, 0xFFFFFF00, "Type: /vote [Yes/No]");
  33.         if(!strcmp(cmd, "yes", true)) return SendClientMessage(playerid, 0xFFFFFF00, "[System] You chose in the survey as the answer: Yes."), YesNo[0]++, AChose[playerid] = true;
  34.         if(!strcmp(cmd, "no", true)) return SendClientMessage(playerid, 0xFFFFFF00, "[System] You chose in the survey as the answer: No."), YesNo[1]++, AChose[playerid] = true;
  35.     }
  36.     return false;
  37. }
  38. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  39. {
  40.     switch(dialogid)
  41.     {
  42.         case STitle:
  43.         {
  44.             if(!response) return true;
  45.             format(Title, 30, "%s", inputtext);
  46.             ShowPlayerDialog(playerid, SText, DIALOG_STYLE_INPUT, "Create a new survey: Text.", "Please write the text of your survey.", "Create", "Back");
  47.         }
  48.         case SText:
  49.         {
  50.             new string[256], AName[24];
  51.             GetPlayerName(playerid, AName, 24);
  52.             if(!response) return ShowPlayerDialog(playerid, STitle, DIALOG_STYLE_INPUT, "Create a new survey: Title.", "Please write the title of your survey.", "Next", "Cancel");
  53.             SurveyOn = true;
  54.             for(new p = 0; p < MAX_PLAYERS; p++)
  55.             {
  56.                 if(!IsPlayerConnected(p)) continue;
  57.                 AChose[p] = false;
  58.             }
  59.             format(string, 128, "New survey in the server! Title: %s by %s.", Title, AName);
  60.             SendClientMessageToAll(0xFFFFFF00, string);
  61.             format(string, 256, "Survey text: %s (Type: /vote).", inputtext);
  62.             SendClientMessageToAll(0xFFFFFF00, string);
  63.             SetTimer("SurveyStop", MaxTime*000, false);
  64.         }
  65.     }
  66.     return true;
  67. }
  68. forward SurveyStop();
  69. public SurveyStop()
  70. {
  71.     if(SurveyOn)
  72.     {
  73.         new string[128];
  74.         SurveyOn = false;
  75.         format(string, 128, "The survey's now ended(Results): %d voted for \"Yes\" and %d voted for \"No\".", YesNo[0], YesNo[1]);
  76.         SendClientMessageToAll(0xFFFFFF00, string);
  77.         YesNo[0] = 0, YesNo[1] = 0;
  78.     }
  79. }
  80. strtok(const string[], &index)
  81. {
  82.     new length = strlen(string);
  83.     while ((index < length) && (string[index] <= ' ')) index++;
  84.     new offset = index;
  85.     new result[20];
  86.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) result[index - offset] = string[index], index++;
  87.     result[index - offset] = EOS;
  88.     return result;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment