ff_u_dbg_goto

Debug chat command: jump to an area.

Enables the /goto <area> chat command in debug mode: the speaker jumps to the WP_GOTO waypoint of the area tagged <area>, or else area_<area>. Place a WP_GOTO waypoint in each area that should be reachable. The chat message is lowercased first, so the area tag must be lowercase. On success the chat line is hidden; on failure the player gets no message and only a warning is written to the server log.

The unit is only active when the NWN_DEBUG environment variable of the server is true.

Source code

// @code


#include "ff_i_core"



// -----------------------------------------------------------------------------

//! @brief Send the /goto help line to the chat speaker.
void OnHelp();
void OnHelp()
{
  object oSpeaker = GetPCChatSpeaker();
  string C1 = CHAT_COLOR_DEBUG;
  string C2 = CHAT_COLOR_SERVER;

  if (!GetIsDebug())
    return;

  SendMessageToPC(oSpeaker, _RGB("/goto STRING: ", C1) + _RGB("Goto area.", C2));
}


// -----------------------------------------------------------------------------

//! @brief Handle the /goto chat command of the chat speaker.
void OnChat();
void OnChat()
{
  object oSpeaker = GetPCChatSpeaker();
  string sMessage = GetPCChatMessage();

  sMessage = GetStringTrim(GetStringLowerCase(sMessage));
  if (sMessage == "")
    return;

  struct CLI_ARGUMENTS sArgs = GetArguments(sMessage);

  if (sArgs.sArg0 != "/goto")
    return;

  string sResRef = sArgs.sArg1;
  object oArea = GetObjectByTag(sResRef);
  if (!GetIsObjectValid(oArea))
    oArea = GetObjectByTag("area_" + sResRef);
  if (!GetIsObjectValid(oArea))
  {
    LogWarning("(/goto) Area is not valid");
    return;
  }

  object oWaypoint = GetFirstObjectInArea(oArea, OBJECT_TYPE_WAYPOINT);
  if (GetTag(oWaypoint) != "WP_GOTO")
    oWaypoint = GetNearestObjectByTag("WP_GOTO", oWaypoint);
  if (!GetIsObjectValid(oWaypoint))
  {
    LogWarning("(/goto) No WP_GOTO in " + GetAreaInfo(oArea));
    return;
  }

  AssignCommand(oSpeaker, ActionJumpToObject(oWaypoint));
  LogWarning("Player " + GetObjectInfo(oSpeaker) + " /goto " + GetAreaInfo(oArea));
  SetPCChatMessage("");
}


// -----------------------------------------------------------------------------

void main()
{
  string sEvent = NWNX_Events_GetCurrentEvent();
  if (sEvent == ON_REGISTER)
  {
    if (!GetIsDebug())
      return;
    SubscribeToEvent(ON_DEFAULT_PLAYER_CHAT, __FILE__);
    SubscribeToEvent(ON_DEFAULT_PLAYER_CHAT_HELP, __FILE__);
  }
  else if (sEvent == ON_DEFAULT_PLAYER_CHAT)
    OnChat();
  else if (sEvent == ON_DEFAULT_PLAYER_CHAT_HELP)
    OnHelp();
}