Raised This Month: $32 Target: $400
 8% 

[L4D/2] Custom Viewmodel


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
foxhound27
AlliedModders Donor
Join Date: Sep 2019
Location: Argentina
Old 10-28-2022 , 20:42   [L4D/2] Custom Viewmodel
Reply With Quote #1

Hello guys, i wanna share how to custom viewmodels on l4d/l4d2 i just added default models of the infected for survivors in order to test known issues on l4d1 the flashlight goes crazy when turned on.. however on l4d2 all is fine hope any can make use of it

NOTE: I only tested as survivor

Image:



Video: https://youtu.be/ED_OctwOYaM

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

int g_iViewModels[MAXPLAYERS 1][2];

Handle g_hCreateViewModel;

int g_iOffset_ViewModel;
int g_iOffset_ActiveWeapon;

int g_iOffset_Weapon;
int g_iOffset_Sequence;
int g_iOffset_PlaybackRate;

int g_AnimOffset = -1;//this only for testing porpuses

char g_szCustomVM_ClassName[3][] = {
    
"pistol",
    
"shotgun",
    
"smg"
};

char g_szCustomVM_Model[3][] = {
    
"models/v_models/weapons/v_claw_hunter.mdl",
    
"models/v_models/weapons/v_claw_smoker.mdl",
    
"models/v_models/weapons/v_claw_boomer.mdl"
};


int g_iCustomVM_ModelIndex[3];

public 
void OnPluginStart() {
    
Handle gameConf LoadGameConfigFile("L4DViewmodels");

    if (!
gameConf) {
        
SetFailState("Fatal Error: Unable to open game config file: \"L4DViewmodels\"!");
    }

    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(gameConfSDKConf_Virtual"CreateViewModel");
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_ByValue);

    if ((
g_hCreateViewModel EndPrepSDKCall()) == INVALID_HANDLE) {
        
SetFailState("Fatal Error: Unable to create SDK call \"CreateViewModel\"!");
    }

    
CloseHandle(gameConf);

    
g_iOffset_ViewModel GetSendPropOffset("CBasePlayer""m_hViewModel");
    
g_iOffset_ActiveWeapon GetSendPropOffset("CBasePlayer""m_hActiveWeapon");
    
g_iOffset_Weapon GetSendPropOffset("CBaseViewModel""m_hWeapon");
    
g_iOffset_Sequence GetSendPropOffset("CBaseViewModel""m_nSequence");
    
g_iOffset_PlaybackRate GetSendPropOffset("CBaseViewModel""m_flPlaybackRate");

    
HookEvent("player_spawn"Event_PlayerSpawn);
}

int GetSendPropOffset(const char[] serverClass, const char[] propName) {
    
int offset FindSendPropInfo(serverClasspropName);

    if (!
offset) {
        
SetFailState("Fatal Error: Unable to find offset: \"%s::%s\"!"serverClasspropName);
    }

    return 
offset;
}

public 
void OnMapStart() {
    for (
int i 03i++) {
        
g_iCustomVM_ModelIndex[i] = PrecacheModel(g_szCustomVM_Model[i], true);
    }
}

public 
void OnClientPostAdminCheck(int client) {
    
g_iViewModels[client][0] = -1;
    
g_iViewModels[client][1] = -1;

    
SDKHook(clientSDKHook_PostThinkOnClientThinkPost);
}

public 
void OnClientThinkPost(int client) {
    static 
int currentWeapon[MAXPLAYERS 1];

    
int viewModel1 g_iViewModels[client][0];
    
int viewModel2 g_iViewModels[client][1];

    if (!
IsPlayerAlive(client)) {
        if (
viewModel2 != -1) {
            
// If the player is dead, hide the secondary viewmodel.

            
g_iViewModels[client][0] = -1;
            
g_iViewModels[client][1] = -1;

            
currentWeapon[client] = 0;
        }

        return;
    }

    
int activeWeapon GetEntDataEnt2(clientg_iOffset_ActiveWeapon);

    
// Check if the player has switched weapon.
    
if (activeWeapon != currentWeapon[client]) {

        
currentWeapon[client] = 0;

        
char className[32];
        
GetEdictClassname(activeWeaponclassNamesizeof(className));


        for (
int i 03i++) {
            if (
StrContains(classNameg_szCustomVM_ClassName[i], false) > -1) {

                
SetEntProp(viewModel2Prop_Send"m_nModelIndex"g_iCustomVM_ModelIndex[i]);
                
SetEntData(viewModel2g_iOffset_WeaponGetEntData(viewModel1g_iOffset_Weapon), _true);

                
currentWeapon[client] = activeWeapon;

                break;
            }
        }
    }

    if (
currentWeapon[client]) {
        
        
SetEntProp(viewModel1Prop_Send"m_nModelIndex"0); //hide original
        
SetEntData(viewModel2g_iOffset_SequenceGetEntData(viewModel1g_iOffset_Sequence)-g_AnimOffset_true);
        
SetEntData(viewModel2g_iOffset_PlaybackRateGetEntData(viewModel1g_iOffset_PlaybackRate), _true);

    }else{

        
SetEntProp(viewModel2Prop_Send"m_nModelIndex"0); //hide fake
    
}
}

public 
Action Event_PlayerSpawn(Handle event, const char[] namebool dontBrodcast) {
    
int client GetClientOfUserId(GetEventInt(event"userid"));

    if (
GetClientTeam(client) > 1) {
        
// Create the second view model.
        
SDKCall(g_hCreateViewModelclient1);

        
g_iViewModels[client][0] = GetViewModel(client0);
        
g_iViewModels[client][1] = GetViewModel(client1);
    }
}

int GetViewModel(int clientint index) {
    return 
GetEntDataEnt2(clientg_iOffset_ViewModel + (index 4));

Attached Files
File Type: sp Get Plugin or Get Source (L4DViewmodels.sp - 179 views - 4.3 KB)
File Type: txt L4DViewmodels.txt (234 Bytes, 142 views)

Last edited by foxhound27; 10-28-2022 at 20:48.
foxhound27 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 06:59.


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