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

Return Ped Entity from spawnPed Function for Improved Management and Deletion #209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MrBolux
Copy link

@MrBolux MrBolux commented Oct 6, 2024

Describe Pull Request

This pull request addresses the issue where the spawnPed function does not return the ped entity, which prevents proper management and deletion of the peds after they are spawned. By updating the function to return the ped, it will allow developers to manage spawned peds more effectively, including actions like tracking, modifying, or deleting them later in the script.

What this PR adds or fixes:

  • Fix: The spawnPed function now returns the ped entity after creation.
  • Reason: This modification is crucial for managing the peds, enabling more flexible control such as proper cleanup or updates to their state, which was previously not possible without having access to the ped entity reference.

This change ensures better ped lifecycle management, especially in scenarios where multiple peds are created and need to be tracked or handled individually.

Issue

This PR fixes the issue where peds created by the spawnPed function were not returned, making it difficult to control or delete them later.


Questions:

  • Have you personally loaded this code into an updated qbcore project and checked all its functionality? [yes/no] (I created a script to try with peds in Config.Peds)
  • Does your code fit the style guidelines? [yes]
  • Does your PR fit the contribution guidelines? [yes]

@@ -1071,19 +1073,33 @@ local function SpawnPed(data)
if nextnumber <= 0 then nextnumber = 1 end

Config.Peds[nextnumber] = data
createdPeds[#createdPeds + 1] = data.currentpednumber

Choose a reason for hiding this comment

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

Could instead return early with the singular ped ID since data wouldn't be a table of peds in this instance.

end

exports('SpawnPed', SpawnPed)

local function RemovePed(peds)

local function removePedByNumber(pedNumber)

Choose a reason for hiding this comment

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

It looks like this could be a typo of placing a function declaration inside of a function declaration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants