Raised This Month: $32 Target: $400
 8% 

[HELP] Detect Team Change (cstrike)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-13-2016 , 12:32   [HELP] Detect Team Change (cstrike)
Reply With Quote #1

Is there any way to detect when a player joins to spectator via cs_set_user_team native?
This won't hook it =d

PHP Code:
register_event"TeamInfo" "fw_EvTeamInfo" "a" ); 
__________________
Depresie is offline
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
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-13-2016 , 13:43   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #3

What i meant was if it is possible to detect when cs_set_user_team is called, but i guess i will just do a work around..
__________________
Depresie is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 10-13-2016 , 19:18   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #4

If you're trying to prevent the spectator bug, i'd recommend ReGameDLL_CS.
safetymoose is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 10-14-2016 , 14:47   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #5

Quote:
Originally Posted by Depresie View Post
What i meant was if it is possible to detect when cs_set_user_team is called, but i guess i will just do a work around..
Only way is to recompile cstrike module by making a forward for cs_set_user_team native.
siriusmd99 is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-14-2016 , 14:59   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #6

Too tired to do such things.. and if i do that, then i will want to start doing more.. and in that way i will never finish my project
__________________
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 10-14-2016 , 19:38   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #7

Use Orpheu to hook that native, kek.

Last edited by klippy; 10-14-2016 at 19:40.
klippy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-15-2016 , 06:26   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #8

Nah, i got a nice workaround method already, i need to create some new natives for my csex API plugin which is an extension of natives for cstrike.. i will handle there and this..

I don't have the required knowledge to use orpheu, and atm i don't have the required time to learn
And if it were to do this, i would rather modify amxx, and i don't want to get into that, because i will want to modify more and more and more and i will never finish my project lol
__________________

Last edited by Depresie; 10-15-2016 at 06:26.
Depresie is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-15-2016 , 10:48   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #9

Edit: Updated per Arkshine & Klippy's comments.

Signature created using cstrike module from 1.8.3 dev+4748

I only tested this on Windows.
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <orpheu>
#include <orpheu_memory>

new const Version[] = "0.2";

const 
CellSizeBytes = ( cellbits );

#define GetParams(%1,%2)    (%1 + (%2 * CellSizeBytes))

public plugin_init()
{
    
register_plugin"cs_set_user_team hook" Version Version );
    
    
OrpheuRegisterHookOrpheuGetFunction"cs_set_user_team" ) , "Hook_cs_set_user_team" );
    
    
register_clcmd"say test" "test" );
}

public 
testid )
{
    
cs_set_user_teamid CS_TEAM_SPECTATOR CS_DONTCHANGE );
}

public 
OrpheuHookReturn:Hook_cs_set_user_teamamx params )
{
    
//From cstrike module: CstrikeNatives.cpp
    //  static cell AMX_NATIVE_CALL cs_set_user_team(AMX *amx, cell *params) // cs_set_user_team(index, team, model = 0); = 3 params
    //  {
          // params[1] = user index
          // params[2] = team
          // params[3] = model = 0
        
    
new iPlayer OrpheuMemoryGetAtAddressGetParamsparams ) , "int" );
    new 
iTeam OrpheuMemoryGetAtAddressGetParamsparams ) , "int" );
    new 
iModel OrpheuMemoryGetAtAddressGetParamsparams ) , "int" );
    
    
client_printiPlayer print_chat "cs_set_user_team was called: id=%d Team=%d Model=%d" iPlayer iTeam iModel );

Output:
Code:
cs_set_user_team : id=1 Team=3 Model=0
File: amxmodx\configs\orpheu\functions\cs_set_user_ team
Code:
{
    "name" : "cs_set_user_team",
    "library" : "cstrike",
    "arguments" :
    [
        {
            "type" : "int"
        },
        {
            "type" : "int"
        }
    ],
    "identifiers":
    [
        {
            "os" : "windows",
            "mod" : "cstrike",
            "value" : [0x55,0x8B,"*",0x83,"*","*",0xA1,0xB8,"*","*","*",0x33,0xC5,0x89,0x45,"*",0x56,0x8B,"*","*",0x8B,0x46,"*",0x57,0x8B,"*","*",0x83,0xF8]
        },
        {
            "os"    : "linux",
            "mod"   : "cstrike",
            "value" : "cs_set_user_team"
        }
    ]
}
File: amxmodx\configs\orpheu\memory\int
Code:
{
    "name"        : "int",
    "type"        : "int",
    "memoryType"  : "data",
    "identifiers" :
    [
        {
            "os"    : "windows",
            "value" : 0
        },
        {
            "os"    : "linux",
            "value" : 0
        }
    ]
}
__________________

Last edited by Bugsy; 10-16-2016 at 14:42.
Bugsy is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 10-15-2016 , 11:25   Re: [HELP] Detect Team Change (cstrike)
Reply With Quote #10

new iTeam = OrpheuMemoryGetAtAddress( params + 4 , "int" );
new iModel = OrpheuMemoryGetAtAddress( params + 8 , "int" );

Why did you add these numbers?
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode