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

entity hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 08-12-2020 , 21:44   entity hook
Reply With Quote #1

is there a correct way to hook an entity?

would like to know how to properly hook an entity so i could replace the model of the target to a custom one
__________________
Teamkiller324 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-12-2020 , 22:02   Re: entity hook
Reply With Quote #2

use this https://sm.alliedmods.net/new-api/sd...nEntityCreated
__________________
8guawong is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 08-12-2020 , 23:03   Re: entity hook
Reply With Quote #3

i may be doing this wrong altough

Code:
public void OnEntityCreated(int entity, const char[] classname)
{
	char model[PLATFORM_MAX_PATH];
	int ent = -1;
	while((ent = FindEntityByClassname(ent, "item_healthkit_small")) != -1)
	{
		GetEntPropString(ent, Prop_Data, "m_ModelName", model, sizeof(model));
		if(StrEqual(model, "item_healthkit_small"))
		{
			SetEntityModel(ent, "models/items/zelda/medkit_small.mdl");
		}
	}
}
Spams CBaseEntity no brush model errors :/
__________________
Teamkiller324 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-12-2020 , 23:19   Re: entity hook
Reply With Quote #4

Quote:
Originally Posted by Teamkiller324 View Post
i may be doing this wrong altough

Code:
public void OnEntityCreated(int entity, const char[] classname)
{
	char model[PLATFORM_MAX_PATH];
	int ent = -1;
	while((ent = FindEntityByClassname(ent, "item_healthkit_small")) != -1)
	{
		GetEntPropString(ent, Prop_Data, "m_ModelName", model, sizeof(model));
		if(StrEqual(model, "item_healthkit_small"))
		{
			SetEntityModel(ent, "models/items/zelda/medkit_small.mdl");
		}
	}
}
Spams CBaseEntity no brush model errors :/
does it spam this error if you use other model?

and you don't need to use a while loop in OnEntityCreated
__________________
8guawong is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 08-12-2020 , 23:22   Re: entity hook
Reply With Quote #5

should there be a better way to force the entity to use a model?

i'm bad at this part
__________________
Teamkiller324 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-12-2020 , 23:33   Re: entity hook
Reply With Quote #6

Quote:
Originally Posted by Teamkiller324 View Post
should there be a better way to force the entity to use a model?

i'm bad at this part
old syntax

try the following snippet

PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if (
StrEqual(classname"item_healthkit_small"))
    {
        new 
String:model[PLATFORM_MAX_PATH];
        
GetEntPropString(entityProp_Data"m_ModelName"modelsizeof(model));
        if(
StrEqual(model"item_healthkit_small"))
            
SDKHook(entitySDKHook_SpawnPostHealthKit);
    }
}

public 
HealthKit(entity)
{
    
SetEntityModel(entity"models/items/zelda/medkit_small.mdl");

__________________
8guawong is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 08-12-2020 , 23:45   Re: entity hook
Reply With Quote #7

Does not seem to replace the model at all

not a single error altough
__________________

Last edited by Teamkiller324; 08-12-2020 at 23:45.
Teamkiller324 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-12-2020 , 23:56   Re: entity hook
Reply With Quote #8

Quote:
Originally Posted by Teamkiller324 View Post
Does not seem to replace the model at all

not a single error altough
add a debug message after
PHP Code:
GetEntPropString(entityProp_Data"m_ModelName"modelsizeof(model)); 
and see what it says
__________________

Last edited by 8guawong; 08-12-2020 at 23:56.
8guawong is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 08-13-2020 , 00:05   Re: entity hook
Reply With Quote #9

i use this atm
Code:
public void OnEntityCreated(int entity, const char[] classname)
{
	if(StrEqual(classname, "item_healthkit_small"))
	{
		PrintToServer("Debug: Checking if item_healthkit_small..");
		char model[PLATFORM_MAX_PATH];
		GetEntPropString(entity, Prop_Data, "m_ModelName", model, sizeof(model));
		PrintToServer("Debug: Getting model name..");
		PrintToServer("Debug: Model name returned: %s", model);
		if(StrEqual(model, "item_healthkit_small"))
		{
			SDKHook(entity, SDKHook_SpawnPost, HealthKit);
			PrintToServer("Debug: Loading SDKHook_SpawnPost");
		}
	}
}

public void HealthKit(int entity)
{
	SetEntityModel(entity, "models/items/zelda/medkit_small.mdl");
	PrintToServer("Debug: Set entity model to %s", entity);
}
Console:

Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
__________________
Teamkiller324 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-13-2020 , 00:16   Re: entity hook
Reply With Quote #10

Quote:
Originally Posted by Teamkiller324 View Post
i use this atm
Code:
public void OnEntityCreated(int entity, const char[] classname)
{
	if(StrEqual(classname, "item_healthkit_small"))
	{
		PrintToServer("Debug: Checking if item_healthkit_small..");
		char model[PLATFORM_MAX_PATH];
		GetEntPropString(entity, Prop_Data, "m_ModelName", model, sizeof(model));
		PrintToServer("Debug: Getting model name..");
		PrintToServer("Debug: Model name returned: %s", model);
		if(StrEqual(model, "item_healthkit_small"))
		{
			SDKHook(entity, SDKHook_SpawnPost, HealthKit);
			PrintToServer("Debug: Loading SDKHook_SpawnPost");
		}
	}
}

public void HealthKit(int entity)
{
	SetEntityModel(entity, "models/items/zelda/medkit_small.mdl");
	PrintToServer("Debug: Set entity model to %s", entity);
}
Console:

Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
Debug: Checking if item_healthkit_small..
Debug: Getting model name..
Debug: Model name returned:
PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if (
StrEqual(classname"item_healthkit_small"))
        
SDKHook(entitySDKHook_SpawnPostHealthKit);
}

public 
HealthKit(entity)
{
        new 
String:model[PLATFORM_MAX_PATH];
        
GetEntPropString(entityProp_Data"m_ModelName"modelsizeof(model));
        if(
StrEqual(model"item_healthkit_small"))
            
SetEntityModel(entity"models/items/zelda/medkit_small.mdl");

__________________
8guawong 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 20:14.


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