nosoop / SM-TFEconData

Read TF2 item information from the game memory in SourceMod.
https://forums.alliedmods.net/showthread.php?t=315011
GNU General Public License v3.0
34 stars 7 forks source link
sourcemod-lib team-fortress-2

TF2 Econ Data

:coffee: fund my caffeine addiction :coffee:

A library to get TF2 item data from game memory, intended as a successor to TF2ItemsInfo and TF2IDB. No more parsing the schema file and maintaining your own structure for plugin support.

I got bored one day and thought about rewriting a few of my internal plugins so they didn't depend on external tooling anymore.

There's a semi-guide on porting from existing libraries to this one, as well as a WIP plugin that implements the natives from those libraries.

Installation

  1. Download all the non-source code files in the latest release.
  2. Copy tf_econ_data.smx to addons/sourcemod/plugins/.
  3. Copy tf2.econ_data.txt to addons/sourcemod/gamedata/.
  4. If you're a developer, copy tf_econ_data.inc to addons/sourcemod/scripting/include/ (or the appropriate path for your compiler toolchain / project).

Features

Note that the abstractions are intentionally low; this plugin doesn't implement higher-level functions in SourcePawn to do things like:

Example

Dump the taunt defindices for a given class:

int g_iTauntSlot = -1;

public void OnAllPluginsLoaded() {
    // you could use a hardcoded value of 11 if you want to bet on valve not changing indices
    g_iTauntSlot = TF2Econ_TranslateLoadoutSlotNameToIndex("taunt");
    if (g_iTauntSlot == -1) {
        SetFailState("Failed to determine index for slot name '%s'", "taunt");
    }

    ArrayList tauntList = TF2Econ_GetItemList(FilterClassTaunts, TFClass_Scout);

    for (int i = 0; i < tauntList.Length; i++) {
        int defindex = tauntList.Get(i);
        PrintToServer("%d", defindex);
    }
    delete tauntList;
}

/**
 * Returns true if the given item is available for the given playerClass as a taunt.
 */
public bool FilterClassTaunts(int defindex, TFClassType playerClass) {
    return TF2Econ_GetItemSlot(defindex, playerClass) == g_iTauntSlot;
}