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

[CS:GO] Custom Viewmodel


Post New Thread Reply   
 
Thread Tools Display Modes
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-11-2015 , 20:23   Re: [CS:GO] Custom Viewmodel
Reply With Quote #41

Quote:
Originally Posted by CareFully View Post
Yes it does. Just make sure you don't set the custom model if you don't want it. It actually resets each time player switches the weapon. That's why we reassign the custom model on each weapon switch.

So your code would be:
PHP Code:
#include <sourcemod>  
#include <sdkhooks>   
#include <sdktools>  

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

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

public 
OnConfigsExecuted()  
{  
    
g_iSMGModel PrecacheModel("models/player/vad36CSO2/arm.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_knife")){
        if (
GetClientTeam(client) == 2){ 
            
SetEntProp(wpnid,Prop_Send,"m_iItemIDLow",0);
            
SetEntProp(wpnid,Prop_Send,"m_iItemIDHigh",0); 
            
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 also optimized the Weapon_GetViewModelIndex() Function by removing the weapon check as it is not needed since there is only one predicted viewmodel per player. Updated code in OP.
the code you posted is like what i had before but i went ahead and tested it anyway but the following is the result (just to show it doesn't reset on spawn)

__________________
8guawong is offline
CareFully
Junior Member
Join Date: Oct 2015
Old 11-12-2015 , 00:03   Re: [CS:GO] Custom Viewmodel
Reply With Quote #42

Then i'm out of ideas. Maybe you have something that blocks the change or conflicts with it.
It seems like you're changing hand models on other weapons, maybe that has something to do with it
CareFully is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-12-2015 , 03:11   Re: [CS:GO] Custom Viewmodel
Reply With Quote #43

Quote:
Originally Posted by CareFully View Post
Then i'm out of ideas. Maybe you have something that blocks the change or conflicts with it.
It seems like you're changing hand models on other weapons, maybe that has something to do with it
ok thanks anyway
__________________
8guawong is offline
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 11-13-2015 , 00:00   Re: [CS:GO] Custom Viewmodel
Reply With Quote #44

Today i rewrite my mod, and tried to remove p_ knife models:
I found method to change world weapon model for player (p_)

In switchpost
Quote:
SetEntProp(iWeapon, Prop_Send, "m_hWeaponWorldModel", 0);
Other intetesting offsets for weapons entity
Member: m_bFlipViewModel (offset 246 (type integer) (bits ()
Member: m_iWorldModelIndex (offset 2340) (type integer) (bits 11) ()
Member: m_iWorldDroppedModelIndex (offset 2344) (type integer) (bits 11) ()

Member: m_hWeaponWorldModel (offset 2352) (type integer) (bits 21) (Unsigned|NoScale)
__________________
gubka is offline
Send a message via ICQ to gubka
CareFully
Junior Member
Join Date: Oct 2015
Old 11-13-2015 , 11:47   Re: [CS:GO] Custom Viewmodel
Reply With Quote #45

Here's my code for changing the world model:
PHP Code:
new g_iWorldSMGModel//precached model index

public OnEntityCreated(entid){
    
decl String:szWpn[64];
    
GetEntityClassname(entidszWpnsizeof(szWpn));
    if(
StrEqual(szWpn"weapon_mac10")){
        
SDKHook(entidSDKHook_SpawnPostOnEntitySpawn);
    }
}
public 
OnEntitySpawn(entid){ 
    
    new 
WMid GetEntPropEnt(entidProp_Send"m_hWeaponWorldModel")
    
SetEntProp(WMidProp_Send"m_nModelIndex"g_iWorldSMGModel);

Now we just have to find a way to change the "dropped" weapon model.
CareFully is offline
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 11-14-2015 , 10:13   Re: [CS:GO] Custom Viewmodel
Reply With Quote #46

All offset of weaponworldmodel entity

Spoiler
__________________
gubka is offline
Send a message via ICQ to gubka
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 11-14-2015 , 10:59   Re: [CS:GO] Custom Viewmodel
Reply With Quote #47

int Owner = GetEntPropEnt(sIndex, Prop_Send, "m_hOwner"); ->
int Owner = GetEntPropEnt(sIndex, Prop_Data, "m_hOwner");

Because predicted_viewmodel is datamap
__________________
gubka is offline
Send a message via ICQ to gubka
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 11-14-2015 , 11:08   Re: [CS:GO] Custom Viewmodel
Reply With Quote #48

May be this m_iWorldDroppedModelIndex?
__________________
gubka is offline
Send a message via ICQ to gubka
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 11-14-2015 , 23:42   Re: [CS:GO] Custom Viewmodel
Reply With Quote #49

This way

PHP Code:
new g_iWorldSMGModel//precached model index

public OnEntityCreated(entid){
    
decl String:szWpn[64];
    
GetEntityClassname(entidszWpnsizeof(szWpn));
    if(
StrEqual(szWpn"weapon_mac10")){
        
SDKHook(entidSDKHook_SpawnPostOnEntitySpawn);
    }
}
public 
OnEntitySpawn(entid){ 
    
    new 
WMid GetEntPropEnt(entidProp_Send"m_hWeaponWorldModel")
    
SetEntProp(WMidProp_Send"m_nModelIndex"g_iWorldSMGModel);

Return wodel if you will respawn player
__________________
gubka is offline
Send a message via ICQ to gubka
CareFully
Junior Member
Join Date: Oct 2015
Old 11-15-2015 , 06:38   Re: [CS:GO] Custom Viewmodel
Reply With Quote #50

Well, don't respawn the player then.
No. Actually just set the model on switchpost, if you need to respawn the player in the middle of a round.

In switchpost:
PHP Code:
    decl String:szWpn[64];
    
GetEntityClassname(entidszWpnsizeof(szWpn));
    if(
StrEqual(szWpn"weapon_mac10")){
        new 
WMid GetEntPropEnt(entidProp_Send"m_hWeaponWorldModel")
        
SetEntProp(WMidProp_Send"m_nModelIndex"g_iWorldSMGModel);
    } 
CareFully is offline
Reply



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 05:44.


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