Example #1
0
    public void ApplyDamage(float damage, string source = "fate")
    {
        if (isServer)
        {
            float original_health = Health;
            Health -= damage;

            if (!IsAlive && original_health > 0.0f)
            {
                Regex           source_filter = new Regex(@"player\:([\dA-Fa-f]{8})");
                MatchCollection matches       = source_filter.Matches(source);
                ScoreHandler    player_score  = GetComponent <ScoreHandler>();

                if (player_score)
                {
                    player_score.AddDeaths();
                }

                if (matches.Count > 0)
                {
                    uint         attacker_netid = Convert.ToUInt32(matches[0].Groups[1].Value, 16);
                    ScoreHandler attacker_score;

                    foreach (GameObject attacker in GameObject.FindGameObjectsWithTag("Player"))
                    {
                        attacker_score = attacker.GetComponent <ScoreHandler>();

                        if (attacker_score && attacker_score.netId.Value == attacker_netid)
                        {
                            attacker_score.AddFrags();
                        }
                    }
                }
            }
        }
    }