Page 1 of 1

[CSGO] Setting Hand Viewmodel

Posted: Sun May 02, 2021 9:47 pm
by Grubbsy
I made myself a command in my plugin to allow players to set their player models to custom models that are downloaded, and I wanted to be able to set the ViewModel to the ones included. However, I'm not sure how to do this.

Syntax: Select all

# Model Link:  https://gamebanana.com/skins/171233
# Model Path: "models/player/custom_player/eminem/player_start/player_start.mdl"
# Model Hand Path: "models\player\custom_player\eminem\player_start\player_start_arms.mdl"
@TypedSayCommand('/model')
def model_test_cmd(cmd):
player = _players[cmd.index] # This is how I keep track of players
player.model = Model("models/player/custom_player/eminem/player_start/player_start.mdl") # This sets the player's model

# This is meant to set the hand model in the first-person mode.
# This is the way I tried and it doesn't change the model, but nothing changes. I am precaching the model.
# This is also the best I've gotten because it didn't throw errors at me or cause some really weird stuff to happen
player.draw_view_model = engine_server.precache_model("models\player\custom_player\eminem\player_start\player_start_arms.mdl")


The way I was trying wasn't visibly changing anything. Could it be I have to hide the ViewModel first? if not I'd like help trying to get the hand model to work, as well as hiding the previous hand model so there's no overlap (if it applies).

Thanks,
- Grubbsy.

Re: [CSGO] Setting Hand Viewmodel

Posted: Sun May 02, 2021 10:43 pm
by VinciT
Setting the m_szArmsModel property should work:

Syntax: Select all

# ../change_model/change_model.py

# Source.Python
from commands import CommandReturn
from commands.client import ClientCommand
from engines.precache import Model
from engines.server import engine_server
from players.entity import Player


model_path = 'models/player/custom_player/legacy/tm_professional.mdl'
arms_path = 'models/weapons/t_arms_professional.mdl'


@ClientCommand('change_model')
def change_model(command, index):
"""Changes the player's world and arms model."""
player = Player(index)
# Change the player's world model.
player.model = Model(model_path)
# Make sure the model is precached, otherwise the arms will be invisible.
engine_server.precache_model(arms_path)
# Change the player's arms model.
player.set_property_string('m_szArmsModel', arms_path)
return CommandReturn.BLOCK

Re: [CSGO] Setting Hand Viewmodel

Posted: Mon May 03, 2021 12:31 am
by Jezza
To avoid overlapping of arm models, you need to prevent the precaching of existing arm models.

Syntax: Select all

# Source.Python Imports 
# Engines
from engines.server import engine_server
# Memory
from memory import get_virtual_function
from memory.hooks import PreHook


@PreHook(get_virtual_function(engine_server, "PrecacheModel"))
def pre_precache_model(args):
if "models/weapons/v_models/arms/glove_hardknuckle/" in args[1]:
return 0

Re: [CSGO] Setting Hand Viewmodel

Posted: Wed May 05, 2021 12:12 am
by Grubbsy
VinciT wrote:Setting the m_szArmsModel property should work:

Syntax: Select all

# ../change_model/change_model.py

# Source.Python
from commands import CommandReturn
from commands.client import ClientCommand
from engines.precache import Model
from engines.server import engine_server
from players.entity import Player


model_path = 'models/player/custom_player/legacy/tm_professional.mdl'
arms_path = 'models/weapons/t_arms_professional.mdl'


@ClientCommand('change_model')
def change_model(command, index):
"""Changes the player's world and arms model."""
player = Player(index)
# Change the player's world model.
player.model = Model(model_path)
# Make sure the model is precached, otherwise the arms will be invisible.
engine_server.precache_model(arms_path)
# Change the player's arms model.
player.set_property_string('m_szArmsModel', arms_path)
return CommandReturn.BLOCK


This works, but not if players have an agent equipped... learned that the hard way lol.

Re: [CSGO] Setting Hand Viewmodel

Posted: Mon May 10, 2021 3:53 am
by VinciT
I have an agent skin and running the code I provided didn't give me any issues, so I'm assuming this only happens with custom models.
I'll see if I can find a workaround for the problems you're facing when I get out of bed in a few hours. :tongue:

Re: [CSGO] Setting Hand Viewmodel

Posted: Mon May 10, 2021 6:37 pm
by VinciT
Jezza already gave us the workaround.. heh.
Jezza wrote:To avoid overlapping of arm models, you need to prevent the precaching of existing arm models.

Syntax: Select all

# Source.Python Imports 
# Engines
from engines.server import engine_server
# Memory
from memory import get_virtual_function
from memory.hooks import PreHook


@PreHook(get_virtual_function(engine_server, "PrecacheModel"))
def pre_precache_model(args):
if "models/weapons/v_models/arms/glove_hardknuckle/" in args[1]:
return 0

Just make sure to change the map at least once after loading this.

Re: [CSGO] Setting Hand Viewmodel

Posted: Wed May 12, 2021 1:55 am
by Grubbsy
Yeah, it's just custom models, like the one I was trying to use that wouldn't work. It gives me the Heavy Assault suit arms when I try changing to the custom model hands. (when having an agent equipped, specifically Bloody Miami Darryl, I haven't tested with anyone else).