Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Survey - filterscript by ZiPoNz ©- Version: 1
- #include <a_samp>
- #define STitle 514
- #define SText 515
- #define MaxTime 30
- new bool:SurveyOn = false, bool:AChose[MAX_PLAYERS] = false, Title[30], YesNo[2];
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128], idx;
- cmd = strtok(cmdtext, idx);
- if(!strcmp(cmdtext, "/survey", true))
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] Your'e not admin rcon.");
- if(SurveyOn) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] There's already survey on.");
- return ShowPlayerDialog(playerid, STitle, DIALOG_STYLE_INPUT, "Create a new survey: Title.", "Please write the title of your survey.", "Next", "Cancel");
- }
- if(!strcmp(cmd, "/stopsurvey", true))
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] Your'e not admin rcon.");
- new AName[24], string[128];
- GetPlayerName(playerid, AName, 24);
- SurveyOn = false;
- YesNo[0] = 0, YesNo[1] = 0;
- format(string, 128, "The administrator %s stopped the survey.", AName);
- return SendClientMessageToAll(0xFFFFFF00, string);
- }
- if(!strcmp(cmd, "/vote", true))
- {
- if(!SurveyOn) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] There's no survey on in the server.");
- if(AChose[playerid]) return SendClientMessage(playerid, 0xFFFFFF00, "[Error] You are already voted at this survey, please wait!");
- cmd = strtok(cmdtext, idx);
- if(!strlen(cmd)) return SendClientMessage(playerid, 0xFFFFFF00, "Type: /vote [Yes/No]");
- if(!strcmp(cmd, "yes", true)) return SendClientMessage(playerid, 0xFFFFFF00, "[System] You chose in the survey as the answer: Yes."), YesNo[0]++, AChose[playerid] = true;
- if(!strcmp(cmd, "no", true)) return SendClientMessage(playerid, 0xFFFFFF00, "[System] You chose in the survey as the answer: No."), YesNo[1]++, AChose[playerid] = true;
- }
- return false;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case STitle:
- {
- if(!response) return true;
- format(Title, 30, "%s", inputtext);
- ShowPlayerDialog(playerid, SText, DIALOG_STYLE_INPUT, "Create a new survey: Text.", "Please write the text of your survey.", "Create", "Back");
- }
- case SText:
- {
- new string[256], AName[24];
- GetPlayerName(playerid, AName, 24);
- if(!response) return ShowPlayerDialog(playerid, STitle, DIALOG_STYLE_INPUT, "Create a new survey: Title.", "Please write the title of your survey.", "Next", "Cancel");
- SurveyOn = true;
- for(new p = 0; p < MAX_PLAYERS; p++)
- {
- if(!IsPlayerConnected(p)) continue;
- AChose[p] = false;
- }
- format(string, 128, "New survey in the server! Title: %s by %s.", Title, AName);
- SendClientMessageToAll(0xFFFFFF00, string);
- format(string, 256, "Survey text: %s (Type: /vote).", inputtext);
- SendClientMessageToAll(0xFFFFFF00, string);
- SetTimer("SurveyStop", MaxTime*000, false);
- }
- }
- return true;
- }
- forward SurveyStop();
- public SurveyStop()
- {
- if(SurveyOn)
- {
- new string[128];
- SurveyOn = false;
- format(string, 128, "The survey's now ended(Results): %d voted for \"Yes\" and %d voted for \"No\".", YesNo[0], YesNo[1]);
- SendClientMessageToAll(0xFFFFFF00, string);
- YesNo[0] = 0, YesNo[1] = 0;
- }
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' ')) index++;
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) result[index - offset] = string[index], index++;
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment