Veteran Member
Join Date: Jan 2012
Location: Dublin
|

11-01-2015
, 10:13
Re: [CS:GO] Custom Viewmodel
|
#6
|
It still flippings on custom models, my way better
Quote:
public void ThinkOnThinkPost(int iPlayer)
{
if(!IsPlayerExist(iPlayer))
{
return;
}
if(gZombie[iPlayer])
{
// Check current weapon
char iWeapon[128];
int iItem = GetEntPropEnt(iPlayer, Prop_Send, "m_hActiveWeapon");
GetEdictClassname(iItem, iWeapon, sizeof(iWeapon));
// If weapon is a knife, then allow pickup.
if (StrEqual(iWeapon, "weapon_knife"))
{
int iButton = GetClientButtons(iPlayer);
// Prevent from flipping on CS:GO
if(iButton & IN_ATTACK || iButton & IN_ATTACK2)
SetEntPropFloat(iPlayer, Prop_Data, "m_flNextAttack", 0.0);
else
SetEntPropFloat(iPlayer, Prop_Data, "m_flNextAttack", 999.0);
// Show custom model
Weapon_SetViewModelIndex(iPlayer, "models/zombie/normal_f/hand/hand_zombie_normal_f.mdl");
}
}
}
/ Set ViewModel and check model index
void Weapon_SetViewModelIndex(int sClient, char[] pModel)
{
// Precache model , this is important
int sIndex = PrecacheModel(pModel);
if (sIndex < 1)
{
LogError("Unable to precache model '%s'", pModel);
return;
}
// Get index of model for changing it
pViewModelIndex[sClient] = Weapon_GetViewModelIndex(sClient, -1);
if (pViewModelIndex[sClient] < 1)
{
LogError("Unable to get a viewmodel index");
return;
}
// Create new vars
int iCurrentWeapon[MAXPLAYERS+1];
int iOldSequence[MAXPLAYERS+1];
float iOldCycle[MAXPLAYERS+1];
// Update some offsets
int iActiveWeapon = GetEntPropEnt(sClient, Prop_Send, "m_hActiveWeapon");
int iSequence = GetEntProp(pViewModelIndex[sClient], Prop_Send, "m_nSequence");
float iCycle = GetEntPropFloat(pViewModelIndex[sClient], Prop_Data, "m_flCycle");
// If valid entity , change view_model for client
if (IsValidEdict(iActiveWeapon))
{
if (iActiveWeapon != iCurrentWeapon[sClient])
{
if (iCurrentWeapon[sClient])
{
ShowViewModel(pViewModelIndex[sClient], false);
}
iCurrentWeapon[sClient] = 0;
ShowViewModel(pViewModelIndex[sClient], true);
SetEntProp(pViewModelIndex[sClient], Prop_Send, "m_nModelIndex", sIndex);
ChangeEdictState(pViewModelIndex[sClient], FindDataMapOffs(pViewModelIndex[sClient], "m_nModelIndex"));
iCurrentWeapon[sClient] = iActiveWeapon;
}
}
// If this is current weapon, check cycles and sequenses
if (iCurrentWeapon[sClient])
{
SetEntProp(pViewModelIndex[sClient], Prop_Send, "m_nSequence", GetEntProp(pViewModelIndex[sClient], Prop_Send, "m_nSequence"));
SetEntPropFloat(pViewModelIndex[sClient], Prop_Send, "m_flPlaybackRate", GetEntPropFloat(pViewModelIndex[sClient], Prop_Send, "m_flPlaybackRate"));
if ((iCycle < iOldCycle[sClient]) && (iSequence == iOldSequence[sClient]))
{
SetEntProp(pViewModelIndex[sClient], Prop_Send, "m_nSequence", 0);
}
}
// Update old sequences
iOldSequence[sClient] = iSequence;
iOldCycle[sClient] = iCycle;
}
// Check and change effect of weapon entity
void ShowViewModel(int iViewModel, bool bShow)
{
int iFlags = GetEntProp(iViewModel, Prop_Send, "m_fEffects");
SetEntProp(iViewModel, Prop_Send, "m_fEffects", bShow ? iFlags & ~EF_NODRAW : iFlags | EF_NODRAW);
}
// Get entity name
int FindEntityByClassname2(int sStartEnt, char[] szClassname)
{
while (sStartEnt > -1 && !IsValidEntity(sStartEnt)) sStartEnt--;
return FindEntityByClassname(sStartEnt, szClassname);
}
// Get model index and prevent server from crash
int Weapon_GetViewModelIndex(int sClient, int sIndex)
{
while ((sIndex = FindEntityByClassname2(sIndex, "predicted_viewmodel")) != -1)
{
int Owner = GetEntPropEnt(sIndex, Prop_Send, "m_hOwner");
int ClientWeapon = GetEntPropEnt(sClient, Prop_Send, "m_hActiveWeapon");
int Weapon = GetEntPropEnt(sIndex, Prop_Send, "m_hWeapon");
if (Owner != sClient)
continue;
if (ClientWeapon != Weapon)
continue;
return sIndex;
}
return -1;
}
|
__________________
|
|