Raised This Month: $ Target: $400
 0% 

Creating forwards


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 05-30-2006 , 18:01   Creating forwards
Reply With Quote #1

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
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 05-30-2006 , 18:35  
Reply With Quote #2

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
Orangutanz is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 05-30-2006 , 22:11  
Reply With Quote #3

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
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 05-30-2006 , 22:20  
Reply With Quote #4

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

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
Orangutanz is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 05-30-2006 , 22:30  
Reply With Quote #5

Thanks.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 05-30-2006 , 22:35  
Reply With Quote #6

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
Orangutanz is offline
BAILOPAN
Join Date: Jan 2004
Old 05-30-2006 , 22:56  
Reply With Quote #7

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.
__________________
egg
BAILOPAN 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 16:26.


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