Raised This Month: $32 Target: $400
 8% 

Ham_TakeDamage on custom entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-06-2012 , 06:36   Ham_TakeDamage on custom entities
Reply With Quote #1

Okay, I've asked a similar question to this before, which didn't get a successful answer. I did find another way around this issue, which I'll get to later.

Quote:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new myStr;
public 
plugin_init()
{
  
myStr engfuncEngFunc_AllocString"info_target" );

  
register_clcmd"make_entity""cmdMakeEntity" );

  
RegisterHam(Ham_TakeDamage"damageHook""MyEntityClass"); // Error!
}
public 
cmdMakeEntityid )
{
  new 
ent engfuncEngFunc_CreateEntitymyStr );
  
set_peventpev_classname"MyEntityClass" );
  
// ...

That will not work, because the class "MyEntityClass" is not native to the gamedll. Instead, you would need to hook TakeDamage for "info_target", and do some form of parsing on the entities that get passed to it (such as checking classname), if you want to deal with custom entity hooking.
Article found here: http://wiki.amxmodx.org/HamSandwich_...age_(AMX_Mod_X)

Obviously you can't directly hook damage to a custom class name because it will error straight away. However, this certain piece says that entity damage can be hooked by hooking damage on "info_target". I've tried the example code and editted it to hook to "info_target", but as soon as the entity is created it errors saying "invalid entity <#>" . That's because the second argument is supposed to be a string right? Or is it that this particular idea won't work altogether?
So I removed that whole part where you assign a global variable. With the basic hook to info_target ( and I removed the part in my code where I assign the entity a class name ), the hook still appears to be failing.

Since there is going to be only one weapon type used to fire at these custom entities, I know that I can use Ham_Weapon_PrimaryAttack and then get_user_aiming() to find the entity. But I figured that if I wanted to use all weapons ( then having to register them all ), then there might be a more efficient way through using Ham_TakeDamage.

Any ideas?

Thanks.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 05-06-2012 at 06:37.
hornet is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-06-2012 , 08:15   Re: Ham_TakeDamage on custom entities
Reply With Quote #2

You have to Register hook with "info_target" classname, or whatever class you used in create_entity.
Then, when callback is fired, check your custom classname, or find another way to figure out if it is your custom entity or not, if you only have 1 entity for example, store the index into a global variable.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-06-2012 , 13:05   Re: Ham_TakeDamage on custom entities
Reply With Quote #3

RegisterHam ( Ham:function, const EntityClass[], const Callback[], Post=0 )

edit: you have the second and third arguments switched.

Last edited by Emp`; 05-06-2012 at 13:53.
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`
DarkGL
Senior Member
Join Date: Aug 2010
Location: Warsaw, Poland
Old 05-06-2012 , 13:44   Re: Ham_TakeDamage on custom entities
Reply With Quote #4

Use http://www.amxmodx.org/funcwiki.php?go=func&id=1181
__________________
DarkGL is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-07-2012 , 06:28   Re: Ham_TakeDamage on custom entities
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
You have to Register hook with "info_target" classname, or whatever class you used in create_entity.
Then, when callback is fired, check your custom classname, or find another way to figure out if it is your custom entity or not, if you only have 1 entity for example, store the index into a global variable.
It seems to be failing, the callback isn't being called.

Quote:
Originally Posted by Emp` View Post
RegisterHam ( Ham:function, const EntityClass[], const Callback[], Post=0 )

edit: you have the second and third arguments switched.
Well not me as such - the code snippet is quoted from the article I linked to in my first post. I noticed this aswell although I forgot to mention that I didn't use that. However, if I did, I would have gotten an error on plugin_init() instead of when the entity was created ;)

Quote:
Originally Posted by DarkGL View Post
That's interesting. I've never seen that before. Looks like it could work ... I'll give it a shot.

Thanks.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet 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 08:43.


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