Advertisement
NatedogServer

player.pl

Sep 13th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 22.48 KB | None | 0 0
  1. sub EVENT_ENTERZONE {
  2.     my $charid = $client->CharacterID();
  3.     $dbh = DBI_CONNECT();
  4.     $sth = $dbh->prepare("SELECT charid, platinum FROM auction_house_money WHERE charid = $charid");
  5.     $sth->execute();
  6.     my @details = $sth->fetchrow_array();
  7.    
  8.     if($details[0])
  9.     {
  10.         $client->Message(335, "You have $details[1] platinum to spend or reclaim.");
  11.     }
  12.     else
  13.     {
  14.         $sth = $dbh->do("INSERT INTO auction_house_money VALUES ($charid, 0, 0, 0, 0)");
  15.         $client->Message(335, "You have been added to the auction house!");
  16.     }
  17.     $client->Message(335, "Type #commandlist for a list of commands!");
  18.     $sth->finish();
  19.     $dbh->disconnect();
  20. }
  21.  
  22. sub EVENT_SAY {
  23.             my $Yel = plugin::PWColor("Yellow");
  24.             my $Blu = plugin::PWColor("Royal Blue4");
  25.             my $Red = plugin::PWColor("Red");
  26.             my $orange = plugin::PWColor("Orange");
  27.             my $grn = plugin::PWColor("Forest Green");
  28.             my $query;
  29.             my $MAXSEARCH = 50;
  30.             my @statlist = ("astr", "asta", "aagi", "adex", "acha", "aint", "awis", "hp", "mana", "ac",
  31.                             "damage", "haste", "heroic_str", "heroic_sta", "heroic_agi", "heroic_dex",
  32.                             "heroic_cha", "heroic_int");
  33.            
  34.     if($text=~/^#sell /i)
  35.     {
  36.         my @prices = split / /, substr($text, 6);
  37.         if($prices[0]) {$plat = $prices[0];} else {$plat = 0;}
  38.         if($prices[1]) {$gold = $prices[1];} else {$gold = 0;}
  39.         if($prices[2]) {$silver = $prices[2];} else {$silver = 0;}
  40.         if($prices[3]) {$copper = $prices[3];} else {$copper = 0;}
  41.         my $qitem = $client->GetItemAt(30);
  42.         my $itemid = $client->GetItemIDAt(30);
  43.         if($qitem)
  44.         {
  45.             if($plat !~ /^[0-9]+$/) {$plat = 0};
  46.             if($gold !~ /^[0-9]+$/) {$gold = 0};
  47.             if($silver !~ /^[0-9]+$/) {$silver = 0};
  48.             if($copper !~ /^[0-9]+$/) {$copper = 0};
  49.            
  50.             if($plat == 0 && $gold == 0 && $silver == 0 && $copper == 0)
  51.             {
  52.                 $client->Message(315, "Set a price!");
  53.                 return;
  54.             }
  55.             if($plat == 0)
  56.             {
  57.                 $client->Message(315, "Set a price!");
  58.                 return;
  59.             }
  60.            
  61.             ## WE HAVE A PRICE NOW CHECK IF ITEM IS NODROP OR ATTUNED
  62.            
  63.             my $nodrop = $client->GetItemStat($itemid, "nodrop");
  64.            
  65.             if($nodrop == 0 || $qitem->IsAttuned())
  66.             {
  67.                 $client->Message(335, "That item is No Trade!");
  68.                 return;
  69.             }
  70.            
  71.             #ITEM IS TRADEABLE AND HAS A PRICE! Now the magic!
  72.             if($qitem->GetCharges() > 1)
  73.             {
  74.                 $charges = $qitem->GetCharges();
  75.             }
  76.             else
  77.             {
  78.                 $charges = 1;
  79.             }
  80.            
  81.            
  82.             #CONNECT
  83.             $dbh = DBI_CONNECT();
  84.             my $charid = $client->CharacterID();
  85.             my $itemid = $qitem->GetID();
  86.             my $itemname = $qitem->GetName();
  87.             my $itemname2 = $qitem->GetName();
  88.             $sth = $dbh->prepare("SELECT max(slotid) FROM auction_house
  89.                                 WHERE seller_id = $charid
  90.                                 ");
  91.             $sth->execute();
  92.             my $SLOT = $sth->fetchrow_array()+1;
  93.             $itemname = ITEMFIX($itemname);
  94.             $query = "INSERT INTO auction_house VALUES ($SLOT, $charid, '$name', $itemid, '$itemname', $plat, $gold, $silver, $copper, $charges)";
  95.             $sth = $dbh->do($query);
  96.             my $plat2 = plugin::commify($plat);
  97.             $client->Message(335, "$charges - $itemname2 now up for auction at $plat2 platinum!");
  98.            
  99.             $client->DeleteItemInInventory(30, 0, true);
  100.         }
  101.         $sth->finish();
  102.         $dbh->disconnect();
  103.     }
  104.     if($text=~/^#bazaar /i)
  105.     {
  106.         my $itemname = ITEMFIX(substr($text, 8));
  107.         if($itemname eq "list")
  108.         {
  109.             my $PRIMSTAT = $client->GetEntityVariable("STATONE");
  110.             my $SECSTAT = $client->GetEntityVariable("STATTWO");
  111.            
  112.             if(($client->EntityVariableExists("STATONE") && $client->GetEntityVariable("STATONE") ne "REMOVE" ) && (!$client->EntityVariableExists("STATTWO") || $client->GetEntityVariable("STATTWO") eq "REMOVE"))
  113.             {
  114.                 $dbh = DBI_CONNECT();  ##1 stat list
  115.                 $query = "SELECT a.slotid, a.item_name, a.itemid, a.platinum, a.gold, a.silver, a.copper, a.amount, a.seller, a.seller_id
  116.                         FROM auction_house a
  117.                         INNER JOIN items i ON i.id = a.itemid
  118.                         WHERE i.$PRIMSTAT > 0 order by $PRIMSTAT desc LIMIT $MAXSEARCH";
  119.                 $sth = $dbh->prepare($query);
  120.                 $sth->execute();
  121.                 $client->Message(261, " ");
  122.                 $client->Message(261, "Bazaar search for [$itemname] ORDER BY [$PRIMSTAT]");
  123.                 $client->Message(261, " ");
  124.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  125.                 {
  126.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  127.                     my $itemlink = quest::varlink($itemid);
  128.                     my $plat2 = plugin::commify($plat);
  129.                     my $stat1 = $client->GetItemStat($itemid, ITEMFIX("$PRIMSTAT"));
  130.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - $PRIMSTAT: $stat1 - [$seller] - [$buybutton]");
  131.                     $client->Message(261, " ");
  132.                 }
  133.                 $sth->finish();
  134.                 $dbh->disconnect();
  135.             }
  136.             elsif(($client->EntityVariableExists("STATONE") && $client->GetEntityVariable("STATONE") ne "REMOVE" ) && ($client->EntityVariableExists("STATTWO") && $client->GetEntityVariable("STATTWO") ne "REMOVE"))
  137.             {
  138.                 $dbh = DBI_CONNECT();   ##2 stats LIST
  139.                 $query = "SELECT a.slotid, a.item_name, a.itemid, a.platinum, a.gold, a.silver, a.copper, a.amount, a.seller, a.seller_id
  140.                         FROM auction_house a
  141.                         INNER JOIN items i ON i.id = a.itemid
  142.                         WHERE i.$PRIMSTAT > 0 AND i.$SECSTAT > 0 order by $PRIMSTAT desc, $SECSTAT desc LIMIT $MAXSEARCH";
  143.                 $sth = $dbh->prepare($query);
  144.                 $sth->execute();
  145.                 $client->Message(261, " ");
  146.                 $client->Message(261, "Bazaar search for [$itemname] ORDER BY [$PRIMSTAT] AND [$SECSTAT]");
  147.                 $client->Message(261, " ");
  148.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  149.                 {
  150.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  151.                     my $itemlink = quest::varlink($itemid);
  152.                     my $plat2 = plugin::commify($plat);
  153.                     my $stat1 = $client->GetItemStat($itemid, ITEMFIX("$PRIMSTAT"));
  154.                     my $stat2 = $client->GetItemStat($itemid, ITEMFIX("$SECSTAT"));
  155.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - $PRIMSTAT: $stat1 - $SECSTAT: $stat2 - [$seller] - [$buybutton]");
  156.                     $client->Message(261, " ");
  157.                 }
  158.                 $sth->finish();
  159.                 $dbh->disconnect();
  160.             }
  161.             else
  162.             {
  163.                 $dbh = DBI_CONNECT();
  164.                 $query = "SELECT slotid, item_name, itemid, platinum, gold, silver, copper, amount, seller, seller_id FROM auction_house LIMIT $MAXSEARCH";
  165.                 $sth = $dbh->prepare($query);
  166.                 $sth->execute();
  167.                 $client->Message(261, " ");
  168.                 $client->Message(261, "Bazaar search for [$itemname]");
  169.                 $client->Message(261, " ");
  170.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  171.                 {
  172.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  173.                     my $itemlink = quest::varlink($itemid);
  174.                     my $plat2 = plugin::commify($plat);
  175.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - [$seller] - [$buybutton]");
  176.                     $client->Message(261, " ");
  177.                 }
  178.                 $sth->finish();
  179.                 $dbh->disconnect();
  180.             }
  181.         }
  182.         elsif($itemname =~/^player /i)
  183.         {
  184.             my $itemname = ITEMFIX(substr($itemname, 7));
  185.             if($itemname ne '')
  186.             {
  187.                 $dbh = DBI_CONNECT();
  188.                 $query = "SELECT slotid, item_name, itemid, platinum, gold, silver, copper, amount, seller, seller_id FROM auction_house WHERE seller = '$itemname' LIMIT $MAXSEARCH";
  189.                 $sth = $dbh->prepare($query);
  190.                 $sth->execute();
  191.                 $client->Message(261, " ");
  192.                 $client->Message(261, "Bazaar Player search for [$itemname]");
  193.                 $client->Message(261, " ");
  194.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  195.                 {
  196.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  197.                     my $itemlink = quest::varlink($itemid);
  198.                     my $plat2 = plugin::commify($plat);
  199.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - [$seller] - [$buybutton]");
  200.                     $client->Message(261, " ");
  201.                 }
  202.                 $sth->finish();
  203.                 $dbh->disconnect();
  204.             }
  205.         }
  206.         elsif($itemname ne '')
  207.         {
  208.             my $PRIMSTAT = $client->GetEntityVariable("STATONE");
  209.             my $SECSTAT = $client->GetEntityVariable("STATTWO");
  210.            
  211.             if(($client->EntityVariableExists("STATONE") && $client->GetEntityVariable("STATONE") ne "REMOVE" ) && (!$client->EntityVariableExists("STATTWO") || $client->GetEntityVariable("STATTWO") eq "REMOVE"))
  212.             {
  213.                 $dbh = DBI_CONNECT();
  214.                 $query = "SELECT a.slotid, a.item_name, a.itemid, a.platinum, a.gold, a.silver, a.copper, a.amount, a.seller, a.seller_id
  215.                         FROM auction_house a
  216.                         INNER JOIN items i ON i.id = a.itemid
  217.                         WHERE a.item_name like '%$itemname%' AND i.$PRIMSTAT > 0 order by $PRIMSTAT desc LIMIT $MAXSEARCH";
  218.                 $sth = $dbh->prepare($query);
  219.                 $sth->execute();
  220.                 $client->Message(261, " ");
  221.                 $client->Message(261, "Bazaar search for [$itemname]");
  222.                 $client->Message(261, " ");
  223.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  224.                 {
  225.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  226.                     my $itemlink = quest::varlink($itemid);
  227.                     my $plat2 = plugin::commify($plat);
  228.                     my $stat1 = $client->GetItemStat($itemid, ITEMFIX("$PRIMSTAT"));
  229.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - $PRIMSTAT: $stat1 - [$seller] - [$buybutton]");
  230.                     $client->Message(261, " ");
  231.                 }
  232.                 $sth->finish();
  233.                 $dbh->disconnect();
  234.             }
  235.             elsif(($client->EntityVariableExists("STATONE") && $client->GetEntityVariable("STATONE") ne "REMOVE" ) && ($client->EntityVariableExists("STATTWO") && $client->GetEntityVariable("STATTWO") ne "REMOVE"))
  236.             {
  237.                 $dbh = DBI_CONNECT();
  238.                 $query = "SELECT a.slotid, a.item_name, a.itemid, a.platinum, a.gold, a.silver, a.copper, a.amount, a.seller, a.seller_id
  239.                         FROM auction_house a
  240.                         INNER JOIN items i ON i.id = a.itemid
  241.                         WHERE a.item_name like '%$itemname%' AND i.$PRIMSTAT > 0 AND i.$SECSTAT > 0 order by $PRIMSTAT desc, $SECSTAT desc LIMIT $MAXSEARCH";
  242.                 $sth = $dbh->prepare($query);
  243.                 $sth->execute();
  244.                 $client->Message(261, " ");
  245.                 $client->Message(261, "Bazaar search for [$itemname] ORDER BY [$PRIMSTAT] AND [$SECSTAT]");
  246.                 $client->Message(261, " ");
  247.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  248.                 {
  249.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  250.                     my $itemlink = quest::varlink($itemid);
  251.                     my $plat2 = plugin::commify($plat);
  252.                     my $stat1 = $client->GetItemStat($itemid, ITEMFIX("$PRIMSTAT"));
  253.                     my $stat2 = $client->GetItemStat($itemid, ITEMFIX("$SECSTAT"));
  254.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - $PRIMSTAT: $stat1 - $SECSTAT: $stat2 - [$seller] - [$buybutton]");
  255.                     $client->Message(261, " ");
  256.                 }
  257.                 $sth->finish();
  258.                 $dbh->disconnect();
  259.             }
  260.             else
  261.             {
  262.                 $dbh = DBI_CONNECT();
  263.                 $query = "SELECT slotid, item_name, itemid, platinum, gold, silver, copper, amount, seller, seller_id FROM auction_house WHERE item_name like '%$itemname%' LIMIT $MAXSEARCH";
  264.                 $sth = $dbh->prepare($query);
  265.                 $sth->execute();
  266.                 $client->Message(261, " ");
  267.                 $client->Message(261, "Bazaar search for [$itemname]");
  268.                 $client->Message(261, " ");
  269.                 while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  270.                 {
  271.                     my $buybutton = quest::saylink("#buy $id $sellerid", 1, "Buy");
  272.                     my $itemlink = quest::varlink($itemid);
  273.                     my $plat2 = plugin::commify($plat);
  274.                     $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - [$seller] - [$buybutton]");
  275.                     $client->Message(261, " ");
  276.                 }
  277.                 $sth->finish();
  278.                 $dbh->disconnect();
  279.             }
  280.         }
  281.         else
  282.         {
  283.             $client->Message(335, "You must search for something!");
  284.         }
  285.     }
  286.     if($text=~/^#buy /i)
  287.     {
  288.         my @buysplit = split / /, SELLID(substr($text, 5));
  289.         my $buyid = $buysplit[0];
  290.         my $sellid = $buysplit[1];
  291.         if($buyid =~/^[0-9]+$/)
  292.         {
  293.             my $charid = $client->CharacterID();
  294.             $dbh = DBI_CONNECT();
  295.             $query = "SELECT platinum FROM auction_house_money WHERE charid = $charid";
  296.             $sth = $dbh->prepare($query);
  297.             $sth->execute();
  298.             my $cur_plat = $sth->fetchrow_array();
  299.             $query = "SELECT slotid, item_name, itemid, platinum, gold, silver, copper, amount, seller, seller_id FROM auction_house WHERE slotid = $buyid AND seller_id = $sellid";
  300.             $sth = $dbh->prepare($query);
  301.             $sth->execute();
  302.             @row = $sth->fetchrow_array();
  303.             if(!$row[0])
  304.             {
  305.                 $client->Message(335, "No such item!");
  306.                 $sth->finish();
  307.                 $dbh->disconnect();
  308.                 return;
  309.             }
  310.             if(plugin::check_hasitem($client, $row[2]))
  311.             {
  312.                 my $LORE = $client->GetItemStat($row[2], "loregroup");
  313.                 if($LORE == 0)
  314.                 {
  315.                 }
  316.                 else
  317.                 {
  318.                     $client->Message(335, "ERROR: You cannot buy a lore item you already possess!");
  319.                     $sth->finish();
  320.                     $dbh->disconnect();
  321.                     return;
  322.                 }
  323.             }
  324.            
  325.             if($cur_plat >= $row[3])
  326.             {
  327.                 my $newplat = $cur_plat - $row[3];
  328.                 my $delitem = $row[0];
  329.                 my $payid = $row[9];
  330.                 my $paypp = $row[3];
  331.                
  332.                 $client->SetEntityVariable("sellid", $sellid);
  333.                 $client->SetEntityVariable("buyid", $buyid);
  334.                 my $plat2 = plugin::commify($cur_plat);
  335.                 my $plat3 = plugin::commify($row[3]);
  336.                 my $plat4 = plugin::commify($newplat);
  337.                
  338.                 my @purchase = "<table border ='5'>
  339.                                 <TR>
  340.                                 <TD> $Yel ItemID: </c><TD>$orange  $row[2] </c><TD> <TD><TD> <TD>  <TD> <TD>
  341.                                 <TR>
  342.                                 <TD> $Yel Name: </c> <TD> $grn $row[1] </c><TD> <TD>  <TD> <TD>  <TD> <TD>
  343.                                 <TR>
  344.                                 <TD> $Yel Quantity: </c> <TD> $grn $row[7] <TD> <TD>  <TD>  <TD>  <TD> <TD>
  345.                                 <TR>
  346.                                 <TD>  $Yel Old Funds: </c><TD> $grn $plat2 </c> <TD> <TD>  </c> <TD>  <TD>  <TD> <TD>
  347.                                 <TR>
  348.                                 <TD> $Yel Cost: </c> <TD> $Red - $plat3 </c>  <TD> <TD>  <TD>  <TD>  <TD> <TD>
  349.                                 <TR>
  350.                                 <TD>  $Yel New Funds: </c> <TD> $grn $plat4 </c> <TD> <TD>  <TD> <TD>  <TD> <TD>
  351.                                 <TR>
  352.                                 <TD>  <br> </c> <TD>  <TD> <TD>  <TD> <TD>  <TD> <TD>
  353.                                 <TR>
  354.                                 <TD>  <br> <TD>  <TD> <br> <TD>  <TD> <TD>  <TD> <TD>
  355.                                 ";
  356.                
  357.                    
  358.        
  359.                 push(@purchase, "</table>");
  360.                 quest::popup("Complete Purchase?", "@purchase", 1000005, 2, 60);
  361.             }
  362.             else
  363.             {
  364.                 $client->Message(335, "Not enough Plat!");
  365.             }
  366.             $sth->finish();
  367.             $dbh->disconnect();
  368.         }
  369.         else
  370.         {
  371.             $client->Message(335, "Invalid Buy command!");
  372.         }
  373.     }
  374.     if($text=~/^#reclaim /i)
  375.     {
  376.         my $reclaim = ITEMID(substr($text, 9));
  377.         my $charid = $client->CharacterID();
  378.         if($reclaim > 0)
  379.         {
  380.             $dbh = DBI_CONNECT();
  381.             $sth = $dbh->prepare("SELECT platinum FROM auction_house_money WHERE charid = $charid");
  382.             $sth->execute();
  383.             my $cur_plat = $sth->fetchrow_array();
  384.            
  385.             if($cur_plat >= $reclaim)
  386.             {
  387.                 $sth = $dbh->do("UPDATE auction_house_money SET platinum = platinum - $reclaim WHERE charid = $charid");
  388.                 my $newplat = int($cur_plat -$reclaim);
  389.                 my $plat2 = plugin::commify($cur_plat);
  390.                 my $plat3 = plugin::commify($reclaim);
  391.                 my $plat4 = plugin::commify($newplat);
  392.                 my @returned = "<table border ='5'>
  393.                                 <TR>
  394.                                 <TD> $Yel Name: </c> <TD> $grn $name </c><TD> <TD>  <TD> <TD>  <TD> <TD>
  395.                                 <TR>
  396.                                 <TD>  $Yel Old Funds: </c><TD> $grn $plat2 </c> <TD> <TD>  </c> <TD>  <TD>  <TD> <TD>
  397.                                 <TR>
  398.                                 <TD> $Yel Reclaimed: </c> <TD> $Red - $plat3 </c>  <TD> <TD>  <TD>  <TD>  <TD> <TD>
  399.                                 <TR>
  400.                                 <TD>  $Yel New Funds: </c> <TD> $grn $plat4 </c> <TD> <TD>  <TD> <TD>  <TD> <TD>
  401.                                 ";
  402.                
  403.                    
  404.        
  405.                 push(@returned, "</table>");
  406.                 quest::popup("Money Reclaimed", "@returned");
  407.                 quest::givecash(0, 0, 0, $reclaim);
  408.             }
  409.             else
  410.             {
  411.                 $client->Message(335, "You do not have $reclaim platinum!");
  412.             }  
  413.             $sth->finish();
  414.             $dbh->disconnect();
  415.         }
  416.     }
  417.     if($text=~/^#myfunds$/i)
  418.     {
  419.    
  420.         $dbh = DBI_CONNECT();
  421.         $sth = $dbh->prepare("SELECT platinum FROM auction_house_money WHERE charid = $charid");
  422.         $sth->execute();
  423.         my $money = $sth->fetchrow_array();
  424.         $sth->finish();
  425.         $dbh->disconnect();
  426.         my $plat2 = plugin::commify($money);
  427.         my @funds = "<table border ='5'>
  428.                                 <TR>
  429.                                 <TD> $Yel Name: </c> <TD> $grn $name </c><TD> <TD>  <TD> <TD>  <TD> <TD>
  430.                                 <TR>
  431.                                 <TD>  $Yel Funds: </c><TD> $grn $plat2 </c> <TD> <TD>  </c> <TD>  <TD>  <TD> <TD>
  432.                                 ";
  433.                
  434.                    
  435.        
  436.                 push(@funds, "</table>");
  437.                 quest::popup("Current Funds", "@funds");
  438.     }
  439.     if($text=~/^#commandlist$/i)
  440.     {
  441.         $client->Message(261, "Command List");
  442.         $client->Message(261, " ");
  443.         $client->Message(261, "#sell [platinum] - List item for X platinum when holding it on cursor.");
  444.         $client->Message(261, "#bazaar [search string] - Browse bazaar by search string.");
  445.         $client->Message(261, "#bazaar list - View all items that are for sale.");
  446.         $client->Message(261, "#bazaar player [Name] - View all items that are for sale by player Name.");
  447.         $client->Message(261, "#reclaim [platinum] - Return bazaar funds into your inventory.");
  448.         $client->Message(261, "#myfunds - Display your current Auction House funds.");
  449.         $client->Message(261, "#mybazaar - Display items you have for auction. This will allow you to remove them.");
  450.     }
  451.     if($text=~/^#mybazaar$/i)
  452.     {
  453.         $dbh = DBI_CONNECT();
  454.         $query = "SELECT slotid, item_name, itemid, platinum, gold, silver, copper, amount, seller, seller_id FROM auction_house WHERE seller = '$name'";
  455.         $sth = $dbh->prepare($query);
  456.         $sth->execute();
  457.         $client->Message(261, " ");
  458.         $client->Message(261, "Your Bazaar Items");
  459.         $client->Message(261, " ");
  460.         while (my ($id, $iname, $itemid, $plat, $gold, $silver, $copper, $amount, $seller, $sellerid) = $sth->fetchrow_array())
  461.         {
  462.             my $removebutton = quest::saylink("#bremove $id $sellerid", 1, "Remove");
  463.             my $itemlink = quest::varlink($itemid);
  464.             my $plat2 = plugin::commify($plat);
  465.             $client->Message(261, "$itemlink - $plat2 plat - QTY $amount - [$seller] - [$removebutton]");
  466.             $client->Message(261, " ");
  467.         }
  468.     }
  469.     if($text=~/^#bremove /i)
  470.     {
  471.         my @removesplit = split / /, SELLID(substr($text, 9));
  472.         my $buyid = $removesplit[0];
  473.         my $sellid = $removesplit[1];
  474.         $dbh = DBI_CONNECT();
  475.         $query = "SELECT seller_id, itemid, amount FROM auction_house WHERE seller_id = $sellid and slotid = $buyid";
  476.         $sth = $dbh->prepare($query);
  477.         $sth->execute();
  478.         my @STUFF= $sth->fetchrow_array();
  479.         my $CHECK = $STUFF[0];
  480.         my $ITEM = $STUFF[1];
  481.         my $AMOUNT = $STUFF[2];
  482.         my $charid = $client->CharacterID();
  483.         if(!$STUFF[1])
  484.         {
  485.             $client->Message(335, "ERROR: Invalid item!");
  486.             $sth->finish();
  487.             $dbh->disconnect();
  488.             return;
  489.            
  490.         }
  491.         if(plugin::check_hasitem($client, $STUFF[1]))
  492.         {
  493.             my $LORE = $client->GetItemStat($STUFF[1], "loregroup");
  494.             if($LORE == 0)
  495.             {
  496.             }
  497.             else
  498.             {
  499.                 $client->Message(335, "ERROR: You cannot remove a lore item you already possess!");
  500.                 $sth->finish();
  501.                 $dbh->disconnect();
  502.                 return;
  503.             }
  504.         }
  505.         if($CHECK == $charid)
  506.         {
  507.             $sth = $dbh->do("DELETE FROM auction_house WHERE slotid = $buyid and seller_id = $sellid");
  508.             quest::summonitem($ITEM, $AMOUNT);
  509.             my $ITEMLINK = quest::varlink($ITEM);
  510.             $client->Message(261, "Your $ITEMLINK is no longer up for auction!");
  511.         }
  512.         else
  513.         {
  514.             $client->Message(261, "You may not remove items that do not belong to you!");
  515.         }
  516.         $sth->finish();
  517.         $dbh->disconnect();
  518.     }
  519. }
  520.  
  521.  
  522. sub EVENT_POPUPRESPONSE {
  523.  
  524.     my $Yel = plugin::PWColor("Yellow");
  525.     my $Blu = plugin::PWColor("Royal Blue4");
  526.     my $Red = plugin::PWColor("Red");
  527.     my $orange = plugin::PWColor("Orange");
  528.     my $grn = plugin::PWColor("Forest Green");
  529.  
  530.     if($popupid == 1000005 && $client->EntityVariableExists("sellid") && $client->EntityVariableExists("buyid"))
  531.     {
  532.         #my @buysplit = split / /, SELLID(substr($text, 5));
  533.         my $buyid = $client->GetEntityVariable("buyid");
  534.         my $sellid = $client->GetEntityVariable("sellid");
  535.         if($buyid =~/^[0-9]+$/)
  536.         {
  537.             my $charid = $client->CharacterID();
  538.             $dbh = DBI_CONNECT();
  539.             $query = "SELECT platinum FROM auction_house_money WHERE charid = $charid";
  540.             $sth = $dbh->prepare($query);
  541.             $sth->execute();
  542.             my $cur_plat = $sth->fetchrow_array();
  543.             $query = "SELECT slotid, item_name, itemid, platinum, gold, silver, copper, amount, seller, seller_id FROM auction_house WHERE slotid = $buyid AND seller_id = $sellid";
  544.             $sth = $dbh->prepare($query);
  545.             $sth->execute();
  546.             @row = $sth->fetchrow_array();
  547.             if(!$row[0])
  548.             {
  549.                 $client->Message(335, "No such item!");
  550.                 $sth->finish();
  551.                 $dbh->disconnect();
  552.                 return;
  553.             }
  554.             if($cur_plat >= $row[3])
  555.             {
  556.                 my $newplat = $cur_plat - $row[3];
  557.                 my $delitem = $row[0];
  558.                 my $payid = $row[9];
  559.                 my $paypp = $row[3];
  560.                 $sth = $dbh->do("UPDATE auction_house_money SET platinum = $newplat WHERE charid = $charid");
  561.                 $sth = $dbh->do("UPDATE auction_house_money SET platinum = platinum + $paypp WHERE charid = $payid");
  562.                 $sth = $dbh->do("DELETE FROM auction_house WHERE slotid = $delitem and seller_id = $sellid");
  563.                 quest::summonitem($row[2], $row[7]);
  564.                 my $plat2 = plugin::commify($cur_plat);
  565.                 my $plat3 = plugin::commify($row[3]);
  566.                 my $plat4 = plugin::commify($newplat);
  567.                 my @purchase = "<table border ='5'>
  568.                                 <TR>
  569.                                 <TD> $Yel ItemID: </c><TD>$orange  $row[2] </c><TD> <TD><TD> <TD>  <TD> <TD>
  570.                                 <TR>
  571.                                 <TD> $Yel Name: </c> <TD> $grn $row[1] </c><TD> <TD>  <TD> <TD>  <TD> <TD>
  572.                                 <TR>
  573.                                 <TD> $Yel Quantity: </c> <TD> $grn $row[7] <TD> <TD>  <TD>  <TD>  <TD> <TD>
  574.                                 <TR>
  575.                                 <TD>  $Yel Old Funds: </c><TD> $grn $plat2 </c> <TD> <TD>  </c> <TD>  <TD>  <TD> <TD>
  576.                                 <TR>
  577.                                 <TD> $Yel Cost: </c> <TD> $Red - $plat3 </c>  <TD> <TD>  <TD>  <TD>  <TD> <TD>
  578.                                 <TR>
  579.                                 <TD>  $Yel New Funds: </c> <TD> $grn $plat4 </c> <TD> <TD>  <TD> <TD>  <TD> <TD>
  580.                                 ";
  581.                
  582.                    
  583.        
  584.                 push(@purchase, "</table>");
  585.                 quest::popup("Purchase Complete", "@purchase");
  586.                 quest::crosszonemessageplayerbyname(335, $row[8], "$name has purchased your $row[1] for $plat3 platinum!");
  587.             }
  588.             else
  589.             {
  590.                 $client->Message(335, "Not enough Plat!");
  591.             }
  592.             $sth->finish();
  593.             $dbh->disconnect();
  594.         }
  595.         else
  596.         {
  597.             $client->Message(335, "Invalid Buy command!");
  598.         }
  599.     }
  600.  
  601. }
  602.  
  603.  
  604. sub ITEMFIX
  605. {
  606.     local $_    = shift;
  607.     s/[^A-Za-z ]+//g;
  608.     return $_;
  609. }
  610.  
  611. sub ITEMID
  612. {
  613.     local $_    = shift;
  614.     s/[^0-9]+//g;
  615.     return $_;
  616. }
  617.  
  618. sub SELLID
  619. {
  620.     local $_    = shift;
  621.     s/[^0-9 ]+//g;
  622.     return $_;
  623. }
  624.  
  625.  
  626.  
  627. sub DBI_CONNECT {
  628.     use DBI;
  629.     $database = "peq";
  630.     $host = "localhost";
  631.     $username = "root";
  632.     $password = "PASSWORD";
  633.     $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", "$username", "$password", {RaiseError => 1});
  634.     return $dbh;
  635. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement