want to know something please read it
#1

well i have INI saving system it has many things on it like admin level score money so i want to know how can i make a command if player is not in the server but that player is registered so how can i make a command like i want to read his score but he is not online so how can i read his ini in game and it will show me his score in game if he is online or not like /check playername when i enter the player name if he is registered that command show me his score so how can i make this function i have INI saving system please help me i asked it many times but no one helped me today i am asking again please a guy a scripter can explain me it just take your few minutes to explain me but it will help me alot in my server so i am requesting you to all please tell me how can i check offline player stats with a command thanx
Reply
#2

Код:
CMD:stats(playerid, params[])
{
	if (isnull(params))
		return SendClientMessage(playerid, -1, "Usage: /stats [player name]");

	new path[35];
	format(path, sizeof (path), "users/%s.ini", params);
	// Change path to whatever your user path is

	if (!fexist(path))
		return SendClientMessage(playerid, -1, "Player is not registered.");

	new File: file = fopen(path, io_read);
	if (!file)
		return SendClientMessage(playerid, -1, "An error occured. Try again.");

	new string[128], dialogstr[512];
	while (fread(file, string))
	{
		string[strlen(string) - 1 EOS];
		if (!strcmp(string, "Password = ", true, 11))
			continue;

		/* To skip stuff (I skipped Password)
		if (!strcmp(string, "STAT_NAME = ", true, LENGTH OF "STAT_NAME = "))
			continue;
		*/
		strcat(dialogstr, string);
		strcat(dialogstr, "\n");
	}
	dialogstr[strlen(dialogstr) - 1] = EOS;
	fclose(file);

	format(string, sizeof (string), "%s's stats", params);
	ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, string, dialogstr, "Close", "");
	return 1;
}
Remove spaces between = if your files don't have spaces between =
Код:
entry = something
entry=string
Make sure to adjust your lengths.
Reply
#3

Lets say your account database structure is like this :
Код:
users/userName.ini
So when a user types say, "/check test"
Then you will check whether a file like this exits or not :
Код:
users/test.ini
If not then send the player a message like "no such player in database!"

If yes then load the player info like you load when player logs in. Only difference: load it in different variable.
When i used to use ini systems what i did was that I used to declare player info variable like this :
Код:
new playerInfo[MAX_PLAYERS + 1];
See the "+1" here? I used to load offline player info in this extra index.

EDIT: late
Reply
#4

Errors what should i have to do?

Код:
(26156) : error 001: expected token: "]", but found "-identifier-"
(26156) : warning 215: expression has no effect
(26156) : error 001: expected token: ";", but found "]"
(26156) : error 029: invalid expression, assumed zero
(26156) : fatal error 107: too many error messages on one line
on this line

Quote:

string[strlen(string) - 1 EOS];
if (!strcmp(string, "Password = ", true, 11))
continue;

Reply
#5

Change it to this:
Код:
string[strlen(string) - 1] = EOS;
Reply
#6

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Change it to this:
Код:
string[strlen(string) - 1] = EOS;
bro thank you soo much how can i say thanks to you' You fixed my problem bro thank you soooooo much but now i just want one thing it showing me player all stats but i want that this only show me one stats like i want to check player admin level so how can i make it that it only show me user admin level not all the other stats?
Reply
#7

Код:
CMD:getadminlevel(playerid, params[])
{
	if (isnull(params))
		return SendClientMessage(playerid, -1, "Usage: /getadminlevel [player name]");

	new path[35];
	format(path, sizeof (path), "users/%s.ini", params);
	// Change path to whatever your user path is

	if (!fexist(path))
		return SendClientMessage(playerid, -1, "Player is not registered.");

	new File: file = fopen(path, io_read);
	if (!file)
		return SendClientMessage(playerid, -1, "An error occured. Try again.");

	new string[64];
	while (fread(file, string))
	{
		string[strlen(string) - 1 EOS];
		if (!strcmp(string, "Admin = ", true, 8))
		{
			format(string, sizeof (string), "%s's admin level: %i", params, string[8]);
			SendClientMessage(playerid, -1, string)
			break;
		}
	}
	fclose(file);
	return 1;
}
Reply
#8

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Код:
CMD:getadminlevel(playerid, params[])
{
	if (isnull(params))
		return SendClientMessage(playerid, -1, "Usage: /getadminlevel [player name]");

	new path[35];
	format(path, sizeof (path), "users/%s.ini", params);
	// Change path to whatever your user path is

	if (!fexist(path))
		return SendClientMessage(playerid, -1, "Player is not registered.");

	new File: file = fopen(path, io_read);
	if (!file)
		return SendClientMessage(playerid, -1, "An error occured. Try again.");

	new string[64];
	while (fread(file, string))
	{
		string[strlen(string) - 1 EOS];
		if (!strcmp(string, "Admin = ", true, 8))
		{
			format(string, sizeof (string), "%s's admin level: %i", params, string[8]);
			SendClientMessage(playerid, -1, string)
			break;
		}
	}
	fclose(file);
	return 1;
}
it's working fine but it showing the player level is 138 but that player having level 5
Reply
#9

Sorry about that. Change the format line to this:
Код:
format(string, sizeof (string), "%s's admin level: %s", params, string[8]);
It should work.
Reply
#10

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Sorry about that. Change the format line to this:
Код:
format(string, sizeof (string), "%s's admin level: %s", params, string[8]);
It should work.
thanks a lot for helping it worked thank you soo much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)