Calling SetPedAsNoLongerNeeded right after CreatePed makes GetEntityPopulationType in entityCreating event return 5 instead of 7

For a good bug report you should probably include:

  1. Client (production/canary) and FXServer version
    Client: Canary
    DLC Version: 2802
    FXServer: 6497(vanilla server with vMenu)
  2. What you expected to happen
    entityCreating event to always return 7 on script created peds
  3. What actually happens
    Calling SetPedAsNoLongerNeeded right after CreatePed will make the native GetEntityPopulationType return 5 instead of 7 inside entityCreating server event
  4. Category of bug (eg. client, server, weapons, peds, native)
    client
    server
    peds
    native
  5. Reproducible steps, preferably with example script(s)

Client Script


CreateThread(function()
-- just to not spam the event
    while true do
        SetPedDensityMultiplierThisFrame(0.0)
        SetVehicleDensityMultiplierThisFrame(0.0)
        Wait(0)
    end
end)

RegisterCommand("spawnped", function(source, args, rawCommand)
    local playerPed = PlayerPedId()
    local playerCoords = GetEntityCoords(playerPed)
    local heading = GetEntityHeading(playerPed)

    local model = GetHashKey("cs_amandatownley")
    RequestModel(model)
    while not HasModelLoaded(model) do
        Citizen.Wait(0)
    end

    local spawnedPed = CreatePed(4, model, playerCoords.x + 2.0, playerCoords.y, playerCoords.z, heading, true, false)
    print(GetEntityPopulationType(spawnedPed))
    SetPedAsNoLongerNeeded(spawnedPed)
    print(GetEntityPopulationType(spawnedPed))
end, false)

Server Event

AddEventHandler('entityCreating', function(handle)
    print(GetEntityPopulationType(handle))
end)

while I understand why this happens, I still think it can be considered unintended behaviour

This could be a viable thing to do (not resetting the population type when the script owner is cleared), but that might have odd side effects if other game code expects this.

What’s the use case here? For example, as a workaround, can’t you e.g. wait a little while before removing script ownership from your ped, or just create the ped from a server-side setter? It feels like this is yet another ‘XY problem’ style post and this isn’t the actual root issue.

I have a hunting script that only allows skinning a game created animal. Lately I have found some players circumventing this by calling SetPedAsNoLongerNeeded right after creating an scripted ped. I’m aware of your stance on requesting changes that could be classified as ‘I need this for my anticheat’. While I still feel this is unintended behaviour I understand your concerns with

might have odd side effects if other game code expects this

Right, the request here is rather to better be able to tell the opposite state (a population entity more conclusively being a population entity).

Yes sir, unsure on what that actually entails since GetEntityPopulationType seems to work for most if not all situations when excluding this edge case. That is why I opened this as a bug report and not as a feature request.

The real problem is that people with cheats can execute this code to make vehicles, objects or ped appear that are noted as NPC entities. And so we server creators don’t really have a solution to this, apart from removing NPCs from the server altogether.

Yep agree, now a cheater can create a ped with population 5 like NPC entities so we can’t detect them