Jump to content
  • 0

Problema sistem Trivia


Attil4S

Question

Salut,am un sistem trivia pe serverul meu ,cand raspund la el imi arata ca mi se adauga banii ,dar imi dispar dupa 2 secunde.. daca am 0 tot cu 0 raman,
 

#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               ( "GivePlayerMoney" )                // Daca aveti vreun money anticheat, definiti aceasta constanta cu numele functiei de dat ban a anticheat-ului
#define CASE_SENSITIVE                      ( true )                           // true / false
#define MAX_QUESTIONS 						( 5 )                              // Numarul maxim de intrebari ce poate fi incarcat din fisier
#define TRIVIA_PATH 						( "trivia.cfg" )                    // Fisierul cu intrebarile
#define ASK_INTERVAL 						( 5 )                             // 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[Trivia] - Loaded\n\nSimple Trivia System \n" );
	if ( !fexist ( TRIVIA_PATH ) ) return print ( "[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 ( "[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;
}

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 ), "[Trivia] {FF0000}%s {FFFFFF}a raspuns primul si a castigat {00FF00}5000$", 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;
}

public rtTimer ( )
{
	new string [ 128 ];
	rtQuestionID = random ( rtLoadedQuestions );
	format ( string, sizeof ( string ), "[Trivia] {FFFFFF}%s ?", rtTrivia [ rtQuestionID ] [ rtQuestion ] );
	SendClientMessageToAll ( 0x00FF00FF, string );
	SendClientMessageToAll ( 0x00FF00FF, "[Trivia] {FFFFFF}Tastati raspunsul in {00FF00}chat {FFFFFF}." );
	rtAnswerTimerID = SetTimer ( "rtTimerAnswer", RESPONSE_INTERVAL * 1000, false );
	return 1;
}

public rtTimerAnswer ( )
{
	new string [ 128 ];
	format ( string, sizeof ( string ), "[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

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Asta inseamna ca ai un timer in gamemode care iti verifica daca bani pe care ii ai in mana sunt aceiasi cu o variabila in care se stocheaza in gamemode , da nu sunt la fel iti resteaza bani si iti da cat aveai normal.

Si ai deja chestia pe care voiam sa o zic . Si anume sa chemi GivePlayerCash(sau cum ai tu in gamemode) folosind CallRemoteFunction

#define GIVE_MONEY_FUNCTION               ( "FunctiaDinGmDeDatBani" )

Si mai mult de atat. Te duci in gm la functia de dat bani din gm si ii pui 

forward functia(playerid, money);
public functia(playerid,money){
//codu de dat bani pe care il ai
}

Si astfel o sa-ti mearga

Asta daca il bagi in gm

Edited by Banditul
Link to comment
Share on other sites

  • 0
La 04.11.2017 la 20:12, Banditul a spus:

Asta inseamna ca ai un timer in gamemode care iti verifica daca bani pe care ii ai in mana sunt aceiasi cu o variabila in care se stocheaza in gamemode , da nu sunt la fel iti resteaza bani si iti da cat aveai normal.

Si ai deja chestia pe care voiam sa o zic . Si anume sa chemi GivePlayerCash(sau cum ai tu in gamemode) folosind CallRemoteFunction


#define GIVE_MONEY_FUNCTION               ( "FunctiaDinGmDeDatBani" )

Si mai mult de atat. Te duci in gm la functia de dat bani din gm si ii pui 


forward functia(playerid, money);
public functia(playerid,money){
//codu de dat bani pe care il ai
}

Si astfel o sa-ti mearga

Asta daca il bagi in gm

 

tot nu am reusit .. :(

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.