Skip to content

Commit

Permalink
show new leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
McDiod committed Jan 25, 2017
1 parent 2bed503 commit 1833fda
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 21 deletions.
3 changes: 3 additions & 0 deletions functions/cfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class mcd {
file = functions;
class addGear {};
class addKilledEH {};
class compileForGRADScoreboard {};
class endingCeremony {};
class endMission {};
class findGreatestNum {};
Expand All @@ -18,9 +19,11 @@ class mcd {
class scoreBoard {};
class setScore {};
class showCamper {};
class showGRADScoreboard {};
class skipVote {};
class strToVar {};
class teleport {};
class updateLeaderboard {};
class updateVotesMarker {};
class upgradeWeapon {};
class upgradeWeaponTitle {};
Expand Down
10 changes: 10 additions & 0 deletions functions/fn_compileForGRADScoreboard.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
params ["_stats"];

_compiledStats = [["NAME","K/D","GAMES","POINTS"]];
{
_x params ["_points","_UID","_name","_playerStats"];
_playerStats params ["_kills","_deaths","_games"];
_compiledStats pushBack [_name,(round ((_kills/_deaths)*100))/100,_games,round _points];
} forEach _stats;

_compiledStats
30 changes: 15 additions & 15 deletions functions/fn_endingCeremony.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Plays game end procedure
/* Plays game end procedure
*
* remote executed by server via server\endGame.sqf
* remote executed by server via server\endGame.sqf
*/

if (!hasInterface) exitWith {};
Expand All @@ -10,19 +10,19 @@ GAMEENDED = true;

//respawn player instantly if dead
if (!alive player) then {
_camera = player getVariable "killCam";
if (!isNil "_camera") then {
_killCamHandle = (player getVariable ["killCamHandle", [scriptNull]]) select 0;
terminate _killCamHandle;
camDestroy _camera;
showCinemaBorder false;
};

iJustSpawned = true;
setPlayerRespawnTime 0;
forceRespawn player;
waitUntil {alive player};
cutText ["", "BLACK IN", 0.5];
_camera = player getVariable "killCam";
if (!isNil "_camera") then {
_killCamHandle = (player getVariable ["killCamHandle", [scriptNull]]) select 0;
terminate _killCamHandle;
camDestroy _camera;
showCinemaBorder false;
};

iJustSpawned = true;
setPlayerRespawnTime 0;
forceRespawn player;
waitUntil {alive player};
cutText ["", "BLACK IN", 0.5];
};

player allowDamage false;
Expand Down
15 changes: 15 additions & 0 deletions functions/fn_showGRADScoreboard.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
params ["_serverStats"];

_kills = player getVariable ["kills", 0];
_deaths = player getVariable ["deaths", 0];
_kd = (_kills max 1) / (_deaths max 1);
_longestKill = (round ((player getVariable ["longestKill", 0])*10)) / 10;
_distanceMoved = round (player getVariable ["totalDistance", 0]);


_myStats = [
["KILLS","DEATHS","K/D","LONGEST KILL","DISTANCE MOVED"],
[_kills,_deaths,(round (_kd*100))/100,format ["%1m",round _longestKill],format ["%1m",_distanceMoved]]
];

[20,_compiledStats,"GAME OF GUNS LEADERBOARD",false,_myStats,"MY STATS THIS GAME",false,false] call grad_scoreboard_fnc_loadScoreboard;
137 changes: 137 additions & 0 deletions functions/fn_updateLeaderboard.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
_stats = profileNameSpace getVariable "mcd_gameofguns_stats";
if (isNil "_stats") exitWith {"ERROR: STATS NOT FOUND IN SERVER PROFILENAMESPACE."};


//UPDATE STATS =================================================================
{
_playerUID = _x;
_ID = [_stats, _playerUID, 1] call mcd_fnc_findStringInArray;
if (_ID == -1) then {
diag_log format ["updateLeaderboard.sqf - ERROR: COULD NOT FIND PLAYER %1 DURING UPDATE.", name _x];
} else {
_playerArray = _stats select _ID;
_playerStats = _playerArray select 3;

//name
_playerUnit = [_playerUID] call BIS_fnc_getUnitByUID;
if (!isNull _playerUnit) then {
_newName = name _playerUnit;
if (_newName != "Error: No vehicle" && _newName != "Error: No unit") then {
_playerArray set [2, _newName];
};
};

//kills
_oldKills = _playerStats select 0;
_playerStats set [0, _oldKills + (_playerUnit getVariable ["kills",0])];
diag_log format ["updateLeaderboard.sqf - Player %1 scored %2 kills this game.", name _playerUnit, _playerUnit getVariable ["kills",0]];

//deaths
_oldDeaths = _playerStats select 1;
_playerStats set [1, _oldDeaths + (_playerUnit getVariable ["deaths", 0])];
diag_log format ["updateLeaderboard.sqf - Player %1 died %2 times this game.", name _playerUnit, _playerUnit getVariable ["deaths", 0]];

//games
_oldGames = _playerStats select 2;
_playerStats set [2, _oldGames + 1];
diag_log format ["updateLeaderboard.sqf - Player %1 now has a total of %2 games.", name _playerUnit, _playerStats select 3];
};
} forEach ALLPLAYERUIDS;

diag_log "updateLeaderboard.sqf - Stats have been updated. Here is the new array:";
diag_log "NAME, KILLS, DEATHS, GAMES ===========================================";
{
diag_log str _x;
} forEach _stats;
diag_log "======================================================================";


//UPDATE POINTS ================================================================
//CURRENTRANKING: [score, group displayname, groupname, [groupmemberUID, groupmemberUID, ...]]

//get average elo of all teams
_eloArray = [];
_memberPoints = 100;
{
_groupArray = _x;
_groupMemberUIDs = _groupArray select 3;
_totalPoints = 0;
{
_memberUID = _x;
_pointsID = [_stats, _memberUID, 1] call mcd_fnc_findStringInArray;
if (_pointsID == -1) then {
diag_log format ["updateLeaderboard.sqf - ERROR: COULD NOT FIND %1 POINTS.", _memberUID];
_memberPoints = 100;
} else {
_memberPoints = (_stats select _pointsID) select 0;
diag_log format ["updateLeaderboard.sqf - Group %1: Player %2 currently has %3 points.", _groupArray select 0, _memberUID, _memberPoints];
};
_totalPoints = _totalPoints + _memberPoints;
} forEach _groupMemberUIDs;

_averagePoints = _totalPoints / (count _groupMemberUIDs);
_eloArray pushBack _averagePoints;

diag_log format ["updateLeaderboard.sqf - Team %1 has an average of %2 points.", _groupArray select 1, _averagePoints];
} forEach CURRENTRANKING;

//update elo for all players
{
_playerUID = _x;
_playerUnit = [_playerUID] call BIS_fnc_getUnitByUID;
_playerEloGain = 0;
_playerEloIndex = [_stats, _playerUID, 1] call mcd_fnc_findStringInArray;
if (_playerEloIndex == -1) exitWith {diag_log format ["updateLeaderboard.sqf - ERROR: COULD NOT FIND %1 POINTS.", name _playerUnit]};
_playerStats = _stats select _playerEloIndex;
_playerElo = _playerStats select 0;

_rankIndex = [CURRENTRANKING, _playerUID, 3] call mcd_fnc_findStringInArray;
if (_rankIndex == -1) exitWith {diag_log format ["updateLeaderboard.sqf - ERROR: COULD NOT FIND %1 IN CURRENTRANKING.", name _playerUnit]};

//negative points
for [{_i=0}, {_i<_rankIndex}, {_i=_i+1}] do {
_otherPlayerElo = _eloArray select _i;
_playerEloGain = _playerEloGain - (_playerElo/_otherPlayerElo);
};

//positive points
for [{_i=_rankIndex+1}, {_i<(count _eloArray)}, {_i=_i+1}] do {
_otherPlayerElo = _eloArray select _i;
_playerEloGain = _playerEloGain + (_otherPlayerElo/_playerElo);
};

//elo gain factor
_playerEloGain = _playerEloGain * 2;

diag_log format ["updateLeaderboard.sqf - Player %1 gained %2 points this game for a new total of %3.", name _playerUnit, _playerEloGain, _playerElo + _playerEloGain];
_playerUnit setVariable ["eloThisGame", _playerEloGain, true];
_playerStats set [0, (_playerElo + _playerEloGain) max 0];
} forEach ALLPLAYERUIDS;


//SORT =========================================================================
_allAbove = [];
_allBelow = [];
{
if ((_x select 3) select 2 < SCORETHRESHOLD) then {
_allBelow pushBack _x;
} else {
_allAbove pushBack _x;
};
} forEach _stats;
_allAbove sort false;
_allBelow sort false;
_stats = _allAbove + _allBelow;

//SAVE AND RETURN ==============================================================
diag_log "updateLeaderboard.sqf - Points have been updated. Here is the new array:";
diag_log "NAME, POINTS =========================================================";
{
diag_log str _x;
} forEach _stats;
diag_log "======================================================================";

profileNamespace setVariable ["mcd_gameofguns_stats",_stats];
saveProfileNamespace;

_stats
2 changes: 2 additions & 0 deletions initServer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SPAWNGROUPMINDIST = 50;
STARTDISTTOLEADER = 30;
SPAWNDISTTOLEADER = [50,100];
VOTINGTIME = 60;
SCORETHRESHOLD = 5;

VOTINGDONE = false;
GAMEENDED = false;
Expand All @@ -54,6 +55,7 @@ publicVariable "SPAWNGROUPMINDIST";
publicVariable "STARTDISTTOLEADER";
publicVariable "SPAWNDISTTOLEADER";
publicVariable "VOTINGTIME";
publicVariable "SCORETHRESHOLD";
publicVariable "VOTINGDONE";
publicVariable "GAMEENDED";

Expand Down
12 changes: 6 additions & 6 deletions server/endGame.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ params ["_winner"];

//update stats
_startTime = serverTime;
/*_updateStats = [] execVM "server\updateLeaderboard.sqf";*/
waitUntil {scriptDone _updateStats};
sleep ((10 - (serverTime - _startTime)) max 0);
_stats = [] call mcd_fnc_updateLeaderboard;
_compiledStats = [_stats] call mcd_fnc_compileForGRADScoreboard;

//show leaderboard on clients
/*[GOGSTATS] remoteExec ["mcd_fnc_showLeaderboard", 0, false];*/
//show on clients
[_compiledStats] remoteExec ["mcd_fnc_showGRADScoreboard",0,false];

sleep 27;
//end mission
sleep 24;
[_winner] remoteExec ["mcd_fnc_endMission",0,false];

0 comments on commit 1833fda

Please sign in to comment.