eq2emubot-functions.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. //EXAMPLE FUNCTION IN THIS CASE 8BALL
  3. function ball()
  4. {
  5. $answers = [
  6. // Positive
  7. "It is certain",
  8. "Without a doubt",
  9. "Yes, definitely",
  10. "It is decidedly so",
  11. // Half positive
  12. "Yes",
  13. "Most likely",
  14. "The outlook good",
  15. "As I see it, yes",
  16. "All signs point to yes",
  17. "You may rely on it",
  18. // Neutral
  19. "You should ask again later",
  20. "I cannot predict now",
  21. "Reply hazy try again",
  22. "Better not tell you now",
  23. "Concentrate and ask again",
  24. // Negative
  25. "Don't count on it",
  26. "My reply is no",
  27. "My sources say no",
  28. "The outlook not so good",
  29. "Its very doubtful",
  30. ];
  31. $rnd = rand(1, 20);`
  32. $rnd = rand(1, 20);
  33. $rnd = rand(1, 20);
  34. return $answers[$rnd];
  35. }
  36. function isadmin($user, $userid)
  37. {
  38. if (!isset($user) or !isset($userid)) {
  39. return 0;
  40. }
  41. $isadmin = 0;
  42. if ($user == ADMINNAME && $userid == ADMINID) {
  43. return 1;
  44. } else {
  45. return 0;
  46. }
  47. }
  48. //The following 2 functions show examples for accessing the EQ2EMu Database.
  49. //function onlineusers($isadmin) -- This creates the list of online users and formats it. Hides zone if not an admin
  50. //function getzone($zone) -- Simple function that takes zoneID and gives you a speakable name.
  51. function onlineusers($isadmin = 0)
  52. {
  53. $link = mysqli_connect(MYSQLHOST, MYSQLUSER, MYSQLPASS, MYSQLDB);
  54. $sql = "SELECT * from characters where is_online=1 order by name ASC limit 25";
  55. $result = $link->query($sql);
  56. if (mysqli_num_rows($result) == 0 or mysqli_num_rows($result) == null) {
  57. $msg = "There are currently no players online!\n";
  58. mysqli_close($link);
  59. return $msg;
  60. }
  61. $msg = "```\nThe following players are online (limit 25):";
  62. $numb = 1;
  63. while ($row = $result->fetch_array()) {
  64. if ($numb == 1) {
  65. if ($isadmin != 1) {
  66. $zoneid = "**HIDDEN**";
  67. } else {
  68. $zoneid = getzone($row[10]);
  69. }
  70. $level = $row[11];
  71. $msg .= "\n" . $row[3] . "(" . $level . "/" . $zoneid . ")";
  72. $numb++;
  73. } else {
  74. if ($isadmin != 1) {
  75. $zoneid = "**HIDDEN**";
  76. } else {
  77. $zoneid = getzone($row[10]);
  78. }
  79. $level = $row[11];
  80. $msg .= " || " . $row[3] . "(" . $level . "/" . $zoneid . ")";
  81. }
  82. }
  83. mysqli_close($link);
  84. return $msg;
  85. }
  86. function getzone($zone)
  87. {
  88. $link = mysqli_connect(MYSQLHOST, MYSQLUSER, MYSQLPASS, MYSQLDB);
  89. $sql = "SELECT * from zones where id=$zone limit 1";
  90. $query = $link->query($sql);
  91. $row = mysqli_fetch_row($query);
  92. $zone = $row[2];
  93. mysqli_close($link);
  94. return $zone;
  95. }
  96. ?>