The code can exclude player classes, skins, and voice packs either by PackageName.Element or by its description in the .int file.
Useful to randomize a player if he's using an illegal class/skin, or a default one (not installed on server).
Code: Select all
var config string ExcludedClasses[24];
var config string ExcludedSkins[24];
var config string ExcludedVoices[24];
function GenerateRandom()
{
local class<PlayerPawn> theClass;
local string rSkin, rFace, rVoice;
theClass = RandomPlayerClass();
rSkin = RandomPlayerSkin( theClass);
rFace = RandomPlayerFace( theClass, rSkin);
rVoice = RandomPlayerVoice( theClass);
//Do something else with this
}
final function class<PlayerPawn> RandomPlayerClass()
{
local int NumPlayerClasses, i;
local string NextPlayer, NextDesc, sCurrent;
local float Factor;
Factor = 1.0;
GetNextIntDesc( "BotPack.TournamentPlayer", 0, NextPlayer, NextDesc);
while( (NextPlayer != "") && (NumPlayerClasses < 64) )
{
if ( FRand() * Factor < 1.0 )
{
//Faster if exclusion check is done here
For ( i=0 ; (i<24)&&(ExcludedClasses[i]!="") ; i++ )
if ( (ExcludedClasses[i] ~= NextPlayer) || (ExcludedClasses[i] ~= NextDesc) )
Goto EXCLUSION;
sCurrent = NextPlayer;
}
EXCLUSION:
if ( sCurrent != "")
Factor += 1.0;
NumPlayerClasses++;
GetNextIntDesc("BotPack.TournamentPlayer", NumPlayerClasses, NextPlayer, NextDesc);
}
return class<PlayerPawn>( DynamicLoadObject( sCurrent, class'Class') );
}
final function string RandomPlayerSkin( class<PlayerPawn> TheClass )
{
local string SkinName, SkinDesc, TestName, Temp, ASkin, result;
local int i;
local float Factor;
Factor = 1.0;
SkinName = "None";
TestName = "";
while ( True )
{
SKIN_EXCLUSION:
GetNextSkin( GetItemName(string(TheClass.Default.Mesh)), SkinName, 1, SkinName, SkinDesc);
if( SkinName == TestName )
break;
if( TestName == "" )
TestName = SkinName;
// Multiskin format
if( SkinDesc != "")
{
Temp = GetItemName(SkinName);
if(Mid(Temp, 5, 64) == "")
{
// This is a skin
if ( FRand() * Factor < 1.0 )
{
ASkin = Left(SkinName, Len(SkinName) - Len(Temp)) $ Left(Temp, 4);
For ( i=0 ; (i<24)&&(ExcludedSkins[i]!="") ; i++ )
if ( (ExcludedSkins[i] ~= ASkin) || (ExcludedSkins[i] ~= SkinDesc) )
Goto SKIN_EXCLUSION;
result = ASkin;
}
if ( result != "" )
Factor += 1.0;
}
}
}
return result;
}
final function string RandomPlayerFace( class<PlayerPawn> TheClass, string InSkinName)
{
local string SkinName, SkinDesc, TestName, Temp, result;
local float Factor;
Factor = 1.0;
SkinName = "None";
TestName = "";
while ( True )
{
GetNextSkin( GetItemName(string(TheClass.Default.Mesh)), SkinName, 1, SkinName, SkinDesc);
if( SkinName == TestName )
break;
if( TestName == "" )
TestName = SkinName;
// Multiskin format
if( SkinDesc != "")
{
Temp = GetItemName(SkinName);
if(Mid(Temp, 5) != "" && Left(Temp, 4) == GetItemName(InSkinName))
{ if ( FRand() * Factor < 1.0 )
{
result = Left(SkinName, Len(SkinName) - Len(Temp)) $ Mid(Temp, 5);
}
if ( result != "" )
Factor += 1.0;
}
}
}
return result;
}
final function string RandomPlayerVoice( class<PlayerPawn> TheClass)
{
local int NumVoices, i;
local string NextVoice, NextDesc, result;
local string VoicepackMetaClass;
local float Factor;
Factor = 1.0;
if(ClassIsChildOf(TheClass, class'TournamentPlayer'))
VoicePackMetaClass = class<TournamentPlayer>(TheClass).default.VoicePackMetaClass;
else
VoicePackMetaClass = "Botpack.ChallengeVoicePack";
// Load the base class into memory to prevent GetNextIntDesc crashing as the class isn't loadded.
DynamicLoadObject(VoicePackMetaClass, class'Class');
GetNextIntDesc(VoicePackMetaClass, 0, NextVoice, NextDesc);
while( (NextVoice != "") && (NumVoices < 64) )
{
if ( FRand() * Factor < 1.0 )
{
For ( i=0 ; (i<24)&&(ExcludedVoices[i]!="") ; i++ )
if ( (ExcludedVoices[i] ~= NextVoice) || (ExcludedVoices[i] ~= NextDesc) )
Goto VOICE_EXCLUSION;
result = NextVoice;
}
if ( result != "" )
Factor += 1.0;
VOICE_EXCLUSION:
NumVoices++;
GetNextIntDesc(VoicePackMetaClass, NumVoices, NextVoice, NextDesc);
}
return result;
}