Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Add cooldown mechanism to DZLLoadOutListener #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DayZLifeClient/stringtable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,4 @@ 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.","警報、ジョブビルが襲われます。",
"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.","警報、ジョブビルが襲われます。",
36 changes: 34 additions & 2 deletions DayZLifeServer/scripts/4_World/EventListener/DZLLoadOutListener.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class DZLLoadOutListener: DZLBaseEventListener {
// A map to store the last access time of each player
private ref map<string, float> playerLoadoutAccessTimes;

void DZLLoadOutListener() {
playerLoadoutAccessTimes = new map<string, float>();
}

override void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) {
if(rpc_type == DZL_RPC.LOAD_OUT) {
Expand All @@ -14,8 +20,15 @@ class DZLLoadOutListener: DZLBaseEventListener {
return;
}

if (IsCooldownActive(player)) {
DZLSendMessage(sender, "You need to wait one hour to pickup Loadout again");
return;
}

DZLLoadOuts loadOut = DZLConfig.Get().jobConfig.GetLoadOuts(job);
SearchLoadOutAndEquip(categoryName, loadOut.loadOutCategories, sender, player);
if (SearchLoadOutAndEquip(categoryName, loadOut.loadOutCategories, sender, player)) {
UpdatePlayerAccessTime(player);
}
}
}
}
Expand All @@ -29,7 +42,7 @@ class DZLLoadOutListener: DZLBaseEventListener {
Add(player, type);
}
GetGame().RPCSingleParam(null, DZL_RPC.LOAD_OUT_RESPONSE, null, true, sender);
return true;;
return true;
}
}

Expand Down Expand Up @@ -79,4 +92,23 @@ class DZLLoadOutListener: DZLBaseEventListener {
}
}
}

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);
}
}