Advertisement
Guest User

Auto pool script.

a guest
Mar 13th, 2015
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 6.15 KB | None | 0 0
  1. -- This script will take data from the first entry for each creature in the entries list
  2. -- and use that data to populate the pool_creature_info table.
  3. -- It will take all spawn points for the creature within the range
  4. -- Pool ID to work with. 0 means take the next one.
  5. SET @Pool_ID = 0;
  6. -- Creature guid to add. Keep unused = 0. Choose a guid (not entry) for an example of the creature you want.
  7. -- guid is used so as to only get others in the "range" of that creature.
  8. SET @Creature0 = 0;
  9. SET @Creature1 = 0;
  10. SET @Creature2 = 0;
  11. SET @Creature3 = 0;
  12. SET @Creature4 = 0;
  13. SET @Creature5 = 0;
  14. SET @Creature6 = 0;
  15. SET @Creature7 = 0;
  16. SET @Creature8 = 0;
  17. SET @Creature9 = 0;
  18. -- Mainly fixed variables
  19. SET @MinPool = 100000;
  20. SET @MaxPool = 199999;
  21. SET @Range = 600;
  22. SELECT IFNULL(max(entry)+1, @MinPool) INTO @NextPool
  23. FROM pool_template
  24. WHERE entry BETWEEN @MinPool AND @MaxPool;
  25.  
  26. SET @Pool_ID = CASE WHEN @Pool_ID = 0 THEN @NextPool ELSE @Pool_ID END;
  27.  
  28. -- Get position of creature 0
  29. SELECT position_x, position_y, position_z INTO @posx, @posy, @posz
  30. FROM creature
  31. WHERE guid = @Creature0
  32. LIMIT 1;
  33.  
  34. -- Insert creature always with qualifier 0, don't overwrite, chance 0 (equal) into pool data with default times
  35. INSERT IGNORE INTO pool_creature_info
  36. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  37. FROM creature
  38. WHERE guid = @Creature0;
  39. INSERT IGNORE INTO pool_creature_info
  40. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  41. FROM creature
  42. WHERE guid = @Creature1;
  43. INSERT IGNORE INTO pool_creature_info
  44. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  45. FROM creature
  46. WHERE guid = @Creature2;
  47. INSERT IGNORE INTO pool_creature_info
  48. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  49. FROM creature
  50. WHERE guid = @Creature3;
  51. INSERT IGNORE INTO pool_creature_info
  52. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  53. FROM creature
  54. WHERE guid = @Creature4;
  55. INSERT IGNORE INTO pool_creature_info
  56. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  57. FROM creature
  58. WHERE guid = @Creature5;
  59. INSERT IGNORE INTO pool_creature_info
  60. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  61. FROM creature
  62. WHERE guid = @Creature6;
  63. INSERT IGNORE INTO pool_creature_info
  64. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  65. FROM creature
  66. WHERE guid = @Creature7;
  67. INSERT IGNORE INTO pool_creature_info
  68. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  69. FROM creature
  70. WHERE guid = @Creature8;
  71. INSERT IGNORE INTO pool_creature_info
  72. SELECT @Pool_ID, id, 0, 0, spawnMask, phaseMask, modelid, equipment_id, 0, 0, 0, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags
  73. FROM creature
  74. WHERE guid = @Creature9;
  75.  
  76. SET @RowID = (SELECT IFNULL(MAX(guid),0) FROM pool_spawns WHERE pool_id = @Pool_ID);
  77.  
  78. -- Add spawn points
  79. INSERT INTO pool_spawns
  80. SELECT @Pool_ID, @RowID:=@RowID+1, cr. map, cr.zoneId, cr.areaId, cr. position_x, cr.position_y, cr.position_z, cr.orientation
  81. FROM creature cr
  82. LEFT OUTER JOIN pool_spawns ps
  83.         ON ps.pool_id = 100000 AND ps.position_x = cr.position_x AND ps.position_y = cr.position_y
  84. WHERE id IN
  85. (
  86.         SELECT id
  87.         FROM creature
  88.         WHERE guid IN(@Creature0, @Creature1, @Creature2, @Creature3, @Creature4, @Creature5, @Creature6, @Creature7, @Creature8, @Creature9)
  89. )
  90. AND cr.position_x BETWEEN @posx-@Range AND @posx+@Range
  91. AND cr.position_y BETWEEN @posy-@Range AND @posy+@Range
  92. AND cr.position_z BETWEEN @posz-@Range AND @posz+@Range
  93. AND ps.guid IS NULL;
  94.  
  95. -- Create the backup table if it doesn't already exist. No records though.
  96. CREATE TABLE IF NOT EXISTS creature_backup_pooling
  97. (
  98.         SELECT cr.*, CONCAT(ct.name,' on date ', DATE_FORMAT(NOW(), '%Y-%m-%d at %H:%i:%S')) as detail
  99.         FROM creature cr INNER JOIN creature_template ct ON ct.entry = cr.id
  100.         WHERE guid = 0
  101. );
  102.  
  103. -- Add template record
  104. INSERT INTO pool_template
  105. SELECT @Pool_ID, 0, COUNT(guid), CONCAT('Creature Spawns AUTOGEN on date ', DATE_FORMAT(NOW(), '%Y-%m-%d at %H:%i:%S'))
  106. FROM pool_spawns
  107. WHERE pool_id = @Pool_ID;
  108.  
  109. -- Backup changed data to the creature backup table.
  110. INSERT INTO creature_backup_pooling
  111. SELECT cr.*, CONCAT(ct.name,' to pool ', @Pool_ID, ' on date ', DATE_FORMAT(NOW(), '%Y-%m-%d at %H:%i:%S')) as detail
  112. FROM creature cr
  113. INNER JOIN creature_template ct ON ct.entry = cr.id
  114. WHERE id IN
  115. (
  116.         SELECT DISTINCT(id)
  117.         FROM creature
  118.         WHERE guid IN(@Creature0, @Creature1, @Creature2, @Creature3, @Creature4, @Creature5, @Creature6, @Creature7, @Creature8, @Creature9)
  119. )
  120. AND position_x BETWEEN @posx-@Range AND @posx+@Range
  121. AND position_y BETWEEN @posy-@Range AND @posy+@Range
  122. AND position_z BETWEEN @posz-@Range AND @posz+@Range;
  123.  
  124. -- Delete existing creatures
  125. DELETE FROM creature
  126. WHERE id IN
  127. (
  128.         SELECT DISTINCT(id)
  129.         FROM creature_backup_pooling
  130.         WHERE guid IN(@Creature0, @Creature1, @Creature2, @Creature3, @Creature4, @Creature5, @Creature6, @Creature7, @Creature8, @Creature9)
  131. )
  132. AND position_x BETWEEN @posx-@Range AND @posx+@Range
  133. AND position_y BETWEEN @posy-@Range AND @posy+@Range
  134. AND position_z BETWEEN @posz-@Range AND @posz+@Range;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement