View Single Post
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 10-13-2016 , 13:37   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #2

I don't know how did you plan to detect a team change by setting someone's team. I guess you meant cs_get_user_team.

Here's a solution using Okapi. Tested and works on Windows.
PHP Code:
#include <amxmodx>
#include <okapi>

#define PLUGIN  "Detect Team Change"
#define VERSION "1.0"
#define AUTHOR  "KliPPy"


public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    new 
methodAddress;
    if(
is_linux_server())
    {
        static const 
symbol[] = "_Z21HandleMenu_ChooseTeamP11CBasePlayeri";
        
methodAddress okapi_mod_get_symbol_ptr(symbol);
    }
    else
    {
        static const 
signature[] = {0x83,0xEC,0xDEF,0x8B,0x0D,0xDEF,0xDEF,0xDEF,0xDEF,0x53,0x55,0x56,0x8B,0x74};
        
methodAddress okapi_mod_find_sig(signaturesizeof(signature));
    }

    if(
methodAddress == 0)
    {
        
set_fail_state("Couldn't find HandleMenu_ChooseTeam.");
        return;
    }

    new 
okapi_func:func_HandleMenu_ChooseTeam okapi_build_function(methodAddressarg_intarg_cbasearg_int);
    
okapi_add_hook(func_HandleMenu_ChooseTeam"Hook_HandleMenu_ChooseTeam"true);
}

public 
Hook_HandleMenu_ChooseTeam(playernewTeam)
{
    
// This function may get called even if the team change wasn't successful. The function returns TRUE if the change was successful.
    
if(okapi_get_orig_return())
        
server_print("Team changed! Player: %d New Team: %d"playernewTeam);


Last edited by klippy; 10-13-2016 at 13:39.
klippy is offline