Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

OnEntityCreated is called right before EntityRemoved is called on player objects on the server #1371

Closed JacobAsmuth closed 5 years ago

JacobAsmuth commented 10 years ago

I know that was a convoluted bug description. Basically here's what happens:

  1. player clicks "disconnect" (or somehow leaves the server)
  2. OnEntityCreated is called, passing that player object (serverside only)
  3. EntityRemoved is called, also passing that player object(shared)

http://facepunch.com/showthread.php?t=1374457&p=45460578#post45460578

edit: as a side note, can the hook names also be standardized? Either OnEntityRemoved or EntityCreated please!

xaviergmail commented 10 years ago

I do agree with the hook / functions being standardized. I know shit will break but perhaps we could deprecate them for a while and maybe throw off warnings so that server owners can bitch at addon creators to fix their addons in advance? I'm not really a huge fan of the things that this would break, but I've grown tired of coding gamemodes / addons for garry's mod just for the simple fact that it is just one big mess and there's no established standard and everything looks ugly.

Kefta commented 6 years ago

It seems players aren't the only entities created on disconnect. These are created when a player exits a single-player game:

Entity [2][soundent]
Entity [3][player_manager]
Entity [4][gmod_gamerules]
Entity [5][bodyque]
Entity [6][bodyque]
Entity [7][bodyque]
Entity [8][bodyque]
Entity [9][ai_network]
Entity [174][spotlight_end]
Entity [175][beam]
Entity [176][spotlight_end]
Entity [177][beam]
Entity [178][spotlight_end]
Entity [179][beam]
Entity [180][spotlight_end]
Entity [181][beam]
Entity [182][spotlight_end]
Entity [183][beam]
Entity [116][physgun_beam]
Entity [120][predicted_viewmodel]
Entity [121][predicted_viewmodel]
Entity [122][scene_manager]
TIMONz1535 commented 5 years ago

If you save the player’s entity in a variable while he played on the server, and then compare it with the player’s entity passed as an argument in the EntityRemoved hook, you will get a false result because these are different entities :sob: but same player and same EntIndex

robotboy655 commented 5 years ago

Should be solved on Dev.