From 3b9ace8c415a65ac1c50fc52922a3e666a3723d7 Mon Sep 17 00:00:00 2001 From: Rafhael Oliveira Date: Sat, 18 May 2024 06:24:27 +0000 Subject: [PATCH 1/4] try add ScheduleItemAddition function harcoded time added --- .../EventListener/DZLLoadOutListener.c | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c index 9b745ac9..3e68fd2e 100644 --- a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c +++ b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c @@ -21,21 +21,30 @@ class DZLLoadOutListener: DZLBaseEventListener { } private bool SearchLoadOutAndEquip(string categoryName, array categories, PlayerIdentity sender, PlayerBase player) { - foreach(DZLLoadOutCategory category: categories) { - if(categoryName == category.name) { - DZLLogLoadOut(sender.GetId(), categoryName); - player.RemoveAllItems(); - foreach(DZLLoadOutType type: category.items) { - Add(player, type); - } - GetGame().RPCSingleParam(null, DZL_RPC.LOAD_OUT_RESPONSE, null, true, sender); - return true;; - } + foreach (DZLLoadOutCategory category : categories) { + if (categoryName == category.name) { + DZLLogLoadOut(sender.GetId(), categoryName); + player.RemoveAllItems(); + ScheduleItemAddition(player, category.items, 0); + GetGame().RPCSingleParam(null, DZL_RPC.LOAD_OUT_RESPONSE, null, true, sender); + return true; } + } + return false; +} - return false; + private void ScheduleItemAddition(PlayerBase player, array items, int index) { + if (index < items.Count()) { + Add(player, items[index]); + GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(this, "ScheduleItemAdditionCallback", 1000 * 60 * 180, false, player, items, index + 1); + } } + void ScheduleItemAdditionCallback(PlayerBase player, array items, int index) { + ScheduleItemAddition(player, items, index); + } + + private void Add(PlayerBase player, DZLLoadOutType type) { EntityAI item; InventoryLocation inventoryLocation = new InventoryLocation; @@ -57,6 +66,7 @@ class DZLLoadOutListener: DZLBaseEventListener { if(item && type.quickBarEntityShortcut != -1) { player.SetQuickBarEntityShortcut(item, type.quickBarEntityShortcut, true); } + } private void AddAttachments(DZLLoadOutType type, EntityAI item) { From a943bc1e539b52bb9e3267d8f28c761f168d8415 Mon Sep 17 00:00:00 2001 From: Rafhael Oliveira Date: Sat, 18 May 2024 12:25:45 -0300 Subject: [PATCH 2/4] Fix: instance as the first argument to CallLater --- .../EventListener/DZLLoadOutListener.c | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c index 3e68fd2e..7abbfcb3 100644 --- a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c +++ b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c @@ -1,15 +1,15 @@ -class DZLLoadOutListener: DZLBaseEventListener { +class DZLLoadOutListener : DZLBaseEventListener { override void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) { - if(rpc_type == DZL_RPC.LOAD_OUT) { + if (rpc_type == DZL_RPC.LOAD_OUT) { autoptr Param1 paramLoadOut; - if(ctx.Read(paramLoadOut)) { + if (ctx.Read(paramLoadOut)) { PlayerBase player = PlayerBase.Cast(target); DZLPlayer dzlPlayer = player.GetDZLPlayer(); string categoryName = paramLoadOut.param1; string job = dzlPlayer.GetActiveJob(); - if(DAY_Z_LIFE_JOB_CIVIL == job) { + if (DAY_Z_LIFE_JOB_CIVIL == job) { DZLSendMessage(sender, "#error_category_not_found"); return; } @@ -21,22 +21,23 @@ class DZLLoadOutListener: DZLBaseEventListener { } private bool SearchLoadOutAndEquip(string categoryName, array categories, PlayerIdentity sender, PlayerBase player) { - foreach (DZLLoadOutCategory category : categories) { - if (categoryName == category.name) { - DZLLogLoadOut(sender.GetId(), categoryName); - player.RemoveAllItems(); - ScheduleItemAddition(player, category.items, 0); - GetGame().RPCSingleParam(null, DZL_RPC.LOAD_OUT_RESPONSE, null, true, sender); - return true; + foreach (DZLLoadOutCategory category : categories) { + if (categoryName == category.name) { + DZLLogLoadOut(sender.GetId(), categoryName); + player.RemoveAllItems(); + ScheduleItemAddition(player, category.items, 0); + GetGame().RPCSingleParam(null, DZL_RPC.LOAD_OUT_RESPONSE, null, true, sender); + return true; + } } + return false; } - return false; -} private void ScheduleItemAddition(PlayerBase player, array items, int index) { if (index < items.Count()) { Add(player, items[index]); - GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(this, "ScheduleItemAdditionCallback", 1000 * 60 * 180, false, player, items, index + 1); + // Schedule the next item addition + DZLSleep(1000 * 60 * 180, this, "ScheduleItemAdditionCallback", new Param3, int>(player, items, index + 1)); } } @@ -44,49 +45,51 @@ class DZLLoadOutListener: DZLBaseEventListener { ScheduleItemAddition(player, items, index); } - private void Add(PlayerBase player, DZLLoadOutType type) { EntityAI item; InventoryLocation inventoryLocation = new InventoryLocation; - if(player.GetInventory().FindFirstFreeLocationForNewEntity(type.type, FindInventoryLocationType.ANY, inventoryLocation)) { + if (player.GetInventory().FindFirstFreeLocationForNewEntity(type.type, FindInventoryLocationType.ANY, inventoryLocation)) { item = player.GetHumanInventory().CreateInInventory(type.type); - } else if(!player.GetHumanInventory().GetEntityInHands()) { + } else if (!player.GetHumanInventory().GetEntityInHands()) { item = player.GetHumanInventory().CreateInHands(type.type); } - if(!item) { + if (!item) { item = player.SpawnEntityOnGroundPos(type.type, player.GetPosition()); } - if(item && type.attachments) { + if (item && type.attachments) { AddAttachments(type, item); } - if(item && type.quickBarEntityShortcut != -1) { + if (item && type.quickBarEntityShortcut != -1) { player.SetQuickBarEntityShortcut(item, type.quickBarEntityShortcut, true); } - } private void AddAttachments(DZLLoadOutType type, EntityAI item) { - if(!item) return; + if (!item) return; - foreach(DZLLoadOutType attachment: type.attachments) { - if(item.GetInventory()) { + foreach (DZLLoadOutType attachment : type.attachments) { + if (item.GetInventory()) { EntityAI itemAttachment = item.GetInventory().CreateInInventory(attachment.type); - if(!itemAttachment) { + if (!itemAttachment) { itemAttachment = item.GetInventory().CreateEntityInCargo(attachment.type); - if(!itemAttachment) { + if (!itemAttachment) { itemAttachment = item.GetInventory().CreateAttachment(attachment.type); } } - if(itemAttachment && attachment.attachments) { + if (itemAttachment && attachment.attachments) { AddAttachments(attachment, itemAttachment); } } } } + + void DZLSleep(int milliseconds, Class callbackClass, string callbackMethod, Param param = null) { + GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(callbackClass, callbackMethod, milliseconds, false, param); + } } From 14bda86befcaacf3d581730bf76ae16354bc5e27 Mon Sep 17 00:00:00 2001 From: Rafhael Oliveira Date: Sat, 18 May 2024 12:53:37 -0300 Subject: [PATCH 3/4] Refac: // A map to store the last access time of each player --- DayZLifeClient/stringtable.csv | 3 +- .../EventListener/DZLLoadOutListener.c | 85 ++++++++++++------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/DayZLifeClient/stringtable.csv b/DayZLifeClient/stringtable.csv index e5991382..2c124602 100644 --- a/DayZLifeClient/stringtable.csv +++ b/DayZLifeClient/stringtable.csv @@ -324,4 +324,5 @@ Language,original,english,german,chinesesimp,chinese,russian,czech,polish,hungar "raid_can_not_start_to_less_players","Raid can not start, to less players","Raid can not start, to less players","Raid kann nicht starten, zu wenige Spieler","突袭无法开始,玩家太少","突襲無法開始,玩家太少","Рейд не может начаться, игроков слишком мало","Raid nemůže začít, příliš málo hráčů","Raid nie może się rozpocząć, za mało graczy","A rajt nem indulhat el, túl kevés játékos","Il raid non può iniziare, troppi pochi giocatori","El asalto no puede comenzar, hay pocos jugadores","Le raid ne peut pas commencer, trop peu de joueurs","O ataque não pode começar, há poucos jogadores","プレイヤーが少なすぎてレイドを開始できません", "error_not_enough_money","Error not enough money","Error not enough money","Fehler nicht genug Geld","错误,钱不够","錯誤,錢不夠","Ошибка недостаточно денег","Chyba ne dost peněz","Błąd nie wystarczająco pieniędzy","Hiba nincs elég pénz","Errore non abbastanza soldi","Error no hay suficiente dinero","Erreur pas assez d'argent","Erro dinheiro insuficiente","エラー、お金が足りません", "break_door","Break door","Break door","Tür aufbrechen","打破门","打破門","Взломать дверь","Zničit dveře","Zniszcz drzwi","Ajtót törni","Rompi la porta","Romper la puerta","Casser la porte","Quebrar a porta","ドアを壊す", -"cop_message_job_house_alarm","Alarm, a job building will raided.","Alarm, a job building will raided.","Alarm, ein Jobgebäude wird überfallen.","警报,一个工作建筑将被抢劫。","警報,一個工作建築將被搶劫。","Тревога, здание работы будет ограблено.","Poplach, budova práce bude vykradena.","Alarm, budynek pracy zostanie obrabowany.","Riasztás, egy munkahelyi épületet kirabolnak.","Allarme, un edificio di lavoro verrà derubato.","Alarma, un edificio de trabajo será saqueado.","Alarme, un bâtiment de travail sera cambriolé.","Alarme, um prédio de trabalho será saqueado.","警報、ジョブビルが襲われます。", \ No newline at end of file +"cop_message_job_house_alarm","Alarm, a job building will raided.","Alarm, a job building will raided.","Alarm, ein Jobgebäude wird überfallen.","警报,一个工作建筑将被抢劫。","警報,一個工作建築將被搶劫。","Тревога, здание работы будет ограблено.","Poplach, budova práce bude vykradena.","Alarm, budynek pracy zostanie obrabowany.","Riasztás, egy munkahelyi épületet kirabolnak.","Allarme, un edificio di lavoro verrà derubato.","Alarma, un edificio de trabajo será saqueado.","Alarme, un bâtiment de travail sera cambriolé.","Alarme, um prédio de trabalho será saqueado.","警報、ジョブビルが襲われます。", +"cooldown_active","One Hour Cooldown Activate","One Hour Cooldown Activate","Kategorie nicht gefunden","未找到类别","未找到類別","Категория не найдена","Kategorie nenalezena","Kategoria nie znaleziona","Kategória nem található","Categoria non trovata","Categoría no encontrada","Catégorie non trouvée","Categoria não encontrada","カテゴリが見つかりません", \ No newline at end of file diff --git a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c index 7abbfcb3..27305fd9 100644 --- a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c +++ b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c @@ -1,95 +1,114 @@ -class DZLLoadOutListener : DZLBaseEventListener { +class DZLLoadOutListener: DZLBaseEventListener { + // A map to store the last access time of each player + private ref map playerLoadoutAccessTimes; + + void DZLLoadOutListener() { + playerLoadoutAccessTimes = new map(); + } override void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) { - if (rpc_type == DZL_RPC.LOAD_OUT) { + if(rpc_type == DZL_RPC.LOAD_OUT) { autoptr Param1 paramLoadOut; - if (ctx.Read(paramLoadOut)) { + if(ctx.Read(paramLoadOut)) { PlayerBase player = PlayerBase.Cast(target); DZLPlayer dzlPlayer = player.GetDZLPlayer(); string categoryName = paramLoadOut.param1; string job = dzlPlayer.GetActiveJob(); - if (DAY_Z_LIFE_JOB_CIVIL == job) { + if(DAY_Z_LIFE_JOB_CIVIL == job) { DZLSendMessage(sender, "#error_category_not_found"); return; } + if (IsCooldownActive(player)) { + DZLSendMessage(sender, "#cooldown_active"); + return; + } + DZLLoadOuts loadOut = DZLConfig.Get().jobConfig.GetLoadOuts(job); - SearchLoadOutAndEquip(categoryName, loadOut.loadOutCategories, sender, player); + if (SearchLoadOutAndEquip(categoryName, loadOut.loadOutCategories, sender, player)) { + UpdatePlayerAccessTime(player); + } } } } private bool SearchLoadOutAndEquip(string categoryName, array categories, PlayerIdentity sender, PlayerBase player) { - foreach (DZLLoadOutCategory category : categories) { - if (categoryName == category.name) { + foreach(DZLLoadOutCategory category: categories) { + if(categoryName == category.name) { DZLLogLoadOut(sender.GetId(), categoryName); player.RemoveAllItems(); - ScheduleItemAddition(player, category.items, 0); + foreach(DZLLoadOutType type: category.items) { + Add(player, type); + } GetGame().RPCSingleParam(null, DZL_RPC.LOAD_OUT_RESPONSE, null, true, sender); return true; } } - return false; - } - private void ScheduleItemAddition(PlayerBase player, array items, int index) { - if (index < items.Count()) { - Add(player, items[index]); - // Schedule the next item addition - DZLSleep(1000 * 60 * 180, this, "ScheduleItemAdditionCallback", new Param3, int>(player, items, index + 1)); - } - } - - void ScheduleItemAdditionCallback(PlayerBase player, array items, int index) { - ScheduleItemAddition(player, items, index); + return false; } private void Add(PlayerBase player, DZLLoadOutType type) { EntityAI item; InventoryLocation inventoryLocation = new InventoryLocation; - if (player.GetInventory().FindFirstFreeLocationForNewEntity(type.type, FindInventoryLocationType.ANY, inventoryLocation)) { + if(player.GetInventory().FindFirstFreeLocationForNewEntity(type.type, FindInventoryLocationType.ANY, inventoryLocation)) { item = player.GetHumanInventory().CreateInInventory(type.type); - } else if (!player.GetHumanInventory().GetEntityInHands()) { + } else if(!player.GetHumanInventory().GetEntityInHands()) { item = player.GetHumanInventory().CreateInHands(type.type); } - if (!item) { + if(!item) { item = player.SpawnEntityOnGroundPos(type.type, player.GetPosition()); } - if (item && type.attachments) { + if(item && type.attachments) { AddAttachments(type, item); } - if (item && type.quickBarEntityShortcut != -1) { + if(item && type.quickBarEntityShortcut != -1) { player.SetQuickBarEntityShortcut(item, type.quickBarEntityShortcut, true); } } private void AddAttachments(DZLLoadOutType type, EntityAI item) { - if (!item) return; + if(!item) return; - foreach (DZLLoadOutType attachment : type.attachments) { - if (item.GetInventory()) { + foreach(DZLLoadOutType attachment: type.attachments) { + if(item.GetInventory()) { EntityAI itemAttachment = item.GetInventory().CreateInInventory(attachment.type); - if (!itemAttachment) { + if(!itemAttachment) { itemAttachment = item.GetInventory().CreateEntityInCargo(attachment.type); - if (!itemAttachment) { + if(!itemAttachment) { itemAttachment = item.GetInventory().CreateAttachment(attachment.type); } } - if (itemAttachment && attachment.attachments) { + if(itemAttachment && attachment.attachments) { AddAttachments(attachment, itemAttachment); } } } } - void DZLSleep(int milliseconds, Class callbackClass, string callbackMethod, Param param = null) { - GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(callbackClass, callbackMethod, milliseconds, false, param); + private bool IsCooldownActive(PlayerBase player) { + string playerId = player.GetIdentity().GetId(); + float currentTime = GetGame().GetTime() / 1000.0; // Get the current time in seconds + if (playerLoadoutAccessTimes.Contains(playerId)) { + float lastAccessTime = playerLoadoutAccessTimes.Get(playerId); + // Check if 1 hour (3600 seconds) has passed + if (currentTime - lastAccessTime < 3600) { + return true; + } + } + return false; + } + + private void UpdatePlayerAccessTime(PlayerBase player) { + string playerId = player.GetIdentity().GetId(); + float currentTime = GetGame().GetTime() / 1000.0; // Get the current time in seconds + playerLoadoutAccessTimes.Set(playerId, currentTime); } } From bafe6e0ba4a243519acd5193a2b8930dda29efd4 Mon Sep 17 00:00:00 2001 From: Rafhael Oliveira Date: Sat, 18 May 2024 13:00:02 -0300 Subject: [PATCH 4/4] Fix: translate string dont work, removed! --- DayZLifeClient/stringtable.csv | 1 - .../scripts/4_World/EventListener/DZLLoadOutListener.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DayZLifeClient/stringtable.csv b/DayZLifeClient/stringtable.csv index 2c124602..d63cdee3 100644 --- a/DayZLifeClient/stringtable.csv +++ b/DayZLifeClient/stringtable.csv @@ -325,4 +325,3 @@ Language,original,english,german,chinesesimp,chinese,russian,czech,polish,hungar "error_not_enough_money","Error not enough money","Error not enough money","Fehler nicht genug Geld","错误,钱不够","錯誤,錢不夠","Ошибка недостаточно денег","Chyba ne dost peněz","Błąd nie wystarczająco pieniędzy","Hiba nincs elég pénz","Errore non abbastanza soldi","Error no hay suficiente dinero","Erreur pas assez d'argent","Erro dinheiro insuficiente","エラー、お金が足りません", "break_door","Break door","Break door","Tür aufbrechen","打破门","打破門","Взломать дверь","Zničit dveře","Zniszcz drzwi","Ajtót törni","Rompi la porta","Romper la puerta","Casser la porte","Quebrar a porta","ドアを壊す", "cop_message_job_house_alarm","Alarm, a job building will raided.","Alarm, a job building will raided.","Alarm, ein Jobgebäude wird überfallen.","警报,一个工作建筑将被抢劫。","警報,一個工作建築將被搶劫。","Тревога, здание работы будет ограблено.","Poplach, budova práce bude vykradena.","Alarm, budynek pracy zostanie obrabowany.","Riasztás, egy munkahelyi épületet kirabolnak.","Allarme, un edificio di lavoro verrà derubato.","Alarma, un edificio de trabajo será saqueado.","Alarme, un bâtiment de travail sera cambriolé.","Alarme, um prédio de trabalho será saqueado.","警報、ジョブビルが襲われます。", -"cooldown_active","One Hour Cooldown Activate","One Hour Cooldown Activate","Kategorie nicht gefunden","未找到类别","未找到類別","Категория не найдена","Kategorie nenalezena","Kategoria nie znaleziona","Kategória nem található","Categoria non trovata","Categoría no encontrada","Catégorie non trouvée","Categoria não encontrada","カテゴリが見つかりません", \ No newline at end of file diff --git a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c index 27305fd9..8b33e000 100644 --- a/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c +++ b/DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c @@ -21,7 +21,7 @@ class DZLLoadOutListener: DZLBaseEventListener { } if (IsCooldownActive(player)) { - DZLSendMessage(sender, "#cooldown_active"); + DZLSendMessage(sender, "You need to wait one hour to pickup Loadout again"); return; }