AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Detect Team Change (cstrike) (https://forums.alliedmods.net/showthread.php?t=289032)

Depresie 10-13-2016 12:32

[HELP] Detect Team Change (cstrike)
 
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" ); 


klippy 10-13-2016 13:37

Re: [HELP] Detect Team Change (cstrike)
 
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);



Depresie 10-13-2016 13:43

Re: [HELP] Detect Team Change (cstrike)
 
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..

safetymoose 10-13-2016 19:18

Re: [HELP] Detect Team Change (cstrike)
 
If you're trying to prevent the spectator bug, i'd recommend ReGameDLL_CS.

siriusmd99 10-14-2016 14:47

Re: [HELP] Detect Team Change (cstrike)
 
Quote:

Originally Posted by Depresie (Post 2461720)
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.

Depresie 10-14-2016 14:59

Re: [HELP] Detect Team Change (cstrike)
 
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

klippy 10-14-2016 19:38

Re: [HELP] Detect Team Change (cstrike)
 
Use Orpheu to hook that native, kek.

Depresie 10-15-2016 06:26

Re: [HELP] Detect Team Change (cstrike)
 
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

Bugsy 10-15-2016 10:48

Re: [HELP] Detect Team Change (cstrike)
 
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
        }
    ]
}


Bos93 10-15-2016 11:25

Re: [HELP] Detect Team Change (cstrike)
 
new iTeam = OrpheuMemoryGetAtAddress( params + 4 , "int" );
new iModel = OrpheuMemoryGetAtAddress( params + 8 , "int" );

Why did you add these numbers?


All times are GMT -4. The time now is 09:56.

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