Znote / ZnoteAAC

Developement repository for the Znote AAC project. A website portal to represent and manage your Open Tibia server.
MIT License
145 stars 127 forks source link

[Suggestion] kill statistics page #379

Open EPuncker opened 4 years ago

EPuncker commented 4 years ago

What about adding a kill count statistics page (as additional feature ofc) just like cipbia have: https://www.tibia.com/community/?subtopic=killstatistics

it is cool to see amount of killed monsters and players by monsters

Znote commented 4 years ago

Sure, good idea. Might also want to tie this into #318 as well. Considering making a revScriptSys module for maintaining monster list and efficiently tracking monster data.

slawkens commented 4 years ago

I might contribute to this as well.

I was always interested in making kill statistics for TFS.

Znote commented 4 years ago

Instead of parsing monsters.xml, which might be obsolete soon enough, a smarter way might be to utilize: https://github.com/otland/forgottenserver/pull/2798 Together with an onkill checker for unique monsters spawned after server startup. Then a revscriptsys module could keep everything up to date and fairly live, without too much performance impact.

onStartup = grab initial monster information and sync to a table.

onKill = store killdata quickly on a metatable to be accessed through a less hitted event. If you kill a special monster that wasn't known to us at startup, add this info as well.

globalevent (each x minutes/seconds) loads data stored from onKill events, builds an async insert query to populate the db.

db interactions purposely avoided from onKill event, because that can quickly choke the server with uneccesary many queries. (think 100-1000 monsters slaughtered every second on big highexp servers).

So the onKill should only focus on quickly obtaining monster and player information and store it in a table to be accessed on globalevent.

The globalevent, which is configured to only run once at specific intervals, can then build bigger queries that populate multiple rows to the db at the same time, potentially making 200 separate queries into 1. And with the query set as async, it should hopefully not disturb the server and dispatcher from doing its thing.

The power of SQL in Lua is stronger than what is normally utilized in OT scripts, here is a sample where I remake the storagevalue system in Lua (prototype to practice): Do NOT actually use this in production, especially if you like the /reload command as it will break the storagevalue system. https://gist.github.com/Znote/0317d3667447ad0f5473221e116eea7f