citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.48k stars 2.06k forks source link

Server-Side CreatePed doesn't trigger entityCreated/entityCreating #2658

Open Abasalt-yar opened 1 month ago

Abasalt-yar commented 1 month ago

What happened?

Hi, When I execute this code, only entityRemoved is being triggered

let JOB_PED
let INT
AddEventHandler("onResourceStart",res => {
    if (res != GetCurrentResourceName()) return
    let [x,y,z,heading] = [142.48,-871.71,30.62,207]
    JOB_PED = CreatePed(26,GetHashKey("s_m_y_airworker"),x,y,z - 1,heading,true,true)
    console.log(`Entity ID: `,JOB_PED)
    INT = setInterval(() => {
        if (DoesEntityExist(JOB_PED)) console.log("Ped Exists")
        if (NetworkGetNetworkIdFromEntity(JOB_PED)) {
            console.log("Ped Net ID Exists",NetworkGetNetworkIdFromEntity(JOB_PED))
            clearInterval(INT)
        }
    }, 1000);
    setTimeout(DeleteEntity,10000,JOB_PED)
})
AddEventHandler("entityCreated",en => console.log(`New Entity Created`,en))
AddEventHandler("entityCreating",en => console.log(`Creating New Entity`,en))
AddEventHandler("entityRemoved",en => console.log(`Entity Removed`,en))

image

Expected result

it should log Creating New Entity or New Entity Created

Reproduction steps

  1. Add the code above in a server-side script
  2. start the resource

Importancy

Slight inconvenience

Area(s)

FiveM, FXServer, OneSync

Specific version(s)

FXServer-master SERVER v1.0.0.8695 win32 Client: b2802 Canary

Additional information

No response

AvarianKnight commented 1 month ago

I don't think server-created entities should trigger entityCreating at all because the server expects it to 'just exist'.

iirc the reason this wasn't fixed before for entityCreated is that there was the off chance that it would break compatibility existing usages of entityCreated which might expect entityCreated to have a valid owner and could break/error out if it doesn't

Abasalt-yar commented 1 month ago

I don't think server-created entities should trigger entityCreating at all because the server expects it to 'just exist'.

iirc the reason this wasn't fixed before for entityCreated is that there was the off chance that it would break compatibility existing usages of entityCreated which might expect entityCreated to have a valid owner and could break/error out if it doesn't

Oh I see, So it won't be fixed ? Or is there a chance it could be fixed in future

visibait commented 1 month ago

I don't think server-created entities should trigger entityCreating at all because the server expects it to 'just exist'. iirc the reason this wasn't fixed before for entityCreated is that there was the off chance that it would break compatibility existing usages of entityCreated which might expect entityCreated to have a valid owner and could break/error out if it doesn't

Oh I see, So it won't be fixed ? Or is there a chance it could be fixed in future

Unless they create another game event (e.g., serverEntityCreated) for server-created entities, I don't think this issue is fixable, as it would break compatibility for many resources.

Abasalt-yar commented 1 month ago

I see, So we have to wait. Thank you