Raised This Month: $51 Target: $400
 12% 

SDKCall Problem (TF2)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 07-06-2014 , 15:22   SDKCall Problem (TF2)
Reply With Quote #1

Hello, I have tried creating my own method of changing a clients team in TF2, My aim here is to be able to move a player to another team safely without killing him.

I have already tried SetEntProp but that messes up team counts.

I am trying to use CTFPlayer::ChangeTeam(int) 91 92 92 0x00B6F500
So here is my failed attempt:

Errors:
PHP Code:
L 07/06/2014 15:25:16SourceMod error session started
L 07
/06/2014 15:25:16Info (map "dr_safety_first_final") (file "errors_20140706.log")
L 07/06/2014 15:25:16: [SMNative "SDKCall" reportedInvalid Handle 0 (error 4)
L 07/06/2014 15:25:16: [SMDisplaying call stack trace for plugin "teamswitchtest.smx":
L 07/06/2014 15:25:16: [SM]   [0]  Line 61C:\Users\Michael\Desktop\teamswitchtest.sp::SetTeam()
L 07/06/2014 15:25:16: [SM]   [1]  Line 42C:\Users\Michael\Desktop\teamswitchtest.sp::SwitchPlayers()
L 07/06/2014 15:25:16: [SM]   [2]  Line 24C:\Users\Michael\Desktop\teamswitchtest.sp::OnRoundStart() 
gamedata (plugin.switchteam.txt)
PHP Code:
"Games"
{
    
/* Team Fortress 2 */
    
"tf"
    
{
        
"Offsets"
        
{
            
"switchteam"
            
{
                
"windows"    "91"
                "linux"        "92"
                "mac"        "92"
            
}
        }
    }

Plugin Source:
PHP Code:
#include <sourcemod>
#include <tf2_stocks>

new Handle:hGameConf;
new 
Handle:hSwitchTeam;

public 
Plugin:myinfo 
{
    
name "Team Switcher Test"
}

public 
OnPluginStart()
{
    
hGameConf LoadGameConfigFile("plugin.switchteam");
    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Signature"switchteam");
    
hSwitchTeam EndPrepSDKCall();
    
    
HookEvent("arena_round_start"OnRoundStart);
}

public 
Action:OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
SwitchPlayers();


SwitchPlayers()
{
    for (new 
client 1client <= MaxClientsclient++)
    {
        if(
Client_IsValid(client))
        {
            switch(
GetClientTeam(client))
            {
                case 
2// Red
                
{
                    
SetTeam(client3);
                }
            
                case 
3// Blue
                
{
                    
SetTeam(client2);
                }
            }
        }
    }
}

stock bool:Client_IsValid(clientbool:checkConnected=true
{
    if (
client 4096client EntRefToEntIndex (client);
    if (
client || client MaxClients) return false;
    if ( ! (
<= client <= MaxClients) || ! IsClientInGame (client)) return false;
    if (
checkConnected && ! IsClientConnected (client)) return false
    
    
return true
}

stock SetTeam(clientTeamNum)
{
    
SDKCall(hSwitchTeamclientTeamNum);

Attached Files
File Type: sp Get Plugin or Get Source (teamswitchtest.sp - 262 views - 1.2 KB)
File Type: txt plugin.switchteam.txt (146 Bytes, 70 views)

Last edited by SM9; 07-06-2014 at 15:28.
SM9 is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-06-2014 , 15:28   Re: SDKCall Problem (TF2)
Reply With Quote #2

This TFCond_Reprogrammed condition used to switch a players team to the opposing team on the spot for the duration of the condition, dunno if it still does
__________________

Last edited by Pelipoika; 07-06-2014 at 15:29.
Pelipoika is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 07-06-2014 , 15:39   Re: SDKCall Problem (TF2)
Reply With Quote #3

Quote:
Originally Posted by Pelipoika View Post
This TFCond_Reprogrammed condition used to switch a players team to the opposing team on the spot for the duration of the condition, dunno if it still does
So do you know possible way to achieve this?

Cheers
SM9 is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-06-2014 , 15:53   Re: SDKCall Problem (TF2)
Reply With Quote #4

Quote:
Originally Posted by xCoderx View Post
So do you know possible way to achieve this?

Cheers
What? Just apply the condition i mentioned
__________________
Pelipoika is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-06-2014 , 16:07   Re: SDKCall Problem (TF2)
Reply With Quote #5

ChangeClientTeam already calls CTFPlayer::ChangeTeam. The version of ChangeTeam that doesn't kill players seems to be CTFPlayer::ChangeTeam(int, bool, bool) which can only be called via a signature.

Incidentally, the full function name (including arg names) is
Code:
void CBasePlayer::ChangeTeam( int iTeamNum, bool bAutoTeam, bool bSilent)
(Note: That's actually the parent of CTFPlayer's version)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-06-2014 at 16:11.
Powerlord is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 07-06-2014 , 16:23   Re: SDKCall Problem (TF2)
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
ChangeClientTeam already calls CTFPlayer::ChangeTeam. The version of ChangeTeam that doesn't kill players seems to be CTFPlayer::ChangeTeam(int, bool, bool) which can only be called via a signature.

Incidentally, the full function name (including arg names) is
Code:
void CBasePlayer::ChangeTeam( int iTeamNum, bool bAutoTeam, bool bSilent)
(Note: That's actually the parent of CTFPlayer's version)
So how would I go about using this? (If possible, I'm not understanding very well)

Thanks
SM9 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-07-2014 , 03:57   Re: SDKCall Problem (TF2)
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
Code:
void CBasePlayer::ChangeTeam( int iTeamNum, bool bAutoTeam, bool bSilent)
Quote:
Originally Posted by xCoderx View Post
So how would I go about using this? (If possible, I'm not understanding very well)

Thanks
When set last bool "silent", it will hide chat announce when player change team.
And yes, this also kill player when change team.
PHP Code:
#include <sdktools>

public OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}

public 
Action:test(clientargs)
{
// server.so (Linux)    418    CBasePlayer::ChangeTeam(int,bool,bool)

    // CBasePlayer::
    
StartPrepSDKCall(SDKCall_Player);

    
// 418 (Linux ?) (seems work in Win)
    
PrepSDKCall_SetVirtual(418);

    
// int
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_ByValue);
    
// bool
    
PrepSDKCall_AddParameter(SDKType_BoolSDKPass_ByValue);
    
// bool
    
PrepSDKCall_AddParameter(SDKType_BoolSDKPass_ByValue);

    
// End
    
new Handle:hCallEndPrepSDKCall();

    new 
team GetClientTeam(client) == 3:2;

    
//Call
    //SDKCall(hCall, client, team, false, true);
    
SDKCall(hCallclientteamtruetrue);

    
CloseHandle(hCall);
    return 
Plugin_Handled;

Bacardi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-07-2014 , 09:18   Re: SDKCall Problem (TF2)
Reply With Quote #8

My mistake, it's CTFPlayer::ForceChangeTeam(int, bool) that doesn't kill the player and requires a signature. The int is the team number, the bool is whether to clear dominations or not.

I have some test code for it and some Linux gamedata, but no Windows gamedata. I also haven't touched that in months, so the Linux gamedata may be out of date.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-07-2014 at 09:22.
Powerlord is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 07-07-2014 , 14:16   Re: SDKCall Problem (TF2)
Reply With Quote #9

Quote:
Originally Posted by Powerlord View Post
My mistake, it's CTFPlayer::ForceChangeTeam(int, bool) that doesn't kill the player and requires a signature. The int is the team number, the bool is whether to clear dominations or not.

I have some test code for it and some Linux gamedata, but no Windows gamedata. I also haven't touched that in months, so the Linux gamedata may be out of date.
This works perfectly! Thankyou.

Also I have found another method here:

PHP Code:
stock ChangeTeam(clientTeamNum)
{
    new 
EntProp GetEntProp(clientProp_Send"m_lifeState");
    
SetEntProp(clientProp_Send"m_lifeState"2);
    
ChangeClientTeam(clientTeamNum);
    
SetEntProp(clientProp_Send"m_lifeState"EntProp);
    
    
//SDKCall(g_hForceChangeTeam, client, TeamNum, false);

SM9 is offline
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 04:41.


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