Monthly Target: $400 Donations: $269
 67% 

[SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction


Post New Thread Reply   
 
Thread Tools Display Modes
triohala
Junior Member
Join Date: Apr 2012
Old 04-05-2012 , 16:26   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #11

I created demo for you, and add it to rar with models included
http://www5.zippyshare.com/v/20169786/file.html
triohala is offline
Andersso
Member
Join Date: Nov 2009
Location: E8 2A 2A 2A 2A
Old 04-07-2012 , 07:49   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #12

Very nice find blodia!

I got this to work in DoD:S by creating a second viewmodel with CreateViewModel()!
Andersso is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 04-08-2012 , 08:40   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #13

Quote:
Originally Posted by blodia View Post
the code doesn't handle spectators, i did try it but it resulted in invisible world models when spectating in 3rd pesron so i left it.
Using the method that 'flickers' works fine from a spectators point of view. Maybe both methods could be used at once.
__________________
GoD-Tony is offline
Andersso
Member
Join Date: Nov 2009
Location: E8 2A 2A 2A 2A
Old 04-08-2012 , 13:46   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #14

Here is my version of the snippet. I made various improvements and support for DoD:S or any other game that only has one VM

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define EF_NODRAW 32

new g_iViewModels[MAXPLAYERS 1][2];

new 
Handle:g_hCreateViewModel;

new 
g_iOffset_Effects;

new 
g_iOffset_ViewModel;
new 
g_iOffset_ActiveWeapon;

new 
g_iOffset_Weapon;
new 
g_iOffset_Sequence;
new 
g_iOffset_ModelIndex;
new 
g_iOffset_PlaybackRate;

static const 
String:g_szCustomVM_ClassName[3][] =
{
    
"garand",
    
"k98",
    
"thompson"
};

static const 
String:g_szCustomVM_Model[3][] =
{
    
"models/weapons/v_pistol.mdl",
    
"models/weapons/v_357.mdl",
    
"models/weapons/v_smg1.mdl"
};

new 
g_iCustomVM_ModelIndex[3];

public 
OnPluginStart()
{
    new 
Handle:gameConf LoadGameConfigFile("plugin.viewmodel");

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

    
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_Effects        GetSendPropOffset("CBaseEntity""m_fEffects");
    
    
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_ModelIndex     GetSendPropOffset("CBaseViewModel""m_nModelIndex");
    
g_iOffset_PlaybackRate   GetSendPropOffset("CBaseViewModel""m_flPlaybackRate");
    
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

GetSendPropOffset(const String:serverClass[], const String:propName[])
{
    new 
offset FindSendPropOffs(serverClasspropName);

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

    return 
offset;
}

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

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

    
SDKHook(clientSDKHook_PostThinkOnClientThinkPost);
}

public 
OnClientThinkPost(client)
{
    static 
currentWeapon[MAXPLAYERS 1];
    
    new 
viewModel1 g_iViewModels[client][0];
    new 
viewModel2 g_iViewModels[client][1];
    
    if (!
IsPlayerAlive(client))
    {
        if (
viewModel2 != -1)
        {
            
// If the player is dead, hide the secondary viewmodel.
            
ShowViewModel(viewModel2false);
            
            
g_iViewModels[client][0] = -1;
            
g_iViewModels[client][1] = -1;
            
            
currentWeapon[client] = 0;
        }
        
        return;
    }
    
    new 
activeWeapon GetEntDataEnt2(clientg_iOffset_ActiveWeapon);
    
    
// Check if the player has switched weapon.
    
if (activeWeapon != currentWeapon[client])
    {
        
// Hide the secondary viewmodel, if necessary.
        
if (currentWeapon[client])
        {
            
ShowViewModel(viewModel2false);
        }
        
        
currentWeapon[client] = 0;
        
        
decl String:className[32];
        
GetEdictClassname(activeWeaponclassNamesizeof(className));
        
        if (
ReplaceString(classNamesizeof(className), "weapon_"NULL_STRING))
        {
            for (new 
03i++)
            {
                if (
StrEqual(classNameg_szCustomVM_ClassName[i]))
                {
                    
// Hide the primary viewmodel.
                    
ShowViewModel(viewModel1false);
                    
                    
// Show the secondary viewmodel.
                    
ShowViewModel(viewModel2true);
                    
                    
SetEntData(viewModel2g_iOffset_ModelIndexg_iCustomVM_ModelIndex[i], _true);
                    
SetEntData(viewModel2g_iOffset_WeaponGetEntData(viewModel1g_iOffset_Weapon), _true);
                    
                    
currentWeapon[client] = activeWeapon;
                    
                    break;
                }
            }
        }
    }
    
    if (
currentWeapon[client])
    {
        
SetEntData(viewModel2g_iOffset_SequenceGetEntData(viewModel1g_iOffset_Sequence), _true);
        
SetEntData(viewModel2g_iOffset_PlaybackRateGetEntData(viewModel1g_iOffset_PlaybackRate), _true);
    }
}

ShowViewModel(viewModelbool:show)
{
    new 
flags GetEntData(viewModelg_iOffset_Effects);
    
    
SetEntData(viewModelg_iOffset_Effectsshow flags & ~EF_NODRAW flags EF_NODRAW_true);
}

public 
Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBrodcast)
{
    new 
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);
    }
}

GetViewModel(clientindex)
{
    return 
GetEntDataEnt2(clientg_iOffset_ViewModel + (index 4));

Attached Files
File Type: txt plugin.viewmodel.txt (115 Bytes, 210 views)

Last edited by Andersso; 04-08-2012 at 13:49.
Andersso is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 04-08-2012 , 19:44   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #15

I made three scripts using this code, each changing one model but the three do not work together, but separately they work, how to fix this? would do everything in one script only? Thank you.

Thanks.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 04-08-2012 , 20:16   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #16

Extremely cool. Thanks!
KyleS is offline
andi67
Veteran Member
Join Date: Mar 2007
Location: Somewhere near you!!!
Old 04-09-2012 , 14:00   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #17

Just a quick test on DODS with custommodel(only replaced knife not hands)
http://youtu.be/rXk_k0eLjfw
__________________
andi67 is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 04-13-2012 , 16:54   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #18

i had a look at the issue triohala was having and it seems like there is a drawback with this method. if the same animation is played in succession before ending it isn't played at all, so if you knife the air the same slash animation is normally played over and over, with this method you will only play the slash animation the first time and then nothing until you hit something or switch back to play a different animation.
this could have been fixed with "m_flCycle" which stores how far along the animation is but it doesn't exist as a netprop for the viewmodel so the client isn't sent the updated data (for css anyway), i'm guessing this is where the prediction comes in.
when i have some free time i have a few ideas on how to bypass the issue i want to test.

Last edited by blodia; 04-13-2012 at 16:55.
blodia is offline
Andersso
Member
Join Date: Nov 2009
Location: E8 2A 2A 2A 2A
Old 04-19-2012 , 17:58   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #19

There are probably dirty ways to solve this, like switching to an other animation between each animation loop or have two of the same animation in the model and then switch between them
Andersso is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 04-21-2012 , 15:09   Re: [SNIPPET][CSS]custom viewmodels without flickers and without disabling prediction
Reply With Quote #20

i haven't had time to mess around with this yet but your first idea is one of the things i had in mind andersso. i was thinking of tracking "m_flCycle" so i can tell if the animation is being played from the start then tracking and checking "m_nSequence" to see if it has changed, if not then for 1 gameframe change the animation to the idle animation (0) then back, hopefully that should do it.
blodia is offline
Reply


Thread Tools
Display Modes

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 13:34.


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