Advertisement
LeonardoBradoks

Sistema de Perguntas por ID

Apr 3rd, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.95 KB | None | 0 0
  1. /*****************************************************************************
  2.     Criado por: Leonardo Bradoks
  3.     Referente ao Tópico: http://forum.sa-mp.com/showthread.php?t=652142&page=2
  4. *****************************************************************************/
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <dof2>
  8. #include <sscanf2>
  9.  
  10. #define PASTA_PERGUNTAS  "Perguntas/pergunta%d.ini"
  11. #define MAX_PERGUNTAS 100
  12. #define PREMIO_VALOR 4000
  13.  
  14. public OnFilterScriptInit()
  15. {
  16.     print("\n------------------------------------------------");
  17.     print("- Sistema de Perguntas - Apenas Logado na RCON -");
  18.     print("------------------------------------------------\n");
  19.     return 1;
  20. }
  21.  
  22. public OnFilterScriptExit()
  23. {
  24.     DOF2_Exit();
  25.     return 1;
  26. }
  27.  
  28. CMD:pergunta(playerid, params[]) {
  29.     new texto[20];
  30.     if(sscanf(params, "s[20]", texto)) return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Use: /pergunta [criar] ou [responder] ou [resposta]");
  31.     if(strfind(texto, "criar", true) != -1) {
  32.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Você não tem acesso a este comando !");
  33.         new pergunta[128];
  34.         if(sscanf(params, "s[20]s[128]", texto, pergunta)) return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Use: /pergunta criar [pergunta]");
  35.         new file[50];
  36.         for(new i = 1; i < MAX_PERGUNTAS; i++) {
  37.             format(file, sizeof(file), PASTA_PERGUNTAS, i);
  38.             if(!DOF2_FileExists(file)) {
  39.                 new aname[MAX_PLAYER_NAME], string[128];
  40.                 GetPlayerName(playerid, aname, sizeof(aname));
  41.                 DOF2_CreateFile(file);
  42.                 DOF2_SetInt(file, "ID", i);
  43.                 DOF2_SetString(file, "Pergunta", pergunta);
  44.                 DOF2_SetString(file, "Criado", aname);
  45.                 DOF2_SaveFile();
  46.                 format(string, sizeof(string), "* Você criou a pergunta ID: %d agora qual é a resposta ? use: /pergunta resposta [id da pergunta] [resposta]", i);
  47.                 SendClientMessage(playerid, 0xFF8080AA, string);
  48.                 return 1;
  49.             }
  50.         }
  51.         return 1;
  52.     }
  53.     else if(strfind(texto, "responder", true) != -1) {
  54.         new resposta[128], id;
  55.         if(sscanf(params, "s[20]ds[128]", texto, id, resposta)) return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Use: /pergunta responder [ID da Pergunta] [texto]");
  56.         new file[50];
  57.         format(file, sizeof(file), PASTA_PERGUNTAS, id);
  58.         if(DOF2_FileExists(file)) {
  59.             if(!strcmp(DOF2_GetString(file, "Resposta"), resposta)) {
  60.                 new string[155], pname[MAX_PLAYER_NAME];
  61.                 GetPlayerName(playerid, pname, sizeof(pname));
  62.                 format(string, sizeof(string), "* RESULTADO * O(A) Administrador(a) %s havia criado a pergunta ID: %d ( %s )", DOF2_GetString(file, "Criado"), id, DOF2_GetString(file, "Pergunta"));
  63.                 SendClientMessageToAll(0xFFFF00AA, string);
  64.                 format(string, sizeof(string), "* PREMIADO * %s respondeu que a pergunta ( %s ) ID: %d é ( %s ) e ganhou R$4.000", pname, DOF2_GetString(file, "Pergunta"), id, resposta);
  65.                 SendClientMessageToAll(0xFFFF00AA, string);
  66.                 GivePlayerMoney(playerid, PREMIO_VALOR);
  67.                 DOF2_RemoveFile(file);
  68.                 return 1;
  69.             } else {
  70.                 return SendClientMessage(playerid, -1, "[ RESULTADO ] {FF0000}Poxa que pena não foi desta vez !");
  71.             }
  72.         } else {
  73.             return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Está ID de pergunta não existe !");
  74.         }
  75.     }
  76.     else if(strfind(texto, "resposta", true) != -1) {
  77.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Você não tem acesso a este comando !");
  78.         new id, resposta[128];
  79.         if(sscanf(params, "s[20]ds[128]", texto, id, resposta)) return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Use: /pergunta resposta [ID da Pergunta] [resposta]");
  80.         new file[50], aname[MAX_PLAYER_NAME];
  81.         GetPlayerName(playerid, aname, sizeof(aname));
  82.         format(file, sizeof(file), PASTA_PERGUNTAS, id);
  83.         if(DOF2_FileExists(file) && strfind(DOF2_GetString(file, "Criado"), aname, true) != -1) {
  84.             new string[128];
  85.             DOF2_SetString(file, "Resposta", resposta);
  86.             DOF2_SaveFile();
  87.             format(string, sizeof(string), "* PERGUNTA * O(A) Administrador(a) %s criou a pergunta ID: %d ( %s )", aname, id, DOF2_GetString(file, "Pergunta"));
  88.             SendClientMessageToAll(0xFFFF00AA, string);
  89.             SendClientMessageToAll(0x0080FFAA, "* Para responder a pergunta use: /pergunta responder [id da pergunta] [resposta]");
  90.             return 1;
  91.         } else {
  92.             return SendClientMessage(playerid, -1, "[ ERRO ] {FF0000}Não é possível setar a resposta pois ou o arquivo não existe ou você não é o criador da pergunta !");
  93.         }
  94.     }
  95.     return 1;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement