Forum > Serverside Modding
[SOLVED] [C++] Set PvP FFA when player enter map
<< < (2/5) > >>
Rochet2:
Most likely (did not check) the player enter map hook runs before updatezone function is called for the player. In that function call the pvp flags are set again.
Incase you want to have the pvp flag on even though the player changes zones, you might want to use the update zone hook.
For the timed event, See how BasicEvent is used.
It goes about like this:
--- Code: ---class MyEvent : public BasicEvent { MyEvent(Player* player) : player {} bool Execute(uint32, uin64) { // my code to do on timed event return true; } Player* player; };
player->m_events->ScheduleEvent(new MyEvent(player), player->m_events->CalculateTime(0));
--- End code ---
Wrote that from memory so dont expect it to work without edits.
bizzlesnaff:
Okay, I searched some time arround copied many things and worked...something...out :D
--- Code: ---#include "ScriptPCH.h"
#include "ScriptPCH.h"
enum Enums { FIRST_TELEDELAY = 1000, };
struct Event { uint8 Events; }; static std::map<uint32, Event> _events;
class Teleport : public BasicEvent { public: Teleport(Player* player) : _Plr(player) {}
bool Execute(uint64 /*time*/, uint32 /*diff*/) { uint32 pEvent; pEvent = _Plr->GetGUID();
switch (_events[pEvent].Events) { case 0: // First Teleport if (_Plr->GetMapId() == 9999) _Plr->SetPvP(true); _Plr->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); _events[pEvent].Events = 1; break;
} return true; } Player* _Plr; };
class OnMapEnter : public PlayerScript { public: OnMapEnter() : PlayerScript("OnMapEnter") {}
void OnChangeMap(Player* player) { if (player->GetMapId() == 9999) player->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); printf("FFA worked?n"); player->m_Events.AddEvent(new Teleport(player), player->m_Events.CalculateTime(FIRST_TELEDELAY)); } };
void AddSC_OnMapEnter() { new OnMapEnter(); }
--- End code ---
Take most of the code from a teleport script or something.. But...I've made any mistake...the server crashs, when I entered the area with an playerchar. The "FFA worked?" is still printed in the console..
Rochet2:
Hmm, dont see a reason for it to crash. Only that it has a thread safety issue.
Removed some of the useless code:
--- Code: ---#include "ScriptPCH.h"
enum Enums { FIRST_TELEDELAY = 1000, };
class Teleport : public BasicEvent { public: Teleport(Player* player) : _Plr(player) { }
bool Execute(uint64 /*time*/, uint32 /*diff*/) { if (_Plr->GetMapId() == 9999) { printf("Executing timed eventn"); _Plr->SetPvP(true); _Plr->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); }
return true; } Player* _Plr; };
class OnMapEnter : public PlayerScript { public: OnMapEnter() : PlayerScript("OnMapEnter") { }
void OnChangeMap(Player* player) { if (player->GetMapId() == 9999) { printf("Adding timed eventn"); player->m_Events.AddEvent(new Teleport(player), player->m_Events.CalculateTime(FIRST_TELEDELAY)); } } };
void AddSC_OnMapEnter() { new OnMapEnter(); }
--- End code ---
Maybe you should try build in debug mode and or run it under a debugger?
bizzlesnaff:
I'll try that. But for now I take the code you write, and the good thing is...the server don't crash any longer, when I join my map..:D Bad thing is, that there is nothing more in the console...:(
Ascathos:
I haven't used TimedEvents. I assume you have to effectively call Execute()
--- Code: ---enum Enums { FIRST_TELEDELAY = 1 * IN_MILLISECONDS };
class Teleport : public BasicEvent { public: Teleport(Player* player) : _Plr(player) { }
bool Teleport::Execute(uint64 /*time*/, uint32 /*diff*/) { if (_Plr->GetMapId() == 9999) { printf("Executing timed eventn"); _Plr->SetPvP(true); _Plr->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); }
return true; }
private: Player* _Plr; };
class OnMapEnter : public PlayerScript { public: OnMapEnter() : PlayerScript("OnMapEnter") { }
void OnChangeMap(Player* player) { if (player->GetMapId() == 9999) { printf("Adding timed eventn"); Teleport* tele = new Teleport(player); player->m_Events.AddEvent(tele, player->m_Events.CalculateTime(FIRST_TELEDELAY)); } } }; --- End code ---
Does this work ? I based it off BattlegroundQueue
Navigation
[0] Message Index
[#] Next page
[*] Previous page
|