Hello, i am very new to this and i experimenting on some hooks to wrote a plugin.
i want use this as example
if player start looting all good msg is come up, but if a player start looting ends it and agian start looting it will spam the server with the msg. so i want add something to avoid it for example 2-3 minutes.Code:void OnLootEntity(BasePlayer player, BaseEntity entity) { Puts("OnLootEntity works!"); }
example: player start looting, the msg comes, and then it will not show the msg for 2-3minutes anymore, if the hook is calleds.
thx in advance
Avoid spam msg on Hook
Discussion in 'Rust Development' started by trixxxi, Jun 15, 2018.
-
Wulf Community Admin
Add a variable that stores when the hook was last ran, then check that each time the hook is called to see if it can be called again.
-
i think i have found now a solution for it
Code:DateTime lastLootStart = new DateTime(2009, 8, 1, 0, 0, 0); DateTime lastLootEnd = new DateTime(2009, 8, 1, 0, 0, 0);void OnLootEntity(BasePlayer player, BaseEntity entity) { if (lastLootEnd >= lastLootStart) { lastLootStart = DateTime.Now; lastLootStart = lastLootStart.AddSeconds(60); Puts("OnLootEntity works!"); } lastLootEnd = DateTime.Now; }
-
Wulf Community Admin
You can clean that up a bit yet, but that'd be essentially a way to do it.
-
Something to keep in mind as I also started developing recently, this is going to affect all players.
You may want to keep a running collection of players and their own loot times. Can implement easily with a structure like
Code:public static Dictionary<ulong, DateTime> PlayerLootTimers = new Dictionary<ulong, DateTime>();
!