spawn entity with index only

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

spawn entity with index only

Postby D3CEPTION » Tue Jan 24, 2017 5:53 pm

is it possible to tell a client to render a model on a networked entity after precaching the path by the index only?

"ent.model_index" -> doesnt work
"ent.model_path" -> does work
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: spawn entity with index only

Postby L'In20Cible » Wed Jan 25, 2017 12:28 am

I'm not sure to understand your question. You want to set the model of an entity from an index?
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

Re: spawn entity with index only

Postby D3CEPTION » Wed Jan 25, 2017 1:21 am

i am wondering why it isnt possible to set a model by ent.modelindex only in my posted situation. while ent.modelpath works. but my fear is that setting the path makes sp send the client the whole string via network? shouldnt setting .modelindex suffice in my case? its actually a question if sp is able to handle it..
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

Re: spawn entity with index only

Postby D3CEPTION » Wed Jan 25, 2017 1:25 am

but it might just be that the server always uses sendtables to handle edict traffic...which would leave no option for sp to make it more efficient... but maybe sp could make it easier on the script-end by letting users set the model_index only and then internally create the sendtable from looking up the path in preache... but i havent looked into it really
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: spawn entity with index only

Postby L'In20Cible » Wed Jan 25, 2017 1:31 am

That is not how it works. The entity itself doesn't network the model name to clients (m_szModelName is not networkable while m_nModelIndex is). But the entity creation needs the model name to instantiate the entity (for debugging if you try to set a static model to a physic entity, etc.) and is responsible to internally set the model index. The indexes are only the slot of the strings in the precache tables. If you only have an index, you can retrieve the name. For example:

Syntax: Select all

from engines.precache import Model
from stringtables import string_tables

ent.model = Model(string_tables[Model.precache_table][index])


In short, this is not related to "can SP handle it", this is how the engine works; you need a model name to create an entity.
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

Re: spawn entity with index only

Postby D3CEPTION » Wed Jan 25, 2017 1:39 am

i dont really get what you are trying to say... my question is if/why sp cant handle setting ent.model_index only.. i only explained it to hlep you understand my question better. sp could easily retrieve the modelpath from the preache table by index only and then send a working sendtable at ent.spawn()
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: spawn entity with index only

Postby L'In20Cible » Wed Jan 25, 2017 1:47 am

Entity.model_name and Entity.model_index are wrapping existing properties/keyvalues of the entity itself and I don't believe it to be our role to override them to allow different types (would add unnecessary isinstance checkings). We already added an Entity.model property to make it easier to set a model (it internally set the model_name and the model_index based on the given Model instance). Though, we could certainly allow the Model class to accept either a path or an index, but I'm really unsure if it worth it. Majority of cases, users have a model path, and if they want to set a model by its index, they already have the possibility to extract the path themselve.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 23 guests