Modcraft - The community dedicated to quality WoW modding!

Wrath of the Lich King Modding => Serverside Modding => Topic started by: deep6ixed on November 01, 2014, 01:25:58 am

Title: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed 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?
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed 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?
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: Kaev on November 03, 2014, 02:38:26 pm
Why do you use x01 instead of 1?
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed 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.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: Kaev 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();
}
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed 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.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: Kaev 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.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed on November 04, 2014, 02:08:01 pm
I'm using instancing, so all I do is use the OnEnter event.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed on November 04, 2014, 02:08:01 pm
I'm using instancing, so all I do is use the OnEnter event.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: Kaev on November 04, 2014, 10:18:48 pm
Uhm, isn't an instance bound to a map?
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed 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.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: Heliocratic 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.
Title: Re: [QUESTION] C++ Question SetPhaseMask
Post by: deep6ixed 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.