[CSGO] Setting Hand Viewmodel

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Grubbsy
Junior Member
Posts: 12
Joined: Sat Aug 29, 2020 10:12 pm

[CSGO] Setting Hand Viewmodel

Postby Grubbsy » Sun May 02, 2021 9:47 pm

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.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [CSGO] Setting Hand Viewmodel

Postby VinciT » Sun May 02, 2021 10:43 pm

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
ImageImageImageImageImage
Jezza
Junior Member
Posts: 16
Joined: Tue Aug 28, 2012 5:52 pm

Re: [CSGO] Setting Hand Viewmodel

Postby Jezza » Mon May 03, 2021 12:31 am

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
User avatar
Grubbsy
Junior Member
Posts: 12
Joined: Sat Aug 29, 2020 10:12 pm

Re: [CSGO] Setting Hand Viewmodel

Postby Grubbsy » Wed May 05, 2021 12:12 am

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.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [CSGO] Setting Hand Viewmodel

Postby VinciT » Mon May 10, 2021 3:53 am

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:
ImageImageImageImageImage
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [CSGO] Setting Hand Viewmodel

Postby VinciT » Mon May 10, 2021 6:37 pm

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.
ImageImageImageImageImage
User avatar
Grubbsy
Junior Member
Posts: 12
Joined: Sat Aug 29, 2020 10:12 pm

Re: [CSGO] Setting Hand Viewmodel

Postby Grubbsy » Wed May 12, 2021 1:55 am

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).

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests