Skip to content

Commit

Permalink
fix: gain enemy ownership before stunning them
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Feb 13, 2024
1 parent 97b314d commit ebb1ad3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lc-hax/Scripts/Mixins/IStun.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using GameNetcodeStuff;
using Hax;
using UnityEngine;

internal interface IStun { }

internal static class IStunMixin {
internal static void Stun(this IStun _, Vector3 position, float radius, float duration = 1.0f) =>
internal static void Stun(this IStun _, Vector3 position, float radius, float duration = 1.0f) {
if (Helper.LocalPlayer is not PlayerControllerB localPlayer) return;

Physics.OverlapSphere(position, radius, 524288)
.ForEach(collider => {
if (!collider.TryGetComponent(out EnemyAICollisionDetect enemy)) return;
enemy.mainScript.ChangeEnemyOwnerServerRpc(localPlayer.actualClientId);
enemy.mainScript.SetEnemyStunned(true, duration);
});
}
}

7 comments on commit ebb1ad3

@joep26020
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confused on what this does too

@winstxnhdw
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't stun an enemy you don't have ownership over.

@Dexteriority
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does that mean? whats ownership? XD

@winstxnhdw
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Lethal Company, the AI computation is run on the ‘owner’ of the enemy. In vanilla, the ‘owner’ of the enemy is usually the target of the enemy. For example, when a coil-head chases after you, the computation for that chasing is done by your computer. Basically, you are telling the coil-head to chase you.

Thus, to control the enemy, you must first gain ownership of the enemy. You can do that by sending a request to host to ask for ownership permission, which they would usually give almost all the time. Once you have ownership of the enemy, you can do anything you want to it and the server will respect it. This includes being stunned, killed, or possessed.

@Dexteriority
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request to host to ask for the ownership permission? its automatic when we perform certain command right?
im just dumb to think that we are asking the server host to give us permission XDD

@winstxnhdw
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap. If the host is not modded, it is automatically given without issues.

@Dexteriority
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modded? i got some of the server i joined is using Control Company... this affects?

Please sign in to comment.