View Single Post
Epal
Junior Member
Join Date: Feb 2016
Old 07-08-2016 , 15:44   Re: [CS:GO] Custom Viewmodel
Reply With Quote #63

how add
[code]
new g_iWorldSMGModel; //precached model index

public OnEntityCreated(entid){
decl String:szWpn[64];
GetEntityClassname(entid, szWpn, sizeof(szWpn));
if(StrEqual(szWpn, "weapon_mac10")){
SDKHook(entid, SDKHook_SpawnPost, OnEntitySpawn);
}
}
public OnEntitySpawn(entid){

new WMid = GetEntPropEnt(entid, Prop_Send, "m_hWeaponWorldModel")
SetEntProp(WMid, Prop_Send, "m_nModelIndex", g_iWorldSMGModel);
}
/[code]

for this
[code]
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

#define MODEL "models/weapons/epal.mdl" // custom view model

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/epal_.mdl"); // Custom model
}

public OnClientPostAdminCheck(client){
SDKHook(client, SDKHook_WeaponSwitchPost, OnClientWeaponSwitchPost);
}

public OnClientWeaponSwitchPost(client, wpnid)
{

decl String:szWpn[64];
GetEntityClassname(wpnid,szWpn,sizeof(szWpn)) ;

if(StrEqual(szWpn, "weapon_galilar")){
SetEntProp(wpnid, Prop_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(client, sIndex)
{
while ((sIndex = FindEntityByClassname2(sIndex, "predicted_viewmodel")) != -1)
{
new Owner = GetEntPropEnt(sIndex, Prop_Send, "m_hOwner");

if (Owner != client)
continue;

return sIndex;
}
return -1;
}
// Get entity name
FindEntityByClassname2(sStartEnt, String:szClassname[])
{
while (sStartEnt > -1 && !IsValidEntity(sStartEnt)) sStartEnt--;
return FindEntityByClassname(sStartEnt, szClassname);
}

public OnMapStart()
{
g_iSMGModel = PrecacheModel(MODEL); // Custom model

// model downloads

}
/[code]
Epal is offline