Log in

View Full Version : logging joins



frankpetrov
10-01-2011, 07:13 PM
Ok, so first off, is there anyway I can compile my script and have it actually show any errors? cause when i try to compile it, it doesn't compile, cause of the errors, but the .bat just flashes. I can't see what errors there are.

Anyway, This is what I'm trying to put in.




public OnClientAuthenticate(const name{}, const pwd{})
{
JoinLog(name);
return true;
}

// logging test
public JoinLog(string[])
{
new entry[200];
format(entry, sizeof(entry), "%s\n",string);
new File:hFile;
hFile = fopen("Logs/join.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
}


I'm using compuphase's file.inc for the include and i have it listed in the script to include it. But it's giving errors. I'm just trying to get a basic log so that if someone joins, it writes their name into this log file. any help?

foxtacles
10-01-2011, 07:47 PM
Edit your compile.bat, and add a new line:

PAUSE

Use this code (I put comments where you made mistakes):



public OnClientAuthenticate(const name{}, const pwd{})
{
JoinLog(name);
return true;
}


// logging test
stock JoinLog(const string{}) // no need to declare this public. also, the parameter need to be const qualified (see callback)
{
new entry{200}; // not an error, but it is highly recommended to use packed strings
strformat(entry, sizeof(entry), true, "%s\n", string); // format is actually strformat (it's "format" in SA-MP, but default PAWN declares it strformat)
new File:hFile;
hFile = fopen("Logs/join.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
}

frankpetrov
10-01-2011, 07:59 PM
Thanks for the help. Yeah, I was a scripter in sa-mp so I know a little PAWN from that.
However, it still won't write to the file.

foxtacles
10-01-2011, 08:11 PM
Currently all PAWN file functions use your operating systems temporary folder as a root (I'll change that with the next release). Also, the folder Logs must exist (it won't be created automatically there).

frankpetrov
10-01-2011, 08:40 PM
Currently all PAWN file functions use your operating systems temporary folder as a root (I'll change that with the next release). Also, the folder Logs must exist (it won't be created automatically there).

I'm confused on what you mean it uses my temp folder as a root. How does this affect it? It compiles correctly and i can run the script without any problem, but it just won't write to the Log file(which already exists).

foxtacles
10-01-2011, 08:56 PM
That means when you do:


hFile = fopen("Logs/join.log", io_append);

It actually tries to open / write to the file

<your temp system path>/Logs/join.log

and not to

<your vaultserverd.exe path>/Logs/join.log

(open cmd.exe and run:
echo %TMP%
and it will reveal your temp folder)

frankpetrov
10-01-2011, 09:00 PM
is it possible to specify it even more? as in putting C:\Desktop\etc\etc ?

foxtacles
10-01-2011, 09:03 PM
No, it is not possible to use such an absolute path. With the next release, all files will go into a "files" folder in the root of vaultserverd.exe ;) (similar to SA-MPs scriptfiles, if I remember correctly)

frankpetrov
10-01-2011, 09:07 PM
Alright, i'll just mirror the folder then. Thanks a lot though! ;D