altmp / altv-issues

Issues and roadmap for alt:V project
93 stars 16 forks source link

Entity script handle is not always valid in gameEntityCreate event #663

Open Heryshaf opened 4 years ago

Heryshaf commented 4 years ago

Client/server version

build #1286, branch release, also on 2.1-dev2 Current behavior

Trying to obtain an entity's scriptID when the event is called returns an invalid scriptID.. timeouting for some time will give you the proper scriptID for the entity. perhaps the event is called pre creation of the entity in the memory of other players thus its scriptID is invalid?

Expected behavior

that it works as expected.. Steps to reproduce

alt.on( 'gameEntityCreate', ( entity ) => {
    if(entity instanceof alt.Player)
      {
        alt.log(entity.scriptID); // original scriptID
        alt.setTimeout(() => {
        alt.log(entity.scriptID); // different scriptID after timeout
        }, 600);
       }
} ); 
ThomasMarangoni commented 4 years ago

It's normal that a scriptID can change, because it is verifying to the original GTA Entity ID. It's changing when the gta entity is changing.

Heryshaf commented 4 years ago

But shouldn't altv fire the entity creation event after it has been created for the player already? so the entity scriptID should already be the new one? no?

FabianTerhorst commented 4 years ago

Sounds Like a issue in dev Branch then.

Heryshaf commented 4 years ago

@FabianTerhorst As stated, i tried on both release and latest dev, same behavior.

FabianTerhorst commented 4 years ago

Can you try with a clean server with no other resources and code. So that no other code can influence that.

Heryshaf commented 4 years ago

@FabianTerhorst I don't have any special things being used or editing the scriptID in anyway, the same ped model of the player is used before streaming in / out (and yeah it's not the free model), i've attached a simple test code for anyone to test in less than a minute. Would be glad if anyone with any script can test it up with anyone they know. Thanks.

martonp96 commented 4 years ago

@Heryshaf can you interact with the player using the "wrong" scriptid? e.g. setting the position or something

Heryshaf commented 4 years ago

@martonp96 I've already tried to use some natives that use the 'wrong' scriptid and it won't work. I've also sent you them on discord.

insus100 commented 3 years ago

I have the same issue, entity.scriptID is invalid unless you use alt.setTimeout() in gameEntityCreate: When gameEntityCreate is just called: [23:32:03] gameEntityCreate (BEFORE) entity.scriptID 17410

...2 seconds later (alt.setTimeout) [23:32:05] gameEntityCreate (AFTER) entity.scriptID 17666

As you can see entity.scriptID is different (the valid scriptID is the one after 2 seconds timeout)

xxshady commented 2 weeks ago

I have the same issue, entity.scriptID is invalid unless you use alt.setTimeout() in gameEntityCreate: When gameEntityCreate is just called: [23:32:03] gameEntityCreate (BEFORE) entity.scriptID 17410

...2 seconds later (alt.setTimeout) [23:32:05] gameEntityCreate (AFTER) entity.scriptID 17666

As you can see entity.scriptID is different (the valid scriptID is the one after 2 seconds timeout)

does it happen when you re-create an entity? i experienced similar behavior when i re-created a vehicle (destroyed old one and after that created new one)

i think delaying deletion may help in that case

// serverside

// remove entity from the game
oldVehicle.streamed = false

// create new one
const newVehicle = new alt.Vehicle(...)

alt.setTimeout(() => {
  oldVehicle.destroy()
}, 3000)

probably related: https://github.com/altmp/altv-js-module/issues/289