This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [QUESTION] C++ Question SetPhaseMask  (Read 2554 times)

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
[QUESTION] C++ Question SetPhaseMask
« on: November 01, 2014, 01:25:58 am »
Okay, i'm very new to c++, but I have a question about how to set a phasemask via c++

here is the script i have so far:

        void OnPlayerEnter(Player* player) OVERRIDE
        {
                if player->HasSpell(95000)
                      Set a specific creature spawn with a specific guid to x01;
         }

I know the method is SetPhaseMask(Mask, false) but how do you specify the GUID of the spawn to modify?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #1 on: November 01, 2014, 01:40:16 am »
Okay after some digging, I think it's this:

void OnPlayerEnter(Player* player) OVERRIDE
  {
     if player->HasSpell(95000)
        Creature* temp =  instance->GetCreature(CreatureGUID);
        temp -> SetPhaseMask(x01, false);
   }

Am i close or way the hell off?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #2 on: November 03, 2014, 02:38:26 pm »
Why do you use x01 instead of 1?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #3 on: November 03, 2014, 11:25:28 pm »
Your right, it should be 1, guess all the flag work I do in dbcs got me thinking wrong.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #4 on: November 04, 2014, 07:45:40 am »
Not sure how about the GUID thing.
Maybe you could spawn an invisible GO on that place and use this:

Code: [Select]
if (Creature *npc = go->FindNearestCreature(/*entry here*/, /*distance*/30, /*alive*/true))
{
uint64 guid = npc->GetGUID();
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #5 on: November 04, 2014, 08:57:27 am »
What I'm doing is attempting to make a player housing script using instances.  That part works fine, now I spawned everything on the map with a phase of 32, and if the player has unlocked say the banker, when he enters, it shifts the phase from 32 to 1.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #6 on: November 04, 2014, 01:30:47 pm »
Luzifix did this for Schattenhain, didn't he?
Afaik they set some points/coordinates and create a shape, like an areatrigger, from it.
If a players coordinates are in this shape (or maybe they really did it with an dynamic areatrigger? dunno), the players phase will change.
That means, that you will probably need at least the basics of 3d math to calculate the shape.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #7 on: November 04, 2014, 02:08:01 pm »
I'm using instancing, so all I do is use the OnEnter event.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #8 on: November 04, 2014, 02:08:01 pm »
I'm using instancing, so all I do is use the OnEnter event.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #9 on: November 04, 2014, 10:18:48 pm »
Uhm, isn't an instance bound to a map?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #10 on: November 10, 2014, 05:03:46 pm »
Yeah, an instance is bound to a map.  Ive made a separate map for player housing, and when you enter it should shift all the creatures / Gameobjects that your character can use to your phase.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Heliocratic

  • Registred Member
  • BLP Convertor
  • *****
  • Posts: 6
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #11 on: November 30, 2014, 09:49:40 am »
Hi, I haven't worked on TrinityCore for 3 months now, but I'll give you a definite answer. I worked on a creature deathsystem, on the technical side I decided to phase all the creatures instead of kill/delete them from the DB, to avoid abuse. So I messed with phasing and found that your solution is right but only works untill the next server restart because you're changing the phase of a creature in memory only, not through the Database.

Code: [Select]
void OnPlayerEnter(Player* player) OVERRIDE
{
if player->HasSpell(95000)
Creature* temp = instance->GetCreature(CreatureGUID);
temp -> SetPhaseMask(x01, false);
}

Like I said, this is only a temporary solution, if you want to permanently add a NPC to a phase then this little snippet of code is required.

Code: [Select]
killed->SetPhaseMask(8, true); //Put NPC in phase 8
WorldDatabase.PExecute("UPDATE creature SET phaseMask = 8 WHERE guid = %u;", killed->GetGUIDLow()); // Update the database to set the creature's phase mask.

I've tested this snippet and it works.

So, here is your slightly corrected code,
Code: [Select]
void OnPlayerEnter(Player* player)
{
if (player->HasSpell(95000))
Creature* temp = instance->GetCreature(CreatureGUIDLow);
temp -> SetPhaseMask(1, true);
WorldDatabase.PExecute("UPDATE creature SET phaseMask = 1 WHERE guid = %u;", killed->GetGUIDLow());
}

Again, the executing to database is if you want to make the NPC stay there permanently, just remove the SQL line if you want the NPC to be temporary.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

deep6ixed

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 189
    • View Profile
Re: [QUESTION] C++ Question SetPhaseMask
« Reply #12 on: November 30, 2014, 10:49:23 pm »
This script is run inside of an instance, modifying the database would modify all copies of the instance.  The script I wrote modifies the spawn flag for that specific instance.  and if a server reload happens, the script will rerun as the player enters the instance upon login.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »