• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Looting log

Grandelf

Esteemed Member
Some general information

So I finally got to rewrite this for Eluna, a promise I made to Foe over a year ago when it wasn't possible
to convert the script to Eluna yet because of the lack of a loot hook. Well that loot hook has been around
for quite some time now so about time that I convert this to Eluna =P.

So what this script does is basically logging every single item a player loots. This is useful when you have
whining players that apparently lost loot on a server crash (rollback) but can't provide any proof. This script
will provide the proof for them.

Differences from the arcemu version.

I have completely rewritten the script.
This version uses a database rather than a .txt file. This because of two reasons:

  • A database table is easier to read;
  • SQL provides options to auto clean up your table.
Yes, automatic clean up, whenever a character is deleted, his loot data will be deleted aswell
(same goes for name changes, only then it will update the name).

Usage

To check someones loot history you can either find the player in the database table, or you
can use the command provided below under the following conditions:
You target a player and type:
Code:
.char loot [, item_entry]
You use the player's name in the command.
Code:
.char loot plrname [, item_entry]
Item entry is optional and if specified it will only search for that specific item.

Setting up the script

All you have to do is put the script in your scripts folder and run the SQL query provided below.
At the top of the script you will find two variables that you can change:
the command syntax and the maximum results shown on usage. Simply edit these to your liking.

Script: http://pastebin.com/thTXXAsx

Future updates

I am planning on updating this a bit when I have the time.

  • Upgrade the command so you can also use a character name to search for loot;
    [*]Implement some table clean-up (this table may become huge);
    [*]Change the command so it shows the item name / link instead of the entry id.

Grandelf.

EDIT:

SQL query:
Code:
/* We only want to run this if the table does not exist. */
DROP TABLE IF EXISTS player_loots;
CREATE TABLE player_loots (
	/* Loot table. */
	id			int unsigned		NOT NULL 	AUTO_INCREMENT,
	player		varchar(12)         COLLATE utf8_bin NOT NULL,
	date_time	int unsigned		NOT NULL,
	item_id		int unsigned		NOT NULL,
	item_count	tinyint unsigned	NOT NULL,
	deleted		tinyint(1) unsigned	NOT NULL 	DEFAULT '0',
	/* Table rules ... */
	/* Constraints for player_loots. */
	PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/* Creating the trigger that will mark the records as deleted */
DELIMITER // /* Changing the delimiter, so we can use ';'. */
DROP TRIGGER IF EXISTS character_on_delete//
CREATE TRIGGER character_on_delete AFTER DELETE ON characters
	FOR EACH ROW 
BEGIN
	UPDATE player_loots SET deleted = 1 where player = OLD.name;
END//
/* Creating the trigger that will update the name in 'player_loots'
	after an update on characters. */
DROP TRIGGER IF EXISTS character_on_update//
CREATE TRIGGER character_on_update AFTER UPDATE ON characters
	FOR EACH ROW
BEGIN
	UPDATE player_loots SET player = NEW.name where player = OLD.name;
END//
/* Weekly clean up event. */
SET GLOBAL event_scheduler = ON// -- Just in case ... it was off in my database so.
DROP EVENT IF EXISTS loot_cleanup//
CREATE EVENT loot_cleanup ON SCHEDULE EVERY 1 WEEK STARTS '2014-12-14 00:00:00' 
DO BEGIN
	DELETE FROM player_loots WHERE deleted = 1;
END//
DELIMITER ; /* obviously we have to set it back to ';' again ... */

If you want to delete the script, be sure to run this query to delete the database content:
Code:
DROP TABLE IF EXISTS player_loots;
DROP TRIGGER IF EXISTS character_on_delete;	
DROP TRIGGER IF EXISTS character_on_update;
DROP EVENT IF EXISTS loot_cleanup;
SET GLOBAL event_scheduler = OFF;
 
Last edited:

Foereaper

Founder
Very nice, thanks a bunch! I haven't had the time to check yet, but deletion of entries when a character is deleted should possibly be a delayed cleanup routine? Possibly done once per week or something amongst those lines? Could do it with a marked for deletion field in the database and a weekly cleanup event. This way you can restore (to an extent) deleted character items if a character would happen to be deleted by accident.
 

Grandelf

Esteemed Member
Very nice, thanks a bunch! I haven't had the time to check yet, but deletion of entries when a character is deleted should possibly be a delayed cleanup routine? Possibly done once per week or something amongst those lines? Could do it with a marked for deletion field in the database and a weekly cleanup event. This way you can restore (to an extent) deleted character items if a character would happen to be deleted by accident.

Hmmm I haven't thought about it that way, makes sense =P. I'll definitely look into it.
 

Grandelf

Esteemed Member
Thanks =D.

I am almost done rewriting certain parts to support item links and an extra argument (player name).
Also a better system of handling the data, because the script right now has a table that can easily
reach 10000 elements that might not even be used that often.
 

Grandelf

Esteemed Member
Updated the main post, I have rewritten the entire script for better performance.
Updates:

  • Made a system to properly load things from the database;
  • The lua table will now clean itself whenever it gets to big;
  • The results are now shown as item links and not item ids;
  • You can use the player's name in the command.
 

sapphire

Emulation Addict
Hello Grandelf,

first things first, I love your idea about the loot logging system!
But on my side, there seems to be something not working correctly or I don't understand the whole script.

For example, I entered Naxxramas, killed a boss and looted an item.
Then I checked the DB and there was no entry for this.

But yesterday we did Molten Core. And the items other players looted are in the Database.
Same for some world drops.

I'm using mangos zero Rel20 on Ubuntu.


Greetings!
 

Grandelf

Esteemed Member
I would suggest using the "command" hook instead of the chat hook, that way you can make it into a proper command instead of the normal chat hook stuff :p

I noticed this hook lately and already gave it a go actually, however my first thought wasn't to update this script xd.
But it is actually a good idea, so I can do it. Should be a minor change anyway.

Hello Grandelf,

first things first, I love your idea about the loot logging system!
But on my side, there seems to be something not working correctly or I don't understand the whole script.

For example, I entered Naxxramas, killed a boss and looted an item.
Then I checked the DB and there was no entry for this.

But yesterday we did Molten Core. And the items other players looted are in the Database.
Same for some world drops.

I'm using mangos zero Rel20 on Ubuntu.


Greetings!

Hmm that is weird, that isn't supposed to be happening. The script uses a 'ON_LOOT_HOOK',
which means that all the loot that is captured with that hook should be logged.
So either the database content wasn't loaded yet, the script wasn't loaded or the
hook didn't function as it should (however I doubt this, because the hook works perfect
on my server, trinitycore however).

