Skip to content

Instantly share code, notes, and snippets.

@Lillecarl
Created April 13, 2013 16:12
Show Gist options
  • Save Lillecarl/5379003 to your computer and use it in GitHub Desktop.
Save Lillecarl/5379003 to your computer and use it in GitHub Desktop.
bool ChatHandler::HandleWarpCommand(char* args)
{
// Based on a concept by Pwntzyou
if (!*args)
return false;
Player* _player = m_session->GetPlayer();
char* direction = ExtractQuotedOrLiteralArg(&args);
if (!direction)
return false;
float amount;
if (!ExtractFloat(&args, amount))
return false;
bool useVMap = false;
ExtractOnOff(&args, useVMap);
float x = _player->GetPositionX();
float y = _player->GetPositionY();
float z = _player->GetPositionZ();
float o = _player->GetOrientation();
switch (direction[0])
{
case 'x':
{
x = x + cos(o-(M_PI/2))*amount;
y = y + sin(o-(M_PI/2))*amount;
_player->SendChatMessage("%s[Warp Info]%s You teleported %g yards in x direction",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE,amount);
}
break;
case 'y':
{
x = x + cosf(o)*amount;
y = y + sinf(o)*amount;
_player->SendChatMessage("%s[Warp Info]%s You teleported %g yards in y direction",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE,amount);
}
break;
case 'z':
{
z += amount;
_player->SendChatMessage("%s[Warp Info]%s You teleported %g yards in z direction",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE,amount);
}
break;
case 'o':
{
o = MapManager::NormalizeOrientation((amount * M_PI_F/180.0f)+o);
_player->SendChatMessage("%s[Warp Info]%s You rotated %g degrees (%g radians)",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE,amount,amount * M_PI / 180.0f);
_player->SendChatMessage("%sCurrent radian/degree: %g %g",MSG_COLOR_WHITE,o,o*180.0f/M_PI);
}
break;
}
if (useVMap && z == _player->GetPositionZ())
{
z = _player->GetMap()->GetHeight(x, y, MAX_HEIGHT);
_player->SendChatMessage("%s[Warp Info]%s You were also teleported %g yards in z direction to be on ground.",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE, z - _player->GetPositionZ());
}
else
{
if (abs(_player->GetMap()->GetHeight(x, y, MAX_HEIGHT) - z) >= 0.5f)
{
WorldPacket data;
data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
data << _player->GetPackGUID();
data << uint32(0);
_player->SendMessageToSet(&data, true);
_player->SendChatMessage("%s[Warp Info]%s Enabled fly cheat, we expect you do not want to fall down.",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE);
}
}
_player->NearTeleportTo(x,y,z,o);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment