From 86c2c2db0222896c5d49df86970f09cf42f8c293 Mon Sep 17 00:00:00 2001
From: David Anderson <dvander@alliedmods.net>
Date: Sun, 2 Oct 2005 09:57:25 +0000
Subject: [PATCH] Fixed bug where core isn't notified of a team change

---
 dlls/cstrike/amxxmodule.cpp | 3 +++
 dlls/cstrike/amxxmodule.h   | 4 ++++
 dlls/cstrike/cstrike.cpp    | 7 +++++++
 3 files changed, 14 insertions(+)

diff --git a/dlls/cstrike/amxxmodule.cpp b/dlls/cstrike/amxxmodule.cpp
index e374e441..d0a5fb0d 100755
--- a/dlls/cstrike/amxxmodule.cpp
+++ b/dlls/cstrike/amxxmodule.cpp
@@ -2502,6 +2502,7 @@ PFN_FORMAT					g_fn_Format;
 PFN_REGISTERFUNCTION		g_fn_RegisterFunction;
 PFN_REQ_FNPTR				g_fn_RequestFunction;
 PFN_AMX_PUSH				g_fn_AmxPush;
+PFN_SET_TEAM_INFO			g_fn_SetTeamInfo;
 
 // *** Exports ***
 C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo)
@@ -2611,6 +2612,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
 	REQFUNC("GetPlayerFlags", g_fn_GetPlayerFlags, PFN_GETPLAYERFLAGS);
 	REQFUNC("GetPlayerEdict", g_fn_GetPlayerEdict, PFN_GET_PLAYER_EDICT);
 	REQFUNC("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH);
+	REQFUNC("SetPlayerTeamInfo", g_fn_SetTeamInfo, PFN_SET_TEAM_INFO);
 
 #ifdef MEMORY_TEST
 	// Memory
@@ -2733,6 +2735,7 @@ void ValidateMacros_DontCallThis_Smiley()
 	MF_GetPlayerEdict(0);
 	MF_Format("", 4, "str");
 	MF_RegisterFunction(NULL, "");
+	MF_SetPlayerTeamInfo(0, 0, "");
 }
 #endif
 
diff --git a/dlls/cstrike/amxxmodule.h b/dlls/cstrike/amxxmodule.h
index 0a000d20..65622fd5 100755
--- a/dlls/cstrike/amxxmodule.h
+++ b/dlls/cstrike/amxxmodule.h
@@ -2003,6 +2003,7 @@ typedef	void			(*PFN_MERGEDEFINITION_FILE)		(const char * /*filename*/);
 typedef const char *	(*PFN_FORMAT)					(const char * /*fmt*/, ... /*params*/);
 typedef void			(*PFN_REGISTERFUNCTION)			(void * /*pfn*/, const char * /*desc*/);
 typedef	int				(*PFN_AMX_PUSH)					(AMX * /*amx*/, cell /*value*/);
+typedef	int				(*PFN_SET_TEAM_INFO)			(int /*player */, int /*teamid */, const char */*name */);
 
 extern PFN_ADD_NATIVES				g_fn_AddNatives;
 extern PFN_BUILD_PATHNAME			g_fn_BuildPathname;
@@ -2066,6 +2067,7 @@ extern PFN_GET_PLAYER_TEAM			g_fn_GetPlayerTeam;
 extern PFN_REGISTERFUNCTION			g_fn_RegisterFunction;
 extern PFN_REQ_FNPTR				g_fn_RequestFunction;
 extern PFN_AMX_PUSH					g_fn_AmxPush;
+extern PFN_SET_TEAM_INFO			g_fn_SetTeamInfo;
 
 #ifdef MAY_NEVER_BE_DEFINED
 // Function prototypes for intellisense and similar systems
@@ -2126,6 +2128,7 @@ void			MF_RegisterFunction			(void *pfn, const char *description) { }
 void *			MF_RequestFunction			(const char *description) { }
 int				MF_AmxPush					(AMX *amx, cell *params) { }
 int				MF_AmxExec					(AMX *amx, cell *retval, int idx) { }
+int				MF_SetPlayerTeamInfo		(int id, int teamid, const char *teamname) { }
 #endif	// MAY_NEVER_BE_DEFINED
 
 #define MF_AddNatives g_fn_AddNatives
@@ -2191,6 +2194,7 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...);
 #define MF_RegisterFunction g_fn_RegisterFunction
 #define MF_RequestFunction g_fn_RequestFunction;
 #define MF_AmxPush g_fn_AmxPush
+#define	MF_SetPlayerTeamInfo g_fn_SetTeamInfo
 
 #ifdef MEMORY_TEST
 /*** Memory ***/
diff --git a/dlls/cstrike/cstrike.cpp b/dlls/cstrike/cstrike.cpp
index 99f8cf1a..89196fad 100755
--- a/dlls/cstrike/cstrike.cpp
+++ b/dlls/cstrike/cstrike.cpp
@@ -140,6 +140,13 @@ static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params) // cs_set
 	WRITE_SHORT(*((int *)pPlayer->pvPrivateData + OFFSET_TEAM)); // should these be byte?
 	MESSAGE_END();
 
+	if (params[2] == 1)
+		MF_SetPlayerTeamInfo(params[1], params[2], "TERRORIST");
+	else if (params[2] == 2)
+		MF_SetPlayerTeamInfo(params[1], params[2], "CT");
+	else
+		MF_SetPlayerTeamInfo(params[1], params[2], NULL);
+
 	return 1;
 }