Logs...
#1

pawn Код:
forward ServerLog(playerid, string[]);

public ServerLog(playerid, string[])
{
    new day, month, year, hour, minute, second, entry[192], filename[32], File:file;
    getdate(year, month, day);
    gettime(hour, minute, second);
    format(entry, sizeof (entry), "[%02i:%02i:%02i] %s(%d): %s\r\n", hour, minute, second, PlayerName(playerid), playerid, string);
    format(filename, sizeof (filename), "Server/Logs/%02i.%s.%i.log", day, GetMonth(), year); //
    file = ((fexist(filename)) ? (fopen(filename, io_append)) : (fopen(filename, io_write)));
    fwrite(file, entry);
    fclose(file);
    return 1;
}
Can someone change that to.. so i can use it like this:
pawn Код:
ServerLog("%s(%d) Is a banana", PlayerName(playerid), playerid);

&&

ServerLog(string);
Both in same function?

with other words
Like the "printf"
pawn Код:
printf("%s(%d) Is a banana", PlayerName(playerid), playerid);

&&

printf(string);
Reply
#2

Adding custom format-functionality is an annoying thing. Take a look at this function:

pawn Код:
stock SendPlayerDebugMessage(playerid, debuglevel, const message[], {Float,_}:...)
{
    if(gPlayers[playerid][debugmode] < debuglevel) return false;
    new text[256], tmptext[256], curpos, lastpos, nextpos, bool:extended;
    for(new i = 3; i < numargs(); i ++)    // This is the important part, it formats the string parameter by parameter
    {
                // Get position in string
        curpos = (i == 3) ? (0) : (strfind(message, "%", true, lastpos) + (extended ? 4 : 2));
        nextpos = strfind(message, "%", true, curpos);
                // Check if the current format string has additional data (e.g. %.2f, %3d)
        extended = (message[nextpos + 1] != 'd' && message[nextpos + 1] != 'i' && message[nextpos + 1] != 'f' && message[nextpos + 1] != 's' && \
            message[nextpos + 1] != 'c' && message[nextpos + 1] != 'b' && message[nextpos + 1] != 'x' && message[nextpos + 1] != '%');
                // Cut out the format string
        strmid(tmptext, message, curpos, nextpos + (extended ? 4 : 2));
        lastpos = curpos + 1;
                // Finally format the substring
        format(tmptext, sizeof(tmptext), tmptext, getarg(i));
        format(text, sizeof(text), "%s%s", text, tmptext);
    }
    strmid(tmptext, message, nextpos + (extended ? 5 : 3), strlen(message));
    format(text, sizeof(text), "%s%s", text, tmptext);
    SendClientMessage(playerid, COLOR_DEBUG, text);
    return true;
}
However, it does not work perfectly and it is damn ugly code (I wrote it for testing only), but it should give you an idea of what you had to do. It also works with no additional parameters (your second wanted usage)

Edit: Added some explaining comments
Reply
#3

WoW, and thanks =/

Looks advanced xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)