[DiscordArchive] Is it possible to schedule an event to happen f...
[DiscordArchive] Is it possible to schedule an event to happen f...
Archived author: stoneharry • Posted: 2024-12-18T23:47:13.523000+00:00
Original source
```c++
void OnUpdate(Map* map, uint32 diff)
{
// Ensure we don't tick more than once a second
_elapsedTime += diff;
if (_elapsedTime < 1000)
return;
_elapsedTime = 0;
// More expensive logic
if (map->ShouldActivateMidnight())
{
}
}
```
Archived author: stoneharry • Posted: 2024-12-18T23:47:42.996000+00:00
Original source
so you're updating the state and the update script is reacting to that
Archived author: Drikish • Posted: 2024-12-18T23:48:49.480000+00:00
Original source
That makes perfect sense
Archived author: Drikish • Posted: 2024-12-18T23:48:56.933000+00:00
Original source
Your a legend thank you very much ❤️
Archived author: Drikish • Posted: 2024-12-18T23:49:52.347000+00:00
Original source
Just working out now how to keep track of time here and keeping it progressing forward at a new rate based on the loginSpeedTime
Archived author: Drikish • Posted: 2024-12-19T00:06:56.607000+00:00
Original source
```c++
#include "WorldPacket.h"
#include "MiscPackets.h"
class StormsReachMapScript : public WorldMapScript
{
public:
StormsReachMapScript() : WorldMapScript("storms_reach_map_script", 2000)
{
}
void OnCreate(Map* map) override
{
mapCurrentTime = GameTime::GetGameTime();
}
void OnPlayerEnter(Map* map, Player* player) override
{
// Nightfall: Change in game speed to 2 hours per day-night cycle (4 hour day)
WorldPackets::Misc::LoginSetTimeSpeed loginSetTimeSpeed;
loginSetTimeSpeed.NewSpeed = 0.10000002f;
loginSetTimeSpeed.GameTime = mapCurrentTime;
loginSetTimeSpeed.ServerTime = GameTime::GetGameTime();
player->SendDirectMessage(loginSetTimeSpeed.Write());
}
void OnPlayerLeave(Map* map, Player* player) override
{
// Reset time progression back to normal time for players leaving the map
WorldPackets::Misc::LoginSetTimeSpeed loginSetTimeSpeed;
loginSetTimeSpeed.NewSpeed = 0.01666667f;
loginSetTimeSpeed.GameTime = GameTime::GetGameTime();
loginSetTimeSpeed.ServerTime = GameTime::GetGameTime();
player->SendDirectMessage(loginSetTimeSpeed.Write());
}
void OnUpdate(Map* map, uint32 diff) override
{
// Update the current time every 10 seconds (6x faster time = 10 seconds per in game minute)
_timeLoopDelta += diff;
if (_timeLoopDelta > 10000) {
mapCurrentTime += 60;
_timeLoopDelta = 0;
}
// Make sure we only tick 1 per second for core logic
_coreLoopTime += diff;
if (_coreLoopTime < 1000)
return;
_coreLoopTime = 0;
// Core Logic
//
}
private:
uint32 _coreLoopTime = 0;
uint32 _timeLoopDelta = 0;
time_t mapCurrentTime;
};
void NightfallMapScripts()
{
new StormsReachMapScript();
}
```
Archived author: Drikish • Posted: 2024-12-19T00:07:28.460000+00:00
Original source
So this is my testing trying to keep track of two loops, can't think of a better way to do it
Archived author: stoneharry • Posted: 2024-12-19T00:08:18.309000+00:00
Original source
it might be a little buggy manually incrementing `_timeLoopDelta` there
Archived author: stoneharry • Posted: 2024-12-19T00:08:24.236000+00:00
Original source
you don't get a gurantee how long the diff will be
Archived author: stoneharry • Posted: 2024-12-19T00:08:36.285000+00:00
Original source
it might be 1ms it might be 5000ms