Question about setting models

Please post any questions about developing your plugin here. Please use the search function before posting!
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Question about setting models

Postby 8guawong » Tue Oct 14, 2014 6:15 am

how to set player's model using the offical csgo model

Syntax: Select all

t1 = -65158  #pirate
t2 = -65149 #phoenix

@Event
def player_spawn(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
if player.team == 2:
rand = random.randint(1, 2)
if rand == 1:
color = (255*65792+255)
player.set_prop_int('m_nModelIndex', t1)
player.set_prop_int("m_nRenderMode", player.get_prop_int("m_nRenderMode") | 1)
player.set_prop_int("m_nRenderFX", player.get_prop_int("m_nRenderFX") | 256)
player.set_prop_int("m_clrRender", color)
if rand == 2:
color = (255*65792+255)
player.set_prop_int('m_nModelIndex', t2)
player.set_prop_int("m_nRenderMode", player.get_prop_int("m_nRenderMode") | 1)
player.set_prop_int("m_nRenderFX", player.get_prop_int("m_nRenderFX") | 256)
player.set_prop_int("m_clrRender", color)


does not work~
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Oct 14, 2014 11:28 am

Syntax: Select all

from engines.precache import Model
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from random import choice

models = [Model('models/player/tm_phoenix.mdl'),
Model('models/player/tm_pirate.mdl')]

@Event
def player_spawn(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
if player.team != 2:
return
player.set_model_index(choice(models).index)
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Tue Oct 14, 2014 12:07 pm

L'In20Cible wrote:

Syntax: Select all

from engines.precache import Model
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from random import choice

models = [Model('models/player/tm_phoenix.mdl'),
Model('models/player/tm_pirate.mdl')]

@Event
def player_spawn(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
if player.team != 2:
return
player.set_model_index(choice(models).index)


could you tell me why mine doesn't work? :grin:
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Oct 14, 2014 12:47 pm

Cause -65158 and -65149 are everything except model indexes. Also, precached models are refreshed every maps so their indexes are most likely going to change into the "modelprecache" stringtable. And then, like I explained here, there is no need to reset the player's color unless you are raw setting m_nModelIndex.
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Wed Oct 15, 2014 2:13 am

thanks for the explanination

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/packages/source-python/plugins/manager.py', line 72, in __missing__
    instance = self.instance(plugin_name, self.base_import)
  File '../addons/source-python/packages/source-python/plugins/instance.py', line 82, in __init__
    self._plugin = import_module(import_name)
  File '../addons/source-python/plugins/test/test.py', line 1, in <module>
    from engines.precache import Model

ImportError: No module named 'engines.precache'


using source-python-csgo-Sep-17-2014
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Oct 15, 2014 2:49 am

That class was just recently added. It is not included in the current release, which nearly a month old. I was hoping to get the entities_changes branch complete and merged with the master branch before posting a new release.
Image
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Wed Oct 15, 2014 3:06 am

satoon101 wrote:That class was just recently added. It is not included in the current release, which nearly a month old. I was hoping to get the entities_changes branch complete and merged with the master branch before posting a new release.


yea thats what i was guessing... guess i'll wait for new version out to test it :cool:

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 107 guests