You mention that the drops are being logged now, I suggest you try to loot something again.
If that works then it should be fine and the problem was probably that something wasn't loaded yet.

EDIT:

Updated the script:
  • Changed the 'chat hook' to the 'command hook';
  • Added a gm check (/facepalm).
 
Last edited:

sapphire

Emulation Addict
Updated the script:
  • Changed the 'chat hook' to the 'command hook';
  • Added a gm check (/facepalm).

Yeah, I wanted to ask for a GM check right now :D Tried to do it myself, but I'm very fresh to lua - and I didn't get the check added myself. So thanks on this way :)

We did Molten Core yesterday and it seems like every relevant items got logged.
 

Foereaper

Founder
Another idea is to make this more configurable, add a minimum threshold for item quality and minimum level etc. Anything below said config options won't get logged. You'd normally not want to bother with logging white items etc eh?
 

Grandelf

Esteemed Member
Yeah, I wanted to ask for a GM check right now :D Tried to do it myself, but I'm very fresh to lua - and I didn't get the check added myself. So thanks on this way :)

We did Molten Core yesterday and it seems like every relevant items got logged.

Great! :top:

Another idea is to make this more configurable, add a minimum threshold for item quality and minimum level etc. Anything below said config options won't get logged. You'd normally not want to bother with logging white items etc eh?

That is a really good point, the level might be debatable but it doesn't hurt to add a config option though.
I am currently busy writing another script, but I will look into it after I am done with that =D.
 

sapphire

Emulation Addict
There is some problem now since you changed it to be a real . command. I can't use .guild anymore for example, when I use your lua script.
 

Grandelf

Esteemed Member
Yea that was a mistake I made with the command, I almost fixed that right after I updated the script.
Seems like you took the script before I fixed it though xd. Replacing your script with this one will fix it.
 

Rochet2

Moderator / Eluna Dev
There is some problem now since you changed it to be a real . command. I can't use .guild anymore for example, when I use your lua script.
Yea that was a mistake I made with the command, I almost fixed that right after I updated the script.
Seems like you took the script before I fixed it though xd. Replacing your script with this one will fix it.
What kind of edit did you make?
Nvm, found all the pastes from google.

The reason I wanted to know was that the command scripts in lua should never block the C++ commands.
However that works as intended it seems.
 
Last edited:

Grandelf

Esteemed Member
Yea they don't block the C++ commands. However I forgot to include a check,
to see if the loot command was used. So on any other command (other than the C++ ones) you used,
it would use my script xd..
 
Top