Changing View Model
Posted: Tue Feb 13, 2018 5:40 pm
I am wondering if there is a good way of changing the view model of a players weapon to something else.
I'm currently testing and I can change the viewmodel, but it flickers a lot and the animations do not match up with the actual shooting and reloading.
I'm using this for testing:
The "goal" is to be able to download just any skin that changes viewmodel for any weapon and be able to use this on your server without having players to install it.
I'm currently testing and I can change the viewmodel, but it flickers a lot and the animations do not match up with the actual shooting and reloading.
I'm using this for testing:
Syntax: Select all
from listeners import OnPlayerRunCommand
from players.entity import Player
from filters.players import PlayerIter
from entities.entity import Entity
from filters.entities import BaseEntityIter
from events import Event
from players.helpers import inthandle_from_userid
from entities.helpers import inthandle_from_index
from listeners import OnTick
from listeners import OnPlayerRunCommand
from engines.precache import Model
model = Model("models/weapons/v_rif_aug.mdl")
player_weapons = {}
@Event('player_say')
def _say(ev):
player = Player.from_userid(int(ev['userid']))
if player.userid not in player_weapons:
player_weapons[player.userid] = {}
weapon = player.active_weapon
player_weapons[player.userid][weapon.classname] = 1
for entity in BaseEntityIter(class_names='predicted_viewmodel'):
ent = Entity(entity.index)
if inthandle_from_userid(int(ev['userid'])) == ent.owner_handle:
ent.set_property_short('m_nModelIndex',model.index)
@OnPlayerRunCommand
def _use_command_hook(player,command):
if command.weaponselect:
if Entity(command.weaponselect).classname in player_weapons[player.userid]:
for entity in BaseEntityIter(class_names='predicted_viewmodel'):
ent = Entity(entity.index)
weapon_handle = inthandle_from_index(command.weaponselect)
if inthandle_from_userid(player.userid) == ent.owner_handle:
if ent.weapon_handle == weapon_handle:
ent.set_property_short('m_nModelIndex',model.index)
@OnTick
def _on_tick():
for player in PlayerIter('all'):
if player.steamid != 'BOT':
if player.userid not in player_weapons:
player_weapons[player.userid] = {}
if player.active_weapon:
if player.active_weapon.classname in player_weapons[player.userid]:
if player_weapons[player.userid][player.active_weapon.classname] == 1:
for entity in BaseEntityIter(class_names='predicted_viewmodel'):
ent = Entity(entity.index)
weapon_handle = inthandle_from_index(player.active_weapon.index)
if inthandle_from_userid(player.userid) == ent.owner_handle:
if ent.weapon_handle == weapon_handle:
ent.set_property_short('m_nModelIndex',model.index)
The "goal" is to be able to download just any skin that changes viewmodel for any weapon and be able to use this on your server without having players to install it.