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

Kills not logged when player is on vehicle. #437

Open
EugeneBeanblossom opened this issue Apr 24, 2023 · 2 comments
Open

Kills not logged when player is on vehicle. #437

EugeneBeanblossom opened this issue Apr 24, 2023 · 2 comments
Assignees

Comments

@EugeneBeanblossom
Copy link

EugeneBeanblossom commented Apr 24, 2023

The server tools doesn't capture kills and give rewards when a player kills someone who's on a vehicle. I ran into this on my mod on the same server. For my mod, I hooked into EntityAlive:ProcessDamageResponse and the DamageResponse.Source entityId is -1. I'm currently looking to see how I can get the killer when the player is killed on a vehicle.

@EugeneBeanblossom
Copy link
Author

EugeneBeanblossom commented Apr 24, 2023

Following up on this. I did some testing and this was with one shot from a T3 sniper rifle to the head while I was riding on a motorcycle/bike.

2023-04-23T21:47:45 195.484 INF Fatal: False Victim: Player, Killer -1, 178, state: True
2023-04-23T21:47:45 195.484 INF Fatal: False Victim: Unknown, Killer -1, 178, state: True
2023-04-23T21:47:45 195.484 INF Fatal: False Victim: Player, Killer -1, 178, state: True
2023-04-23T21:47:45 195.538 INF Fatal: False Victim: Player, Killer -1, 178, state: True
2023-04-23T21:47:45 195.538 INF GMSG: Player 'Eugene Beanblossom' killed by 'Kodos The Executioner'
2023-04-23T21:47:45 195.539 INF Fatal: True Victim: Player, Killer -1, -1, state: True
2023-04-23T21:47:45 195.595 INF Fatal: True Victim: Player, Killer -1, -1, state: False

and this is the code that's generating that log:

[HarmonyPatch(typeof(EntityAlive), "ProcessDamageResponse")]
public class EntityPlayerProcessDamageResponse
{
    private static void Prefix(EntityAlive __instance, DamageResponse _dmResponse, out bool __state)
    {
        __state = __instance.IsAlive();
    }

    // Using __state to see if the entity was alive before processing damage
    private static async void Postfix(EntityAlive __instance, DamageResponse _dmResponse, bool __state)
    {
        Log.Out($"Fatal: {_dmResponse.Fatal} Victim: {__instance.entityType}, Killer {_dmResponse.Source.CreatorEntityId}, {_dmResponse.Source.getEntityId()}, state: {__state}");
    }
}

So it's trying the call 6 times but the attacker is only in it the first 4 times before the damage is recognized as "fatal". The next two after the kill shows it can't identify the killer. Now this was from one shot to the head while the victim is on a bike. I did some further testing and serialized the DamageResponse object out for one of the times the source entityId was -1 and got this:

{
  "Source": {
    "uvHit": {
      "x": 0.0,
      "y": 0.0,
      "magnitude": 0.0,
      "sqrMagnitude": 0.0
    },
    "hitTransformName": "",
    "hitTransformPosition": {
      "x": 0.0,
      "y": 0.0,
      "z": 0.0,
      "magnitude": 0.0,
      "sqrMagnitude": 0.0
    },
    "BuffClass": null,
    "AttackingItem": null,
    "damageSource": 1,
    "damageType": 11,
    "bIsDamageTransfer": false,
    "DismemberChance": 0.0,
    "BonusDamageType": 0,
    "DamageTypeTag": {
      "IsEmpty": false
    },
    "CreatorEntityId": -1,
    "ItemClass": null,
    "CanStun": false,
    "DamageMultiplier": 1.0
  },
  "Strength": 1,
  "ModStrength": 0,
  "MovementState": 0,
  "HitDirection": 2,
  "HitBodyPart": 0,
  "PainHit": false,
  "Fatal": true,
  "Critical": false,
  "Dismember": false,
  "CrippleLegs": false,
  "TurnIntoCrawler": false,
  "Random": 0.9297966,
  "ImpulseScale": 0.0,
  "Stun": 0,
  "StunDuration": 0.0,
  "ArmorSlot": 8,
  "ArmorSlotGroup": 1,
  "ArmorDamage": 0
}

Notice that the DamageType was 11 here which I believe is "Disease". This makes me consider the possibility that perhaps the death wasn't from the shot itself but debuffs as a result of the critical hit to the head? Another possibility is that it applies the damage to the player while on the vehicle, sees that they're dead, detaches them, and applies damage again afterwards defaulting to "Disease" type. I'm not sure but still investigating on my end. Since my mod fails to capture the kills the same time this one does, I believe if I can figure it out for mine, it'll likely be the same solution for yours (or vise versa).

@ObsComp
Copy link
Collaborator

ObsComp commented Apr 30, 2023

You need to check the attached entity is null. If not null then that is the player it needs to process. It sounds like damage may or may not apply to the vehicle first so my system just was not coded with that in mind. You are correct that people can die from a buff

@ObsComp ObsComp self-assigned this Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants