private void cmdListKillBy(IPlayer parPlayer, string command, string[] args) { BasePlayer player = (BasePlayer)parPlayer.Object; if (permission.UserHasPermission(player.UserIDString, FPerm) && args.Length >= 1 && AshTools) { PlayerData playerData = PlayerData.Find(args[0]); if (playerData != null) { if (playerData.FImprovedKillByInfos.Count == 0) { PrintToConsole(player, $"le joueur '{playerData.FId}' n'a jamais été tué"); } else { PrintToConsole(player, $"le joueur '{playerData.FImprovedKillInfos[0].FNameTo}' ({playerData.FId}) a été tué par"); foreach (ImprovedKillInfo iki in playerData.FImprovedKillByInfos.OrderBy((p) => p.FIdFrom)) { PrintToConsole(player, $"{iki.FIdFrom} {iki.FNameFrom} {iki.FDates.Count} fois"); foreach (DateTime date in iki.FDates) { PrintToConsole(player, $"--> {date.ToString("dd/MM/yyyy HH:mm:ss.fff")}"); } } } } } }
private JObject GetTransactions(string id, string currency) { var player = PlayerData.Find(id); var data = player?.FindCurrency(currency); return(data == null ? null : JObject.FromObject(data.Transactions)); }
private double GetBalance(string id, string currency) { var player = PlayerData.Find(id); var data = player?.FindCurrency(currency); return(data?.Balance ?? double.NaN); // Yeah it could be just a one line but I made it bigger for u }
private bool TransferBalance(string idFrom, string idTo, string currencyFrom, string currencyTo, double changeFrom, double changeTo, string descriptionFrom, string descriptionTo) { var playerFrom = PlayerData.Find(idFrom); if (playerFrom == null) { return(false); } var playerTo = PlayerData.Find(idTo); if (playerTo == null) { return(false); } var currencyDataFrom = playerFrom.FindCurrency(currencyFrom); if (currencyDataFrom == null) { return(false); } var currencyDataTo = playerFrom.FindCurrency(currencyTo); if (currencyDataTo == null) { return(false); } currencyDataFrom.Add(changeFrom, descriptionFrom); currencyDataTo.Add(changeTo, descriptionTo); return(true); }
internal static PlayerData Find(string playerIdOrName) { BasePlayer user = (BasePlayer)FInstance.AshTools?.Call("GetPlayerActifOnTheServerByIdOrNameIFN", playerIdOrName); if (user != null) { TryLoad(user.userID); return(PlayerData.Find(user)); } return(null); }
private bool AddTransaction(string id, string currency, double amount, string description) { var player = PlayerData.Find(id); var data = player?.FindCurrency(currency); if (data == null) { return(false); } data.Add(amount, description); player.Update(); return(true); }
void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { try { if (entity == info.Initiator) { return; } if (entity == null || info.Initiator == null) { return; } if (info?.Initiator?.ToPlayer() == null && (entity?.name?.Contains("autospawn") ?? false)) { return; } if (entity.ToPlayer() != null) { if (entity.ToPlayer().IsWounded()) { info = TryGetLastWounded(entity.ToPlayer().userID, info); } } if (entity != null && entity is BasePlayer && info?.Initiator != null && info.Initiator is BasePlayer) { PlayerData victimData = PlayerData.Find((BasePlayer)entity); PlayerData attackerData = PlayerData.Find((BasePlayer)info.Initiator); victimData.deaths++; attackerData.kills++; victimData.Save(); attackerData.Save(); if (!AllPlayerIds.Contains(victimData.id)) { AllPlayerIds.Add(victimData.id); } if (!AllPlayerIds.Contains(attackerData.id)) { AllPlayerIds.Add(attackerData.id); } SaveAllPlayers(); } } catch (Exception ex) { } }
private void OnUserConnected(IPlayer player) { var data = PlayerData.Find(player.Id); if (data == null) { data = new PlayerData { Id = player.Id }; _data.Players.Add(data); } data.UpdateCurrencies(); data.Update(); }
private void cmdListHitInfo(IPlayer parPlayer, string command, string[] args) { BasePlayer player = (BasePlayer)parPlayer.Object; if (permission.UserHasPermission(player.UserIDString, FPerm) && args.Length >= 1 && AshTools) { PlayerData playerData = PlayerData.Find(args[0]); if (playerData != null) { PrintToConsole(player, "\nDate idAttacker nameAttacker positionAttacker weapon distance idVictim nameVictim positionVictim damageType"); foreach (ImprovedHitInfo ihi in playerData.FImprovedHitInfos.OrderByDescending((d) => d.FDate).Take((args.Length >= 2 ? int.Parse(args[1]) : 15)).Reverse()) { PrintToConsole(player, $"{ihi.FDate.ToString("dd/MM/yyyy HH:mm:ss.fff")} {ihi.FIdFrom} {ihi.FNameFrom} {ihi.FPositionFrom.ToString().Replace(",", "")} {ihi.FWeaponName} {ihi.FDistance.ToString("F1")}m {ihi.FIdTo} {ihi.FNameTo} {ihi.FPositionTo.ToString().Replace(",", "")} {ihi.FDamageType.ToString()}"); } } } }
private void cmdShowHitInfo(IPlayer parPlayer, string command, string[] args) { BasePlayer player = (BasePlayer)parPlayer.Object; if (permission.UserHasPermission(player.UserIDString, FPerm) && args.Length >= 1 && AshTools) { PlayerData playerData = PlayerData.Find(args[0]); if (playerData != null) { uint index = 0; float duration = FConfigFile.DisplayDuration; float distanceMax = FConfigFile.DistanceShowSingle; DateTime dateFrom = new DateTime(), dateTo = new DateTime(); bool checkDateFrom = false, checkDateTo = false; string dateTimeFormat = "dd/MM/yyyy HH:mm:ss"; if (args.Length >= 2 && DateTime.TryParseExact(args[1], dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateFrom)) { checkDateFrom = true; } if (args.Length >= 3 && DateTime.TryParseExact(args[2], dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTo)) { checkDateTo = true; } Vector3 currentPosition = player.ServerPosition; PrintToConsole(player, "\nDate idAttacker nameAttacker positionAttacker weapon distance idVictim nameVictim positionVictim damageType"); foreach (ImprovedHitInfo ihi in playerData.FImprovedHitInfos.OrderBy((d) => d.FDate)) { if ((Vector3.Distance(currentPosition, ihi.FPositionFrom) < distanceMax || Vector3.Distance(currentPosition, ihi.FPositionTo) < distanceMax) && (!checkDateFrom || DateTime.Compare(ihi.FDate, dateFrom) > 0) && (!checkDateTo || DateTime.Compare(ihi.FDate, dateTo) < 0) && (ihi.FWeaponName != null)) { PrintToConsole(player, $"[{++index}] {ihi.FDate.ToString("dd/MM/yyyy HH:mm:ss.fff")} {ihi.FIdFrom} {ihi.FNameFrom} {ihi.FPositionFrom.ToString().Replace(",", "")} {ihi.FWeaponName} {ihi.FDistance.ToString("F1")}m {ihi.FIdTo} {ihi.FNameTo} {ihi.FPositionTo.ToString().Replace(",", "")} {ihi.FDamageType.ToString()}"); Color color = ihi.FIdFrom == playerData.FId ? Color.green : Color.red; Color invertColor = ihi.FIdFrom == playerData.FId ? Color.red : Color.green; Vector3 wristFrom = ihi.FPositionFrom; wristFrom[1] += 1; Vector3 wristTo = ihi.FPositionTo; wristTo[1] += 1; player.SendConsoleCommand("ddraw.arrow", duration, color, wristFrom, wristTo, 0.25); player.SendConsoleCommand("ddraw.text", duration, color, wristFrom, ihi.FNameFrom); player.SendConsoleCommand("ddraw.text", duration, invertColor, wristTo, ihi.FNameTo); player.SendConsoleCommand("ddraw.text", duration, color, (wristFrom + wristTo) / 2, (index).ToString() + ":-> " + ihi.FWeaponName); } } } } }
private List <string> GetCurrencies(string id) { var player = PlayerData.Find(id); if (player == null) { return(null); } var data = new List <string>(); for (var i = 0; i < player.Currencies.Count; i++) { data.Add(player.Currencies[i].Abbreviation); } return(data); }
void OnServerInitialized() { FInstance = this; if (!AshTools) { PrintError("AshTools is not present, this plugins will not works"); Unsubscribe("OnEntityTakeDamage"); Unsubscribe("OnEntityDeath"); return; } LoadAllPlayers(); foreach (BasePlayer player in BasePlayer.activePlayerList) { PlayerData.TryLoad(player); PrintWarning($"Loaded ICL data from OnServerInitialized for '{player.userID}/{player.displayName}= {PlayerData.Find(player)?.FImprovedHitInfos.Count.ToString() ?? "0"}'"); if (!FAllPlayerIds.Contains(player.userID)) { FAllPlayerIds.Add(player.userID); AllPlayersDataHasChanged(); } } foreach (ulong playerId in FAllPlayerIds) { if (PlayerData.TryLoad(playerId)) { PrintWarning($"Loaded ICL data from OnServerInitialized/FAllPlayerIds for '{playerId}= {PlayerData.Find(playerId)?.FImprovedHitInfos.Count.ToString() ?? "0"}'"); } } timer.Every(FConfigFile.DelayBetweenSave, () => { SaveAllPlayersIFN(); foreach (PlayerData playerData in FLoadedPlayerData) { playerData.ForceSave(); } }); }
void RecordHitInfo(BasePlayer parAttacker, BasePlayer parVictim, HitInfo parHitInfo, bool parIsKill) { string weaponName = parHitInfo?.WeaponPrefab?.ShortPrefabName; if (weaponName == null) { return; } ImprovedHitInfo improvedHitInfo = new ImprovedHitInfo(); improvedHitInfo.FDate = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Local); improvedHitInfo.FIdFrom = parAttacker.userID; improvedHitInfo.FNameFrom = parAttacker.displayName; improvedHitInfo.FPositionFrom = parAttacker.ServerPosition; improvedHitInfo.FIdTo = parVictim.userID; improvedHitInfo.FNameTo = parVictim.displayName; improvedHitInfo.FPositionTo = parVictim.ServerPosition; improvedHitInfo.FWeaponName = parHitInfo.WeaponPrefab.ShortPrefabName; improvedHitInfo.FDistance = parHitInfo?.ProjectileDistance ?? 0f; improvedHitInfo.FDamageType = parVictim.lastDamage; PlayerData attackerPlayerData = PlayerData.Find(parAttacker); if (attackerPlayerData != null) { attackerPlayerData.FImprovedHitInfos.Add(improvedHitInfo); if (!FAllPlayerIds.Contains(attackerPlayerData.FId)) { FAllPlayerIds.Add(attackerPlayerData.FId); AllPlayersDataHasChanged(); } if (parIsKill) { ImprovedKillInfo iki = attackerPlayerData.FImprovedKillInfos.Find((p) => p.FIdTo == parVictim.userID); if (iki == null) { iki = new ImprovedKillInfo(); iki.FDates = new List <System.DateTime>(); iki.FIdFrom = parAttacker.userID; iki.FNameFrom = parAttacker.displayName; iki.FIdTo = parVictim.userID; iki.FNameTo = parVictim.displayName; attackerPlayerData.FImprovedKillInfos.Add(iki); } iki.FDates.Add(improvedHitInfo.FDate); iki.FNameFrom = parAttacker.displayName; iki.FNameTo = parVictim.displayName; } attackerPlayerData.Save(); } else { PrintWarning($"{parAttacker.userID} is not found in the DB"); return; } PlayerData victimPlayerData = PlayerData.Find(parVictim); if (victimPlayerData != null) { victimPlayerData.FImprovedHitInfos.Add(improvedHitInfo); if (!FAllPlayerIds.Contains(victimPlayerData.FId)) { FAllPlayerIds.Add(victimPlayerData.FId); AllPlayersDataHasChanged(); } if (parIsKill) { ImprovedKillInfo iki = victimPlayerData.FImprovedKillByInfos.Find((p) => p.FIdFrom == parAttacker.userID); if (iki == null) { iki = new ImprovedKillInfo(); iki.FDates = new List <System.DateTime>(); iki.FIdFrom = parAttacker.userID; iki.FNameFrom = parAttacker.displayName; iki.FIdTo = parVictim.userID; iki.FNameTo = parVictim.displayName; victimPlayerData.FImprovedKillByInfos.Add(iki); } iki.FDates.Add(improvedHitInfo.FDate); iki.FNameFrom = parAttacker.displayName; iki.FNameTo = parVictim.displayName; } victimPlayerData.Save(); } else { PrintWarning($"{parVictim.userID} is not found in the DB"); return; } }