Mutators & UnrealScript

How to find out the average perk level of all players in the game

Support Specialist perk art Support Specialist, the shotgun and welding perk.

function bool TeamIsStrong()
{
    local Controller C;
    local int levelSum;
    local int N;
    for( C = Level.ControllerList; C != None; C = C.nextController )
    {
        if( C.IsA('PlayerController') && C.Pawn!=None && C.PlayerReplicationInfo.PlayerID>0 && C.Pawn.Health>0)
        {
            levelSum+=KFPlayerReplicationInfo(C.PlayerReplicationInfo).ClientVeteranSkillLevel;
            N++;
        }
    }
    if(levelSum/N>=11) return true;
    return false;
}

If on the client, then it’s much better to use

var() array<PlayerReplicationInfo> PRIArray;

from GameReplicationInfo

If this is some kind of GUI element, then you can do this

local GameReplicationInfo GRI;
local PlayerReplicationInfo PRI;
GRI = PlayerController(PlayerOwner()).GameReplicationInfo;
for ( i = 0; i < GRI.PRIArray.Length; i++)
{
    PRI = GRI.PRIArray[i];
    ...
}

If this is SRScoreBoard, then there is already a GRI there (obtained from the great-great-grandparent of ScoreBoard from Engine) If not GUI, then the local controller can be obtained from here: Level.GetLocalPlayerController()

Why a dedicated server shows 0.0

From the "KFPlayerReplicationInfo" thread on the killingfloor.ru forum. Dr_Killjoy's calculation worked on a listen server but always showed 0.0 on a dedicated one: the function was called from the scoreboard but ran in the game type. Flame explained that if the function is called on the server and the client needs the result, replication is unavoidable; on the client it is better to take the data from GRI.PRIArray. The conclusion Dr_Killjoy posted at the end of the thread: if a function is replicated, it always returns zero, so only non-replicated functions should be used for calculations.

For reference, the inheritance chain: Actor -> Info -> ReplicationInfo -> PlayerReplicationInfo -> TeamPlayerReplicationInfo -> xPlayerReplicationInfo -> KFPlayerReplicationInfo, so KFPlayerReplicationInfo is an Actor and can be iterated with DynamicActors.