Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define USE_SSCANF_PLUGIN // Daca nu folositi sscanf plugin, stergeti
- #define EXACTLY_ANSWER // Daca aceasta constanta e definita, raspunsul 'abc' nu este acelasi lucru cu 'abc.'
- //#define GIVE_MONEY_FUNCTION ( "GivePlayerCash" ) // Daca aveti vreun money anticheat, definiti aceasta constanta cu numele functiei de dat ban a anticheat-ului
- //#define COMMAND_NAME "/an" // Daca doriti sa folositi o comanda pt. tastarea raspunsului, definiti aceasta constanta cu numele comenzii
- #define CASE_SENSITIVE ( false ) // true / false
- #define MAX_QUESTIONS ( 50 ) // Numarul maxim de intrebari ce poate fi incarcat din fisier
- #define TRIVIA_PATH ( "trivia.cfg" ) // Fisierul cu intrebarile
- #define ASK_INTERVAL ( 600 ) // Intervalul de timp dintre intrebari ( secunde )
- #define RESPONSE_INTERVAL ( 60 ) // Peste cat timp sa fie afisat raspunsul corect daca nu s-a raspuns ( secunde )
- #define MONEY_WON ( 5000 ) // Banii castigati
- // Sintaxa:
- // INTREBARE|RASPUNS
- #if ASK_INTERVAL <= RESPONSE_INTERVAL
- #undef ASK_INTERVAL
- #define ASK_INTERVAL ( RESPONSE_INTERVAL + 10 )
- #endif
- #include < a_samp >
- #if defined USE_SSCANF_PLUGIN
- #include < sscanf2 >
- #endif
- forward rtTimer ( );
- forward rtTimerAnswer ( );
- enum ertTrivia
- {
- rtQuestion [ 64 ],
- rtAnswer [ 64 ]
- };
- new rtTrivia [ MAX_QUESTIONS ] [ ertTrivia ];
- new rtTimerID;
- new rtAnswerTimerID;
- new rtQuestionID;
- new rtLoadedQuestions;
- public OnFilterScriptInit ( )
- {
- print ( "\n[R-TRIVIA] - Loaded\n\nSimple Trivia System v1.1 by RaZVaN ^ xD @ gta-mp.ro\n" );
- if ( !fexist ( TRIVIA_PATH ) ) return print ( "[R-TRIVIA]: Trivia config file was not found." );
- new
- File: rtFile = fopen ( TRIVIA_PATH, io_read ),
- string [ 128 + 1 ]
- ;
- rtQuestionID = -1;
- rtLoadedQuestions = 0;
- while ( fread ( rtFile, string ) )
- {
- #if defined USE_SSCANF_PLUGIN
- if ( !sscanf ( string, "p<|>s[64]s[64]", rtTrivia [ rtLoadedQuestions ] [ rtQuestion ], rtTrivia [ rtLoadedQuestions ] [ rtAnswer ] ) )
- #else
- if ( !sscanf ( string, "p|ss", rtTrivia [ rtLoadedQuestions ] [ rtQuestion ], rtTrivia [ rtLoadedQuestions ] [ rtAnswer ] ) )
- #endif
- {
- for ( new i = 0, j = strlen ( rtTrivia [ rtLoadedQuestions ] [ rtAnswer ] ); i != j; ++i )
- {
- switch ( rtTrivia [ rtLoadedQuestions ] [ rtAnswer ] [ i ] )
- {
- case '\r', '\n': strdel ( rtTrivia [ rtLoadedQuestions ] [ rtAnswer ], i, i + 1 );
- default: continue;
- }
- }
- ++rtLoadedQuestions;
- if ( rtLoadedQuestions == MAX_QUESTIONS )
- {
- print ( "[R-TRIVIA]: Limit of questions - reached." );
- break;
- }
- }
- }
- fclose ( rtFile );
- printf ( "[R-TRIVIA]: %i questions - loaded.", rtLoadedQuestions );
- if ( rtLoadedQuestions != 0 ) rtTimerID = SetTimer ( "rtTimer", ASK_INTERVAL * 1000, true );
- return 1;
- }
- public OnFilterScriptExit ( )
- {
- print ( "\n[R-TRIVIA] - Unloaded\n" );
- KillTimer ( rtTimerID );
- if ( rtQuestionID != -1 ) KillTimer ( rtAnswerTimerID );
- return 1;
- }
- #if !defined COMMAND_NAME
- public OnPlayerText ( playerid, text [ ] )
- {
- if ( rtQuestionID != -1 )
- {
- if ( text [ 0 ] == 0 || ( text [ 0 ] == 1 && text [ 1 ] == 0 ) ) return 1;
- #if defined EXACTLY_ANSWER
- if ( !strcmp ( text, rtTrivia [ rtQuestionID ] [ rtAnswer ], !CASE_SENSITIVE ) )
- #else
- if ( strfind ( text, rtTrivia [ rtQuestionID ] [ rtAnswer ], !CASE_SENSITIVE ) != -1 )
- #endif
- {
- new string [ 160 ];
- GetPlayerName ( playerid, string, MAX_PLAYER_NAME );
- format ( string, sizeof ( string ), "[R-TRIVIA]: %s {FFFFFF}a raspuns corect ( {00FF00}%s {FFFFFF}) .", string, rtTrivia [ rtQuestionID ] [ rtAnswer ] );
- SendClientMessageToAll ( 0x00FF00FF, string );
- #if defined GIVE_MONEY_FUNCTION
- CallRemoteFunction ( GIVE_MONEY_FUNCTION, "ii", playerid, MONEY_WON );
- #else
- GivePlayerMoney ( playerid, MONEY_WON );
- #endif
- KillTimer ( rtAnswerTimerID );
- rtQuestionID = -1;
- return 0;
- }
- }
- return 1;
- }
- #else
- public OnPlayerCommandText ( playerid, cmdtext [ ] )
- {
- new
- rtCommand [ 16 ],
- rtPAnswer [ 64 ]
- ;
- #if defined USE_SSCANF_PLUGIN
- sscanf ( cmdtext, "s[16]s[64]", rtCommand, rtPAnswer );
- #else
- sscanf ( cmdtext, "ss", rtCommand, rtPAnswer );
- #endif
- if ( !strcmp ( rtCommand, COMMAND_NAME, true ) )
- {
- if ( rtPAnswer [ 0 ] == 0 || ( rtPAnswer [ 0 ] == 1 && rtPAnswer [ 1 ] == 0 ) ) return SendClientMessage ( playerid, 0x00FF00FF, "[R-TRIVIA]: {FFFFFF}"#COMMAND_NAME" [ raspuns ]" );
- if ( rtQuestionID != -1 )
- {
- #if defined EXACTLY_ANSWER
- if ( !strcmp ( rtPAnswer, rtTrivia [ rtQuestionID ] [ rtAnswer ], !CASE_SENSITIVE ) )
- #else
- if ( strfind ( rtPAnswer, rtTrivia [ rtQuestionID ] [ rtAnswer ], !CASE_SENSITIVE ) != -1 )
- #endif
- {
- new string [ 160 ];
- GetPlayerName ( playerid, string, MAX_PLAYER_NAME );
- format ( string, sizeof ( string ), "[R-TRIVIA]: %s {FFFFFF}a raspuns corect ( {00FF00}%s {FFFFFF}) .", string, rtTrivia [ rtQuestionID ] [ rtAnswer ] );
- SendClientMessageToAll ( 0x00FF00FF, string );
- #if defined GIVE_MONEY_FUNCTION
- CallRemoteFunction ( GIVE_MONEY_FUNCTION, "ii", playerid, MONEY_WON );
- #else
- GivePlayerMoney ( playerid, MONEY_WON );
- #endif
- KillTimer ( rtAnswerTimerID );
- rtQuestionID = -1;
- }
- else SendClientMessage ( playerid, 0x00FF00FF, "[R-TRIVIA]: {FFFFFF}Raspuns gresit ." );
- }
- else SendClientMessage ( playerid, 0x00FF00FF, "[R-TRIVIA]: {FFFFFF}Nu este niciun eveniment trivia in desfasurare ." );
- return 1;
- }
- return 0;
- }
- #endif
- public rtTimer ( )
- {
- new string [ 128 ];
- rtQuestionID = random ( rtLoadedQuestions );
- format ( string, sizeof ( string ), "[R-TRIVIA]: {FFFFFF}%s {00FF00}?", rtTrivia [ rtQuestionID ] [ rtQuestion ] );
- SendClientMessageToAll ( 0x00FF00FF, string );
- #if !defined COMMAND_NAME
- SendClientMessageToAll ( 0x00FF00FF, "[R-TRIVIA]: {FFFFFF}Tastati raspunsul in {00FF00}chat {FFFFFF}." );
- #else
- SendClientMessageToAll ( 0x00FF00FF, "[R-TRIVIA]: {FFFFFF}Tastati comanda {00FF00}"#COMMAND_NAME" {FFFFFF}si {00FF00}raspunsul {FFFFFF}." );
- #endif
- rtAnswerTimerID = SetTimer ( "rtTimerAnswer", RESPONSE_INTERVAL * 1000, false );
- return 1;
- }
- public rtTimerAnswer ( )
- {
- new string [ 128 ];
- format ( string, sizeof ( string ), "[R-TRIVIA]: {FFFFFF}Raspunsul era {00FF00}%s {FFFFFF}.", rtTrivia [ rtQuestionID ] [ rtAnswer ] );
- SendClientMessageToAll ( 0x00FF00FF, string );
- rtQuestionID = -1;
- return 1;
- }
- #if !defined USE_SSCANF_PLUGIN
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement