Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This script was created by HighDefinition (Or_Yagoda)
- MSN: [email protected]
- Skype: oryagoda
- Also programing PHP, SQL, HTML and more.
- If you need a pawn script or a website, contact me.
- */
- //==============================================================================
- #include a_samp
- //==============================================================================
- #define MAX_ANSWERS_PER_SURVEY 5 // How mach answers can you set in-game
- //==============================================================================
- enum gSurveyE
- {
- Started,
- Creation,
- Question[128],
- NumberOfAnswers,
- CreationProgress,
- SurveyTime
- };
- enum pSurveyE
- {
- Voted
- };
- //==============================================================================
- new pSurveyVB[MAX_PLAYERS][pSurveyE],gSurveyVB[gSurveyE],gSurveyAnswers[MAX_ANSWERS_PER_SURVEY + 1][80],MessageString[1024];
- //==============================================================================
- #define Voted_Yes 1
- #define Voted_No 2
- //==============================================================================
- #define Dialog_SurveyOptions 11542
- #define Dialog_SurveyMessage 11543
- #define Dialog_SurveyCreate 11544
- #define Dialog_SurveyConfirm 11545
- #define Dialog_SurveyVote 11546
- #define Dialog_SurveyTime 11547
- //==============================================================================
- #define COLOR_RED 4278190160
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_YELLOW 0xFFFF00AA
- //==============================================================================
- forward SurveyResult();
- forward EndSurvey();
- //==============================================================================
- public OnFilterScriptInit()
- {
- gSurveyVB[Creation] = 0;
- print("Survey system by HighDefinition (Or_Yagoda) loaded !");
- return 1;
- }
- //==============================================================================
- public OnFilterScriptExit()
- {
- print("Survey system by HighDefinition (Or_Yagoda) unloaded !");
- return 1;
- }
- //==============================================================================
- public OnPlayerConnect(playerid)
- {
- pSurveyVB[playerid][Voted] = -1;
- return 1;
- }
- //==============================================================================
- public OnPlayerCommandText(playerid,cmdtext[])
- {
- if(!strcmp(cmdtext,"/Survey",true) && IsPlayerAdmin(playerid))
- {
- if(gSurveyVB[Started] == 1) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey system","Please wait for the survey to end","Ok"," ");
- gSurveyVB[CreationProgress] = 1;
- gSurveyVB[Creation] = 1;
- ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Survey system - Create","Enter survey question","Create","Cancel");
- return 1;
- }
- if(!strcmp(cmdtext,"/Vote",true))
- {
- if(gSurveyVB[Started] == 0) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey system","There is no active surevy at this moment","Ok"," ");
- 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"," ");
- if(strlen(gSurveyAnswers[0]) != 0){ format(MessageString,sizeof(MessageString),"1. %s",gSurveyAnswers[0]); }
- for(new m = 1; m < MAX_ANSWERS_PER_SURVEY + 1; m ++)
- {
- if(strlen(gSurveyAnswers[m]) != 0)
- {
- format(MessageString,sizeof(MessageString),"%s\r\n%d. %s",MessageString,m + 1,gSurveyAnswers[m]);
- }
- }
- ShowPlayerDialog(playerid,Dialog_SurveyVote,DIALOG_STYLE_LIST,gSurveyVB[Question],MessageString,"Choose","Cancel");
- return 1;
- }
- return 0;
- }
- //==============================================================================
- public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
- {
- if(response == 1)
- {
- switch(dialogid)
- {
- case Dialog_SurveyMessage: return 1;
- case Dialog_SurveyCreate:
- {
- if(gSurveyVB[CreationProgress] == 1)
- {
- 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");
- MessageString = "2";
- for(new q = 3; q < MAX_ANSWERS_PER_SURVEY + 1; q ++)
- {
- format(MessageString,sizeof(MessageString),"%s\r\n%d",MessageString,q);
- }
- gSurveyVB[CreationProgress] = 2;
- format(gSurveyVB[Question],sizeof(gSurveyVB[Question]),"%s",inputtext);
- return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_LIST,"How mach answers will be for this survey?",MessageString,"Choose","Cancel");
- }
- if(gSurveyVB[CreationProgress] == 2)
- {
- gSurveyVB[CreationProgress] = 3;
- gSurveyVB[NumberOfAnswers] = listitem + 2;
- return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers","Enter answer number 1","Continue","Cancel");
- }
- if((gSurveyVB[NumberOfAnswers] - 1) == (gSurveyVB[CreationProgress] - 3))
- {
- if(!strlen(inputtext))
- {
- format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 2);
- SendClientMessage(playerid,COLOR_RED,MessageString);
- format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 2);
- return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers",MessageString,"Continue","Cancel");
- }
- format(gSurveyAnswers[gSurveyVB[CreationProgress] - 3],sizeof(gSurveyAnswers[]),"%s",inputtext);
- ShowPlayerDialog(playerid,Dialog_SurveyTime,DIALOG_STYLE_INPUT,"Choose time","How mach time you want to let the people vote (in seconds)?","Continue","Cancel");
- }
- else
- {
- if(gSurveyVB[CreationProgress] > 2)
- {
- if(!strlen(inputtext))
- {
- format(MessageString,sizeof(MessageString),"You didnt enter answer number %d",gSurveyVB[CreationProgress] - 2);
- SendClientMessage(playerid,COLOR_RED,MessageString);
- format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 2);
- return ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers",MessageString,"Continue","Cancel");
- }
- format(gSurveyAnswers[gSurveyVB[CreationProgress] - 3],sizeof(gSurveyAnswers[]),"%s",inputtext);
- format(MessageString,sizeof(MessageString),"Enter answer number %d",gSurveyVB[CreationProgress] - 1);
- ShowPlayerDialog(playerid,Dialog_SurveyCreate,DIALOG_STYLE_INPUT,"Enter answers",MessageString,"Continue","Cancel");
- gSurveyVB[CreationProgress] ++;
- }
- }
- return 1;
- }
- case Dialog_SurveyTime:
- {
- gSurveyVB[SurveyTime] = strval(inputtext);
- 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]);
- for(new m; m < gSurveyVB[NumberOfAnswers]; m ++)
- {
- format(MessageString,sizeof(MessageString),"%s\r\nAnswer number %d: %s",MessageString,m + 1,gSurveyAnswers[m]);
- }
- ShowPlayerDialog(playerid,Dialog_SurveyConfirm,DIALOG_STYLE_MSGBOX,"Accept survey and start",MessageString,"Start","Cancel");
- return 1;
- }
- case Dialog_SurveyVote:
- {
- if(gSurveyVB[Started] == 0) return ShowPlayerDialog(playerid,Dialog_SurveyMessage,DIALOG_STYLE_MSGBOX,"Survey system","There is no active surevy at this moment","Ok"," ");
- 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"," ");
- pSurveyVB[playerid][Voted] = listitem + 1;
- return 1;
- }
- case Dialog_SurveyConfirm:
- {
- gSurveyVB[Started] = 1;
- gSurveyVB[Creation] = 0;
- SetTimer("EndSurvey",gSurveyVB[SurveyTime] * 1000,0);
- for(new i; i < MAX_PLAYERS; i ++)
- {
- pSurveyVB[i][Voted] = -1;
- }
- GameTextForAll("/Vote",3000,3);
- format(MessageString,sizeof(MessageString),"A new survey started: %s",gSurveyVB[Question]);
- SendClientMessageToAll(COLOR_GREEN,MessageString);
- SendClientMessageToAll(COLOR_YELLOW,"Choose option:");
- for(new s; s < gSurveyVB[NumberOfAnswers]; s ++)
- {
- if(strlen(gSurveyAnswers[s]) > 0)
- {
- format(MessageString,sizeof(MessageString),"%d. %s",s + 1,gSurveyAnswers[s]);
- SendClientMessageToAll(COLOR_GREEN,MessageString);
- }
- }
- SendClientMessageToAll(COLOR_YELLOW,"To vote type: /Vote.");
- return 1;
- }
- }
- } else gSurveyVB[Creation] = 0;
- return 1;
- }
- //==============================================================================
- public EndSurvey()
- {
- gSurveyVB[Started] = 0;
- new Votes[MAX_ANSWERS_PER_SURVEY + 1],Winer,AllVotes;
- for(new i; i < MAX_PLAYERS; i ++)
- {
- if(IsPlayerConnected(i))
- {
- if(pSurveyVB[i][Voted] != -1)
- {
- Votes[pSurveyVB[i][Voted] - 1] ++;
- AllVotes ++;
- }
- }
- }
- format(MessageString,sizeof(MessageString),"Survey results - %s",gSurveyVB[Question]);
- SendClientMessageToAll(COLOR_YELLOW,MessageString);
- if(AllVotes != 0)
- {
- for(new s; s < gSurveyVB[NumberOfAnswers]; s ++)
- {
- if(strlen(gSurveyAnswers[s]) > 0)
- {
- if(Votes[s] > Winer){ Winer = s; }
- format(MessageString,sizeof(MessageString),"%s - %d Votes - (%d Present)",gSurveyAnswers[s],Votes[s],((Votes[s] * 100) / AllVotes),"%");
- SendClientMessageToAll(COLOR_GREEN,MessageString);
- }
- }
- format(MessageString,sizeof(MessageString),"The answer with most of the votes is: %s",gSurveyAnswers[Winer]);
- SendClientMessageToAll(COLOR_YELLOW,MessageString);
- }
- else SendClientMessageToAll(COLOR_RED,"Nobody voted.");
- return 1;
- }
- //==============================================================================
- /*
- This script was created by HighDefinition (Or_Yagoda)
- MSN: [email protected]
- Skype: oryagoda
- Also programing PHP, SQL, HTML and more.
- If you need a pawn script or a website, contact me.
- */
Advertisement
Add Comment
Please, Sign In to add comment