View Single Post
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 11-28-2017 , 05:02   Re: [H3LP] PlayerClass Fortress Forever
Reply With Quote #3

You will want to use "m_iClassStatus". But that won't work to set the class, so read all to the end.

GetClassSlot
PHP Code:
GetClassSlot(iClient)
{
    return (
GetEntProp(iClientProp_Send"m_iClassStatus") & 0x0000000F);

SetClassForClient
PHP Code:
SetClassForClient(iClientiSlot)
{
    
SetEntProp(iClientProp_Send"m_iClassStatus"iSlot 0x0000000F);

However, because "m_iNextClass" is not changed the server will put you back to your original class. The variable "m_iNextClass" is what ultimately decides what class you will be when you respawn. The problem is "m_iNextClass" is not accessible through netprops or datamaps. The easiest solution in your case would be to simply force the player to call the "ChangeClass" function. We do this by force using the "class" console command.

Here is a simple plugin I whipped up so you can see how to change a client's class in Fortress-Forever.
PHP Code:
#include <sourcemod>
#include <sdktools_functions>

#pragma semicolon 1

new const String:PLUGIN_NAME[] = "Testing";
new const 
String:PLUGIN_VERSION[] = "1.0";

public 
Plugin:myinfo =
{
    
name PLUGIN_NAME,
    
author "hlstriker",
    
description "Testing.",
    
version PLUGIN_VERSION,
    
url "www.swoobles.com"
}

new const 
String:g_szClasses[][] =
{
    
"none",
    
"scout",
    
"sniper",
    
"soldier",
    
"demoman",
    
"medic",
    
"hwguy",
    
"pyro",
    
"spy",
    
"engineer",
    
"civilian"
};


public 
OnPluginStart()
{
    
RegConsoleCmd("sm_class"OnClass);
}

public 
Action:OnClass(iClientiArgs)
{
    if(!
iClient)
        return;
    
    if(!
iArgs)
    {
        
ReplyToCommand(iClient"Enter a class number 1-10.");
        return;
    }
    
    
decl String:szClass[3];
    
GetCmdArg(1szClasssizeof(szClass));
    
    new 
iClass StringToInt(szClass);
    if(
iClass || iClass 10)
    {
        
ReplyToCommand(iClient"Enter a class number 1-10.");
        return;
    }
    
    
ReplyToCommand(iClient"Current class: %s. New class: %s"g_szClasses[GetClassSlot(iClient)], g_szClasses[iClass]);
    
ForceChangeClass(iClientiClass);
}

GetClassSlot(iClient)
{
    return (
GetEntProp(iClientProp_Send"m_iClassStatus") & 0x0000000F);
}

// It would be nice if we could simply use SetClassForClient, but we must use ForceChangeClass instead.
// This is here just for an example.
stock SetClassForClient(iClientiSlot)
{
    
SetEntProp(iClientProp_Send"m_iClassStatus"iSlot 0x0000000F);
}

ForceChangeClass(iClientiClass)
{
    
// Make sure the team's class limits don't override the class we are trying to force to.
    
decl iOriginalClassLimit;
    new 
iTeamManager GetTeamManager(GetEntProp(iClientProp_Data"m_iTeamNum"));
    if(
iTeamManager)
    {
        
iOriginalClassLimit GetEntProp(iTeamManagerProp_Send"m_iClasses"_iClass);
        
SetEntProp(iTeamManagerProp_Send"m_iClasses"99_iClass);
    }
    
    
// Force the client to change their class and instantly respawn them on the next frame.
    
FakeClientCommand(iClient"class %s"g_szClasses[iClass]);
    
    
// Put the team's class limits back to normal.
    
if(iTeamManager)
        
SetEntProp(iTeamManagerProp_Send"m_iClasses"iOriginalClassLimit_iClass);
}

GetTeamManager(iTeam)
{
    static 
iTeamManagers[6], bool:bHasManagers;
    
    if(
iTeam >= sizeof(iTeamManagers))
        return 
0;
    
    if(!
bHasManagers)
    {
        
decl iTeamNum;
        new 
iEnt = -1;
        while((
iEnt FindEntityByClassname(iEnt"ff_team_manager")) != -1)
        {
            
iTeamNum GetEntProp(iEntProp_Send"m_iTeamNum");
            if(
iTeamNum >= sizeof(iTeamManagers))
                continue;
            
            
iTeamManagers[iTeamNum] = iEnt;
        }
        
        
bHasManagers true;
    }
    
    return 
iTeamManagers[iTeam];


Last edited by hlstriker; 11-28-2017 at 16:24.
hlstriker is offline