Stock does'nt work correct...
#1

pawn Код:
#define ServerLog       "Server/Log/%02d-%02d-%04d.txt"

public OnPlayerSpawn(playerid)
{
    PrintX("Lol? (ID %d)", playerid);
}



stock PrintX(const string[], {Float,_}:...)
{
    new Hour, Minute, Second;
    new Year, Month, Day;
    new LogFile[128], entry[128], File:Log;
    gettime(Hour, Minute, Second);
    getdate(Year, Month, Day);
    format(LogFile, sizeof(LogFile), ServerLog, Day, Month, Year);
    if(!fexist(LogFile))
    {
        dini_Create(LogFile);
        printf("New Log File: %02d-%02d-%04d.txt", Day, Month, Year);
        Log = fopen(LogFile, io_append);
        format(entry, sizeof(entry), "[%02d:%02d:%02d] %s\r\n", Hour, Minute, Second, string);
        fwrite(Log, entry);
        fclose(Log);
    }
    else
    {
        format(entry, sizeof(entry), "[%02d:%02d:%02d] %s\r\n", Hour, Minute, Second, string);
        Log = fopen(LogFile, io_append);
        fwrite(Log, entry);
        fclose(Log);
    }
    return 1;
}
And what do i get in my custom log?

Quote:

[15:24:02] Lol? (ID %d)

What am I forgotten?
Reply
#2

I'm not sure if this is the problem but OnPlayerSpawn callback should be public function.
Reply
#3

Nope.. I was just forgotten to scribe that here, i have that in my real GM.
Reply
#4

I know the problem.
Код:
OnPlayerSpawn(playerid)
{
	PrintX("Lol? (ID %d)", playerid);
}



stock PrintX(const format[], {Float,_}:...)
{
	new Hour, Minute, Second;
	new Year, Month, Day;
	new LogFile[128], entry[128], File:Log;
	gettime(Hour, Minute, Second);
	getdate(Year, Month, Day);
	format(LogFile, sizeof(LogFile), ServerLog, Day, Month, Year); //>>>>>> RULE 64 <<<<<<
	if(!fexist(LogFile))
	{
		dini_Create(LogFile);
		printf("New Log File: %02d-%02d-%04d.txt", Day, Month, Year);
		Log = fopen(LogFile, io_append);
		format(entry, sizeof(entry), "[%02d:%02d:%02d] %s\r\n", Hour, Minute, Second, string);
		fwrite(Log, entry);
		fclose(Log);
	}
	else
	{
		format(entry, sizeof(entry), "[%02d:%02d:%02d] %s\r\n", Hour, Minute, Second, string);
		Log = fopen(LogFile, io_append);
		fwrite(Log, entry);
		fclose(Log);
	}
	return 1;
}
It must be
Код:
const format[]
and not
Код:
const string[]
But now some errors.
Код:
(64) : error 012: invalid function call, not a valid address
(64) : warning 215: expression has no effect
(64) : warning 215: expression has no effect
(64) : warning 215: expression has no effect
(64) : warning 215: expression has no effect
(64) : warning 215: expression has no effect
(64) : warning 215: expression has no effect
(64) : error 001: expected token: ";", but found ")"
(64) : error 029: invalid expression, assumed zero
(64) : fatal error 107: too many error messages on one line
Reply
#5

Yes, that are the errors i get with that format. I can use that, but how do I avoid those errors?
Reply
#6

Look into sscanf,to find what you are wrong,and learn.

Maybe the solution.
pawn Код:
static stock
  s_printX_str[128];
#deine printX(%1,%2) \
  format(s_printX_str,128,(%1),%2); \
  printX_proc()
stock printX(const str[]){
  format(s_printX_str,128,"%s",str);
  printX_proc();
}

stock printX_proc(){
  new Hour, Minute, Second;
new Year, Month, Day;
new LogFile[128], entry[128], File:Log;
gettime(Hour, Minute, Second);
getdate(Year, Month, Day);
format(LogFile, sizeof(LogFile), ServerLog, Day, Month, Year); //>>>>>> RULE 64 <<<<<<
if(!fexist(LogFile))
{ dini_Create(LogFile);
printf("New Log File: %02d-%02d-%04d.txt", Day, Month, Year);
Log = fopen(LogFile, io_append);
format(entry, sizeof(entry), "[%02d:%02d:%02d] %s\r\n", Hour, Minute, Second, s_printX_str);
fwrite(Log, entry);
fclose(Log);
} else
{ format(entry, sizeof(entry), "[%02d:%02d:%02d] % s\r\n", Hour, Minute, Second, s_printX_str);
Log = fopen(LogFile, io_append);
fwrite(Log, entry);
fclose(Log);
}
}
Reply
#7

If you can't fix the errors, just don't post. And why look into sscanf? That's a really different thing, i think?
Reply
#8

Quote:
Originally Posted by Remi-X
If you can't fix the errors, just don't post. And why look into sscanf? That's a really different thing, i think?
I've edited my reply.
And my fault,not to look into,to skim sscanf is enough for you : p
Reply
#9

pawn Код:
new printx_array[256]; //that is suppost to be above the first function
#define PrintX(%1) (format(printx_array, sizeof(printx_array), %1), print(printx_array), Log(printx_array))
pawn Код:
public OnPlayerSpawn(playerid)
{
    PrintX("Lol? (ID %d)", playerid);
}
pawn Код:
stock Log(text[])
{
    new
        Hour,
        Minute,
        Second,
        Year,
        Month,
        Day,
        temp[256],
        File:Log;
    getdate(Year, Month, Day), gettime(Hour, Minute, Second);
    format(temp, sizeof(temp), "Server/Log/%02d-%02d-%04d.txt", Day, Month, Year);
    if(!fexist(temp)) Log = fopen(temp, io_write); else Log = fopen(temp, io_append);
    format(temp, sizeof(temp), "[%02d:%02d:%02d] %s\r\n", Hour, Minute, Second, text);
    fwrite(Log, temp), fclose(Log);
    return true;
}
Reply
#10

Lolled, can't that be easier? xD
Reply


Forum Jump:


Users browsing this thread: