Raised This Month: $ Target: $400
 0% 

RegisterHamFromEntity sends incorrectly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-15-2009 , 04:01   RegisterHamFromEntity sends incorrectly
Reply With Quote #1

I have two plugins that use two different custom entities to think.

In the first code:
Code:
	new ent = fm_create_entity("info_target");
	set_pev(ent, pev_classname, "PPloop");
	RegisterHamFromEntity(Ham_Think, ent, "PartyLoop", 1);
	set_pev(ent, pev_nextthink, get_gametime()+1.0);
Second code:
Code:
		if( !pev_valid(hill) )
			hill = fm_create_entity("info_target");
		set_pev(hill, pev_classname, "PPHill");
		set_pev(hill, pev_iuser1, HILL_TIME);

		if( HamThink == HamHook:-1 )
			HamThink = RegisterHamFromEntity(Ham_Think, hill, "HillThink", 1);
		else
			EnableHamForward( HamThink );

		set_pev(hill, pev_nextthink, get_gametime()+1.0);
However, the second HamThink is being passed the entity from the first HamThink.
Code:
public HillThink( ent )
{
	if( ent != hill ){
		new name[32];
		pev(ent, pev_classname, name, 31);
		client_print(0, print_chat, "%d is a hill apparently. class %s", ent, name );
		return;
	}
	//...
}
It prints: 82 is a hill apparently. class PPloop

Obviously I can do a classname check to get around this problem, but IMO it should not be doing this.

Have I misinterpreted RegisterHamFromEntity, after changing the classname do I need a delay before RegisterHamFromEntity, or is it just whacky?
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 05-15-2009 , 05:15   Re: RegisterHamFromEntity sends incorrectly
Reply With Quote #2

RegisterHamFromEntity checks the entitys classname and registeres a hook for all entitys whith the same classname. if your classname was a info_target, it will register a hook for info_target even though you might have changed the classname.
all you have to do is a single Ham_Think hook for info_targets and check which costum entities id matches the send one of Ham_Think
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-15-2009 , 09:42   Re: RegisterHamFromEntity sends incorrectly
Reply With Quote #3

Quote:
Originally Posted by SchlumPF* View Post
if your classname was a info_target, it will register a hook for info_target even though you might have changed the classname.
That doesn't seem to make sense. RegisterHamFromEntity is supposed to be used on none default entities, why would I want to use it on "info_target" (I thought that was a default entity)

Quote:
Originally Posted by SchlumPF* View Post
all you have to do is a single Ham_Think hook for info_targets and check which costum entities id matches the send one of Ham_Think
I'd rather not...
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 05-15-2009 , 11:08   Re: RegisterHamFromEntity sends incorrectly
Reply With Quote #4

From hamsandwich.inc:
PHP Code:
/**
 * Hooks the virtual table for the specified entity's class.
 * An example would be: RegisterHam(Ham_TakeDamage, id, "player_hurt");
 * Look at the Ham enum for parameter lists.
 * Note: This will cause hooks for the entire internal class that the entity is
 *       not exclusively for the provided entity.
 *
 * @param function        The function to hook.
 * @param EntityId        The entity classname to hook.
 * @param callback        The forward to call.
 * @param post            Whether or not to forward this in post.
 * @return                 Returns a handle to the forward.  Use EnableHamForward/DisableHamForward to toggle the forward on or off.
 */
native HamHook:RegisterHamFromEntity(Ham:function, EntityId, const Callback[], Post=0); 
So, it does make more sense to use RegisterHam() if you already know your entities classname.
hlstriker is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-15-2009 , 11:15   Re: RegisterHamFromEntity sends incorrectly
Reply With Quote #5

RegisterHam() accepts only default entities as classname. I would use register_think(), it rocks. ^^
Arkshine is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-15-2009 , 15:44   Re: RegisterHamFromEntity sends incorrectly
Reply With Quote #6

Quote:
Originally Posted by arkshine View Post
I would use register_think(), it rocks. ^^
Ya... but I want to be able to disable it.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-15-2009 , 16:36   Re: RegisterHamFromEntity sends incorrectly
Reply With Quote #7

What about to change the classname when you want to disable it. Like "_PPloop" and the function will not called ?
Arkshine 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 01:30.


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