AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Why return PLUGIN_HANDLED doesnt work :angry: ? (https://forums.alliedmods.net/showthread.php?t=280719)

axelnieves2012 03-23-2016 02:44

Why return PLUGIN_HANDLED doesnt work :angry: ?
 
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

Chihuahuax 03-23-2016 02:53

Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
 
Use hamsandwich's Ham_TakeDamage

Artifact 03-23-2016 04:22

Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
 
Quote:

Originally Posted by KliPPy (Post 2399017)
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.


Kowalsky 03-23-2016 05:23

Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
 
Spoiler


Just use ham_takedamage forward

fysiks 03-23-2016 23:00

Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
 
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.

axelnieves2012 03-26-2016 19:35

Re: Why return PLUGIN_HANDLED doesnt work :angry: ?
 
Thanks everyone. I could finish my plugin. I will post it soon


All times are GMT -4. The time now is 09:18.

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