Jump to content
Michael Marsh

Find highest kill count player

Recommended Posts

Hello,

 

Could someone please help me to retrieve the person at the top of the scoreboard, or the player who has the most kills?

 

_myscores = getPlayerScores player;
_myscore = _myscores # 0;
 

 

This gives me my own personal kills, but I would like to know who has the highest so I can display their name and kills.

 

I have tried messing around with this snippet of code, but I am stuck. I just need the rest.

 

_players = allPlayers apply {[getPlayerScores _x param [5, 0], _x]};

Share this post


Link to post
Share on other sites
_scores = allPlayers apply{ [ getPlayerScores _x param[5,0], name _x ] };
_scores sort true;
hint format[ "%1 has the highest score of %2", _scores #0#1, _scores #0#0 ];

If the top score is tied then the top player will be sorted by name.

  • Like 3

Share this post


Link to post
Share on other sites
On 9/19/2019 at 3:23 PM, Larrow said:

_scores = allPlayers apply{ [ getPlayerScores _x param[5,0], name _x ] };
_scores sort true;
hint format[ "%1 has the highest score of %2", _scores #0#1, _scores #0#0 ];

If the top score is tied then the top player will be sorted by name.

 

@Larrow can't get this to work properly, its very inconsistent with which player gets displayed. Top scoring player not always the one to be displayed, can you give me any advise on if I'm doing things in the correct way ? Thanks.

 

Highest scorer preprocessFile functions.sqf

Spoiler

//// SET HIGHEST SCORER TEXT \\\\
_highest_scorer_text = {
    params ["_text"];
    if (isNull (uiNameSpace getVariable "RscStatusBar")) exitWith {true};
    ((uiNameSpace getVariable "RscStatusBar") displayCtrl 520522) ctrlSetText _text;
};

 

//// HIGHEST SCORER LOOP \\\\
fnc_highest_scorer = {
    while {true} do {
        private ["_array","_score","_name","_text"];
        _allPlayers = call BIS_fnc_listPlayers;
        _array = _allPlayers apply {[getPlayerScores _x param [5,0], name _x]};
        _array sort true;
        _score = _array #0#0;
        _name = _array #0#1;
        if (_score > 0) then {
            _text = format ["%1 has the highest score of %2", _name, _score];
            [_text] remoteExec ["fnc_highest_scorer_text", 0];
        };
        sleep 1;
    };
};

 

Mission int.sqf.

Spoiler

call compile preprocessFileLineNumbers "functions.sqf";

 

if (isServer) then {
    [] spawn fnc_highest_scorer; // Get highest scorer loop
};

 

Share this post


Link to post
Share on other sites

Code looks ok (remoteExec every second? Maybe only remoteExec if the top scorer/score has changed).

Would need debugging, outputting getPlayerScores and comparing it to what you think it should be, see if there is a noticeable difference. Are you using any custom scoring ie addScore etc.

I don't have the time right now to play about with it.

  • Thanks 1

Share this post


Link to post
Share on other sites
8 hours ago, Larrow said:

Code looks ok (remoteExec every second? Maybe only remoteExec if the top scorer/score has changed).

Would need debugging, outputting getPlayerScores and comparing it to what you think it should be, see if there is a noticeable difference. Are you using any custom scoring ie addScore etc.

I don't have the time right now to play about with it.

 

@Larrow Thanks mate I changed my code and got it working thanks for your advise.

 

functions.sqf

Spoiler

//// SET HIGHEST SCORER TEXT \\\\
_highest_scorer_text = {
    params ["_name","_score"];
    if (isNull (uiNameSpace getVariable "RscStatusBar")) exitWith {true};
    private _text = format ["%1 has the highest score of %2", _name, _score];
    ((uiNameSpace getVariable "RscStatusBar") displayCtrl 520522) ctrlSetText _text;
};

//// HIGHEST SCORER LOOP \\\\
fnc_highest_scorer = {
    private ["_arrayC","_allplayers","_arrayA","_arrayB","_score","_name"];
    _arrayC = [];
     while {true} do {
        _allplayers = call BIS_fnc_listPlayers;
        _arrayA = _allplayers apply {[getPlayerScores _x param [5,0], name _x]};
        _arrayA = [_arrayA, [], {_x#0}, "DESCEND"] call BIS_fnc_sortBy;
        _arrayB = _arrayA#0;
        _score = _arrayB#0;
        _name = _arrayB#1;
         if (!(_arrayB isEqualTo _arrayC) and (_score > 0)) then {
            [_name,_score] remoteExec ["fnc_highest_scorer_text", 0];
            _arrayC = _arrayB;
        };
        sleep 1;
    };
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×