[Help] How to make .tele teleport to certain phases

Hi, I’m trying to make certain teleports in certain phases.

For example, teleport name is “kingdom” and is in phase 30. When I teleport to “kingdom” I am automatically placed in phase 1. How can I make it so when I teleport to “kingdom” I go into phase 30?

Thanks!

Looks like that will require both code and database table changes. In the world database, the game_tele table has no method for storing a phase at this time. It might be a good addition to the core, though. When “.tele add” is used, store the player’s phasemask as well as the currently stored coordinates and orientation. I imagine it wasn’t thought that saving the phasemask would ever be needed, thus it wasn’t added already.

Oh dear. Looks like I’ve got work to do!

Note that if you dont use spells, the phase is back to 1 when relogged.

Otherwise you need to code it so that everyone on the map has the phase or the area you want or whatever, not just upon teleporting.

Would anyone be willing to help me out on this?

(I’m still in High School, and I’ve only taken 2 programming courses. /emoticons/default_sad.png )

I don’t think 30 is a valid phase. If I remember correctly, the phases use bitmask values, so… 1 2 4 8 16 32 64 128 etc. and, I’m fairly certain you can’t be in multiple phases at once, so…

Of course, if I’m right about that, using bitmask values doesn’t seem like a good way of doing it, since the whole point of them is allowing more than one value to be stored in a single number…

You can be in multiple phases at once. Thats how GM phase works also (you can see all phases and all phases see you)

30 = 2 + 4 + 8 + 16

The script needs to be made for what you need the phase for.

Do all players on the map need to be in phase 30?

Or just after teleporting? Is it a specific area?

?

This small script sets your phase to 30 (+ any other phases you might have had except phase 1)

When you enter map 1.

It also removes phase 30 and adds phase 1 back when you leave.

#include “ScriptPCH.h”

class PhaseOnMap : public WorldMapScript
{
public:
PhaseOnMap() : WorldMapScript(“PhaseOnMap”, 1) // The mapID
{
}

void OnPlayerEnter(Map* map, Player* player)
{
    player->SetPhaseMask(player->GetPhaseMask() & ~1 | 30, true);
}


void OnPlayerLeave(Map* map, Player* player)
{
    player->SetPhaseMask(player->GetPhaseMask() & ~30 | 1, true);
}

};

void AddSC_PhaseOnMap()
{
new PhaseOnMap();
}

This patch would only phase when you teleport:

diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index c5c97e7…8c6aa28 100644
— a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -7791,8 +7791,8 @@ void ObjectMgr::LoadGameTele()

 _gameTeleStore.clear();                                  // for reload case
  • // 0 1 2 3 4 5 6
  • QueryResult result = WorldDatabase.Query(“SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele”);
  • // 0 1 2 3 4 5 6 7

  • QueryResult result = WorldDatabase.Query(“SELECT id, position_x, position_y, position_z, orientation, map, name, phase FROM game_tele”);

    if (!result)
    {
    @@ -7816,6 +7816,7 @@ void ObjectMgr::LoadGameTele()
    gt.orientation = fields[4].GetFloat();
    gt.mapId = fields[5].GetUInt16();
    gt.name = fields[6].GetString();

  •    gt.phase          = fields[7].GetUInt32();
    
       if (!MapManager::IsValidMapCoord(gt.mapId, gt.position_x, gt.position_y, gt.position_z, gt.orientation))
       {
    

diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index b1f80af…dfa3284 100644
— a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -133,6 +133,8 @@ typedef UNORDERED_MAP<uint16, InstanceTemplate> InstanceTemplateContainer;

struct GameTele
{

  • GameTele() : phase(0) { }
  • float position_x;
    float position_y;
    float position_z;
    @@ -140,6 +142,7 @@ struct GameTele
    uint32 mapId;
    std::string name;
    std::wstring wnameLow;
  • uint32 phase;
    };

typedef UNORDERED_MAP<uint32, GameTele > GameTeleContainer;
diff --git a/src/server/scripts/Commands/cs_tele.cpp b/src/server/scripts/Commands/cs_tele.cpp
index f661822…5930bef 100644
— a/src/server/scripts/Commands/cs_tele.cpp
+++ b/src/server/scripts/Commands/cs_tele.cpp
@@ -191,7 +191,9 @@ public:
// save only in non-flight case
else
target->SaveRecallPosition();

  •        if (tele->phase)
    
  •            target->SetPhaseMask(tele->phase, true);
           target->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
       }
       else
    

@@ -287,7 +289,9 @@ public:
// save only in non-flight case
else
player->SaveRecallPosition();

  •        if (tele->phase)
    
  •            player->SetPhaseMask(tele->phase, true);
           player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
       }
    

@@ -336,6 +340,8 @@ public:
else
me->SaveRecallPosition();

  •    if (tele->phase)
    
  •        me->SetPhaseMask(tele->phase, true);
       me->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
       return true;
    
    }

For that you also need this:

ALTER TABLE `game_tele`
	ADD COLUMN `phase` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `map`;

Can you make a PR for that Rochet2?

Of course, Rochet, been a while since I messed with phases, and, I forgot about GM phase being all phases…

I couldn’t exactly tell in the patch (maybe if I apply it to the code), but will that cause a “.tele add” to save your current phase or will that need to be altered manually in the database?

No, the patch is a DB only feature.

I decided to leave .tele add out since it would either force me to code an extra optional argument or use player phase, which is often the GM phase anyways or a phase generated by misc spells on you.

Fair enough. But I figured that needed to be asked and answered for others to know if they really wanted to use the patch as is or take the time to added in the support for specifying a phase on the add. As you pointed out, taking the player’s phase would most likely result in the -1 phase from GM mode. I think the optional argument of a phasemask would be the best way to do it.