· 6 years ago · Jun 16, 2019, 03:54 AM
1//===== Table: ===============================================
2/*
3CREATE TABLE IF NOT EXISTS `event_woe_rank` (
4 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
5 `aid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
6 `cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
7 `gid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
8 `char_name` VARCHAR(30) NOT NULL DEFAULT '',
9 `guild_name` VARCHAR(30) NOT NULL DEFAULT '',
10 `map` VARCHAR(30) NOT NULL DEFAULT '',
11 `woe_type` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
12 `status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
13 `todate` INT(11) UNSIGNED NOT NULL DEFAULT '0',
14 PRIMARY KEY (`id`)
15) ENGINE=MyISAM;
16*/
17//============================================================
18
19- script WoE_Kill_Counter FAKE_NPC,{
20
21OnInit:
22 // Ranking Limit
23 .Display_Limit = 10;
24
25 // List of Castle
26 setarray .woe_1$, "aldeg_cas", "gefg_cas", "payg_cas", "prtg_cas";
27 setarray .woe_2$, "arug_cas", "schg_cas";
28
29 for (.@i = 0; .@i < 2; .@i++) {
30 .@size = getarraysize(getd(".woe_"+(.@i + 1)+"$"));
31 if (.@size > 0) {
32 for (.@x = 0; .@x < .@size; .@x++) {
33 for (.@c = 1; .@c <= 5; .@c++)
34 setd(".map_"+getd(".woe_"+(.@i+1)+"$["+.@x+"]")+"0"+.@c+"_agit", (.@i+1));
35 }
36 }
37 }
38 bindatcmd("woerank",strnpcinfo(NPC_NAME_UNIQUE)+"::OnAtCommand",0,99);
39
40OnHour00:
41 .todate = atoi(gettimestr("%Y%m%d", 10));
42 end;
43
44OnPCKillEvent:
45 if (.woe_running) {
46 .@aid = getcharid(3);
47 .@cid = getcharid(0);
48 .@killedrid = killedrid;
49 .@map$ = strcharinfo(3);
50 .@gid = getcharid(2);
51 .@woe_type = getd(".map_"+.@map$+"_agit");
52
53 if (.@killedrid != .@aid && .@gid > 0 && .@woe_type) {
54 .@char_name$ = strcharinfo(0);
55 .@guild_name$ = strcharinfo(2);
56 .@sql$ = "INSERT INTO `event_woe_rank` (`aid`,`cid`,`gid`,`char_name`,`guild_name`,`map`,`woe_type`,`todate`) VALUES ("+.@aid+","+.@cid+","+.@gid+",'"+escape_sql(.@char_name$)+"','"+escape_sql(.@guild_name$)+"','"+escape_sql(.@map$)+"',"+.@woe_type+","+.todate+")";
57 query_sql(.@sql$);
58 }
59 }
60 end;
61
62OnAgitStart2:
63 .@woe_type++;
64OnAgitStart:
65 .@woe_type++;
66 query_sql("UPDATE `event_woe_rank` SET `status` = 2 WHERE `status` = 1 AND `woe_type` = "+.@woe_type);
67
68OnAgitEnd:
69OnAgitEnd2:
70 .woe_running = (agitcheck() || agitcheck2());
71 end;
72
73OnAtCommand:
74 .@todate = atoi(.@atcmd_parameters$[1]);
75
76 .@aid = -1;
77 .@cid = -1;
78 .@gid = -1;
79
80 if (compare(.@atcmd_parameters$[0], "me")) {
81 .@type = 1;
82 .@cid = getcharid(0);
83 }
84 else if (compare(.@atcmd_parameters$[0], "player")) {
85 .@type = 1;
86 }
87 else if (compare(.@atcmd_parameters$[0], "guild")) {
88 .@type = 2;
89 } else {
90 dispbottom "Usage: "+.@atcmd_command$+" <me|player|guild> <date>";
91 dispbottom "Example: "+.@atcmd_command$+" me";
92 dispbottom "Example: "+.@atcmd_command$+" player";
93 dispbottom "Example: "+.@atcmd_command$+" player 20181109";
94 dispbottom "Example: "+.@atcmd_command$+" guild";
95 dispbottom "Example: "+.@atcmd_command$+" guild 20181109";
96 end;
97 }
98 callsub(L_Rank, .@type, .@aid, .@cid, .@gid, .@woe_type, .@todate);
99 end;
100
101L_Rank:
102 .@type = getarg(0, 0);
103 .@aid = getarg(1, 0);
104 .@cid = getarg(2, 0);
105 .@gid = getarg(3, 0);
106 .@woe_type = getarg(4, 0);
107 .@todate = getarg(5, 0);
108
109 .@sql$ = "SELECT tbl.`char_name`,tbl.`guild_name`,COUNT(tbl.`id`) AS `kill` "
110 + "FROM `event_woe_rank` tbl "
111 + "WHERE ("
112 + "`status` = 1"
113 + " AND ("+.@aid+" = -1 OR ("+.@aid+" > 0 AND `aid` = "+.@aid+"))"
114 + " AND ("+.@cid+" = -1 OR ("+.@cid+" > 0 AND `cid` = "+.@cid+"))"
115 + " AND ("+.@gid+" = -1 OR ("+.@gid+" > 0 AND `gid` = "+.@gid+"))"
116 + " AND ("+.@woe_type+" <= 0 OR ("+.@woe_type+" > 0 AND `woe_type` = "+.@woe_type+"))"
117 + " AND ("+.@todate+" <= 0 OR ("+.@todate+" > 0 AND `todate` = "+.@todate+"))"
118 + ") "
119 + "GROUP BY "+(.@type == 2 ? "`gid`" : "`cid`")+" "
120 + "ORDER BY `kill` DESC "
121 + "LIMIT "+.Display_Limit;
122
123 .@size = query_sql(.@sql$, .@name$, .@guild_name$, .@killcount);
124
125 dispbottom sprintf("Top WoE %s Kills %s", .@type == 2 ? "Guild" : "Player", .@todate > 0 ? "(Date "+.@todate+")" : "" );
126 dispbottom "----------------------------";
127 if (.@size) {
128 for (.@i = 0; .@i < .@size; .@i++) {
129 dispbottom sprintf("%2d - %-24s - %5d", (.@i+1), (.@type == 2 ? .@guild_name$[.@i] : .@name$[.@i]), .@killcount[.@i]);
130 }
131 } else {
132 dispbottom "No record found.";
133 }
134 return;
135}