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

Why return PLUGIN_HANDLED doesnt work :angry: ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 03-23-2016 , 02:44   Why return PLUGIN_HANDLED doesnt work :angry: ?
Reply With Quote #1

Hello, I noticed return PLUGIN_HANDLED doent work properly.
Part of my mod, sets custom damage for "almost invincible" property, but I am still getting same damage than always :angry: :angry: :angry: :angry: :angry: :angry: :angry: :angry: :angry:

Check this source out:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <engine_const>
#include <float>
#include <fun>
#include <cstrike>
#include <engine>

new PLUGINNAME[] = "blablalba"
new VERSION[] = "1.2.3.4"
new AUTHORS[] = "Axel Juan Nieves"

public plugin_init()
{
register_plugin(PLUGINNAMEVERSIONAUTHORS);
register_event"Damage""damage_event""b"
}

public 
damage_event(victim)
{
static 
damage
damage 
get_user_health(victim)-1
set_user_health
(victimdamage)
return 
PLUGIN_HANDLED
}
/* rest of plugin ... */ 
This plugins should rest 1 from victim's health, each time he is hit (no matter what weapon is used)

I even tested this, to nobody gets hurt, but it doesnt work either :megaangry:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <engine_const>
#include <float>
#include <fun>
#include <cstrike>
#include <engine>

new PLUGINNAME[] = "blablalba"
new VERSION[] = "1.2.3.4"
new AUTHORS[] = "Axel Juan Nieves"

public plugin_init()
{
register_plugin(PLUGINNAMEVERSIONAUTHORS);
register_event"Damage""damage_event""b"
}

public 
damage_event(victim)
{
return 
PLUGIN_HANDLED
}
/* rest of plugin ... */ 
Can anyone tell me why? I know set_pev(blablaabla, take_damage, 0.0) makes player godmode. But it doesnt work if you want custom damage (top example) because "damage_event()" is never called because victim's godmode.

Thanks in advance
axelnieves2012 is offline
Chihuahuax
Senior Member
Join Date: Oct 2014
Location: Malaysia
Old 03-23-2016 , 02:53   Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
Reply With Quote #2

Use hamsandwich's Ham_TakeDamage
Chihuahuax is offline
Send a message via Skype™ to Chihuahuax
Artifact
Veteran Member
Join Date: Jul 2010
Old 03-23-2016 , 04:22   Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
PLUGIN_* return values are used for general plugin callbacks, like command callbacks. Engine forwards use them too.
HAM_* return values are used for hamsandwich forwards. Here is what ham_const.inc says about them:
Code:
#define HAM_IGNORED		1	/**< Calls target function, returns normal value */
#define HAM_HANDLED		2	/**< Tells the module you did something, still calls target function and returns normal value */
#define HAM_OVERRIDE	3	/**< Still calls the target function, but returns whatever is set with SetHamReturn*() */
#define HAM_SUPERCEDE	4	/**< Block the target call, and use your return value (if applicable) (Set with SetHamReturn*()) */
SUPERCEDE has nothing to do with something being "super", it's a single word.

There are also these return values from fakemeta_const.inc, used for controlling fakemeta forwards:
Code:
#define FMRES_IGNORED	1	// Calls target function, returns normal value
#define FMRES_HANDLED	2	// Tells metamod you did something, still calls target function and returns normal value
#define FMRES_OVERRIDE	3	// Supposed to still call the target function but return your value instead
							// however this does not work properly with metamod; use supercede instead.
#define FMRES_SUPERCEDE	4	// Block the target call, and use your return value (if applicable)
Pretty much the same as Ham's.
__________________
Artifact is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 03-23-2016 , 05:23   Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
Reply With Quote #4

Spoiler


Just use ham_takedamage forward
Kowalsky is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-23-2016 , 23:00   Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
Reply With Quote #5

When you register an "event", the event has already happened so you can't change it, you can only react to it. You have to hook Ham_TakeDamage as a prehook so that you can catch the event before the event even happens. Only then can you actually do anything to change the circumstances of the event itself.
__________________
fysiks is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 03-26-2016 , 19:35   Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
Reply With Quote #6

Thanks everyone. I could finish my plugin. I will post it soon
axelnieves2012 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 00:40.


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