示例#1
0
        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)
            {
            }
        }
示例#2
0
        void OnPlayerDeath(PlayerSession session, EntityEffectSourceData source)
        {
            string SDKey = !string.IsNullOrEmpty(source.SourceDescriptionKey) ? source.SourceDescriptionKey : Singleton <GameManager> .Instance.GetDescriptionKey(source.EntitySource);

            if (SDKey.EndsWith("(P)"))
            {
                string KillerName = SDKey.Substring(0, SDKey.Length - 3);

                foreach (IPlayer Player in players.Connected)
                {
                    if (Player.Name == KillerName)
                    {
                        DynamicConfigFile PlayerData;

                        if (Interface.Oxide.DataFileSystem.ExistsDatafile(Player.Id))
                        {
                            int KillAmount = 0;
                            PlayerData = Interface.Oxide.DataFileSystem.GetDatafile(Player.Id);

                            if (int.TryParse(PlayerData["Kills"].ToString(), out KillAmount))
                            {
                                PlayerData["Kills"] = KillAmount++;
                            }
                            else
                            {
                                PlayerData["Kills"] = 1;
                            }
                        }
                        else
                        {
                            PlayerData          = Interface.Oxide.DataFileSystem.GetDatafile(Player.Id);
                            PlayerData["Kills"] = 1;
                        }

                        PlayerData.Save();

                        break;
                    }
                }
            }
        }
示例#3
0
        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;
            }
        }