AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=58)
-   -   How to change npc models using sourcemod? (https://forums.alliedmods.net/showthread.php?t=312129)

Mandrew 11-17-2018 10:55

How to change npc models using sourcemod?
 
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.

Mrs cheng 11-17-2018 19:18

Re: How to change npc models using sourcemod?
 
native SetEntityModel(entity, const String:model[]);

Mandrew 11-17-2018 21:26

Re: How to change npc models using sourcemod?
 
Quote:

Originally Posted by Mrs cheng (Post 2624524)
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]);
}

Mrs cheng 11-17-2018 22:35

Re: How to change npc models using sourcemod?
 
I suggest that you systematically go to the wiki website to learn the language.(https://wiki.alliedmods.net/Category...eMod_Scripting)

Franc1sco 11-18-2018 16:44

Re: How to change npc models using sourcemod?
 
What npcs from what game?

poachedegg 11-18-2018 21:28

Re: How to change npc models using sourcemod?
 
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.

Mandrew 11-19-2018 16:48

Re: How to change npc models using sourcemod?
 
Quote:

Originally Posted by poachedegg (Post 2624681)
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.

poachedegg 11-19-2018 22:16

Re: How to change npc models using sourcemod?
 
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.

poachedegg 11-19-2018 22:22

Re: How to change npc models using sourcemod?
 
1 Attachment(s)
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.


All times are GMT -4. The time now is 22:52.

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