-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDictionarySort.as
57 lines (48 loc) · 1.43 KB
/
DictionarySort.as
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
dictionary mydict={
{"map1",15},
{"map2",14},
{"map3",30},
{"map4",20}
};
CClientCommand sortDict( "sortDict", "Dictionary sort test", @DoTheThing );
void PluginInit(){
g_Module.ScriptInfo.SetAuthor("MrOats");
g_Module.ScriptInfo.SetContactInfo("N/A");
}
void DoTheThing(const CCommand@ args){
dictionary meh=PostVote(mydict);
array<string> mehkeys=meh.getKeys();
g_PlayerFuncs.ShowMessageAll(""+int(mydict["map"]));
}
dictionary PostVote(dictionary votedmaps){
uint length=votedmaps.getSize();
array<int> myvalues(length);
array<int> sortedvalues(length);
array<string> mykeys=votedmaps.getKeys();
//Fill array of keys with dictionary keys
for (uint i = 0; i < length; i++) {
myvalues[i]=int(votedmaps[mykeys[i]]);
}
array<string> mykeys_dictorder(length);
//Organize mykeys to match order of Dictionary
for (uint i = 0; i < length; i++) {
for (uint x = 0; x < length; x++) {
if(votedmaps.get(mykeys[i],myvalues[x])){
mykeys_dictorder[i]=mykeys[i];
}
}
}
sortedvalues=myvalues;
sortedvalues.sortDesc();
//Begin sorting
for (uint i = 0; i < myvalues.length(); i++){
for (uint x = 0; x < length; x++){
if (int(votedmaps[mykeys_dictorder[i]])==myvalues[x]) {
votedmaps.set(mykeys_dictorder[i],sortedvalues[x]);
myvalues.removeAt(x);
length--;
}
}
}
return votedmaps;
}