Forum > Serverside Modding

[SOLVED] [C++] Set PvP FFA when player enter map

(1/5) > >>

bizzlesnaff:
Hey guys,

I try today to set the pvp stat of every player to ffa, when they entered a specific map (9999)
So...I searched some time and, yeah, thats what i tried out..


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

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

void OnPlayerEnterMap(Map* map, Player* player)
{

if (player->GetMapId() == 9999)
player->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
}

};

void AddSC_OnMapEnter()
{
new OnMapEnter();
}

--- End code ---

I can compile it, but ingame it didn't work...
Someone an idea ;)?

Kaev:
Did you add it to the ScriptLoader? Don't just say yes, look in the file.  I thought i already addes scripts there, but never did.. :P
If yes: Does the Script trigger at all? Print out a message before changing the flag for testing.

bizzlesnaff:
void AddSC_OnMapEnter(); and AddSC_OnMapEnter();, yes it's in the scriptloader ;)

I'm not quit sure, if I understand the second part. Do you mean I should print out some text, if someone enter the map?

Edit:
tried also to write something like :

--- Code: ---if (player->GetMapId() == 9999)
player->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
return (true);

--- End code ---
but it's always an error, when i write "return true", and just "return" doesn't change anything..

Rochet2:
OnPlayerEnterMap is not a hook.

If you look in ScriptMgr.cpp you see that OnPlayerEnterMap triggers the hook OnMapChanged, which is what you should be using as well.
C++ has this great new keyword "override" and I recommend using it.
It makes sure the function actually overrides a virtual function like it is supposed to.



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

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

    void OnMapChanged(Player* player) override
    {
        if (player->GetMapId() == 9999)
            player->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
    }

};

void AddSC_OnMapEnter()
{
    new OnMapEnter();
}

--- End code ---

By adding prints Kaev meant that you should add code that outputs something to the worldserver console or elsewhere so you can see that the code actually runs.
For example

--- Code: ---printf("Does this appear in console?n");
--- End code ---


If the code above still does not work, it might be that the flags are reverted back after the hook runs.
Many hooks actually execute BEFORE the event actually happens.
You can make a function trigger after the event by using a timed event with 0 as the delay so it will execute "as soon as possible".

bizzlesnaff:
I used the code now, and added just this:

--- Code: ---printf("FFA worked?n");

--- End code ---
In the console it appears (sadly everytime any player change the map) not only if a player join my map.
But as you said it doesn't work.
I really don't like to leach code, but can u explain me how this should work?

Navigation

[0] Message Index

[#] Next page

Go to full version