1. /*
  2. Used variables, set up as you like.
  3. Thank you, Rochet.
  4. */
  5. SET
  6. @ENTRY = 120000,
  7. @NAME = "Honorable Kills",
  8. @SUBNAME = "",
  9. @MODEL = 21572,
  10. @TEXT_ID = 40000;
  11. -- Delete existing data
  12. DELETE FROM world.creature_template WHERE entry = @ENTRY ;
  13. DELETE FROM world.npc_text WHERE ID BETWEEN @TEXT_ID AND @TEXT_ID+2;
  14. DELETE FROM world.gossip_menu WHERE entry BETWEEN 41000 AND 41002;
  15. DELETE FROM world.gossip_menu_option WHERE menu_id BETWEEN 41000 AND 41002;
  16. -- Creature
  17. INSERT INTO world.creature_template (entry, modelid1, NAME, subname, IconName, gossip_menu_id, minlevel, maxlevel, faction, npcflag, speed_walk, speed_run, scale, rank, unit_class, unit_flags, TYPE, type_flags, InhabitType, RegenHealth, flags_extra, AiName) VALUES
  18. (@ENTRY, @MODEL, @NAME, @SUBNAME, "Directions", 41000, 71, 71, 35, 3, 1, 1.14286, 1.25, 1, 1, 2, 7, 138936390, 3, 1, 2, "");
  19. -- Link text to gossip menu.
  20. INSERT INTO world.gossip_menu (entry, text_id) VALUES
  21. (41000, @TEXT_ID),
  22. (41001, @TEXT_ID+1),
  23. (41002, @TEXT_ID+2);
  24. -- Add the text'.
  25. INSERT INTO world.npc_text (ID, text0_0, em0_1) VALUES
  26. (@TEXT_ID, "Greetings.", 0),
  27. (@TEXT_ID+1, "Top kills all time.", 0),
  28. (@TEXT_ID+2, "Top kills today.", 0);
  29. -- Add the menu.
  30. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text) VALUES
  31. (41000, 1, 0, 'Top kills', 1, 1, 41001, 0, 0, 0, NULL),
  32. (41000, 2, 0, 'Top kills today', 1, 1, 41002, 0, 0, 0, NULL);
  33. -- Populate lifetime kills with already existing data
  34. SET @id = 0;
  35. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text)
  36. SELECT 41001, @id:=@id+1, 0, CONCAT(NAME, ' - lifetime kills: ', totalkills), 1, 1, 0, 0, 0, 0, NULL
  37. FROM characters.Characters AS C
  38. ORDER BY totalKills DESC
  39. LIMIT 30;
  40. -- Add a back button
  41. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text) VALUES
  42. (41001, @id+1, 0, '[Back]', 1, 1, 41000, 0, 0, 0, NULL);
  43. -- Populate today kills with the already exiting data
  44. SET @id = 0;
  45. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text)
  46. SELECT 41002, @id:=@id+1, 0, CONCAT(NAME, ' - today kills: ', todaykills), 1, 1, 0, 0, 0, 0, NULL
  47. FROM characters.Characters AS C
  48. ORDER BY todaykills DESC
  49. LIMIT 30;
  50. -- Add a back button
  51. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text) VALUES
  52. (41002, @id+1, 0, '[Back]', 1, 1, 41000, 0, 0, 0, NULL);
  53. -- Change delimiter, so we can use ';' in the trigger.
  54. DELIMITER //
  55. -- Trigger that will update the todaykills/totalkill whenever
  56. -- a character kill is updated.
  57. DROP TRIGGER IF EXISTS characters.tr_update_kills//
  58. CREATE TRIGGER characters.tr_update_kills
  59. AFTER UPDATE
  60. ON characters.Characters
  61. FOR EACH ROW
  62. BEGIN
  63. IF NEW.todaykills <> OLD.todaykills THEN
  64. DELETE FROM world.gossip_menu_option
  65. WHERE menu_id = 41002;
  66. SET @id = 0;
  67. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text)
  68. SELECT 41002, @id:=@id+1, 0, CONCAT(NAME, ' - today kills: ', todaykills), 1, 1, 0, 0, 0, 0, NULL
  69. FROM characters.Characters AS C
  70. ORDER BY todaykills DESC
  71. LIMIT 30;
  72. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text) VALUES
  73. (41002, @id+1, 0, '[Back]', 1, 1, 41000, 0, 0, 0, NULL);
  74. END IF;
  75. IF NEW.totalkills <> OLD.totalkills THEN
  76. DELETE FROM world.gossip_menu_option
  77. WHERE menu_id = 41001;
  78. SET @id = 0;
  79. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text)
  80. SELECT 41001, @id:=@id+1, 0, CONCAT(NAME, ' - lifetime kills: ', totalkills), 1, 1, 0, 0, 0, 0, NULL
  81. FROM characters.Characters AS C
  82. ORDER BY totalKills DESC
  83. LIMIT 30;
  84. INSERT INTO world.gossip_menu_option (menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, action_menu_id, action_poi_id, box_coded, box_money, box_text) VALUES
  85. (41001, @id+1, 0, '[Back]', 1, 1, 41000, 0, 0, 0, NULL);
  86. END IF;
  87. END//
  88. DELIMITER ;