[DiscordArchive] Is it possible to schedule an event to happen f...
[DiscordArchive] Is it possible to schedule an event to happen f...
Archived author: Needle • Posted: 2024-12-18T18:41:59.412000+00:00
Original source
Archived author: Needle • Posted: 2024-12-18T18:42:00.294000+00:00
Original source
Thread automatically created by Drikish in <#415944535718494208>
Archived author: stoneharry • Posted: 2024-12-18T18:43:59.508000+00:00
Original source
not with anything that exists today
It can be set up in DB with the game events system
Or you can write a new command to do it
Archived author: Drikish • Posted: 2024-12-18T19:17:31.908000+00:00
Original source
```c++
static bool HandleNightfallTrigger(ChatHandler* handler, char const* /*args*/)
{
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
WorldPackets::Misc::LoginSetTimeSpeed loginSetTimeSpeed;
loginSetTimeSpeed.NewSpeed = 2.0f;
loginSetTimeSpeed.GameTime = GameTime::GetGameTime();
loginSetTimeSpeed.ServerTime = GameTime::GetGameTime();
handler->GetSession()->GetPlayer()->SendDirectMessage(loginSetTimeSpeed.Write());
// Time out here
target->AddDelayedEvent(5000, [handler]() {
handler->SendSysMessage("Hello world!");
});
return true;
}
```
Archived author: Drikish • Posted: 2024-12-18T19:17:57.821000+00:00
Original source
I mean like this basically trying to schedule after X Seconds something else happens <@271350028985958408>
Archived author: Drikish • Posted: 2024-12-18T19:18:34.434000+00:00
Original source
This is wrong and crashes server as i think the context is long deleted before the event can be fired but it kind of illustrates what im trying to do
Archived author: Drikish • Posted: 2024-12-18T19:18:54.078000+00:00
Original source
I was hoping there was a World events scheduler that I could hook into that's basically the world server itself
Archived author: stoneharry • Posted: 2024-12-18T19:22:07.994000+00:00
Original source
I'm not familiar with the scheduling API (I can dig into it if you are really stuck) but that pointer `handler` might have been invalidated, and when you try to access it, it crashes.
You should store the player GUID and fetch the player reference again by GUID, checking if you get a value back
Archived author: Drikish • Posted: 2024-12-18T19:22:55.041000+00:00
Original source
Well to be honest I need to do this server side, i did it as a GM command just as a test.
Archived author: Drikish • Posted: 2024-12-18T19:23:03.916000+00:00
Original source
I think the Events system is maybe the best way like you said