GM:PlayerDisconnected problem

I have some code that saves a var set on the player to a .txt file every time that player disconnects, and reloads it each time they reconnect.

  1. However, when clients crash, is PlayerDisconnected still called?
  2. What about when the server crashes, is there a function called then so I can save the var then too? (GM:ShutDown() maybe?)
  3. Would saving the var for everyone on the server their each individual text file lag anything/anyone out?

Hopefully I was clear on what I’m trying to get at here, thanks for reading.

What’s on the text file? Why can’t you just save it whenever it actually gets changed instead of when the player disconnects?

  1. When a client crash all code stops being executed
  2. When the server crashes, PlayerDisconnected is not called as all code stops being executed too
  3. It could cause security issues such as player modifying the file and/or using it to reverse engineer your system.

I’d recommend you save it when the data actually changes and on a more reliable and safe place (file on server or database).

Doesn’t writing to a text file lag the server/client while doing it often?

Also, I’ll try to add in the save function to my Set/Add/Remove currency functions. Should I still save on PlayerDisconnect for safe measures? I don’t think it would really be needed if it saves every time it changes, but it wouldn’t hurt.

Sort of off topic here, but is there a tool/command i can use to measure server lag rather than looking at my ping? There probably is and I’m just being dumb but i’ve never used anything like that before.

EDIT: The file is saved on a .txt file in the server’s data directory, is that what you mean by a file on the server?

Most addons do that, but if you’re really worried about lag you can switch to database saving with the sql library.

If it saves every time it changes, there shouldn’t be any problems when the player disconnects, no need to do extra operations and put more load on the server.

You can look in the useful lua tips/snippets thread, The Commander posted a lua garbage collector HUD indicator there. This would indicate leaks in your code.
Or you can take a look at DBugR though I’m not 100% sure its still functional.

Yes, but the sql library is also an option too.