Raised This Month: $51 Target: $400
 12% 

[CS:GO] Custom Viewmodel


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
CareFully
Junior Member
Join Date: Oct 2015
Old 10-28-2015 , 15:08   [CS:GO] Custom Viewmodel
Reply With Quote #1

PHP Code:
#include <sourcemod>
#include <sdkhooks> 
#include <sdktools>

new g_PVMid[MAXPLAYERS]; // Predicted ViewModel ID's
new g_iSMGModel;    // Custom ViewModel index

public OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
OnConfigsExecuted()
{
    
g_iSMGModel PrecacheModel("models/weapons/paintball/v_pbgunt.mdl"); // Custom model
}

public 
OnClientPostAdminCheck(client){
    
SDKHook(clientSDKHook_WeaponSwitchPostOnClientWeaponSwitchPost);    
}

public 
OnClientWeaponSwitchPost(clientwpnid)
{
    
    
decl String:szWpn[64];
    
GetEntityClassname(wpnid,szWpn,sizeof(szWpn));
    
    if(
StrEqual(szWpn"weapon_mac10")){
        
SetEntProp(wpnidProp_Send"m_nModelIndex"0);
        
SetEntProp(g_PVMid[client], Prop_Send"m_nModelIndex"g_iSMGModel);
    }
}

public 
Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
g_PVMid[client] = Weapon_GetViewModelIndex(client, -1);
    


// Thanks to gubka for these 2 functions below.

// Get model index and prevent server from crash
Weapon_GetViewModelIndex(clientsIndex)
{
    while ((
sIndex FindEntityByClassname2(sIndex"predicted_viewmodel")) != -1)
    {
        new 
Owner GetEntPropEnt(sIndexProp_Send"m_hOwner");
        
        if (
Owner != client)
            continue;
        
        return 
sIndex;
    }
    return -
1;
}
// Get entity name
FindEntityByClassname2(sStartEntString:szClassname[])
{
    while (
sStartEnt > -&& !IsValidEntity(sStartEnt)) sStartEnt--;
    return 
FindEntityByClassname(sStartEntszClassname);

I've tinkered around with cs:go trying to get custom viewmodels working without flickering or turning off prediction and after hours and hours I think i finally got something that seems to work.

It might work with other mods aswell, but i haven't tested it.

The custom model must have animations in the same order as the original model, oherwise it's going to play wrong animations.

EDIT: I added a custom model to attachments to test the code. It's a paintball gun converted from cs 1.6 to cs:go. Lighting of the model might be a bit glicthy .
Attached Files
File Type: zip custommac10.zip (436.4 KB, 956 views)

Last edited by CareFully; 11-11-2015 at 11:07. Reason: Optimized code.
CareFully is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode