Advertisement
Fubba

[TrinityCore] Warp command

Jun 26th, 2012
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.10 KB | None | 0 0
  1. From ce524527ff819739112cfca7ed5334fc2a0d25dc Mon Sep 17 00:00:00 2001
  2. From: Dany <Kaiosown@gmail.com>
  3. Date: Wed, 27 Jun 2012 00:09:13 +0200
  4. Subject: [PATCH] Script/Command: Implement Warp
  5.  
  6. based on @LilleCarl
  7. ---
  8.  src/server/game/Scripting/ScriptLoader.cpp |    2 +
  9.  src/server/scripts/Commands/CMakeLists.txt |    1 +
  10.  src/server/scripts/Commands/cs_warp.cpp    |   98 ++++++++++++++++++++++++++++
  11.  src/server/shared/Common.h                 |    4 ++
  12.  4 files changed, 105 insertions(+)
  13.  create mode 100644 src/server/scripts/Commands/cs_warp.cpp
  14.  
  15. diff --git a/src/server/game/Scripting/ScriptLoader.cpp b/src/server/game/Scripting/ScriptLoader.cpp
  16. index 3ca7539..1263371 100755
  17. --- a/src/server/game/Scripting/ScriptLoader.cpp
  18. +++ b/src/server/game/Scripting/ScriptLoader.cpp
  19. @@ -65,6 +65,7 @@
  20.  void AddSC_server_commandscript();
  21.  void AddSC_titles_commandscript();
  22.  void AddSC_wp_commandscript();
  23. +void AddSC_warp_commandscript();
  24.  void AddSC_character_commandscript();
  25.  
  26.  #ifdef SCRIPTS
  27. @@ -679,6 +680,7 @@ void AddCommandScripts()
  28.      AddSC_tele_commandscript();
  29.      AddSC_server_commandscript();
  30.      AddSC_titles_commandscript();
  31. +    AddSC_warp_commandscript();
  32.      AddSC_wp_commandscript();
  33.      AddSC_character_commandscript();
  34.  }
  35. diff --git a/src/server/scripts/Commands/CMakeLists.txt b/src/server/scripts/Commands/CMakeLists.txt
  36. index 268d71a..cb222ba 100644
  37. --- a/src/server/scripts/Commands/CMakeLists.txt
  38. +++ b/src/server/scripts/Commands/CMakeLists.txt
  39. @@ -33,6 +33,7 @@ set(scripts_STAT_SRCS
  40.    Commands/cs_vip.cpp
  41.    Commands/cs_titles.cpp
  42.    Commands/cs_wp.cpp
  43. +  Commands/cs_warp.cpp
  44.  #  Commands/cs_lookup.cpp
  45.  #  Commands/cs_pdump.cpp
  46.  #  Commands/cs_guild.cpp
  47. diff --git a/src/server/scripts/Commands/cs_warp.cpp b/src/server/scripts/Commands/cs_warp.cpp
  48. new file mode 100644
  49. index 0000000..62c425e
  50. --- /dev/null
  51. +++ b/src/server/scripts/Commands/cs_warp.cpp
  52. @@ -0,0 +1,98 @@
  53. +#include "ScriptMgr.h"
  54. +#include "Chat.h"
  55. +#include "MapManager.h"
  56. +
  57. +class warp_commandscript : public CommandScript
  58. +{
  59. +public:
  60. +    warp_commandscript() : CommandScript("warp_commandscript") { }
  61. +
  62. +    ChatCommand* GetCommands() const
  63. +    {
  64. +       static ChatCommand warpCommandTable[] =
  65. +        {
  66. +            { "warp",       SEC_ADMINISTRATOR,  true,  &HandleWarpCommand,                      "", NULL },
  67. +            { NULL,             0,                  false, NULL,                                "", NULL }
  68. +        };
  69. +        static ChatCommand commandTable[] =
  70. +        {
  71. +            { "ashen",         SEC_ADMINISTRATOR,   true, NULL,                     "", warpCommandTable },
  72. +            { NULL,            0,                   false, NULL,                                "", NULL }
  73. +        };
  74. +        return commandTable;
  75. +   }
  76. +
  77. +    static bool HandleWarpCommand(ChatHandler* handler, char const* args)
  78. +    {
  79. +        if (!*args)
  80. +            return false;
  81. +
  82. +        Player* player = handler->GetSession()->GetPlayer();
  83. +
  84. +        char* arg1 = strtok((char*)args, " ");
  85. +        char* arg2 = strtok(NULL, " ");
  86. +
  87. +        if (!arg1 || !arg2)
  88. +        return false;
  89. +
  90. +        char dir = arg1[0];
  91. +        float value = float(atof(arg2));
  92. +        float x = player->GetPositionX();
  93. +        float y = player->GetPositionY();
  94. +        float z = player->GetPositionZ();
  95. +        float o = player->GetOrientation();
  96. +    uint32 mapid = player->GetMapId();
  97. +        Map const* map = sMapMgr->CreateBaseMap(mapid);
  98. +        z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
  99. +
  100. +    switch (dir)
  101. +    {
  102. +   case 'l': // left
  103. +        {
  104. +       x = x + cos(o+(M_PI/2))*value;
  105. +           y = y + sin(o+(M_PI/2))*value;
  106. +
  107. +           player->TeleportTo(mapid, x, y, z, o);
  108. +        }
  109. +        break;
  110. +    case 'r': // right
  111. +        {
  112. +       x = x + cos(o-(M_PI/2))*value;
  113. +           y = y + sin(o-(M_PI/2))*value;
  114. +
  115. +           player->TeleportTo(mapid, x, y, z, o);
  116. +        }
  117. +        break;
  118. +    case 'f': // forward
  119. +        {
  120. +       x = x + cosf(o)*value;
  121. +           y = y + sinf(o)*value;
  122. +
  123. +           player->TeleportTo(mapid, x, y, z, o);
  124. +        }
  125. +        break;
  126. +    case 'u': // up
  127. +    {
  128. +           player->TeleportTo(mapid, x, y, z + value, o);
  129. +    }
  130. +        break;
  131. +    case 'd': // down
  132. +    {
  133. +           player->TeleportTo(mapid, x, y, z - value, o);
  134. +    }
  135. +        break;
  136. +    case 'o': //orientation
  137. +        {
  138. +       o = MapManager::NormalizeOrientation((value * M_PI_F/180.0f)+ o);
  139. +
  140. +           player->TeleportTo(mapid, x, y, z, o);
  141. +        }
  142. +        break;
  143. +    }
  144. +    return true;
  145. +  };
  146. +};
  147. +void AddSC_warp_commandscript()
  148. +{
  149. +    new warp_commandscript();
  150. +}
  151. \ No newline at end of file
  152. diff --git a/src/server/shared/Common.h b/src/server/shared/Common.h
  153. index 259c60a..a54f7b0 100755
  154. --- a/src/server/shared/Common.h
  155. +++ b/src/server/shared/Common.h
  156. @@ -202,6 +202,10 @@ enum LocaleConstant
  157.  #define M_PI            3.14159265358979323846f
  158.  #endif
  159.  
  160. +#ifndef M_PI_F
  161. +# define M_PI_F float(M_PI)
  162. +#endif
  163. +
  164.  #define MAX_QUERY_LEN 32*1024
  165.  
  166.  #define TRINITY_GUARD(MUTEX, LOCK) \
  167. --
  168. 1.7.10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement