• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] phase out dueling error

Status
Not open for further replies.

Shaorin

Respected Member
hi all. i ahve this phase out dueling script it works fine in core and so, but when i duel in-game it phase out the falg too so it will be like ppl and fleeing and can i get help to fix it?

i saw on ******* that someon had post a V2 but that one did not work i get error on complite. here is my script.

#include "MapManager.h"

class PhasedDueling : public PlayerScript
{
public:
PhasedDueling() : PlayerScript("PhasedDueling") { }

void OnDuelStart(Player* firstplayer, Player* secondplayer)
{
uint32 PlayersInsidePhase = 0;
uint32 PhaseToCheck = 1;
Map* map = sMapMgr->FindMap(firstplayer->GetMapId(), firstplayer->GetInstanceId());

if (!map)
return;
Map::playerList const& players = map->GetPlayers();
for (Map::playerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
{
Player* check = itr->GetSource();
if (!check || !check->GetSession())
continue;

if (check->GetPhaseMask() == PhaseToCheck)
{
++PlayersInsidePhase;
++PhaseToCheck;
PlayersInsidePhase = 0;
}
}

if (PlayersInsidePhase == 0)
{
firstplayer->SetPhaseMask(PhaseToCheck, true);
secondplayer->SetPhaseMask(PhaseToCheck, true);
}
}
};

void AddSC_PhasedDueling()
{
new PhasedDueling();
}

thx for all your help and support^^
 

Tommy

Founder
Just because the second script had an error, doesn't mean you couldn't paste it so someone could fix it for you. :p

The logic in this script is pretty stupid I must say. There is a 'OnDuelEnd' hook, but it isn't being used to set the phase of the player back once the duel ends. You should also note that not all phases are unique and players can still see each other in some phases.

About the gameobject not being in the same phase, this might work, I haven't tested it. I also set the player's phase back to normal once the duel ends too:

Code:
#include "MapManager.h"

class PhasedDueling : public PlayerScript
{
public:
    PhasedDueling() : PlayerScript("PhasedDueling") { }

    void OnDuelStart(Player* firstPlayer, Player* secondPlayer)
    {
        uint32 playersInsidePhase = 0;
        uint32 phaseToCheck = 1;
        Map* map = sMapMgr->FindMap(firstPlayer->GetMapId(), firstPlayer->GetInstanceId());

        if (!map)
            return;

        Map::PlayerList const& players = map->GetPlayers();
        for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
        {
            Player* player = itr->GetSource();
            if (!player || !player->GetSession())
                continue;

            if (player->GetPhaseMask() == phaseToCheck)
            {
                ++playersInsidePhase;
                ++phaseToCheck;
                playersInsidePhase = 0;
            }
        }

        if (playersInsidePhase == 0)
        {
            firstPlayer->SetPhaseMask(phaseToCheck, true);
            secondPlayer->SetPhaseMask(phaseToCheck, true);
        }

        GameObject* go = map->GetGameObject(firstPlayer->GetUInt64Value(PLAYER_DUEL_ARBITER));
        if (go)
            go->SetPhaseMask(phaseToCheck, true);
    }

    void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType type) 
    {
        winner->SetPhaseMask(1, true);
        loser->SetPhaseMask(1, true);
    }
};

void AddSC_PhasedDueling()
{
    new PhasedDueling();
}
 
Last edited:

Rochet2

Moderator / Eluna Dev
Code:
        [COLOR="#FF8C00"]uint32 PlayersInsidePhase = 0;
[/COLOR].. code..
            if (check->GetPhaseMask() == PhaseToCheck)
            {
                [COLOR="#FF8C00"]++PlayersInsidePhase;[/COLOR]
                ++PhaseToCheck;
                [COLOR="#FF8C00"]PlayersInsidePhase = 0;[/COLOR]
            }
.. code ..
        [COLOR="#FF8C00"]if (PlayersInsidePhase == 0)[/COLOR]
        {
            firstplayer->SetPhaseMask(PhaseToCheck, true);
            secondplayer->SetPhaseMask(PhaseToCheck, true);
        }

.. Right ..
So PlayersInsidePhase is always 0..?


Anyways.
I made my version of this script:
Using only unique phases if available, otherwise dont use phasing.
Removed useless stuff like noted above.
Thanks to Tommy, it phases the flag (in case that worked .. nobody reported back yet..)
Very little looping/weight added compared to the added features :)
Attempt restoring the player's phase so that it includes spell phasing. Also fixed for GMs so you get back to GM phase.
Untested :3

Code:
#include "ScriptPCH.h"
#include "MapManager.h"

class PhasedDueling : public PlayerScript
{
public:
    PhasedDueling() : PlayerScript("PhasedDueling") { }

    void OnDuelStart(Player* firstplayer, Player* secondplayer)
    {
        Map* map = firstplayer->GetMap();
        uint32 usedPhases = 0; // used phases
        Map::PlayerList const& players = map->GetPlayers();
        for (Map::PlayerList::const_iterator iter = players.begin(); iter != players.end(); ++iter)
        {
            Player* check = iter->GetSource();
            if (!check || !check->GetSession())
                continue;
            usedPhases |= check->GetPhaseMask(); // insert player's phases to used phases
        }

        for (uint32 phase = 2; phase <= ULONG_MAX/2; phase *= 2) // loop all unique phases
        {
            if (usedPhases & phase) // If phase in use
                continue;

            firstplayer->SetPhaseMask(phase, true);
            secondplayer->SetPhaseMask(phase, true);
            if (GameObject* go = map->GetGameObject(firstplayer->GetUInt64Value(PLAYER_DUEL_ARBITER)))
                go->SetPhaseMask(phase, true);
            return;
        }

        // Could not phase players :(
    }
    
    // Restore phases
    void OnDuelEnd(Player* firstplayer, Player* secondplayer)
    {
        firstplayer->SetPhaseMask(GetPhase(firstplayer), true);
        secondplayer->SetPhaseMask(GetPhase(secondplayer), true);
    }
    
    // Attempt in storing the player phase with spell phases included.
    uint32 GetPhase(Player* player) const
    {
        if (player->IsGameMaster())
            return uint32(PHASEMASK_ANYWHERE);
        
        // GetPhaseMaskForSpawn copypaste
        uint32 phase = PHASEMASK_NORMAL;
        Player::AuraEffectList const& phases = player->GetAuraEffectsByType(SPELL_AURA_PHASE);
        if (!phases.empty())
            phase = phases.front()->GetMiscValue();
        if (uint32 n_phase = phase & ~PHASEMASK_NORMAL)
            return n_phase;

        return PHASEMASK_NORMAL;
    }
};

void AddSC_PhasedDueling()
{
    new PhasedDueling();
}
 
Last edited:

Barebones

BETA Tester
I got this error:

Error 1 error C4263: 'void PhasedDueling::OnDuelEnd(Player *,Player *)' : member function does not override any base class virtual member function C:\Users\Keith\Desktop\Trinitycore\src\server\scripts\Custom\phaseddueling.cpp 38 1 scripts

and

Error 2 error C4264: 'void PlayerScript::OnDuelEnd(Player *,Player *,DuelCompleteType)' : no override available for virtual member function from base 'PlayerScript'; function is hidden C:\Users\Keith\Desktop\Trinitycore\src\server\scripts\Custom\phaseddueling.cpp 60 1 scripts
 

teroare

Enthusiast
I think you have to add
Code:
DuelCompleteType type
on
Code:
void OnDuelEnd(Player* firstplayer, Player* secondplayer)
so it looks like
Code:
void OnDuelEnd(Player* firstplayer, Player* secondplayer, DuelCompleteType type)
 

Shaorin

Respected Member
flag phaseing work fine.

will test your script also Rochet2

- - - Updated - - -

ok i ge tthis errors:

3>F:\c\Custom\phasedueling.cpp(38): error C4263: 'void PhasedDueling::OnDuelEnd(Player *,Player *)' : member function does not override any base class virtual member function
3>F:\c\Custom\phasedueling.cpp(60): error C4264: 'void PlayerScript::OnDuelEnd(Player *,Player *,DuelCompleteType)' : no override available for virtual member function from base 'PlayerScript'; function is hidden
3> C:/TrinityCore-master/src/server/game/Scripting\ScriptMgr.h(720) : see declaration of 'PlayerScript::OnDuelEnd'
3> C:/TrinityCore-master/src/server/game/Scripting\ScriptMgr.h(678) : see declaration of 'PlayerScript'

- - - Updated - - -

sorry can't fix it myself. i can't even make a script by watch a tut and copy everything and replace names and get errors that the poerson are not getting^^ ofc i do it 100% after the vid.


i will go back and see if my error still stand i will post it what other questings
 

Tommy

Founder
Code:
        [COLOR="#FF8C00"]uint32 PlayersInsidePhase = 0;
[/COLOR].. code..
            if (check->GetPhaseMask() == PhaseToCheck)
            {
                [COLOR="#FF8C00"]++PlayersInsidePhase;[/COLOR]
                ++PhaseToCheck;
                [COLOR="#FF8C00"]PlayersInsidePhase = 0;[/COLOR]
            }
.. code ..
        [COLOR="#FF8C00"]if (PlayersInsidePhase == 0)[/COLOR]
        {
            firstplayer->SetPhaseMask(PhaseToCheck, true);
            secondplayer->SetPhaseMask(PhaseToCheck, true);
        }

.. Right ..
So PlayersInsidePhase is always 0..?


Anyways.
I made my version of this script:
Using only unique phases if available, otherwise dont use phasing.
Removed useless stuff like noted above.
Thanks to Tommy, it phases the flag (in case that worked .. nobody reported back yet..)
Very little looping/weight added compared to the added features :)
Attempt restoring the player's phase so that it includes spell phasing. Also fixed for GMs so you get back to GM phase.
Untested :3

Code:
#include "ScriptPCH.h"
#include "MapManager.h"

class PhasedDueling : public PlayerScript
{
public:
    PhasedDueling() : PlayerScript("PhasedDueling") { }

    void OnDuelStart(Player* firstplayer, Player* secondplayer)
    {
        Map* map = firstplayer->GetMap();
        uint32 usedPhases = 0; // used phases
        Map::PlayerList const& players = map->GetPlayers();
        for (Map::PlayerList::const_iterator iter = players.begin(); iter != players.end(); ++iter)
        {
            Player* check = iter->GetSource();
            if (!check || !check->GetSession())
                continue;
            usedPhases |= check->GetPhaseMask(); // insert player's phases to used phases
        }

        for (uint32 phase = 2; phase <= ULONG_MAX/2; phase *= 2) // loop all unique phases
        {
            if (usedPhases & phase) // If phase in use
                continue;

            firstplayer->SetPhaseMask(phase, true);
            secondplayer->SetPhaseMask(phase, true);
            if (GameObject* go = map->GetGameObject(firstplayer->GetUInt64Value(PLAYER_DUEL_ARBITER)))
                go->SetPhaseMask(phase, true);
            return;
        }

        // Could not phase players :(
    }
    
    // Restore phases
    void OnDuelEnd(Player* firstplayer, Player* secondplayer)
    {
        firstplayer->SetPhaseMask(GetPhase(firstplayer), true);
        secondplayer->SetPhaseMask(GetPhase(secondplayer), true);
    }
    
    // Attempt in storing the player phase with spell phases included.
    uint32 GetPhase(Player* player) const
    {
        if (player->IsGameMaster())
            return uint32(PHASEMASK_ANYWHERE);
        
        // GetPhaseMaskForSpawn copypaste
        uint32 phase = PHASEMASK_NORMAL;
        Player::AuraEffectList const& phases = player->GetAuraEffectsByType(SPELL_AURA_PHASE);
        if (!phases.empty())
            phase = phases.front()->GetMiscValue();
        if (uint32 n_phase = phase & ~PHASEMASK_NORMAL)
            return n_phase;

        return PHASEMASK_NORMAL;
    }
};

void AddSC_PhasedDueling()
{
    new PhasedDueling();
}

I didn't catch that. I was about to facedesk because I was tired, but thanks, Rochet!

flag phaseing work fine.

will test your script also Rochet2

- - - Updated - - -

ok i ge tthis errors:



- - - Updated - - -

sorry can't fix it myself. i can't even make a script by watch a tut and copy everything and replace names and get errors that the poerson are not getting^^ ofc i do it 100% after the vid.


i will go back and see if my error still stand i will post it what other questings


'OnDuelEnd' is missing 'DuelCompleteType type' like, teroare said. It isn't hard to fix at all, go to 'PlayerScript', look at the 'OnDuelEnd' arguments and copy them down. You can also search in ScriptMgr.cpp and ScriptMgr.h to see the hook arguments as well..

Updated and it compiles fine:

Code:
#include "ScriptPCH.h"
#include "MapManager.h"

class PhasedDueling : public PlayerScript
{
public:
    PhasedDueling() : PlayerScript("PhasedDueling") { }

    void OnDuelStart(Player* firstplayer, Player* secondplayer)
    {
        Map* map = firstplayer->GetMap();
        uint32 usedPhases = 0; // used phases
        Map::PlayerList const& players = map->GetPlayers();
        for (Map::PlayerList::const_iterator iter = players.begin(); iter != players.end(); ++iter)
        {
            Player* check = iter->GetSource();
            if (!check || !check->GetSession())
                continue;
            usedPhases |= check->GetPhaseMask(); // insert player's phases to used phases
        }

        for (uint32 phase = 2; phase <= ULONG_MAX/2; phase *= 2) // loop all unique phases
        {
            if (usedPhases & phase) // If phase in use
                continue;

            firstplayer->SetPhaseMask(phase, true);
            secondplayer->SetPhaseMask(phase, true);
            if (GameObject* go = map->GetGameObject(firstplayer->GetUInt64Value(PLAYER_DUEL_ARBITER)))
                go->SetPhaseMask(phase, true);
            return;
        }

        // Could not phase players :(
    }
    
    // Restore phases
    void OnDuelEnd(Player* firstplayer, Player* secondplayer, DuelCompleteType type)
    {
        firstplayer->SetPhaseMask(GetPhase(firstplayer), true);
        secondplayer->SetPhaseMask(GetPhase(secondplayer), true);
    }
    
    // Attempt in storing the player phase with spell phases included.
    uint32 GetPhase(Player* player) const
    {
        if (player->IsGameMaster())
            return uint32(PHASEMASK_ANYWHERE);
        
        // GetPhaseMaskForSpawn copypaste
        uint32 phase = PHASEMASK_NORMAL;
        Player::AuraEffectList const& phases = player->GetAuraEffectsByType(SPELL_AURA_PHASE);
        if (!phases.empty())
            phase = phases.front()->GetMiscValue();
        if (uint32 n_phase = phase & ~PHASEMASK_NORMAL)
            return n_phase;

        return PHASEMASK_NORMAL;
    }
};

void AddSC_PhasedDueling()
{
    new PhasedDueling();
}
 
Status
Not open for further replies.
Top