Want to help test out a new beta version of the plugin with more features? Click Here and please let us know if it works!
This is a library that will allow you to query items or search for them with a specified criteria. For example you can check which slot an item uses or get all items in the melee slot for snipers.
This plugin is meant to replace tf2itemsinfo which has memory leaks and other problems that cannot be fixed and will eventually become permanently broken due to how long it takes to run and that it uses almost the maximum number of handles.
Data is stored in sqlite. A python script is used to update the database. I decided to do it this way because it is a bad idea to put a 10+ second loading time into your server especially when there is time limit for plugins now and is much faster in python. It is recommended to run this after every update. If you do not have python on your server, you can always run it on your computer and upload it to your server.
We need people to start porting plugins to use tf2idb.
I have tried to make the functions close to tf2itemsinfo but unfortunately I could not make them all the same because they were too inefficient, especially for SQLite.
With the TF2IDB_FindItemCustom function, you can create arbitrary SQL queries which should be much faster and much more flexible than the finditem function in tf2itemsinfo.
How to Install - Lazy Method
You can use the pre-made database here but it is not recommended because I will not be updating it. You should follow the additional instructions below so you can make the database yourself after each update.
How to Install - Additional steps to updating your own database
- Put tf2idb.smx into your plugins folder.
- Unzip the sample-db-date.zip file and put the sq3 file into your sourcemod/data/sqlite folder.
- Install Python from python.org. If you are using Linux, it is probably already installed. Type python to check.
- Unzip tf2idb.zip anywhere.
- Follow the instructions below.
You need to first edit tf2idb.py and point it to your TF2 server folder. It will look like this.
TF_FOLDER = r'C:/tf2server/tf/'
ITEMS_GAME = TF_FOLDER + 'scripts/items/items_game.txt'
DB_FILE = TF_FOLDER + 'addons/sourcemod/data/sqlite/tf2idb.sq3'
Normally you will only need to change TF_FOLDER, but if you put items_game.txt or your sqlite folder in a different place, then you will need to change the other 2 lines.
Then run tf2idb.py to create the database. If you need to update the database, run tf2idb.py again.
// If a native returns bool and it is not obvious from the name what it is, then the bool represents whether the native succeeded.
// Natives returning a handle are ADT arrays. You must close them when you are done with them.
native bool:TF2IDB_GetItemName(id, String:string, length);
native bool:TF2IDB_GetItemClass(id, String:string, length);
native bool:TF2IDB_GetItemSlotName(id, String:string, length);
native bool:TF2IDB_GetItemQualityName(id, String:string, length);
native bool:TF2IDB_GetItemLevels(id, &min, &max);
native TF2IDB_GetItemAttributes(id, aid[TF2IDB_MAX_ATTRIBUTES], Float:values[TF2IDB_MAX_ATTRIBUTES]);
native bool:TF2IDB_DoRegionsConflict(const String:region1, const String:region2);
native Handle:TF2IDB_FindItemCustom(const String:query);
native bool:TF2IDB_ItemHasAttribute(id, aid);
Some useful examples.
// If you are creating items, you will want to filter out items with string attributes like this.
TF2IDB_FindItemCustom("SELECT id FROM tf2idb_item WHERE has_string_attribute=0");
// get all medieval and melee items
TF2IDB_FindItemCustom("SELECT a.id FROM tf2idb_item a JOIN tf2idb_item_attributes b ON a.id=b.id WHERE has_string_attribute=0 AND (attribute=2029 OR slot='melee') GROUP BY a.id");
// get all heavy melee items
TF2IDB_FindItemCustom("SELECT a.id FROM tf2idb_item a JOIN tf2idb_class b ON a.id=b.id WHERE b.class='heavy' AND slot='melee' AND has_string_attribute=0");
('CREATE TABLE "tf2idb_class" ("id" INTEGER NOT NULL , "class" TEXT NOT NULL , PRIMARY KEY ("id", "class"))')
('CREATE TABLE "tf2idb_item_attributes" ("id" INTEGER NOT NULL , "attribute" INTEGER NOT NULL , "value" TEXT NOT NULL, PRIMARY KEY ("id", "attribute") )')
('CREATE TABLE "tf2idb_item" ('
'"id" INTEGER PRIMARY KEY NOT NULL ,'
'"name" TEXT NOT NULL,'
'"item_name" TEXT NOT NULL,'
'"class" TEXT NOT NULL,'
'"quality" TEXT NOT NULL,'
('CREATE TABLE "tf2idb_particles" ("id" INTEGER PRIMARY KEY NOT NULL , "name" TEXT NOT NULL )')
('CREATE TABLE "tf2idb_equip_conflicts" ("name" TEXT NOT NULL , "region" TEXT NOT NULL , PRIMARY KEY ("name", "region"))')
('CREATE TABLE "tf2idb_equip_regions" ("id" INTEGER NOT NULL , "region" TEXT NOT NULL , PRIMARY KEY ("id", "region"))')
('CREATE TABLE "tf2idb_capabilities" ("id" INTEGER NOT NULL , "capability" TEXT NOT NULL )')
- Updated tf2idb.py to handle blank item_types.
- Updated tf2idb.sp and tf2idb.smx - fixed GetItemEquipRegions. Thank you Dagothur.
- Updated tf2idb.py to handle the typo in today's schema change. Now all attributes are stored in lowercase.
- Updated tf2idb.py for python 3.5 and added item_name column. Thanks to fakuivan.
- Updated tf2idb.py to support new schema changes, and not to change the database if parsing failed. Added the table "tf2idb_capabilities" with the columns ("id" INTEGER NOT NULL , "capability" TEXT NOT NULL )