Advertisement
Guest User

dynamic_teleporter.cpp

a guest
Mar 24th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. /*******************************************************
  2. * File:'dynamic_teleporter.cpp'
  3. * (c)2011 - Wolf Officious (ladislav.alexa@gmail.com)
  4. *******************************************************/
  5.  
  6. /* ScriptData
  7. ScriptName: dynamic_teleporter
  8. LoaderName: void AddSC_dynamic_teleporter()
  9. %Complete: 100
  10. Comment: Dynamic Teleporter sctipt module (gameobject & npc)
  11. Category: cusomscripts
  12. EndScriptData */
  13.  
  14. /*
  15. -- NPC SQL EXAMPLE
  16. INSERT INTO `creature_template` (`entry`, `modelid_A`, `modelid_H`, `name`,`subname`,`minlevel`,`maxlevel`,`minhealth`,`maxhealth`,`faction_A`,`faction_H`,`npcflag`,`scale`,`mindmg`,`maxdmg`,`attackpower`,`baseattacktime`,`unit_flags`,`minrangedmg`,`maxrangedmg`,`rangedattackpower`,`RegenHealth`, `ScriptName`)
  17. VALUES ('500001', '736', '736','Dynamic Teleporter', 'TEST', '80', '80', '5000', '5000', '35', '35', '1', '2', '50000', '50000', '35000', '1', '512', '10000', '10000', '68', '255','dynamic_teleporter');
  18.  
  19. -- GO SQL EXAMPLE
  20. INSERT INTO `gameobject_template` (`entry`,`type`,`displayId`, `name`,`size`, `ScriptName`)
  21. VALUES ('500001', '1', '17','Dynamic Teleporter', '2','dynamic_teleporter');
  22. */
  23.  
  24. #include "ScriptPCH.h"
  25. #include "DynamicTeleportMgr.h"
  26.  
  27. #ifndef GOSSIP_SENDER_MAIN
  28. #define GOSSIP_SENDER_MAIN 1
  29. #endif
  30.  
  31. // SHOW MENU BY ID
  32. inline void DynamicTeleporter_ShowMenu(Player *player, Unit *unit, uint32 menu_id)
  33. {
  34. if(!sDynamicTeleportMgr->isLoaded())
  35. sDynamicTeleportMgr->Init();
  36.  
  37. uint32 count = 0;
  38. uint8 send_counter = 0;
  39.  
  40. if(player->isGameMaster() && menu_id == 0)
  41. {
  42. ++count;
  43. player->ADD_GOSSIP_ITEM(5, "~RELOAD TELEPORTER DATA~\n", GOSSIP_SENDER_MAIN, 666);
  44. }
  45.  
  46. for(uint32 itr = 0; itr < sDynamicTeleportMgr->GetCount(); itr++)
  47. {
  48. TeleportData const* td;
  49. td = sDynamicTeleportMgr->GetTeleportData(itr);
  50.  
  51. if(td)
  52. {
  53. if(td->menu_parent == menu_id)
  54. {
  55. if(td->faction == 0 || player->GetTeam() == td->faction) // HORDE 67, ALLIANCE 469
  56. {
  57. uint8 icon_id = td->icon;
  58.  
  59. if(icon_id > 9)
  60. {
  61. icon_id = 0;
  62. }
  63.  
  64. player->ADD_GOSSIP_ITEM(icon_id, td->name.c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + td->entry);
  65.  
  66. ++count;
  67. ++send_counter;
  68.  
  69. if(send_counter >= 10)
  70. {
  71. player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, unit->GetGUID());
  72. send_counter = 0;
  73. }
  74. }
  75. }
  76. }
  77. else
  78. {
  79. sLog.outError("TD_ERROR: UNK1 (!td)");
  80. return;
  81. }
  82. }
  83.  
  84. if(send_counter != 0 || count == 0)
  85. player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, unit->GetGUID());
  86. }
  87.  
  88. // TELEPORT PROCESS
  89. inline void DynamicTeleporter_TeleportToTarget(Player *player, uint32 target_id)
  90. {
  91. if(!sDynamicTeleportMgr->isLoaded())
  92. sDynamicTeleportMgr->Init();
  93.  
  94. TeleportLoc const* tl;
  95. tl = sDynamicTeleportMgr->GetTeleportLoc(target_id);
  96.  
  97. if(tl)
  98. {
  99. player->TeleportTo(tl->map, tl->position_x, tl->position_y, tl->position_z, tl->position_o);
  100. }
  101. else
  102. {
  103. sLog.outError("TD_ERROR: UNK1 (!tl)");
  104. }
  105.  
  106. return;
  107. }
  108.  
  109. // ACTION TYPE HANDLER
  110. inline bool DynamicTeleporter_HandleMenuAction(Player *player, Unit *unit, uint32 action)
  111. {
  112. if(!sDynamicTeleportMgr->isLoaded())
  113. sDynamicTeleportMgr->Init();
  114.  
  115. for(uint32 itr = 0; itr < sDynamicTeleportMgr->GetCount(); itr++)
  116. {
  117. TeleportData const* td;
  118. td = sDynamicTeleportMgr->GetTeleportData(itr);
  119.  
  120. if(td)
  121. {
  122. if(td->entry == action - GOSSIP_ACTION_INFO_DEF)
  123. {
  124. if(td->menu_sub < 0)
  125. {
  126. DynamicTeleporter_TeleportToTarget(player, action - GOSSIP_ACTION_INFO_DEF);
  127. return true;
  128. }
  129. else
  130. {
  131. DynamicTeleporter_ShowMenu(player, unit, td->menu_sub);
  132. return true;
  133. }
  134. }
  135. }
  136. else
  137. {
  138. sLog.outError("TD_ERROR: UNK1 (!td)");
  139. return false;
  140. }
  141. }
  142.  
  143. return false;
  144. }
  145.  
  146. // UNIVERSAL GOSSIP HELLO
  147. bool DynamicTeleporter_GossipHello(Player *player, Unit *unit)
  148. {
  149. if(player->isInCombat())
  150. {
  151. player->GetSession()->SendNotification("You are in combat!");
  152. return true;
  153. }
  154.  
  155. DynamicTeleporter_ShowMenu(player, unit, 0);
  156. return true;
  157. }
  158.  
  159. // UNIVERSAL GOSSIP SELECT
  160. bool DynamicTeleporter_GossipSelect(Player *player, Unit *unit, uint32 sender, uint32 action)
  161. {
  162. if(sender != GOSSIP_SENDER_MAIN)
  163. {
  164. player->CLOSE_GOSSIP_MENU();
  165. return true;
  166. }
  167.  
  168. if(player->isInCombat())
  169. {
  170. player->GetSession()->SendNotification("You are in combat!");
  171. player->CLOSE_GOSSIP_MENU();
  172. return true;
  173. }
  174.  
  175. player->PlayerTalkClass->ClearMenus();
  176.  
  177. if(action == 666 && player->isGameMaster())
  178. {
  179. player->CLOSE_GOSSIP_MENU();
  180. sDynamicTeleportMgr->Update();
  181. player->GetSession()->SendNotification("Reloaded..");
  182. return true;
  183. }
  184.  
  185. if(!DynamicTeleporter_HandleMenuAction(player, unit, action))
  186. player->CLOSE_GOSSIP_MENU();
  187.  
  188. return true;
  189. }
  190.  
  191. // GAMEOBJECT GOSSIP HELLO
  192. bool DynamicTeleporter_GO_GossipHello(Player *player, GameObject *gobject)
  193. { return DynamicTeleporter_GossipHello(player, (Unit*)gobject); }
  194.  
  195. // GAMEOBJECT GOSSIP SELECT
  196. bool DynamicTeleporter_GO_GossipSelect(Player *player, GameObject *gobject, uint32 sender, uint32 action)
  197. { return DynamicTeleporter_GossipSelect(player, (Unit*)gobject, sender, action); }
  198.  
  199. // NPC GOSSIP HELLO
  200. bool DynamicTeleporter_NPC_GossipHello(Player *player, Creature *creature)
  201. { return DynamicTeleporter_GossipHello(player, (Unit*)creature); }
  202.  
  203. // NPC GOSSIP SELECT
  204. bool DynamicTeleporter_NPC_GossipSelect(Player *player, Creature *creature, uint32 sender, uint32 action)
  205. { return DynamicTeleporter_GossipSelect(player, (Unit*)creature, sender, action); }
  206.  
  207. void AddSC_dynamic_teleporter()
  208. {
  209. Script *newscript;
  210.  
  211. newscript = new Script;
  212. newscript->Name = "dynamic_teleporter";
  213.  
  214. newscript->pGOHello = &DynamicTeleporter_GO_GossipHello;
  215. newscript->pGOSelect = &DynamicTeleporter_GO_GossipSelect;
  216.  
  217. newscript->pGossipHello = &DynamicTeleporter_NPC_GossipHello;
  218. newscript->pGossipSelect = &DynamicTeleporter_NPC_GossipSelect;
  219.  
  220. newscript->RegisterSelf();
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement