2 Commits 7e91825c79 ... ba698e6ae5

Author SHA1 Message Date
  nosoop ba698e6ae5 Use TF2 Econ Data library 5 years ago
  nosoop 332b81ebb5 Cleanup and correct semantics 5 years ago
2 changed files with 16 additions and 46 deletions
  1. 1 1
      gamedata/csrd.bot_taunt_randomizer.txt
  2. 15 45
      scripting/csrd_bot_taunt_randomizer.sp

+ 1 - 1
gamedata/csrd.bot_taunt_randomizer.txt

@@ -14,7 +14,7 @@
 				{
 					"item_view"
 					{
-						// pointer
+						// this is actually a pointer, but dhooks doesn't support setting pointers
 						"type"	"int"
 					}
 				}

+ 15 - 45
scripting/csrd_bot_taunt_randomizer.sp

@@ -7,17 +7,16 @@
 #include <sourcemod>
 
 #include <tf2_stocks>
-#include <tf2idb>
 
 #pragma newdecls required
 
 #include <dhooks>
 #include <sdktools>
-#include <stocksoup/log_server>
 
 #include <stocksoup/tf/econ>
+#include <tf_econ_data>
 
-#define PLUGIN_VERSION "1.0.0"
+#define PLUGIN_VERSION "1.1.0"
 public Plugin myinfo = {
 	name = "[CSRD] Bot Taunt Randomizer",
 	author = "nosoop",
@@ -28,8 +27,6 @@ public Plugin myinfo = {
 
 Handle g_SDKFindPartnerTauntInitiator;
 
-ArrayList g_TauntEntries[TFClassType];
-
 public void OnPluginStart() {
 	Handle hGameConf = LoadGameConfigFile("csrd.bot_taunt_randomizer");
 	if (!hGameConf) {
@@ -51,33 +48,6 @@ public void OnPluginStart() {
 	DHookEnableDetour(dt_HandleTauntCommand, false, OnHandleTauntCommand);
 	
 	delete hGameConf;
-	
-	for (TFClassType i = TFClass_Unknown; i < TFClassType; i++) {
-		g_TauntEntries[i] = new ArrayList();
-	}
-}
-
-/**
- * Build lists of taunts sorted by class via TF2IDB.
- */
-public void OnAllPluginsLoaded() {
-	ArrayList args = new ArrayList();
-	DBResultSet results = view_as<DBResultSet>(TF2IDB_CustomQuery(
-			"SELECT id, class FROM tf2idb_class WHERE slot = 'taunt'", args, 4));
-	
-	if (!results) {
-		return;
-	}
-	
-	while (results.FetchRow()) {
-		char className[16];
-		
-		int id = results.FetchInt(0);
-		results.FetchString(1, className, sizeof(className));
-		
-		g_TauntEntries[TF2_GetClass(className)].Push(id);
-	}
-	delete results;
 }
 
 /**
@@ -96,7 +66,7 @@ public MRESReturn OnHandleTauntCommand(int client, Handle hParams) {
 		return MRES_Ignored;
 	}
 	
-	// 90% chance of using a taunt item
+	// 90% chance of using a taunt item (10% chance default taunt)
 	if (GetURandomFloat() > 0.90) {
 		return MRES_Ignored;
 	}
@@ -117,8 +87,8 @@ public MRESReturn OnPlayTauntSceneFromItem(int client, Handle hReturn, Handle hP
 		return MRES_Ignored;
 	}
 	
-	int item = DHookGetParam(hParams, 1);
-	if (item) {
+	Address pEconItemView = DHookGetParam(hParams, 1);
+	if (pEconItemView) {
 		return MRES_Ignored;
 	}
 	
@@ -164,19 +134,19 @@ int TF2_FindPartnerTauntInitiator(int client) {
  * Returns a random class-specific or all-class taunt index.
  */
 int TF2_GetRandomTauntForClass(TFClassType playerClass) {
-	int nTauntsAllClass = g_TauntEntries[0].Length;
-	int nTauntsPlayerClass = g_TauntEntries[playerClass].Length;
+	int returnValue = DEFINDEX_UNDEFINED;
 	
-	if (nTauntsAllClass + nTauntsPlayerClass == 0) {
-		return DEFINDEX_UNDEFINED;
+	ArrayList tauntList = TF2Econ_GetItemList(FilterClassTaunts, playerClass);
+	if (tauntList.Length) {
+		returnValue = tauntList.Get(GetRandomInt(0, tauntList.Length - 1));
 	}
+	delete tauntList;
 	
-	int index = GetRandomInt(0, nTauntsAllClass + nTauntsPlayerClass - 1);
-	
-	if (index < nTauntsAllClass) {
-		return g_TauntEntries[0].Get(index);
-	}
-	return g_TauntEntries[playerClass].Get(index - nTauntsAllClass);
+	return returnValue;
+}
+
+public bool FilterClassTaunts(int defindex, TFClassType playerClass) {
+	return TF2Econ_GetItemSlot(defindex, playerClass) == 11;
 }
 
 /**