-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboard.cs
94 lines (76 loc) · 2.29 KB
/
leaderboard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function clearLeaderboardBricks() {
for(%i=1;%i<=26;%i++) {
%brick = "_leaderboard_" @ %i;
%brick.setPrintText("",1);
}
}
function addToLeaderboard(%client) {
// $Platforms::Leaderboard[pos,[name,amount]]
if(!isObject(PlatformsLeaderboard)) {
// awaiting the day to see http://www.garagegames.com/community/resources/view/4711 added
new GuiTextListCtrl(PlatformsLeaderboard);
}
%list = PlatformsLeaderboard;
%data = %list.getRowTextByID(%client.bl_id);
if(%data $= "") {
%list.addRow(%client.bl_id, %client.name @ "\t" @ (%client.totalscore || 0) @ "\t" @ %client.bl_id);
} else {
%list.setRowByID(%client.bl_id, %client.name @ "\t" @ (%client.totalscore || 0) @ "\t" @ %client.bl_id);
}
%list.sortNumerical(1, 0);
switch(%list.getRowNumByID(%client.bl_id)) {
case 0:
%client.awardAchievement("A07");
case 1:
%client.awardAchievement("A08");
case 2:
%client.awardAchievement("A09");
}
}
function PlatformsLeaderboard::saveLeaderboard(%this) {
%filename = "config/server/Platforms/leaderboard.db";
%file = new FileObject();
%file.openForWrite(%filename);
for(%i=0;%i<%this.rowCount();%i++) {
%file.writeLine(%this.getRowText(%i));
}
%file.close();
%file.delete();
}
function loadLeaderboard(%this) {
if(isObject(PlatformsLeaderboard)) {
return;
} else {
new GuiTextListCtrl(PlatformsLeaderboard);
}
%filename = "config/server/Platforms/leaderboard.db";
%file = new FileObject();
%file.openForRead(%filename);
%list = PlatformsLeaderboard;
while(!%file.isEOF()) {
%line = %file.readLine();
%id = getField(%line, 2);
%score = getField(%line, 1);
if(%id $= "" || %score $= "") {
continue;
}
%list.addRow(%id, %line);
}
%file.close();
%file.delete();
%list.sortNumerical(1, 0);
}
package PlatformsLeaderboardPackage {
function GameConnection::onDeath(%this,%obj,%killer,%type,%area) {
if(!isObject(%this.player)) {
return parent::onDeath(%this,%obj,%killer,%type,%area);
}
if(!%this.player.inGame) {
return parent::onDeath(%this,%obj,%killer,%type,%area);
}
addToLeaderboard(%this);
%this.clanPrefix = "\c7[\c5" @ getPositionString(PlatformsLeaderboard.getRowNumByID(%this.bl_id)+1) @ "\c7]" SPC %this.original_prefix;
return parent::onDeath(%this,%obj,%killer,%type,%area);
}
};
activatePackage(PlatformsLeaderboardPackage);