Closed Kefta closed 4 years ago
This does not only happen with NPCs but with other types of entities too. I've been testing this in fact and in most cases the server realm doesn't know about the model of the entity but the client realm does (as in GetModel returns nil serverside).
I think the reason for this is that OnEntityCreate doesn't mean its fully spawned yet, just got created, equivalent of calling ents.Create(class) and then calling this function right away before setting any model or position yet. I normally wait one frame to make sure all the data is set.
I would imagine its point entities which cannot have a model.
@ZehMatt Even so the behavior is different on server and client for this, which should not be the case. @robotboy655 My tests were made with normal props no fancy brush entity or whatsoever.
Its different because the client will initialize the entity from a snapshot and will be created on the client with all data set already, thats just how source works.
That's fine and everything, but empty string would be more appropriate than nil/novalue imo.
Which would break every script that uses nil to test if the entity has a model or not, unfortunately.
Even the base game itself https://github.com/Facepunch/garrysmod/blob/394ae745df8f8f353ea33c8780f012fc000f4f56/garrysmod/gamemodes/sandbox/entities/effects/propspawn.lua#L18
Then the wiki page needs to be updated to 'returns string or nil'
This is intentional behaviour.
Code:
A number of entities when the map spawns don't have models on the server nor client. Spawning NPCs in single-player will result in them having a nil model serverside but a string clientside. Credit to @Earu for noticing this.