Add resource stop handler to prevent crashes and ensure proper player logout #268
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This PR adds a critical fix to prevent issues when the qb-multicharacter resource is stopped or restarted. The fix implements a proper cleanup mechanism using the onResourceStop event handler to ensure all connected players are safely logged out before the resource stops.
What this PR fixes:
Resource Stop Crashes: Prevents the script from crashing when QBCore.Functions.GetPlayers() fails during resource shutdown
Player State Issues: Ensures all players are properly logged out using QBCore.Player.Logout() when the resource stops
Data Integrity: Prevents potential data corruption by properly cleaning up player states during resource restarts
Error Handling: Implements safe error handling with pcall() to gracefully handle failures
Why this should be included:
This fix addresses a common issue where the multicharacter system can leave players in an inconsistent state when the resource is restarted, which can lead to data corruption and server instability. The implementation follows QBCore's error handling patterns and provides proper debugging information.
Technical Details:
Uses pcall() for safe function calls to prevent crashes
Only triggers for the specific qb-multicharacter resource
Includes debug logging for troubleshooting
Follows existing code style and patterns in the file
Questions (please complete the following information):
Have you personally loaded this code into an updated qbcore project and checked all it's functionality? yes
Does your code fit the style guidelines? yes
Does your PR fit the contribution guidelines? yes