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

[TF2] Set Class


Post New Thread Reply   
 
Thread Tools Display Modes
gry
Junior Member
Join Date: Apr 2014
Location: Russia, Moscow
Old 06-12-2017 , 05:40   Re: [TF2] Set Class
Reply With Quote #41

Quote:
Originally Posted by gry View Post
It stop working after last update. When i change class i have no weapons
Can anyone fix it please?
__________________
gry is offline
JoinedSenses
Senior Member
Join Date: Sep 2013
Old 12-01-2018 , 18:46   Re: [TF2] Set Class
Reply With Quote #42

Updated syntax, modified formatting, and set default permission to ADMFLAG_GENERIC. Override or edit the plugin as needed.

https://github.com/JoinedSenses/TF2-SetClass

Haven't encountered the issue related to what gry mentioned
JoinedSenses is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-14-2019 , 11:04   Re: [TF2] Set Class
Reply With Quote #43

Greetings! Can someone modify this plugin to improve the 'random' class?

Command: !setclass @bots random
Current Effect: All 20 bots will be set to the same random class. For example all 20 bots will become a Spy.

Desired Effect: Each of the 20 bots will be a different random class. For example, 3 may become Heavy, 2 might become Medic, 5 might become Scout, etc.
PC Gamer is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 11-15-2019 , 02:34   Re: [TF2] Set Class
Reply With Quote #44

Quote:
Originally Posted by PC Gamer View Post
Greetings! Can someone modify this plugin to improve the 'random' class?

Command: !setclass @bots random
Current Effect: All 20 bots will be set to the same random class. For example all 20 bots will become a Spy.

Desired Effect: Each of the 20 bots will be a different random class. For example, 3 may become Heavy, 2 might become Medic, 5 might become Scout, etc.
I've had a modified version of this plugin for a while. It does exactly what you're asking for.

PHP Code:
#include <sourcemod>
#include <tf2>
#include <tf2_stocks>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.2.3"
 
public Plugin myinfo =
{
    
name "TF2 Set Class",
    
author "Tylerst, Psyk0tik",
    
description "Sets a player's class.",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=141516"
};

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    if (
GetEngineVersion() != Engine_TF2)
    {
        
strcopy(errorerr_max"The \"TF2 Set Class\" supports Team Fortress 2 only.");

        return 
APLRes_SilentFailure;
    }

    return 
APLRes_Success;
}

ConVar g_cvChatg_cvLog;

public 
void OnPluginStart()
{    
    
LoadTranslations("common.phrases");

    
CreateConVar("sm_setclass_version"PLUGIN_VERSION"Set the target(s) class, Usage: sm_setclass \"target\" \"class\""FCVAR_DONTRECORD|FCVAR_NOTIFY);
    
g_cvChat CreateConVar("sm_setclass_chat""1""Show admin activity relevant to the plugin?\n0: OFF\n1: ON"_true0.0true1.0);
    
g_cvLog CreateConVar("sm_setclass_log""1""Log admin activity relevant to the plugin?\n0: OFF\n1: ON"_true0.0true1.0);

    
RegAdminCmd("sm_setclass"cmdSetclassADMFLAG_SLAY"Usage: sm_setclass \"target\" \"class\"");    
}

public 
Action cmdSetclass(int clientint args)
{
    switch (
args)
    {
        case 
12:
        {
            
char target[32], target_name[32], type[32];
            
int target_list[MAXPLAYERS], target_count;
            
bool tn_is_ml;
            
GetCmdArg(1targetsizeof target);

            if (
args == 2)
            {
                
GetCmdArg(2typesizeof type);
            }

            if ((
target_count ProcessTargetString(targetclienttarget_listMAXPLAYERS0target_namesizeof target_nametn_is_ml)) <= 0)
            {
                
ReplyToTargetError(clienttarget_count);

                return 
Plugin_Handled;
            }

            for (
int iPlayer 0iPlayer target_countiPlayer++)
            {
                
vSwitchClass(clienttarget_list[iPlayer], (args == type "random"));
            }
        }
        default: 
ReplyToCommand(client"[SM] Usage: sm_setclass <#userid|name> \"class\"");
    }

    return 
Plugin_Handled;    
}

static 
void vSwitchClass(int clientint target, const char[] type)
{
    
char sClass[32];
    
TFClassType tfClass;
    if (
StrEqual(type"scout"false))
    {
        
strcopy(sClasssizeof sClass"Scout");
        
tfClass TFClass_Scout;
    }
    else if (
StrEqual(type"soldier"false))
    {
        
strcopy(sClasssizeof sClass"Soldier");
        
tfClass TFClass_Soldier;
    }
    else if (
StrEqual(type"pyro"false))
    {
        
strcopy(sClasssizeof sClass"Pyro");
        
tfClass TFClass_Pyro;
    }
    else if (
StrEqual(type"demoman"false))
    {
        
strcopy(sClasssizeof sClass"Demoman");
        
tfClass TFClass_DemoMan;
    }
    else if (
StrEqual(type"heavy"false))
    {
        
strcopy(sClasssizeof sClass"Heavy");
        
tfClass TFClass_Heavy;
    }
    else if (
StrEqual(type"engineer"false))
    {
        
strcopy(sClasssizeof sClass"Engineer");
        
tfClass TFClass_Engineer;
    }
    else if (
StrEqual(type"medic"false))
    {
        
strcopy(sClasssizeof sClass"Medic");
        
tfClass TFClass_Medic;
    }
    else if (
StrEqual(type"sniper"false))
    {
        
strcopy(sClasssizeof sClass"Sniper");
        
tfClass TFClass_Sniper;
    }
    else if (
StrEqual(type"spy"false))
    {
        
strcopy(sClasssizeof sClass"Spy");
        
tfClass TFClass_Spy;
    }
    else if (
StrEqual(type"random"false))
    {
        
int iClass 0iClasses[9] = 0;
        for (
int iClassNum view_as<int>(TFClass_Scout); iClassNum <= view_as<int>(TFClass_Engineer); iClassNum++)
        {
            if (
TF2_GetPlayerClass(target) != view_as<TFClassType>(iClassNum))
            {
                
iClasses[iClass] = iClassNum;
                
iClass++;
            }
        }

        
strcopy(sClasssizeof sClass"Random");
        
tfClass view_as<TFClassType>(iClasses[GetRandomInt(0iClass 1)]);
    }
    else
    {
        
ReplyToCommand(client"[SM] Invalid class");

        return;
    }

    if (
target <= MaxClients && IsClientInGame(target) && !IsClientInKickQueue(target))
    {
        
TF2_SetPlayerClass(targettfClass);

        if (
IsPlayerAlive(target))
        {
            
SetEntityHealth(target25);
            
TF2_RegeneratePlayer(target);

            
int iWeapon GetPlayerWeaponSlot(targetTFWeaponSlot_Primary);
            if (
IsValidEntity(iWeapon))
            {
                
SetEntPropEnt(targetProp_Send"m_hActiveWeapon"iWeapon);
            }
        }

        if (
g_cvChat.BoolValue)
        {
            
ShowActivity2(client"\x01[SM] ","Set class of\x04 %N\x01 to\x03 %s\x01."targetsClass);
        }

        if (
g_cvLog.BoolValue)
        {
            
LogAction(clienttarget"\"%L\" set class of \"%L\" to \"%s.\""clienttargetsClass);
        }
    }

Attached Files
File Type: sp Get Plugin or Get Source (TF2 Set Class.sp - 251 views - 4.5 KB)
__________________
Psyk0tik is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-15-2019 , 12:07   Re: [TF2] Set Class
Reply With Quote #45

Crasher_3637, I tested your version and it works great. Thanks for sharing!
PC Gamer is offline
Stealth_101
Junior Member
Join Date: Oct 2019
Old 06-24-2020 , 04:39   Re: [TF2] Set Class
Reply With Quote #46

I found a glitch
ok i did a test

Say somone is a engie and they build there nest Sentry and dispenser etc if they get swapped class to say sniper there stuff is still there
Stealth_101 is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 07-04-2022 , 15:55   Re: [TF2] Set Class
Reply With Quote #47

Quote:
Originally Posted by Psyk0tik View Post
I've had a modified version of this plugin for a while. It does exactly what you're asking for.

Spoiler
Added MvM health bar icon support per this thread: https://forums.alliedmods.net/showthread.php?t=338125
Attached Files
File Type: sp Get Plugin or Get Source (TF2 Set Class.sp - 88 views - 4.8 KB)

Last edited by Sreaper; 07-07-2022 at 00:21.
Sreaper is offline
Trie1950gustrcom
Member
Join Date: Aug 2016
Old 07-07-2022 , 13:03   Re: [TF2] Set Class
Reply With Quote #48

Quote:
Originally Posted by Sreaper View Post
Added MvM health bar icon support per this thread: https://forums.alliedmods.net/showthread.php?t=338125
This crashes the server when the command is run.
Trie1950gustrcom is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 07-07-2022 , 14:48   Re: [TF2] Set Class
Reply With Quote #49

Quote:
Originally Posted by Trie1950gustrcom View Post
This crashes the server when the command is run.
What do the Sourcemod error logs print out? I compiled it on an older SM 1.11 build but it seems to be working fine on SourceMod 1.11.0.6905 (Linux). See video: https://puu.sh/J9Wdc/a47144a315.mp4

Last edited by Sreaper; 07-07-2022 at 14:59.
Sreaper is offline
Trie1950gustrcom
Member
Join Date: Aug 2016
Old 07-07-2022 , 17:14   Re: [TF2] Set Class
Reply With Quote #50

Quote:
Originally Posted by Sreaper View Post
What do the Sourcemod error logs print out? I compiled it on an older SM 1.11 build but it seems to be working fine on SourceMod 1.11.0.6905 (Linux). See video: https://puu.sh/J9Wdc/a47144a315.mp4
Doesn't seem to have anything in the logs about the plugin itself crashing.
Maybe it's my SourceMod version? ( sourcemod_version 1.10.0.6528 )

Last edited by Trie1950gustrcom; 07-07-2022 at 17:14.
Trie1950gustrcom is offline
Reply


Thread Tools
Display Modes

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 08:47.


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