PDA

View Full Version : Plugin: Player Leaderboards (In-Game)


Akkadius
12-24-2013, 12:49 AM
Purpose:

To display an in-game leaderboards for players to see where they rank.

------------------------

I've had this code written for ages so the quality is so-so. But it definitely does what it needs to do. Feel free to modify if want.

------------------------

Required: Perl DBI - See Google for installing Perl DBI/DBD for Mysql, until I create an article explaining otherwise.
Required: plugin::LoadMysql(); - See thread HERE (http://www.eqemulator.org/forums/showthread.php?p=227039#post227039)
Required: Popup Window plugin utils
Required: Mysql table `cust_ext_leaderboards`

http://wiki.eqemulator.org/i?Module=Pastebin&Paste=BgtI3fWi

http://i.imgur.com/stzAiqT.png

Source Table:

-- ----------------------------
-- Table structure for cust_ext_leaderboards
-- ----------------------------
DROP TABLE IF EXISTS `cust_ext_leaderboards`;
CREATE TABLE `cust_ext_leaderboards` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`class` varchar(255) NOT NULL,
`race` varchar(255) NOT NULL,
`hp` int(11) NOT NULL,
`mana` int(11) NOT NULL,
`ac` int(11) NOT NULL,
`status` int(11) NOT NULL,
`aa` int(11) NOT NULL,
`level` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Usage Example:

sub EVENT_SAY{
if($text=~/hail/i){
quest::say("What do you want?");
quest::say(quest::saylink("I want to check my player leaderboards man!", 1));
}
if($text=~/leaderboards/i){
quest::say("Fine!");
}
# Plugin will match for 'player leaderboards' and display menu options, it will also respond to further saylinks
plugin::LeaderBoardsMenu($text);
}

Note: In order to actually have the players info collected, you have to insert the collection routine somewhere. I usually trigger it in EVENT_ENTERZONE of global_player.pl but you can do it however you want:

plugin::LeaderBoardsUpdate();

Plugin File: (Goes under /plugins folder)
Name: Leaderboards.pl

Options: You can set your website Magelo Path under LoadMageloPath, or you can put in javascript:; or # if you don't have a site.

Enjoy, let me know if you experience issues.

thepoetwarrior
12-24-2013, 07:14 AM
Note: In order to actually have the players info collected, you have to insert the collection routine somewhere. I usually trigger it in EVENT_ENTERZONE of global_player.pl



Nice Akkadius!

+1

I prefer to run the collection routine in this sub:

sub EVENT_CONNECT {}

That way code runs only 1 time when player logs in, instead of every time they zone.

That way it won't spam update the database each time a player dies or zones.

Nibiuno
02-24-2015, 08:24 PM
Is this still working? I installed everything, and queries are working. When I say 'player leaderboards' I get the text "Player Leaderboards" and a list of classes in saylink format. If I click any of the saylinks, nothing happens. If I manually type the trigger, nothing happens as well.

Im not sure if Im missing a plugin. I downloaded the popup_window_utils, DBI is working, and the database table is working and being populated.

Akkadius
02-25-2015, 01:26 AM
Is this still working? I installed everything, and queries are working. When I say 'player leaderboards' I get the text "Player Leaderboards" and a list of classes in saylink format. If I click any of the saylinks, nothing happens. If I manually type the trigger, nothing happens as well.

Im not sure if Im missing a plugin. I downloaded the popup_window_utils, DBI is working, and the database table is working and being populated.

Set quest logging and see if there are any errors? It could be that you are missing a plugin like you said.

I would download a fresh batch of plugins from the stickied SVN in the thread:

http://www.eqemulator.org/forums/showthread.php?t=32608

epilz
03-09-2015, 08:24 PM
I have tried this plugin, and I am running into the same issue that Nibiuno stated above. Verified DBI is working, the cust_ext_leaderboards is being populated correctly. The popup_windows_utils and leaderboards.pl are in the plugin folder. I get the saylinks for classes, but once I click one of them, nothing happens.

ghanja
03-09-2015, 08:37 PM
I have tried this plugin, and I am running into the same issue that Nibiuno stated above. Verified DBI is working, the cust_ext_leaderboards is being populated correctly. The popup_windows_utils and leaderboards.pl are in the plugin folder. I get the saylinks for classes, but once I click one of them, nothing happens.

Do you have quest logging on? Anything in the logs?

epilz
03-09-2015, 08:43 PM
yes I have logging set to 3, I can see the queries happening, but no errors

Akkadius
03-09-2015, 08:45 PM
I have tried this plugin, and I am running into the same issue that Nibiuno stated above. Verified DBI is working, the cust_ext_leaderboards is being populated correctly. The popup_windows_utils and leaderboards.pl are in the plugin folder. I get the saylinks for classes, but once I click one of them, nothing happens.

I'm sorry, but this reminds me of this:

reNvytfN820

THE GIRLS NEVER CAME.

I have to help someone quick but I will check into this plugin. Thanks for reporting.

epilz
03-09-2015, 08:47 PM
LMAO Akka, thanks

Akkadius
03-10-2015, 07:03 PM
Looking at this now

Akkadius
03-10-2015, 08:21 PM
OK, spent about an hour cleaning this up.

Replace Leaderboards.pl in your plugins folder with this code:

http://wiki.eqemulator.org/i?Module=Pastebin&Paste=BgtI3fWi

http://i.imgur.com/stzAiqT.png

Source Table:

-- ----------------------------
-- Table structure for cust_ext_leaderboards
-- ----------------------------
DROP TABLE IF EXISTS `cust_ext_leaderboards`;
CREATE TABLE `cust_ext_leaderboards` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`class` varchar(255) NOT NULL,
`race` varchar(255) NOT NULL,
`hp` int(11) NOT NULL,
`mana` int(11) NOT NULL,
`ac` int(11) NOT NULL,
`status` int(11) NOT NULL,
`aa` int(11) NOT NULL,
`level` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

epilz
03-10-2015, 08:43 PM
Thanks for the update. Copied the new code to Leaderboards.pl in my plugins folder and resourced my DB. Do not get the popup window, but that maybe because the cust_ext_leaderboards table has not been populated yet. I have the following in my global_player.pl file.

sub EVENT_ENTERZONE {
plugin::LeaderBoardsUpdate();
}

Akkadius
03-10-2015, 08:45 PM
Thanks for the update. Copied the new code to Leaderboards.pl in my plugins folder and resourced my DB. Do not get the popup window, but that maybe because the cust_ext_leaderboards table has not been populated yet. I have the following in my global_player.pl file.

sub EVENT_ENTERZONE {
plugin::LeaderBoardsUpdate();
}

Make sure you have the DiaWind plugin.

It has become apparent to me we need a decent way to update plugins because people are apparently downloading the wrong ones...

epilz
03-10-2015, 08:50 PM
Yup. I have it. I downloaded all the plugins from the repository. Check them daily to see if there are any new changes.

Here is the Diawind.pl plugin.

#::: Author: Akkadius
#::: This plugin can work as an extensive drop in replacement for quest::say
#::: This plugin also offers extensive options for easily formatting windows.
#::: Usage: plugin::DiaWind("Window text");
#::: For explanation of use, see: http://wiki.eqemulator.org/p?The_DiaWind_Plugin&frm=Perl_Plugins_Master_Reference

sub DiaWind {
my $Text = $_[0]; my $npc = plugin::val('$npc'); $client = plugin::val('$client'); $name = plugin::val('$name');
my $Opt = 0;
if(!$PopId){ $PopId = 999; }
$Text=~ s/~/<\/c>/g;
$Text=~ s/\{y\}/<c \"#CCFF33\">/g;
$Text=~ s/\{lb\}/<c \"#00FFFF\">/g;
$Text=~ s/\{r}/<c \"#FF0000\">/g;
$Text=~ s/\{g}/<c \"#00FF00\">/g;
$Text=~ s/\{gold}/<c \"#FFFF66\">/g;
$Text=~ s/\{orange}/<c \"#FFA500\">/g;
$Text=~ s/\{gray}/<c \"#808080\">/g;
$Text=~ s/\{tan}/<c \"#daa520\">/g;
$Text=~ s/\{bullet}/•/g;
$Text=~ s/\$name/$name/g;
$Text=~ s/\{linebreak}/--------------------------------------------------------------------/g;
$Text=~ s/\{rowpad}/<tr><td>{tdpad}<\/td><td>{tdpad}<\/td><\/tr>/g;
$Text=~ s/\{tdpad}/----------------------/g;
$Text=~ s/\{in}/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/g;
my ($mvoice) = $Text =~ s/mysterious//g;
my ($achievement) = $Text =~ s/achievement//g;
my ($noquotes) = $Text =~ s/noquotes//g; if($noquotes){ $quo = ""; } else{ $quo = "'"; }
my ($nobracket) = $Text =~ s/nobracket//g;
my ($nosound) = $Text =~ s/nosound//g;
my ($cname) = $Text =~ /{(.*)\>/; $Text =~ s/{$cname\>//g;
if(!$nobracket){
($bracket) = $Text =~ /\[([^\]]+)\].*/;
($bracket2) = $Text =~ /\[(.*)\>/;
}

my ($anim) = $Text =~ /\+(.*)\+/; $Text=~ s/\+$anim\+//g;
my ($Timer) = $Text =~ /\=(.*)\=/; $Text=~ s/\=$Timer\=//g;
my $response = ""; my $ClickQueue = ""; my $Options = "";
my @popupid = $Text =~ /popupid\:(\d+)/g;
if($popupid[0]){ $PopId = $popupid[0]; my $string = "popupid:" . $popupid[0]; $Text=~ s/$string//g; }
my @wintype = $Text =~ /wintype\:(\d+)/g;
if($wintype[0]){ if($wintype[0] == 1){ $Opt = 1; }; my $string = "wintype:" . $wintype[0]; $Text=~ s/$string//g; }
if(!$nobracket){
if($bracket){ $response = $bracket; }
if($bracket2){ $response = $bracket2; }
@data = ($Text =~ m/\[([^\]]+)\]/g);
foreach $val (@data){ $Options .= "" . quest::saylink($val, 1) . " - ";}
if($data[1]){ $client->Message(15, " --- Select Response from Options --- "); $client->Message(0, "[" . substr ($Options, 0, -3) . "]"); }
}
if($anim){ if($anim > 0){ quest::doanim($anim); } else{ plugin::DoAnim($anim);} }
my $string = quotemeta("[" . $bracket2 . ">"); $Text=~ s/$string//g;
if($Timer > 0){ $ClickQueue = "<c \"#F07F00\">This message will disappear in " . $Timer . " second(s)...</c>"; }
elsif($response ne ""){ $client->SetEntityVariable("npcresponse", $response);
if($Opt == 1){ $ClickQueue = "<c \"#F07F00\">Click 'Yes' to continue'...</c>"; }
else{ $ClickQueue = "<c \"#F07F00\">Click 'OK' to respond with '" . $response . "'...</c>"; }
}else{ $client->SetEntityVariable("npcresponse", "");
if($Opt == 1){ $ClickQueue = "<c \"#F07F00\">Click 'Yes' to continue'...</c>";}
else{ $ClickQueue = "<c \"#F07F00\">Click 'OK' to continue...</c>"; }
}
if($achievement){} elsif($cname){ $Speaking = $cname . " says"; } elsif($mvoice){ $Speaking = "A Mysterious Voice says"; } else{ if($npc){ $Speaking = $npc->GetCleanName() . ' says'; } }
if($achievement){ $Title = "New Achievment!"; } else{ $Title = "Dialogue: " . $Speaking; }
if($achievement){ $Timer = 5; quest::popup($Title, $Text . "" . $ClickQueue . "", $PopId, $Opt, $Timer); }
else{ quest::popup($Title, "<c \"#CCFF33\">" . $Speaking . "</c><br><br>" . $quo . "" . $Text . "" . $quo . "" . "<br><br>" . $ClickQueue . "", $PopId, $Opt, $Timer); }
$PopId = undef; $achievement = undef;
}

#::: Used for include of EVENT_POPUPRESPONSE
#::: http://wiki.eqemulator.org/p?The_DiaWind_Plugin#to-activate-this-plugin
sub DiaWind_Process_Response{
my $popupid = plugin::val('$popupid');
my $client = plugin::val('$client');
if($popupid == 999){
my $nresponse = $client->GetEntityVariable("npcresponse");
if($Debug){ $client->Message(15, "Debug Silent Message: '" . $nresponse . "'"); }
if($nresponse ne ""){ $client->SilentMessage($nresponse); } return;
}
}

Akkadius
03-10-2015, 08:52 PM
Yup. I have it. I downloaded all the plugins from the repository. Check them daily to see if there are any new changes.

Here is the Diawind.pl plugin.

#::: Author: Akkadius
#::: This plugin can work as an extensive drop in replacement for quest::say
#::: This plugin also offers extensive options for easily formatting windows.
#::: Usage: plugin::DiaWind("Window text");
#::: For explanation of use, see: http://wiki.eqemulator.org/p?The_DiaWind_Plugin&frm=Perl_Plugins_Master_Reference

sub DiaWind {
my $Text = $_[0]; my $npc = plugin::val('$npc'); $client = plugin::val('$client'); $name = plugin::val('$name');
my $Opt = 0;
if(!$PopId){ $PopId = 999; }
$Text=~ s/~/<\/c>/g;
$Text=~ s/\{y\}/<c \"#CCFF33\">/g;
$Text=~ s/\{lb\}/<c \"#00FFFF\">/g;
$Text=~ s/\{r}/<c \"#FF0000\">/g;
$Text=~ s/\{g}/<c \"#00FF00\">/g;
$Text=~ s/\{gold}/<c \"#FFFF66\">/g;
$Text=~ s/\{orange}/<c \"#FFA500\">/g;
$Text=~ s/\{gray}/<c \"#808080\">/g;
$Text=~ s/\{tan}/<c \"#daa520\">/g;
$Text=~ s/\{bullet}/•/g;
$Text=~ s/\$name/$name/g;
$Text=~ s/\{linebreak}/--------------------------------------------------------------------/g;
$Text=~ s/\{rowpad}/<tr><td>{tdpad}<\/td><td>{tdpad}<\/td><\/tr>/g;
$Text=~ s/\{tdpad}/----------------------/g;
$Text=~ s/\{in}/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/g;
my ($mvoice) = $Text =~ s/mysterious//g;
my ($achievement) = $Text =~ s/achievement//g;
my ($noquotes) = $Text =~ s/noquotes//g; if($noquotes){ $quo = ""; } else{ $quo = "'"; }
my ($nobracket) = $Text =~ s/nobracket//g;
my ($nosound) = $Text =~ s/nosound//g;
my ($cname) = $Text =~ /{(.*)\>/; $Text =~ s/{$cname\>//g;
if(!$nobracket){
($bracket) = $Text =~ /\[([^\]]+)\].*/;
($bracket2) = $Text =~ /\[(.*)\>/;
}

my ($anim) = $Text =~ /\+(.*)\+/; $Text=~ s/\+$anim\+//g;
my ($Timer) = $Text =~ /\=(.*)\=/; $Text=~ s/\=$Timer\=//g;
my $response = ""; my $ClickQueue = ""; my $Options = "";
my @popupid = $Text =~ /popupid\:(\d+)/g;
if($popupid[0]){ $PopId = $popupid[0]; my $string = "popupid:" . $popupid[0]; $Text=~ s/$string//g; }
my @wintype = $Text =~ /wintype\:(\d+)/g;
if($wintype[0]){ if($wintype[0] == 1){ $Opt = 1; }; my $string = "wintype:" . $wintype[0]; $Text=~ s/$string//g; }
if(!$nobracket){
if($bracket){ $response = $bracket; }
if($bracket2){ $response = $bracket2; }
@data = ($Text =~ m/\[([^\]]+)\]/g);
foreach $val (@data){ $Options .= "" . quest::saylink($val, 1) . " - ";}
if($data[1]){ $client->Message(15, " --- Select Response from Options --- "); $client->Message(0, "[" . substr ($Options, 0, -3) . "]"); }
}
if($anim){ if($anim > 0){ quest::doanim($anim); } else{ plugin::DoAnim($anim);} }
my $string = quotemeta("[" . $bracket2 . ">"); $Text=~ s/$string//g;
if($Timer > 0){ $ClickQueue = "<c \"#F07F00\">This message will disappear in " . $Timer . " second(s)...</c>"; }
elsif($response ne ""){ $client->SetEntityVariable("npcresponse", $response);
if($Opt == 1){ $ClickQueue = "<c \"#F07F00\">Click 'Yes' to continue'...</c>"; }
else{ $ClickQueue = "<c \"#F07F00\">Click 'OK' to respond with '" . $response . "'...</c>"; }
}else{ $client->SetEntityVariable("npcresponse", "");
if($Opt == 1){ $ClickQueue = "<c \"#F07F00\">Click 'Yes' to continue'...</c>";}
else{ $ClickQueue = "<c \"#F07F00\">Click 'OK' to continue...</c>"; }
}
if($achievement){} elsif($cname){ $Speaking = $cname . " says"; } elsif($mvoice){ $Speaking = "A Mysterious Voice says"; } else{ if($npc){ $Speaking = $npc->GetCleanName() . ' says'; } }
if($achievement){ $Title = "New Achievment!"; } else{ $Title = "Dialogue: " . $Speaking; }
if($achievement){ $Timer = 5; quest::popup($Title, $Text . "" . $ClickQueue . "", $PopId, $Opt, $Timer); }
else{ quest::popup($Title, "<c \"#CCFF33\">" . $Speaking . "</c><br><br>" . $quo . "" . $Text . "" . $quo . "" . "<br><br>" . $ClickQueue . "", $PopId, $Opt, $Timer); }
$PopId = undef; $achievement = undef;
}

#::: Used for include of EVENT_POPUPRESPONSE
#::: http://wiki.eqemulator.org/p?The_DiaWind_Plugin#to-activate-this-plugin
sub DiaWind_Process_Response{
my $popupid = plugin::val('$popupid');
my $client = plugin::val('$client');
if($popupid == 999){
my $nresponse = $client->GetEntityVariable("npcresponse");
if($Debug){ $client->Message(15, "Debug Silent Message: '" . $nresponse . "'"); }
if($nresponse ne ""){ $client->SilentMessage($nresponse); } return;
}
}

Do you know if you have DBI installed?

epilz
03-10-2015, 08:55 PM
http://i.imgur.com/nAeiXH6.jpgyes its installed. SS below.

Akkadius
03-10-2015, 08:57 PM
http://i.imgur.com/nAeiXH6.jpgyes its installed. SS below.

#logs quest gmsay 20 1
#logs quest gmsay 38 1

What do you see when you try to show a window.

epilz
03-10-2015, 09:20 PM
Nothing displayed when setting logging to 1 or 3. No errors. Tested on other quest NPCs also. Very strange. Verified the log settings are in the logsys_categories table.

Turned on MYSQL Queries and Errors. This is all that was returned when clicking on Top HPs.

http://i.imgur.com/Yvs1Pbk.jpg

epilz
03-10-2015, 09:21 PM
Also, no one is on the server but myself atm. Its not open to public yet. The DB is not populating my stats. It was before.

Akkadius
03-10-2015, 09:23 PM
Nothing displayed when setting logging to 1 or 3. No errors. Tested on other quest NPCs also. Very strange. Verified the log settings are in the logsys_categories table.

Turned on MYSQL Queries and Errors. This is all that was returned when clicking on Top HPs.

http://i.imgur.com/Yvs1Pbk.jpg

Are you missing plugin::commify ?

https://code.google.com/p/eqemupluginsrepo/source/browse/trunk/text_formatting.pl

epilz
03-10-2015, 09:25 PM
Nope. I have text_formatting.pl in my plugins folder.

###AKKADIUS###
###Usage plugin::commify(12302302); Would output value 12,302,302
sub commify {
local $_ = shift;
s{(?<!\d|\.)(\d{4,})}
{my $n = $1;
$n=~s/(?<=.)(?=(?:.{3})+$)/,/g;
$n;
}eg;
return $_;
}

return 1;

Akkadius
03-10-2015, 09:27 PM
Nope. I have text_formatting.pl in my plugins folder.

###AKKADIUS###
###Usage plugin::commify(12302302); Would output value 12,302,302
sub commify {
local $_ = shift;
s{(?<!\d|\.)(\d{4,})}
{my $n = $1;
$n=~s/(?<=.)(?=(?:.{3})+$)/,/g;
$n;
}eg;
return $_;
}

return 1;

I think you're just trolling me

epilz
03-10-2015, 09:30 PM
no way man. I have been working on my server for about 2 months. I come from a very technical background, but not in programming. Learned a lot from this community. I can give you access to my server if you want to look.

Akkadius
03-10-2015, 09:32 PM
no way man. I have been working on my server for about 2 months. I come from a very technical background, but not in programming. Learned a lot from this community. I can give you access to my server if you want to look.

Load up Teamviewer, send me your session and tell me what your server name is.

epilz
03-10-2015, 09:39 PM
PMing you now

epilz
03-10-2015, 10:09 PM
Thanks Akka for the help. I will make changes later tonight and update this thread

epilz
03-11-2015, 12:35 PM
Ok Akka, Cleaned up the system of incorrect version of perl and updated DBI and DBD:mysql. Only issue that I am having now is the popup windows does not populate the information from the DB. Below are SS's.

http://i.imgur.com/9ZDfLmj.jpg

Logging.

http://i.imgur.com/PGIbs7Y.jpg

cust_ext_leaderboards view

http://i.imgur.com/tjuKMEh.jpg

Thanks again for the assistance last night.

Akkadius
03-11-2015, 02:40 PM
Ok Akka, Cleaned up the system of incorrect version of perl and updated DBI and DBD:mysql. Only issue that I am having now is the popup windows does not populate the information from the DB. Below are SS's.

http://i.imgur.com/9ZDfLmj.jpg

Logging.

http://i.imgur.com/PGIbs7Y.jpg

cust_ext_leaderboards view

http://i.imgur.com/tjuKMEh.jpg

Thanks again for the assistance last night.

It won't show you as a GM in the leaderboards table. Any status 0 player would show up fine

epilz
03-11-2015, 02:47 PM
ahh ok, cool! Thanks

N0ctrnl
09-15-2015, 01:44 PM
I made the following modification to the Leaderboards.pl script to report unbuffed hitpoints. Just in case anybody hadn't figure it out yet. :)


my $hp1 = $client->GetMaxHP();
my $hp2 = $client->GetSpellHPBonuses();
my $hp = ($hp1 - $hp2);

Kingly_Krab
09-15-2015, 04:49 PM
I made the following modification to the Leaderboards.pl script to report unbuffed hitpoints. Just in case anybody hadn't figure it out yet. :)


my $hp1 = $client->GetMaxHP();
my $hp2 = $client->GetSpellHPBonuses();
my $hp = ($hp1 - $hp2);

Just made uber people less uber looking on the leaderboard, haha.

N0ctrnl
09-16-2015, 05:06 AM
Hah, yep. Now I gotta figure how to do the same for mana.

cannon
06-09-2016, 10:28 PM
Nice Akkadius!

+1

I prefer to run the collection routine in this sub:

sub EVENT_CONNECT {}

That way code runs only 1 time when player logs in, instead of every time they zone.

That way it won't spam update the database each time a player dies or zones.

How do I get this work in global_player.lua

If I do #showstats on a myself or player as GM a stat box pops up with cancel or update with all the stats, but the quest npc is not popping up the box after clicking the links, just saying Fine!

Akkadius
06-10-2016, 04:43 PM
This is only for Perl, you'd have to write something separate for lua

Maceblade
04-14-2019, 09:36 AM
I know this is an old post, but I have gotten everything to work except the Top HP and AC portion. basically anything linked to the commify plugin yet im fairly certain i have the latest one.

Also, apprently SK's and Warriors no longer show up now lol