AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Creating forwards (https://forums.alliedmods.net/showthread.php?t=29148)

Cheap_Suit 05-30-2006 18:01

Creating forwards
 
I need some info on this function.

Questions:
1. need info on the parameters
2. I want to create a forward that hooks to an event in a plugin (eg. DeathMsg) (example??)
3. According to question 3 (if possible) would it cost less resources?

Code:
/**  * creates a multi-plugin forward.  * results will be > 0 for success  */ native CreateMultiForward(const name[], stop_type, ...);

Code:
#define ET_IGNORE       0   //ignore return val #define ET_STOP         1   //stop on PLUGIN_HANDLED #define ET_STOP2        2   //same, except return biggest #define ET_CONTINUE     3   //no stop, return biggest #define FP_CELL         0 #define FP_FLOAT        1 #define FP_STRING       2 #define FP_ARRAY        4

Orangutanz 05-30-2006 18:35

Code:
#include <amxmodx> new PLUGIN[]="Forward Test" new VERSION[]="0.1" new AUTHOR[]="Orangutanz" new player_died new player_died_ret public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("DeathMsg", "DeathMsg_event", "a")     player_died = CreateMultiForward("player_died", ET_IGNORE, FP_CELL) } public DeathMsg_event() {     new id = read_data(2)     ExecuteForward(player_died, player_died_ret, id) }
As for is it more resourceful its debatable, since it depends what you are doing. A simple forward like this seems pretty pointless, but its a good example to see how it works. If you was hooking DeathMsg and was carrying out vasts checking etc and returning more than just the ID then yes its more resourceful.

How to add on the killer:
Code:
player_died = CreateMultiForward("player_died", ET_IGNORE, FP_CELL, FP_CELL) public DeathMsg_event() {     new killer = read_data(1)     new id = read_data(2)     new ret     ExecuteForward(player_died, player_died_ret, id, killer) }


Regards,

Orange Monkey

Cheap_Suit 05-30-2006 22:11

I was planning to also do this in FM_PlayerPreThink in one plugin and use the forward in the other plugins. Would it cost more resources by doing this?

Code:
#include <amxmodx> #include <fakemeta> new forward_PlayerPreThink, temp public plugin_init() {     register_forward(FM_PlayerPreThink , "fw_PlayerPreThink")     forward_PlayerPreThink = CreateMultiForward("user_prethink", ET_IGNORE, FP_CELL)     } public fw_PlayerPreThink(id) {     ExecuteForward(forward_PlayerPreThink, temp, id)     return FMRES_IGNORED }

Info on the returns? When to use them and such.

Code:
#define ET_IGNORE        0    //ignore return val #define ET_STOP            1    //stop on PLUGIN_HANDLED #define ET_STOP2        2    //same, except return biggest #define ET_CONTINUE        3    //no stop, return biggest

Orangutanz 05-30-2006 22:20

It should be fine, I actually register one in StartFrame and you know how fast that executes 8)

Those return types are what the plugins return. So temp should = one of those values, so you can decided to do a different action after the forward is executed.

So I dunno for example you could be killing clients after your forward but if a plugin returns STOP then you'll ignore that section of the script that kills the client. I think thats how it works :?

Cheap_Suit 05-30-2006 22:30

Thanks.

Orangutanz 05-30-2006 22:35

So if you registered you forward with ET_CONTINUE, you could make up a nice switch statement and get different returns to activate different actions :lol:

BAILOPAN 05-30-2006 22:56

It should be noted that executing a forward with ExecuteForward() is just as fast as how a module would do it (it is the same function).

callfunc_ has the same speed, but it's a bit cruftier to use.


All times are GMT -4. The time now is 16:26.

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