PDA

View Full Version : [SNIPPET] Find the best hud channel to use


Sammy-ROCK!
12-19-2009, 17:58
stock FindBestHudChannel()
{
new EntsUsingChannel[4] = {0, ...};//Track game_text entities and get the channel their set to use.
new MaxEntities = GetMaxEntities();
for(new Entity=MaxPlayers+1; Entity<=MaxEntities; Entity++)
{
if(!IsValidEntity(Entity) || !IsValidEdict(Entity))
continue;
decl String:ClassName[10]; //game_text is 9 bytes so we need 10 to get it fully
GetEdictClassname(Entity, ClassName, sizeof(ClassName));
if(StrEqual(ClassName, "game_text", false))
EntsUsingChannel[GetEntData(Entity, FindDataMapOffs(Entity, "m_textParms.channel")) - 1]++;//-1 so we don't need increase the array size just to keep it justified
}
new BestChannel = 1;
//Starts with channel 1 then check if other channels have less entities using.
if(EntsUsingChannel[1] < EntsUsingChannel[BestChannel-1])
BestChannel = 2;
if(EntsUsingChannel[2] < EntsUsingChannel[BestChannel-1])
BestChannel = 3;
if(EntsUsingChannel[3] < EntsUsingChannel[BestChannel-1])
BestChannel = 4;
return BestChannel; //Tells the best channel
}

This returns the hud channel that fewer used on the map. To cause the minimum of interference against the map's huds.