Advertisement
garfield

[FS/PHP]: Sistema de Quiz Avançado (remote)

Oct 29th, 2012
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.07 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.             Sistema de Quiz avançado, criado por SuYaNw Dácio (Copyright C)
  5.            
  6.            
  7.             Instalação:
  8.                 Primeiramente, instale esta página php (http://pastebin.com/TgD0hkeC),
  9.                 depois você cria um arquivo de texto com nome
  10.                 de "Quiz" (extensão .txt) na mesma pasta do php.
  11.                
  12.                 Bote no arquivo .txt as seguintes linhas:
  13.                 0|NoneQuestion|NoneReply
  14.                
  15.                 Esta linha tem que ser a primeira, se não dará
  16.                 erros fortemente fodásticos.
  17.                
  18.                 Logo ser criado a linha acima, é só criar as perguntas
  19.                 e respostas pelo seguinte modelo:
  20.                
  21.                 ID | PERGUNTA | RESPOSTA
  22.                
  23.                 Exemplo:
  24.                 1|Qual o apelido do antigo presidente do brasil?|Lula
  25.                
  26.                 É só salvar no "Quiz.txt" e pronto!
  27.                
  28.                
  29.  
  30.  
  31. */
  32.  
  33.  
  34. #include a_samp
  35. #include a_http
  36.  
  37. #if !defined Function
  38.     #define Function::%0(%1) %0(%1); public %0(%1)
  39. #endif
  40.  
  41.  
  42.  
  43. #if !defined MAX_STRING
  44.     #define MAX_STRING                  (128)
  45. #endif
  46.  
  47.  
  48.  
  49.  
  50.  
  51. #define HOST_EXTERN_PAGE                "127.0.0.1/Quiz.php?getString"          // Link da página externa;
  52. #define DIALOG_REPLY                    (5467)                                  // ID do dialog *;
  53. #define RECOMPENSA                      (1000)                                  // Reconpensa por acertar palavra.
  54. #define SENSITIVE                       (true)                                  // Diferenciar não maiúsculas/minusculas (TRUE = Não diferenciar, FALSE = diferenciar).
  55. #define TIMER                           (0005)                                  // Defina a quantos segundos terá uma nova pergunta.
  56.  
  57.  
  58.  
  59. new
  60.     Resposta[ MAX_STRING ],
  61.     Pergunta[ MAX_STRING ],
  62.     string  [ MAX_STRING ]
  63. ;
  64.  
  65.  
  66.  
  67.  
  68.  
  69. public OnFilterScriptInit(){
  70.    
  71.    
  72.     SetTimer("CallQuestion", TIMER * 60000, true);
  73.     return true;
  74. }
  75.  
  76.  
  77. public OnPlayerCommandText(playerid, cmdtext[]){
  78.  
  79.     if(!strcmp(cmdtext, "/teste", true)){
  80.         return CallQuestion();
  81.     }
  82.    
  83.     if(!strcmp(cmdtext, "/responder", true)){
  84.    
  85.         format(string, sizeof(string),"A pergunta atual é:\n-%s\nNão nos desaponte!", Pergunta);
  86.         ShowPlayerDialog(playerid, DIALOG_REPLY, DIALOG_STYLE_INPUT, "~ Perguntas & Respostas ~", string, "Responder", "Cancelar");
  87.         return true;
  88.     }
  89.    
  90.     return false;
  91. }
  92.  
  93.  
  94.  
  95.  
  96. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
  97.     if(dialogid == DIALOG_REPLY){
  98.    
  99.         if(response){
  100.        
  101.             if(!strcmp(inputtext, Resposta, SENSITIVE)){
  102.                 static
  103.                     Nome[24]
  104.                 ;
  105.                 format(string, MAX_STRING, "{4EEE94}[Atenção]:{FFFFFF} %s ganhou o Quiz!, Resposta: %s", (GetPlayerName(playerid, Nome, 24), Nome), Resposta);
  106.                 SendClientMessageToAll(-1, string);
  107.                
  108.                 GivePlayerMoney(playerid, RECOMPENSA);
  109.                 return true;
  110.             }
  111.             else{
  112.            
  113.                 SendClientMessage(playerid, -1, "{828282[Erro]:{FFFFFF} Desculpa cheef, resposta incorreta, tenta novamente :(");
  114.             }
  115.            
  116.         }
  117.         return true;
  118.     }
  119.     return true;
  120. }
  121.  
  122.  
  123.  
  124.  
  125. Function::CallQuestion(){
  126.     HTTP(0, HTTP_GET, HOST_EXTERN_PAGE, string, "OnRequestQuestion");
  127.     return true;
  128. }
  129.  
  130. Function::OnRequestQuestion(index, response_code, data[]){
  131.  
  132.     format(Pergunta,    MAX_STRING,     SeparateString(data, 0));              
  133.     format(Resposta,    MAX_STRING,     SeparateString(data, 1));
  134.    
  135.     format(string, MAX_STRING, "{FF0000}[Atenção]: {FFFFFF}Quiz: %s ( {7FFFD4}/Responder{FFFFFF} )", Pergunta);
  136.     SendClientMessageToAll(-1, string);
  137.     return true;
  138. }
  139.  
  140.  
  141.  
  142. stock SeparateString(myString[], parte){
  143.  
  144.     static
  145.         String_Saida[100],
  146.         String_Tamanho,
  147.         String_Posicao
  148.     ;
  149.    
  150.    
  151.     // Limpar Arrays:
  152.     String_Saida[0]         =   '\0';
  153.    
  154.     // Limpar Variável:
  155.     String_Posicao          =   0 ;
  156.     String_Tamanho          =   0 ;
  157.    
  158.     // Setando variáveis:
  159.     String_Tamanho          =   strlen(myString);
  160.     String_Posicao          =   strfind(myString, "|");
  161.    
  162.     switch(parte){
  163.         case 0:     strmid(String_Saida,    myString, 0, String_Posicao);
  164.         case 1:     strmid(String_Saida,    myString, String_Posicao + 1, String_Tamanho);
  165.     }
  166.     return String_Saida;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement