Raised This Month: $51 Target: $400
 12% 

How to change npc models using sourcemod?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mandrew
Junior Member
Join Date: Nov 2018
Old 11-17-2018 , 10:55   How to change npc models using sourcemod?
Reply With Quote #1

Hello, I was wondering if there is a way to change npc models using sourcemod, if so could you give me the lines of code or a guide on how to do it?

Sorry I am a noob at coding on sourcemod and this is my first thread.
Mandrew is offline
Mrs cheng
Member
Join Date: Mar 2017
Old 11-17-2018 , 19:18   Re: How to change npc models using sourcemod?
Reply With Quote #2

native SetEntityModel(entity, const String:model[]);
Mrs cheng is offline
Mandrew
Junior Member
Join Date: Nov 2018
Old 11-17-2018 , 21:26   Re: How to change npc models using sourcemod?
Reply With Quote #3

Quote:
Originally Posted by Mrs cheng View Post
native SetEntityModel(entity, const String:model[]);
Well I am using pawn studio, is this the correct usage? Because I am getting errors when trying to compile:

public OnPluginStart()
{
native SetEntityModel(npc_combine_s, const String:model[models/npc/combine_soldier.mdl]);
}

Last edited by Mandrew; 11-17-2018 at 22:05.
Mandrew is offline
Mrs cheng
Member
Join Date: Mar 2017
Old 11-17-2018 , 22:35   Re: How to change npc models using sourcemod?
Reply With Quote #4

I suggest that you systematically go to the wiki website to learn the language.(https://wiki.alliedmods.net/Category...eMod_Scripting)

Last edited by Mrs cheng; 11-17-2018 at 22:44.
Mrs cheng is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 11-18-2018 , 16:44   Re: How to change npc models using sourcemod?
Reply With Quote #5

What npcs from what game?
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.

Franc1sco is offline
Send a message via MSN to Franc1sco
poachedegg
Junior Member
Join Date: Nov 2018
Location: China
Old 11-18-2018 , 21:28   Re: How to change npc models using sourcemod?
Reply With Quote #6

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.

Last edited by poachedegg; 11-18-2018 at 21:32.
poachedegg is offline
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
poachedegg
Junior Member
Join Date: Nov 2018
Location: China
Old 11-19-2018 , 22:16   Re: How to change npc models using sourcemod?
Reply With Quote #8

PHP Code:
    //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 
Because it is not a complete code, I'm just explaining the usage.
You should choose one way to remove the "//". not remove "//" mean's change all the entity's model.
If you choose 1 mean only change one entity, index is the entity's index.If you choose 2 mean change a type of entity, "classname" is this entity's name. And you should change the index or "classname" by actual situation.
Because I don't know which entity you want to change. I don't even know which game you want to use.

Last edited by poachedegg; 11-20-2018 at 00:38.
poachedegg is offline
poachedegg
Junior Member
Join Date: Nov 2018
Location: China
Old 11-19-2018 , 22:22   Re: How to change npc models using sourcemod?
Reply With Quote #9

For example:
make sure npc_combine_s is a valid entity classname which you want to set model.
PHP Code:
#include <sourcemod> 
#include <sdktools> 
#include <sdkhooks> 

public OnMapStart() 

    
PrecacheModel("models/npc/combine_soldier.mdl"); 


public 
void OnEntityCreated(entity, const String:classname[]) 


    if ( 
StrEqual(classname"npc_combine_s") ) 
    { 
        
SDKHook(entitySDKHook_SpawnPostHook_EntitySpawned); 
    } 


public 
void Hook_EntitySpawned(entity

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

And If you don't know the entity's classname and even don't know how to get it. Use this plugin. Aim at this entity and the classname will print to center.
Attached Files
File Type: sp Get Plugin or Get Source (aim_to_get_classname.sp - 422 views - 598 Bytes)

Last edited by poachedegg; 11-20-2018 at 00:31.
poachedegg 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 07:37.


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