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(iClient, Prop_Send, "m_iClassStatus") & 0x0000000F);
}
SetClassForClient
PHP Code:
SetClassForClient(iClient, iSlot)
{
SetEntProp(iClient, Prop_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(iClient, iArgs)
{
if(!iClient)
return;
if(!iArgs)
{
ReplyToCommand(iClient, "Enter a class number 1-10.");
return;
}
decl String:szClass[3];
GetCmdArg(1, szClass, sizeof(szClass));
new iClass = StringToInt(szClass);
if(iClass < 1 || 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(iClient, iClass);
}
GetClassSlot(iClient)
{
return (GetEntProp(iClient, Prop_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(iClient, iSlot)
{
SetEntProp(iClient, Prop_Send, "m_iClassStatus", iSlot & 0x0000000F);
}
ForceChangeClass(iClient, iClass)
{
// Make sure the team's class limits don't override the class we are trying to force to.
decl iOriginalClassLimit;
new iTeamManager = GetTeamManager(GetEntProp(iClient, Prop_Data, "m_iTeamNum"));
if(iTeamManager)
{
iOriginalClassLimit = GetEntProp(iTeamManager, Prop_Send, "m_iClasses", _, iClass);
SetEntProp(iTeamManager, Prop_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(iTeamManager, Prop_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(iEnt, Prop_Send, "m_iTeamNum");
if(iTeamNum >= sizeof(iTeamManagers))
continue;
iTeamManagers[iTeamNum] = iEnt;
}
bHasManagers = true;
}
return iTeamManagers[iTeam];
}