Guest User

Survey system created by Or_Yagoda HighDefiniton אור יגודה

a guest
Jan 2nd, 2011
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.17 KB | None | 0 0
  1. /*
  2. This script was created by HighDefinition (Or_Yagoda)
  3. Skype: oryagoda
  4.  
  5. Also programing PHP, SQL, HTML and more.
  6. If you need a pawn script or a website, contact me.
  7. */
  8. //==============================================================================
  9. #include a_samp
  10. //==============================================================================
  11. #define MAX_ANSWERS_PER_SURVEY 5 // How mach answers can you set in-game
  12. //==============================================================================
  13. enum gSurveyE
  14. {
  15.     Started,
  16.     Creation,
  17.     Question[128],
  18.     NumberOfAnswers,
  19.     CreationProgress,
  20.     SurveyTime
  21. };
  22. enum pSurveyE
  23. {
  24.     Voted
  25. };
  26. //==============================================================================
  27. new pSurveyVB[MAX_PLAYERS][pSurveyE],gSurveyVB[gSurveyE],gSurveyAnswers[MAX_ANSWERS_PER_SURVEY + 1][80],MessageString[1024];
  28. //==============================================================================
  29. #define Voted_Yes 1
  30. #define Voted_No 2
  31. //==============================================================================
  32. #define Dialog_SurveyOptions 11542
  33. #define Dialog_SurveyMessage 11543
  34. #define Dialog_SurveyCreate 11544
  35. #define Dialog_SurveyConfirm 11545
  36. #define Dialog_SurveyVote 11546
  37. #define Dialog_SurveyTime 11547
  38. //==============================================================================
  39. #define COLOR_RED 4278190160
  40. #define COLOR_GREEN 0x33AA33AA
  41. #define COLOR_YELLOW 0xFFFF00AA
  42. //==============================================================================
  43. forward SurveyResult();
  44. forward EndSurvey();
  45. //==============================================================================
  46. public OnFilterScriptInit()
  47. {
  48.     gSurveyVB[Creation] = 0;
  49.     print("Survey system by HighDefinition (Or_Yagoda) loaded !");
  50.     return 1;
  51. }
  52. //==============================================================================
  53. public OnFilterScriptExit()
  54. {
  55.     print("Survey system by HighDefinition (Or_Yagoda) unloaded !");
  56.     return 1;
  57. }
  58. //==============================================================================
  59. public OnPlayerConnect(playerid)
  60. {
  61.     pSurveyVB[playerid][Voted] = -1;
  62.     return 1;
  63. }
  64. //==============================================================================
  65. public OnPlayerCommandText(playerid,cmdtext[])
  66. {
  67.     if(!strcmp(cmdtext,"/Survey",true) && IsPlayerAdmin(playerid))
  68.     {
  69.         if(gSurveyVB[Started] == 1) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey system","Please wait for the survey to end","Ok"," ");
  70.         gSurveyVB[CreationProgress] = 1;
  71.         gSurveyVB[Creation] = 1;
  72.         ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Survey system - Create","Enter survey question","Create","Cancel");
  73.         return 1;
  74.     }
  75.     if(!strcmp(cmdtext,"/Vote",true))
  76.     {
  77.         if(gSurveyVB[Started] == 0) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey system","There is no active surevy at this moment","Ok"," ");
  78.         if(pSurveyVB[playerid][Voted] != -1) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey syste,","You already votes, please wait for the survey to end","Ok"," ");
  79.         if(strlen(gSurveyAnswers[0]) != 0){ format(MessageString,sizeof(MessageString),"1. %s",gSurveyAnswers[0]); }
  80.         for(new m = 1; m < MAX_ANSWERS_PER_SURVEY + 1; m ++)
  81.         {
  82.             if(strlen(gSurveyAnswers[m]) != 0)
  83.             {
  84.                 format(MessageString,sizeof(MessageString),"%s\r\n%d. %s",MessageString,m + 1,gSurveyAnswers[m]);
  85.             }
  86.         }
  87.         ShowPlayerDialog(playerid,Dialog_SurveyVote,DIALOG_STYLE_LIST,gSurveyVB[Question],MessageString,"Choose","Cancel");
  88.         return 1;
  89.     }
  90.     return 0;
  91. }
  92. //==============================================================================
  93. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  94. {
  95.     if(response == 1)
  96.     {
  97.         switch(dialogid)
  98.         {
  99.             case Dialog_SurveyMessage: return 1;
  100.             case Dialog_SurveyCreate:
  101.             {
  102.                 if(gSurveyVB[CreationProgress] == 1)
  103.                 {
  104.                     if(!strlen(inputtext)) return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Survey system - Create","No question entered.\r\n\r\nEnter survey question","Create","Cancel");
  105.                     MessageString = "2";
  106.                     for(new q = 3; q < MAX_ANSWERS_PER_SURVEY + 1; q ++)
  107.                     {
  108.                         format(MessageString,sizeof(MessageString),"%s\r\n%d",MessageString,q);
  109.                     }
  110.                     gSurveyVB[CreationProgress] = 2;
  111.                     format(gSurveyVB[Question],sizeof(gSurveyVB[Question]),"%s",inputtext);
  112.                     return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_LIST,"How mach answers will be for this survey?",MessageString,"Choose","Cancel");
  113.                 }
  114.                 if(gSurveyVB[CreationProgress] == 2)
  115.                 {
  116.                     gSurveyVB[CreationProgress] = 3;
  117.                     gSurveyVB[NumberOfAnswers] = listitem + 2;
  118.                     return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers","Enter answer number 1","Continue","Cancel");
  119.                 }
  120.                 if((gSurveyVB[NumberOfAnswers] - 1) == (gSurveyVB[CreationProgress] - 3))
  121.                 {
  122.                     if(!strlen(inputtext))
  123.                     {
  124.                         format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 2);
  125.                         SendClientMessage(playerid,COLOR_RED,MessageString);
  126.                         format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 2);
  127.                         return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers",MessageString,"Continue","Cancel");
  128.                     }
  129.                     format(gSurveyAnswers[gSurveyVB[CreationProgress] - 3],sizeof(gSurveyAnswers[]),"%s",inputtext);
  130.                     ShowPlayerDialog(playerid,Dialog_SurveyTime,DIALOG_STYLE_INPUT,"Choose time","How mach time you want to let the people vote (in seconds)?","Continue","Cancel");
  131.                 }
  132.                 else
  133.                 {
  134.                     if(gSurveyVB[CreationProgress] > 2)
  135.                     {
  136.                         if(!strlen(inputtext))
  137.                         {
  138.                             format(MessageString,sizeof(MessageString),"You didnt enter answer number %d",gSurveyVB[CreationProgress] - 2);
  139.                             SendClientMessage(playerid,COLOR_RED,MessageString);
  140.                             format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 2);
  141.                             return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers",MessageString,"Continue","Cancel");
  142.                         }
  143.                         format(gSurveyAnswers[gSurveyVB[CreationProgress] - 3],sizeof(gSurveyAnswers[]),"%s",inputtext);
  144.                         format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 1);
  145.                         ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers",MessageString,"Continue","Cancel");
  146.                         gSurveyVB[CreationProgress] ++;
  147.                     }
  148.                 }
  149.                 return 1;
  150.             }
  151.             case Dialog_SurveyTime:
  152.             {
  153.                 gSurveyVB[SurveyTime] = strval(inputtext);
  154.                 format(MessageString,sizeof(MessageString),"Survey question: %s\r\nVoting time: %d seconds\r\nNumber of answers: %d\r\n",gSurveyVB[Question],gSurveyVB[SurveyTime],gSurveyVB[NumberOfAnswers]);
  155.                 for(new m; m < gSurveyVB[NumberOfAnswers]; m ++)
  156.                 {
  157.                     format(MessageString,sizeof(MessageString),"%s\r\nAnswer number %d: %s",MessageString,m + 1,gSurveyAnswers[m]);
  158.                 }
  159.                 ShowPlayerDialog(playerid,Dialog_SurveyConfirm,DIALOG_STYLE_MSGBOX,"Accept survey and start",MessageString,"Start","Cancel");
  160.                 return 1;
  161.             }
  162.             case Dialog_SurveyVote:
  163.             {
  164.                 if(gSurveyVB[Started] == 0) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey system","There is no active surevy at this moment","Ok"," ");
  165.                 if(pSurveyVB[playerid][Voted] != -1) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey syste,","You already votes, please wait for the survey to end","Ok"," ");
  166.                 pSurveyVB[playerid][Voted] = listitem + 1;
  167.                 return 1;
  168.             }
  169.             case Dialog_SurveyConfirm:
  170.             {
  171.                 gSurveyVB[Started] = 1;
  172.                 gSurveyVB[Creation] = 0;
  173.                 SetTimer("EndSurvey",gSurveyVB[SurveyTime] * 1000,0);
  174.                 for(new i; i < MAX_PLAYERS; i ++)
  175.                 {
  176.                     pSurveyVB[i][Voted] = -1;
  177.                 }
  178.                 GameTextForAll("/Vote",3000,3);
  179.                 format(MessageString,sizeof(MessageString),"A new survey started: %s",gSurveyVB[Question]);
  180.                 SendClientMessageToAll(COLOR_GREEN,MessageString);
  181.                 SendClientMessageToAll(COLOR_YELLOW,"Choose option:");
  182.                 for(new s; s < gSurveyVB[NumberOfAnswers]; s ++)
  183.                 {
  184.                     if(strlen(gSurveyAnswers[s]) > 0)
  185.                     {
  186.                         format(MessageString,sizeof(MessageString),"%d. %s",s + 1,gSurveyAnswers[s]);
  187.                         SendClientMessageToAll(COLOR_GREEN,MessageString);
  188.                     }
  189.                 }
  190.                 SendClientMessageToAll(COLOR_YELLOW,"To vote type: /Vote.");
  191.                 return 1;
  192.             }
  193.         }
  194.     } else gSurveyVB[Creation] = 0;
  195.     return 1;
  196. }
  197. //==============================================================================
  198. public EndSurvey()
  199. {
  200.     gSurveyVB[Started] = 0;
  201.     new Votes[MAX_ANSWERS_PER_SURVEY + 1],Winer,AllVotes;
  202.     for(new i; i < MAX_PLAYERS; i ++)
  203.     {
  204.         if(IsPlayerConnected(i))
  205.         {
  206.             if(pSurveyVB[i][Voted] != -1)
  207.             {
  208.                 Votes[pSurveyVB[i][Voted] - 1] ++;
  209.                 AllVotes ++;
  210.             }
  211.         }
  212.     }
  213.     format(MessageString,sizeof(MessageString),"Survey results - %s",gSurveyVB[Question]);
  214.     SendClientMessageToAll(COLOR_YELLOW,MessageString);
  215.     if(AllVotes != 0)
  216.     {
  217.         for(new s; s < gSurveyVB[NumberOfAnswers]; s ++)
  218.         {
  219.             if(strlen(gSurveyAnswers[s]) > 0)
  220.             {
  221.                 if(Votes[s] > Winer){ Winer = s; }
  222.                 format(MessageString,sizeof(MessageString),"%s - %d Votes - (%d Present)",gSurveyAnswers[s],Votes[s],((Votes[s] * 100) / AllVotes),"%");
  223.                 SendClientMessageToAll(COLOR_GREEN,MessageString);
  224.             }
  225.         }
  226.         format(MessageString,sizeof(MessageString),"The answer with most of the votes is: %s",gSurveyAnswers[Winer]);
  227.         SendClientMessageToAll(COLOR_YELLOW,MessageString);
  228.     }
  229.     else SendClientMessageToAll(COLOR_RED,"Nobody voted.");
  230.     return 1;
  231. }
  232. //==============================================================================
  233. /*
  234. This script was created by HighDefinition (Or_Yagoda)
  235. Skype: oryagoda
  236.  
  237. Also programing PHP, SQL, HTML and more.
  238. If you need a pawn script or a website, contact me.
  239. */
Advertisement
Add Comment
Please, Sign In to add comment