Detect when the GameMode is shutting done.

Hello, i’d like to save all logs of my GameMode to a file. However I can’t find any way to hook when the GameMode gets unloaded.

Do you know any hook that gets called when the gamemode unloads ?

Is this what you want?

Thank you, if this is called when i exit my server (srcds.exe), then it’s exactly what i want !

[editline]15th February 2015[/editline]

It’s broken, doesn’t get called when i press exit window…

[editline]15th February 2015[/editline]

So it works only when i type exit on the console but the close button of the window doesn’t call GM:ShutDown()

That’s because calling exit shuts down the game properly. It’s like pressing the quit button on the menu instead of force closing the program. There is no way to detect if the server or client is shut down incorrectly. If you want to save something before it closes, you have to do it on a regular interval such as every 5 minutes.

I would be cautious with the Shut Down hook; I found it would cause the server to hang from 5-20 seconds or just crash the server entirely on map change

Are you running MySQL Niandra? If you’re running TMySQL it will automatically halt the server while it processes any queries at ShutDown. With MySQLOO you’d have to do it manually which is why I like TMySQL ( and because of persistent connections ) but that may be one of the issues ( or an addon saving to files )…

Also as others have said… if you press the x to close srcds you’re “unnaturally” terminating the process and it triggers an immediate shutdown. There are ways to detect this in C++ to ensure a shutdown protocol is always followed but srcds either doesn’t have that bit of logic or it does something else ( such as unlocking/unbinding the ports and doesn’t call any game-mode functions / hooks ).

So the bug is Source Engine related.

If you know a way to compile a c++ dll for linux server, i’d thank you then.

@Pandaman09
It’s not (for me) a good idea to execute a script every 5 minutes, because the process would be a little bit heavy for the server.

To explain more, i’d like to make all saving systems to engage at shut down, so when you change your inventory (ingame), your RP Name, and your money, updates on the SQL database are made at shutdown instead of each time you change your informations.
That’s just in a way to free the CPU, memory and decrease the hard disk uses of the server.

Yes i think you understand my game mode is optimized client side, but it’s a big mess and a memory/CPU/HardDisk burner server side !

Depending how long you keep your server up… if it crashes and it rolls back hours of play-time; people would be unhappy…

I’d recommend some method of saving data during game-play… Additionally, not all people that joined the server when it opened will be in the game when it shuts-down so if you use player.GetAll( ) to save inventories, some users won’t get saved; make sure you keep all data in memory until it is saved, and, again, depending how long the server is up it could be a lot of data to lose or not…

As long as you don’t use blocking calls when querying, you should be fine updating users over time, on disconnect and on shutdown. Some people even update the database right away when certain changes occur… Depending how your system is set up I’d recommend using a product of both a database for the server, and for the client…

The client could store locations of items in inventory or a cache of everything while the server stores the actual items owned by the player, money, etc…