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

[EXILED::API] Fixing NPC PlayerId assignment #135

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

SrLicht
Copy link

@SrLicht SrLicht commented Oct 14, 2024

Description

Describe the changes

  • Preventing that when spawning an NPC in the long term a player can have the same ID as another player.
  • Adding 2 new methods of destruction.
    • LateDestroy(float) to destroy the NPC after a short delay (similar to the Unity component method).
    • DestroyAll() a static method to destroy all listed NPCs.
  • Deprecating the old NCP.Spawn method because the player should never have been given the option to assign an ID.
  • Creating new method with a parameter to add the NPC to the Round.IgnoredPlayers HashSet.

What is the current behavior? (You can also link to an open issue here)
Currently when creating an NPC an Id is assigned by RecyclablePlayerId and checking if it is in use, this should not be done since when creating a ReferenceHub in the Awake method this already assigns an available ID, which currently causes that we leave an ID permanently created and never destroyed leading to another player can use it and that there are 2 players with the same ID.

imagen

What is the new behavior? (if this is a feature change)

imagen

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Testing

I tested the changes by making every time I jumped an NPC I played a sound to check if the ReferenceHub.OnDestroy is correctly running and it was possible to use it again without another player/npc taking the same id.
imagen

imagen

ReferenceHub.OnDestroy
imagen


Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

* Fixing duplicated player id.

* Created a new method of spawning a NPC

* Added LateDestroy and DestroyAll
* Try Catch on destroying ncp
@SrLicht SrLicht closed this Oct 14, 2024
@SrLicht SrLicht changed the title ``[EXILED::API `[EXILED::API] `Fixing NPC PlayerId assignment Oct 14, 2024
@SrLicht SrLicht changed the title `[EXILED::API] `Fixing NPC PlayerId assignment [EXILED::API] Fixing NPC PlayerId assignment Oct 14, 2024
@SrLicht SrLicht reopened this Oct 14, 2024
@VALERA771 VALERA771 removed the Events label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants