View Single Post
Mandrew
Junior Member
Join Date: Nov 2018
Old 11-19-2018 , 16:48   Re: How to change npc models using sourcemod?
Reply With Quote #7

Quote:
Originally Posted by poachedegg View Post
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

//attention: not On Plugin Start!
public OnMapStart()
{
    
//first: If it is not a Official model, make sure your clients have this model. Or Add this model to download table.
    
AddFileToDownloadsTable("models/npc/combine_soldier.mdl");    //not only .mdl files. your clients should have all the .vtf .vmt .vvd ...... files. 
    
    //second: Precache this model.
    
PrecacheModel("models/npc/combine_soldier.mdl");
}

//third: set entity model when this entity spawn!
public void OnEntityCreated(entity, const String:classname[])
{
    
//Judge which entity is you need. Choose one of the following two.
    //1.if(entity == index)                     //index is the entity's index you want to change model
    //2.if ( StrEqual(classname, "classname"))    //change "classname" to the entity's classname which you want to change model
    
{
        
SDKHook(entitySDKHook_SpawnPostHook_EntitySpawned);
    }
}

public 
void Hook_EntitySpawned(entity)
{
    if(
IsValidEntity(entity))
    {
        
SetEntityModel(entity"models/npc/combine_soldier.mdl");
    }

sorry for my poor english.
My game crashed when trying to use that script.
Mandrew is offline