[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-18T19:51:26.748000+00:00
Original source
Check: `virtual void Update(uint32 /*diff*/) { }`
In: `InstanceScript`
That would be the way to script it, on map update you take the diff and check if it has passed a time. If it has, you can fire your logic and reset the timer. You can check if the server time has passed the 2 hour mark since the last call (currentTime - diff) and if it has fire your event.
You should probably also check if a minimum time has passed since you last checked the time as a performance gain (so you don't check every tick).
Archived author: stoneharry • Posted: 2024-12-18T19:52:18.641000+00:00
Original source
`void Map::Update(uint32 t_diff)` exists in `Map.cpp`
That's where most of the logic exists
Archived author: stoneharry • Posted: 2024-12-18T19:52:55.486000+00:00
Original source
You can see that fires: `void ScriptMgr::OnMapUpdate(Map* map, uint32 diff)`
Archived author: Drikish • Posted: 2024-12-18T21:05:46.471000+00:00
Original source
<@271350028985958408> - so your saying write an instanceScript for this map?
Archived author: stoneharry • Posted: 2024-12-18T21:11:31.669000+00:00
Original source
It can be a map script, see `ScriptMgr::OnMapUpdate(Map* map, uint32 diff)`
Archived author: Drikish • Posted: 2024-12-18T21:18:05.126000+00:00
Original source
```c++
class MapScript : public UpdatableScript<TMap>
{
MapEntry const* _mapEntry;
protected:
MapScript(uint32 mapId) : _mapEntry(sMapStore.LookupEntry(mapId))
{
if (!_mapEntry)
TC_LOG_ERROR("scripts", "Invalid MapScript for %u; no such map ID.", mapId);
}
public:
// Gets the MapEntry structure associated with this script. Can return NULL.
MapEntry const* GetEntry() { return _mapEntry; }
// Called when the map is created.
virtual void OnCreate(TMap* /*map*/) { }
// Called just before the map is destroyed.
virtual void OnDestroy(TMap* /*map*/) { }
// Called when a grid map is loaded.
virtual void OnLoadGridMap(TMap* /*map*/, GridMap* /*gmap*/, uint32 /*gx*/, uint32 /*gy*/) { }
// Called when a grid map is unloaded.
virtual void OnUnloadGridMap(TMap* /*map*/, GridMap* /*gmap*/, uint32 /*gx*/, uint32 /*gy*/) { }
// Called when a player enters the map.
virtual void OnPlayerEnter(TMap* /*map*/, Player* /*player*/) { }
// Called when a player leaves the map.
virtual void OnPlayerLeave(TMap* /*map*/, Player* /*player*/) { }
// Called on every map update tick.
virtual void OnUpdate(TMap* /*map*/, uint32 /*diff*/) { }
};
```
tring name, uint32 mapId) : ScriptObject(name), MapScript<Map>(mapId)Archived author: Drikish • Posted: 2024-12-18T21:20:08.776000+00:00
Original source
```C++
WorldMapScript::WorldMapScript(std:
tring name, uint32 mapId) : ScriptObject(name), MapScript<Map>(mapId)
{
if (GetEntry() && !GetEntry()->IsWorldMap())
TC_LOG_ERROR("scripts", "WorldMapScript for map %u is invalid.", mapId);
ScriptRegistry<WorldMapScript>::AddScript(this);
}
```
Archived author: Drikish • Posted: 2024-12-18T21:20:22.780000+00:00
Original source
I guess this? Sorry im not on the usual TC branch so things a bit diff
Archived author: stoneharry • Posted: 2024-12-18T21:45:55.702000+00:00
Original source
yes so you can hook `OnUpdate` on a script you create
Archived author: stoneharry • Posted: 2024-12-18T21:48:13.923000+00:00
Original source
so create a script in https://github.com/TrinityCore/TrinityCo...loader.cpp